[Tutorial] Simple Camo system
#1

Introductions
Hello. Today I will be teaching you how to make simplest camouflage system.
Things that you will need for this tutorial are ZCMD include and some basic scripting experience.
This code will enable you to use "camo system" which works on this method.
Player will be set to random world for 10 seconds so no one can see him, after it experies he will be set to world 0 again.


Scripting
Step 1
[Includes]
First you will need to include ZCMD include that you can download from the SA:MP forums. We are using ZCMD for this but you can replace it with any command processor.
So put this at the very top of your script. Like below your include for the SA:MP (default one)

pawn Code:
#include <zcmd>

Step 2
[Variables, defines...]
Now we will define some basics.
First thing we will define are the colors needed.
Somewhere at the top of your script add this.
pawn Code:
#define COLOR_RED 0xAA3333AA
#define COLOR_GREEN 0x33AA33AA
And somewhere below it add these things.
pawn Code:
new UsingCamo; //When the player is using camo
new OnCamoCooldown;//When the player is on the camo cooldown
UsingCamo is our way to set the player & check if he is using camouflage and we will use OnCamoCooldown to check & set player when he is on the cooldown.
We will also use stock that will define our randoms. Place it anywhere outside any function in your script.
pawn Code:
stock randomEx(minnum = cellmin, maxnum = cellmax) return random(maxnum - minnum + 1) + minnum;




Step 3
[Command]
Now we will add the command itself. Look at the comments so you understand what is what
pawn Code:
CMD:camo(playerid, params[])
{
        if(UsingCamo == 0) //Checking if the player is using camo. 0 = Not using, 1 = Using
        {
            if(OnCamoCooldown == 0) //Checking if the player is on the camo cooldown. 0 = not using, 1 using
            {
                new Vw = randomEx(1,5); //We are setting players world to random (from 1 to 5) so people that are also using camo wont see each other. You can change this 1,5 to anything you want)
                SetPlayerVirtualWorld(playerid, Vw); //The player is now entering the camo. We are setting his virtual world to the random defined above it
                SetTimerEx("CamoTimer", 10000, false, "i", playerid); //We are making 10 seconds camo usage. When these 10 seconds expire player will be tossed out from the camo.
                SetTimerEx("CamoCooldown", 90000, false, "i", playerid); //We are also setting the players cooldown to 90.000 miliseconds which are 90 seconds, aka 3 minutes, you can also change this.
                UsingCamo = 1; //We are setting that the player is currently using the camouflage
                        OnCamoCooldown = 1; //setting the player onto the cooldown.
            }
            else
            {
                SendClientMessage(playerid, COLOR_RED, "<!>You are on a cooldown!"); //If the player is on the cooldown this will send him the message that he is and he wont be able to use the command.
            }
        }
        else
        {
            SendClientMessage(playerid, COLOR_RED, "<!>You are currently using it already!"); //If the player is trying to enter camo and they are already using it
        }
        return 1;
}

Step 4
[Forwards]
Add these two forwards anywhere in your script. Outside any function. We are forwarding our timers.
pawn Code:
forward CamoCooldown(playerid);
forward CamoTimer(playerid);

Step 5
[Timers]
Now we will get into the main thing with this. We will be looking into the what will happen when the timers elapse. Look at the comments for the full explanation.
Add these ANYWHERE in your script, outside any function.
pawn Code:
public CamoCooldown(playerid) //This defines our Camo Cooldown timer, and now we will add what will happen when it ends.
{
    SendClientMessage(playerid, COLOR_GREEN, "<!>Your camo timer has expired. You can now use it again!");//We are sending player message that tells him that they are no longer on the cooldown.
    OnCamoCooldown = 0; //We are setting the variable to 0 so the player can use the command again.
    return 1;
}

public CamoTimer(playerid) //This is what will happen to the player when the Camo expires.
{
    SetPlayerVirtualWorld(playerid, 0); //We are returning player to the normal world. World 0, so he can play with others normaly.
    UsingCamo = 0; //We are setting this variable to 0 so the player is no longer in the camouflage.
    SendClientMessage(playerid, COLOR_GREEN, "<!>Your camo has expired!"); //Sending a simple message saying that they are no longer using the camo.
    return 1;
}



Credits
Zeex [ZCMD]
Y_Less [RandomEx]



How should it look like
Check the link below to see how should it look like as a finished code
http://paste2.org/4YzVLt86
Reply
#2

Well i wouldn't call it cammo, because the player that has camo enabled won't be able to see other player either...So it's kind of pointless....

Tutorial istself is written well
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)