[Tutorial] Team Casino robbery!
#1

Alright, I'll start off by saying that I'm new to scripting, so my code will be ugly, but it should work! If you have suggestions to improve it, please tell.

I'll be using Streamer plugin and YSI\y_commands.

First of all, you'll need to create robbery checkpoints. I'll be creating two robbery checkpoints in Caligulas Palace and 4 Dragons Casino:

pawn Код:
new caligulacheck;
new dragoncheck;
Then we proceed to create them under OnFilterScriptInit(), if you're doing this in FS or under OnGameModeInit(). I suggest the first, so you don't get confused.

pawn Код:
public OnFilterScriptInit()
{
    caligulacheck = CreateDynamicCP(2144.2002,1635.9196,993.5761, 2, -1, -1, -1, 150); //x,y,z,checkpoint size,worldid,interiorid,playerid to be shown only for him,stream distance
    dragoncheck = CreateDynamicCP(1929.9324,1036.7157,994.4750, 2, 0, -1, -1, 100);
    return 1;
}
Then we need to decide what happens, when the player enters the created checkpoints! So under streamer's callback you put:

pawn Код:
public OnPlayerEnterDynamicCP(playerid, checkpointid)
{
    if(checkpointid == caligulacheck || checkpointid == dragoncheck)
    {
        SendClientMessage(playerid, COLOR_YELLOW, "Type /robbery to start it.");
    }
    return 1;
}
So when they enter either of those checkpoints, they'll see this message! Now you need to decide what happens when they actually write the command, I'm using y_commands, so should be you, as it's much easier, then the default method:
pawn Код:
CMD:robbery(playerid, params[])
{
    if(IsPlayerInDynamicCP(playerid, caligulacheck)) //we check if the player is standing in the checkpoint, when they type /robbery
    {
        if(GetPlayersInRobberyCP(GetPlayerTeam(playerid), caligulacheck) <3) return SendClientMessage(playerid, COLOR_RED, "You need at least 3 gang members at the chechpoint to start the robbery."); //custom function to see how many team members there are at the checkpoint, I'll explain later
        if(GetTickCount() - endCaligulas < 60000*5) return SendClientMessage(playerid, COLOR_RED, "Caligula's Palace has been robbed recently."); //this is so players don't rob the place too frequently. endCaligulas variable is set to tickcount() when the player finishes the robbery and then you're checking if the tickcount() at the moment of typing the command minus the tickcount is less then 5 minutes (60000ms*5) and if so, return them with the message and not proceed the code further!
        if(caligulaRobbery == 1) return SendClientMessage(playerid, COLOR_RED, "A robbery is already in progress."); //check if the robbery already in progress, if so, return with client message and stop the code from proceeding further!
        if(GetPlayerTeam(playerid) == 4) return SendClientMessage(playerid, COLOR_RED, "You can't rob your own casino."); //now this checks if the player, who's trying to rob the place is in team "4". Team 4 owns the casino, so they can't rob it, change it accordingly to your teams
        RobbingCaligulas[playerid] = 1; //set playerid variable so we can track if that player dies or disconnects and end the robbery
        caligulaRobbery = 1; //set the robbery variable so it can't get robbed, while someone is robbing!
        RobberyFormat(playerid); //custom function to display gametext and message  for the player, so you don't have to write it every time you create new casino checkpoint
        SendClientMessageToTeam(playerid, 4, COLOR_BLUE, "[Team]Caligula's Palace is being robbed. Defend it and get rewarded."); //custom functions which loops through all players, checks their team id and sends message to the team, who owns the casino
    }
    else {SendClientMessage(playerid, COLOR_RED, "You must be at casino robbery checkpoint.");} //if they aren't in the checkpoint
    if(IsPlayerInDynamicCP(playerid, dragoncheck)) //same goes for below
    {
        if(GetPlayersInRobberyCP(GetPlayerTeam(playerid), dragoncheck) <1) return SendClientMessage(playerid, COLOR_RED, "You need at least 3 gang members at the chechpoint to start the robbery.");
        if(GetTickCount() - endDragons < 60000*5) return SendClientMessage(playerid, COLOR_RED, "The Four Dragons Casino has been robbed recently.");
        if(dragonRobbery == 1) return SendClientMessage(playerid, COLOR_RED, "A robbery is already in progress.");
        if(GetPlayerTeam(playerid) == 5) return SendClientMessage(playerid, COLOR_RED, "You can't rob your own casino.");
        RobbingDragons[playerid] = 1;
        dragonRobbery = 1;
        RobberyFormat(playerid);
    }
    else {SendClientMessage(playerid, COLOR_RED, "You must be at casino robbery checkpoint.");}
    return 1;
}

//I'll explain the custom functions now! This is the format:
stock RobberyFormat(playerid)
{
    GameTextForPlayer(playerid, "~w~ROBBERY IN PROGRESS~n~~y~STAY IN THE~n~~r~RED CHECKPOINT", 1000, 3); //shows gametext for player for 1 second
    SendClientMessage(playerid, COLOR_BLUE, "Robbery initialized. Stand in the checkpoint for 20 seconds.");
    ApplyAnimation(playerid, "SHOP", "ROB_Loop_Threat", 4.0, 1, 0, 0, 0, 0); //applies robbery animation
    robtimer[playerid] = SetTimerEx("robtimerN",2000,1,"i",playerid); //sets the robbery timer, which checks if the player is still in the CP and time he's been
    new robberTeam = GetPlayerTeam(playerid);
    new robberName[24];
    new string[128];
    GetPlayerName(playerid, robberName, 24);
    format(string,sizeof(string),"[Team]%s has started robbery at %s.", robberName, robberyPlace(playerid)); //robberyPlace is a custom function which returns string with casino's name, depending on the checkpoint you standing at
    SendClientMessageToTeam(playerid, robberTeam, COLOR_BLUE, string); //sends message to team of the robber, so they can assist him
    return 1;
}
For getting players count in the checkpoint:
pawn Код:
stock GetPlayersInRobberyCP(teamid, checkpointid)
{
    new count;
    for(new i=0; i < MAX_PLAYERS; i++) //loops through all players
    {
        if(IsPlayerConnected(i) && GetPlayerTeam(i) == teamid && IsPlayerInDynamicCP(i, checkpointid)) //checks if they're connected, checks if their team is the same of robbers team and check if they're at the specified checkpoint
        {
            count++; //increase the variable by one for everyone who meets the criteria above, so if there are 3 players of team id 3 standing in the specified checkpoint, it will return "3"!
        }
    }
    return count;
}

stock robberyPlace(playerid) //robberyPlace is a custom function which returns string with casino's name, depending on the checkpoint you standing at
{
    new place[30];
    if(IsPlayerInDynamicCP(playerid, caligulacheck)) format(place,sizeof(place),"Caligula's Palace");
    if(IsPlayerInDynamicCP(playerid, dragoncheck)) format(place,sizeof(place),"The Four Dragons Casino");
    return place;
}

stock SendClientMessageToTeam(playerid, team, color, text[]) //this is YSI's custom function, I added playerid here so it doesn't send the message to the player, who's robbing
{
    new ret=0;
    for(new i = 0; i < MAX_PLAYERS; i++) //loops through all players
    {
        if(IsPlayerConnected(i) && GetPlayerTeam(i) == team && playerid != i) //checks if they're connected, checks if their team is the same of robbers team and they're not the player, who's robbing
        {
            SendClientMessage(i, color, text); //send specified message with specified color
            ret++;
        }
    }
    return ret;
}

stock GiveTeamMoney(playerid, team, cash) //giving money for specified team, works the same as above, but sends money, instead of message
{
    new ret=0;
    for(new i = 0; i < MAX_PLAYERS; i++)
    {
        if(IsPlayerConnected(i) && GetPlayerTeam(i) == team && playerid != i)
        {
            GivePlayerMoney(i, cash);
            ret++;
        }
    }
    return ret;
}
Now let's get to the robbery timer, you'll want to forward it somewhere at top of your script:
pawn Код:
public robtimerN(playerid)
{
    new robberTeam = GetPlayerTeam(playerid);
    new robberName[24];
    GetPlayerName(playerid, robberName, 24);
    count5++; //adds one to the count var
    GameTextForPlayer(playerid, "~w~ROBBERY IN PROGRESS~n~~y~STAY IN THE~n~~r~RED CHECKPOINT", 1000, 3); //shows the gametext for one second, as this timer repeats itself every 2 seconds, this text will be flashing
    if(RobbingCaligulas[playerid] == 1) //if the player is robbing Caligulas Palace
    {
        if(!IsPlayerInDynamicCP(playerid, caligulacheck)) //if he moved out of the checkpoint
        {
            SendClientMessage(playerid, COLOR_RED, "Robbery failed."); //it will send him fail message
            RobbingCaligulas[playerid] = 0; //set the variables back to zero, so people can rob it further
            caligulaRobbery = 0;
            KillTimer(robtimer[playerid]); //kill this timer
            new string[128];
            format(string,sizeof(string),"[Team]%s has failed the robbery at %s.", robberName, robberyPlace(playerid)); //send message to his team, so they know he failed the robbery
            SendClientMessageToTeam(playerid, robberTeam, COLOR_BLUE, string);
            count5 = 0; //reset the count
        }
    }
    if(RobbingDragons[playerid] == 1) //same as above
    {
        if(!IsPlayerInDynamicCP(playerid, dragoncheck))
        {
            SendClientMessage(playerid, COLOR_RED, "Robbery failed.");
            RobbingDragons[playerid] = 0;
            dragonRobbery = 0;
            KillTimer(robtimer[playerid]);
            new string[128];
            format(string,sizeof(string),"[Team]%s has failed the robbery at %s.", robberName, robberyPlace(playerid));
            SendClientMessageToTeam(playerid, robberTeam, COLOR_BLUE, string);
            count5 = 0;
        }
    }
    if(count5 >= 10) //if the count reaches 10, and as the timer is repeating itself every 2 seconds, it will reach it after 20 seconds
    {
        SendClientMessage(playerid, COLOR_BLUE, "You have succesfully robbed the safe from the Caligula's Casino. Follow the red checkpoint."); //let the player know he succeed
        GameTextForPlayer(playerid, "~y~BRING THE SAFE TO THE~n~~r~RED CHECKPOINT", 10000, 3);
        new test[] = "12"; //this is an array with 3 numbers! 0 1 2.
        #pragma unused test //this is so it doesn't show the stupid warning message
        new rand = random(sizeof(test)); //gets random number from the 'test' array to create our hideouts randomly!
        if(rand == 0)
        {
            finishIcon[playerid] = CreateDynamicMapIcon(1048.7190,2908.7190,47.8231, 0, COLOR_RED, -1, -1, playerid, 10000.0); //creats map icon pointing to the hideout place (checkpoint)
            TogglePlayerDynamicCP(playerid, finishCheck1, 1); //finishCheck1 is the first hideout checkpoint, toggling it to '1' so the player can see and enter it
        }
        if(rand == 1)
        {
            finishIcon[playerid] = CreateDynamicMapIcon(-902.6438,2687.7029,41.9304, 0, COLOR_RED, -1, -1, playerid, 10000.0);
            TogglePlayerDynamicCP(playerid, finishCheck2, 1);
        }
        if(rand == 2)
        {
            finishIcon[playerid] = CreateDynamicMapIcon(869.0721,-30.8067,62.7581, 0, COLOR_RED, -1, -1, playerid, 10000.0);
            TogglePlayerDynamicCP(playerid, finishCheck3, 1);
        }
        ClearAnimations(playerid); //
        TogglePlayerDynamicCP(playerid, caligulacheck, 0); //toggles the robbery checkpoints player is standing at to 0, so he doesn't see them and so if wont confuse him
        TogglePlayerDynamicCP(playerid, dragoncheck, 0);
        new string[128];
        format(string,sizeof(string),"[Team]%s has robbed the safe at %s, help him deliver it to the hideout!", robberName, robberyPlace(playerid));
        SendClientMessageToTeam(playerid, robberTeam, COLOR_BLUE, string); //sends a message to the robbers team, so they can help him to get to the hideout
        count5 = 0; //resets the count
        KillTimer(robtimer[playerid]); //
    }
    return 1;
}
But I don't remember us actually creating finish checkpoints for hideouts, you'd say and will be right! Create them at the same place, where you created robbery checkpoints:
pawn Код:
finishCheck1 = CreateDynamicCP(1048.7190,2908.7190,47.8231, 4, -1, -1, -1, 100);
finishCheck2 = CreateDynamicCP(-902.6438,2687.7029,41.9304, 4, -1, -1, -1, 100);
finishCheck3 = CreateDynamicCP(869.0721,-30.8067,62.7581, 4, -1, -1, -1, 100);
Don't forget to toggle those checkpoints to zero, when players connect!
pawn Код:
public OnPlayerConnect(playerid)
{
    TogglePlayerDynamicCP(playerid, caligulacheck, 1);
    TogglePlayerDynamicCP(playerid, dragoncheck, 1);
    TogglePlayerDynamicCP(playerid, clowncheck, 1);
    TogglePlayerDynamicCP(playerid, finishCheck1, 0);
    TogglePlayerDynamicCP(playerid, finishCheck2, 0);
    TogglePlayerDynamicCP(playerid, finishCheck3, 0);
    return 1;
}
And when someone dies while robbing, it means the robbery is over:
pawn Код:
public OnPlayerDeath(playerid, killerid, reason)
{
    if(RobbingCaligulas[playerid] == 1) //if the player that died started the robbery
    {
        SendClientMessage(playerid, COLOR_RED, "Robbery failed."); //inform him that the robbery is failed!
        caligulaRobbery = 0; //set the variables back to zero
        RobbingCaligulas[playerid] = 0;
        TogglePlayerDynamicCP(playerid, finishCheck1, 0); //toggle the finish (hideout) checkpoint back to zero, so he wont be able to see and enter it and get the money
        KillTimer(robtimer[playerid]); //kill the timer
        DestroyDynamicMapIcon(finishIcon[playerid]); //destroy the icon that we created earlier
    }
    if(RobbingDragons[playerid] == 1) //the same goes for this
    {
        SendClientMessage(playerid, COLOR_RED, "Robbery failed.");
        dragonRobbery = 0;
        RobbingDragons[playerid] = 0;
        TogglePlayerDynamicCP(playerid, finishCheck1, 0);
        KillTimer(robtimer[playerid]);
        DestroyDynamicMapIcon(finishIcon[playerid]);
    }
    if(RobbingCaligulas[playerid] == 1 && GetPlayerTeam(killerid) == 4) //now this actually checks if the dead player was robbing caligulas and if the player who killed him is in a team, who owns the casino and if so...
    {
        new string[128];
        new pName[24];
        GetPlayerName(killerid, pName, 24);
        GivePlayerCash(killerid, ROBBERY_REWARD / 2); //reward the player, who defended the casino with half of money that the robbing player was supposed to get, you have to define that amount somewhere at top of your script
        format(string,sizeof(string),"[Team]%s has stopped the robbery and gets %d in reward.", pName, ROBBERY_REWARD / 2); //formats the message
        SendClientMessageToTeam(playerid, 4, COLOR_BLUE, string); //sends message to the casino defending players team
    }
    if(RobbingDragons[playerid] == 1 && GetPlayerTeam(killerid) == 5) //same one, but different team
    {
        new string[128];
        new pName[24];
        GetPlayerName(killerid, pName, 24);
        GivePlayerCash(killerid, ROBBERY_REWARD / 2);
        format(string,sizeof(string),"[Team]%s has stopped the robbery and gets %d in reward.", pName, ROBBERY_REWARD / 2);
        SendClientMessageToTeam(playerid, 5, COLOR_BLUE, string);
    }
    TogglePlayerDynamicCP(playerid, caligulacheck, 1); //toggles the robbery checkpoints back to 1, so they can see and enter them.
    TogglePlayerDynamicCP(playerid, dragoncheck, 1);
    return 1;
}
Now we still didn't decide what happens when the player reaches the hideout/enter the finish checkpoint:
pawn Код:
public OnPlayerEnterDynamicCP(playerid, checkpointid)
{
    new robberTeam = GetPlayerTeam(playerid);
    new robberName[24];
    GetPlayerName(playerid, robberName, 24);
    if(checkpointid == finishCheck1 || checkpointid == finishCheck2 || checkpointid == finishCheck3) //if he's in any of the following hideout checkpoints
    {
        new string[128];
        format(string,sizeof(string),"You have succesfully reached the hideout and cracked the safe. You receive %d$", ROBBERY_REWARD); //format with the ROBBERY_REWARD that you have defined at top of your scipt
        SendClientMessage(playerid, COLOR_BLUE, string); //send the above message
        GivePlayerCash(playerid, ROBBERY_REWARD); //give him defined money for completing the robbery
        DestroyDynamicMapIcon(finishIcon[playerid]); //destroys the map icon
        TogglePlayerDynamicCP(playerid, finishCheck1, 0); //toggles
        TogglePlayerDynamicCP(playerid, finishCheck2, 0); //all the finish checkpoints
        TogglePlayerDynamicCP(playerid, finishCheck3, 0); //back to zero
        format(string,sizeof(string),"[Team]%s has cracked the safe and found %d$. You get bonus reward for being in the same team.", robberName, ROBBERY_REWARD);
        SendClientMessageToTeam(playerid, robberTeam, COLOR_BLUE, string); //send the above message to the players team
        GiveTeamCash(playerid, robberTeam, ROBBERY_REWARD / 10); //give the players team defined reward divided by 10
        if(RobbingCaligulas[playerid] == 1) //if the player that entered the finish checkpoint is robbing caligulas
        {
            RobbingCaligulas[playerid] = 0; //set the variable back to zero
            endCaligulas = GetTickCount(); //set the variable "endCaligulas" to the current tickcount(). We then use that variable to check if the specific casino has been robbed recently
            caligulaRobbery = 0; //set the variable back to zero
        }
        if(RobbingDragons[playerid] == 1) //the same
        {
            RobbingDragons[playerid] = 0;
            endDragons = GetTickCount();
            dragonRobbery = 0;
        }
        TogglePlayerDynamicCP(playerid, caligulacheck, 1); //toggles back the robbery checkpoints
        TogglePlayerDynamicCP(playerid, dragoncheck, 1);
    }
    return 1;
}
That's almost it! Now if the player, who's robbing the casino disconnects, we need to set the variables back to zero, so other players can rob:
pawn Код:
public OnPlayerDisconnect(playerid)
{
    if(RobbingCaligulas[playerid] == 1) //if the player that disconnected is robbing caligulas
    {
        caligulaRobbery = 0; //set the global variable back to zero
        RobbingCaligulas[playerid] = 0;
        TogglePlayerDynamicCP(playerid, finishCheck1, 0); //toggle the hideout/finish checkpoint back to zero, as the robbery if failed now
    }
    if(RobbingDragons[playerid] == 1) //same
    {
        dragonRobbery = 0;
        RobbingDragons[playerid] = 0;
        TogglePlayerDynamicCP(playerid, finishCheck1, 0);
    }
    KillTimer(robtimer[playerid]);
    DestroyDynamicMapIcon(finishIcon[playerid]);
    return 1;
}
That's it! I hope you understand something from this tutorial, because I surely wouldn't, if I weren't to write it! If you know how I can improve it, let me know!
Reply
#2

Thanks! I will definitely learn this.
Reply
#3

Very nice TUTORIAL

This was what i wanted to find

gratz!
Reply
#4

PHP код:
C:\Documents and Settings\pc\Desktop\GTA Panic(MS)\gamemodes\gangwars4.pwn(3191) : error 029invalid expressionassumed zero
C
:\Documents and Settings\pc\Desktop\GTA Panic(MS)\gamemodes\gangwars4.pwn(3191) : error 029invalid expressionassumed zero
C
:\Documents and Settings\pc\Desktop\GTA Panic(MS)\gamemodes\gangwars4.pwn(3191) : warning 215expression has no effect
C
:\Documents and Settings\pc\Desktop\GTA Panic(MS)\gamemodes\gangwars4.pwn(3191) : error 001expected token";"but found ")"
C:\Documents and Settings\pc\Desktop\GTA Panic(MS)\gamemodes\gangwars4.pwn(3191) : fatal error 107too many error messages on one line 
And the line 3191:
PHP код:
TogglePlayerDynamicCP(playeridfinishCheck10); 
PHP код:
 TogglePlayerDynamicCP(playeridcaligulacheck1);
    
TogglePlayerDynamicCP(playeriddragoncheck1);
    
TogglePlayerDynamicCP(playeridclowncheck1);
    
TogglePlayerDynamicCP(playeridfinishCheck10);
    
TogglePlayerDynamicCP(playeridfinishCheck20);
    
TogglePlayerDynamicCP(playeridfinishCheck30); 
Reply
#5

Nice I will try Bro
Reply
#6

Very Nice, i learn't something now. XD
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)