[Tutorial] How to make a simple rob player system, with progressbar.
#1

Hi boyz, today i want explain to you how to do this simple rob player system, in a little time. First we need the following includes:
pawn Код:
#include <zcmd>
#include <sscanf2>
#include <progress>
You can find this includes just looking in the sa-mp.com forum.

Well, now we need to declare an enum that contains the informations of each player, so write it above the callback GameModeInit()

pawn Код:
enum playerinfo
{
    money
        score
}

new pinfo[MAX_PLAYERS][playerinfo]; // with this variable we save the informations of all players contained in the enum playerinfo..
Now we must define a global variables that will contain the ID of player that was robbed, the progressbars, one for player that was robbed and another for a player that rob, the counts that will raise first and second progressbar, and the IDs for a kill timers that start when someone type a command for rob.

pawn Код:
new rID;
new PlayerBar:progressrob;
new PlayerBar:progressrob2;
new Float:progresscount;
new Float:progresscount2;
new robtimerprogress;
new robtimerprogress2;
Alrights?
Well we can move on to the next part, where we must define a function that allow us to rob a player.

pawn Код:
forward robplayer();
public robplayer()
{
        new Float:rx, Float:ry, Float:rz; //Define a new Float: variables for get in the position of player that will be robbed
        GetPlayerPos(rID,rx,ry,rz); //Get in variables above the coords of player that will be robbed
        if(IsPlayerInRangeOfPoint(playerid,2.5,rx,ry,rz)) //if player that want rob is near at position of player that will be robbed.
        {
            pinfo[rID][soldi] = GetPlayerMoney(rID); //Get the money of player that will be robbed in a pinfo, variable
            GivePlayerMoney(rID,-(pinfo[rID][money]/3)); //This function removes the player's money with a mathematical operation that divides the player's money for 3 and then subtracts the result for player's money.
            GivePlayerMoney(playerid,pinfo[rID][money]/3);//Same operation but now the result is incremented with money of player that rob.
            new string[128]; //a new string variable
            format(string,128,"[SERVER] You have robbed at player: $%i and ricive +3 Score Points",pinfo[rID][soldi]/3);//Self explanatory..
            SendClientMessage(playerid,-1,string);//Self explanatory..
            SendClientMessage(rID,-1,"[SERVER]Someone rob your money");//return a message to player that was been robbed.
            pinfo[rID][money] = GetPlayerMoney(rID);//Get the current money in variable pinfo that regards the player that was robbed, so if we have this in a /stats command it will be updated foreach time that this system will done.
            pinfo[playerid][money] = GetPlayerMoney(playerid); //same...
            pinfo[rID][score] = pinfo[rID][score] - 3; // With mathematical operation we set the variable that regards the score of the player that was robbed -3..
            pinfo[playerid][score] = pinfo[playerid][score] + 3; //same but here we add +3 at the variable that regards the score of player that rob.
            SetPlayerScore(rID,GetPlayerScore(rID)-3); //here we set the real score game -3 to the player that was robbed..
            SetPlayerScore(playerid,GetPlayerScore(playerid)+3);//and here add +3 score to player that rob.
           
        }
        else //if the player isn't in range of point of the player that will be robbed..
        {
            SendClientMessage(playerid,-1,"[SERVER]You have failed to rob the player.");//send a message to playe that want rob
            SendClientMessage(rID,-1,"[SERVER]Someone have failed to rob you.");//send a message to player that wasn't robbed.
        }
        return 1;
}
Is my first tutorial, sorry if it appears so confused.. if haven't problems we can continue with creating a progressbars for the players, like i sayd, one for the player that rob, and other for the player that will be robbed.

pawn Код:
forward robprogress();
public robprogress()
{
    if(progresscount == 100.0) // if the progress count become 100.0 then..
    {
        HidePlayerProgressBar(playerid,progressrob); //Hide progressbar for player that rob
        StopAudioStreamForPlayer(playerid); //Stop the audio for player that rob
        progresscount = 0.0; //reset the progress count to 0.0 so if we want rob more, the progressbar will be restarted.
        KillTimer(robtimerprogress); // finally KillTimer started when a player type a command /rob [id].
        return 1;
    }//if the count isn't finished, (isn't 100.0)..
    PlayerPlaySound(playerid, 17802, 0.0, 0.0, 0.0);//a player sound for each repeat..
    SetPlayerProgressBarValue(playerid,progressrob,progresscount);//setting a value that define the Float:width of the progressbar with the variable progresscount..
    UpdatePlayerProgressBar(playerid,progressrob);//for each repeat, this function update the progress bar, it will be raise, becaouse for each reapeat progresscount increases of 25.0
    progresscount = progresscount + 25.0;
    return 1;

}

//this function is the same as above, but applies to the player that is stolen

forward robprogress2();
public robprogress2()
{
    if(progresscount2 == 100.0)
    {
        HidePlayerProgressBar(rID,progressrob);
        StopAudioStreamForPlayer(rID);
        progresscount2 = 0.0;
        KillTimer(robtimerprogress2);
        return 1;
    }
    PlayerPlaySound(rID, 17802, 0.0, 0.0, 0.0);
    SetPlayerProgressBarValue(rID,progressrob2,progresscount2);
    UpdatePlayerProgressBar(rID,progressrob2);
    progresscount2 = progresscount2 + 25.0;
    return 1;
}
I hope that is all rights, so we can pass to last step, the rob command:

pawn Код:
CMD:rob(playerid,params[])
{
        if(sscanf(params,"u",rID)) return SendClientMessage(playerid,-1,"[SERVER]USE /rob [ID]"); //with sscanf we can get the input of params in a variable rID, that regards the id of the player thet will be robbed, and if the command doesn't find the value for the id return a client message that sayd 'USE /rob [ID]..
    if(rID == playerid) return SendClientMessage(playerid,-1,"[SERVER]You can't rob at yourself."); // if the ID of the player that will be robbed is the same of the ID of the player that want to rob return a client message that sayd that can't rob at yourself..
   
    new Float:rx, Float:ry, Float:rz; //define float variables for get position of the player that will be robbed.
    GetPlayerPos(rID,rx,ry,rz); // get coords of player that will be robbed in a float variables

    if(IsPlayerInRangeOfPoint(playerid,2.5,rx,ry,rz)) // if the player that want rob is near at the player that will be robbed then...
    {
        progressrob = CreatePlayerProgressBar(playerid,50.0, 300.0,55.5,3.2,0xFFFF00AA,100.0); // creating a progressbar for player that want rob..
        progressrob2 = CreatePlayerProgressBar(rID,50.0, 300.0,55.5,3.2,0xFFFF00AA,100.0);// creating a progressbar for player that will be robbed..
        SetTimerEx("robplayer",5000,false,"i",playerid);//setting the timer at function robplaye that have explain above..
        robtimerprogress = SetTimerEx("rubaprogress",1000,true,"i",playerid); //setting the timer for progressbar of the player that want rob
        robtimerprogress2 = SetTimerEx("rubaprogress2",1000,true,"i",rID);//setting the timer for progressbar of the player that will be robbed
    }
    else //if the player isn't in range of player that will be robbed then..
    {
        SendClientMessage(playerid,-1,"[SERVER]You arent near a player");//return a client message that says that you aren't near a player.
    }
    return 1;
}
And this is all, i hope that it's all right, i hope you can be happy with this system.
Enjoy!

Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)