24.09.2012, 15:27
Here's an example of Bank robbery by detecting whether player is in that Bank's interior or not.
Sorry if mistakes, its not tested.
pawn Код:
new Time[MAX_PLAYERS]; //Creating a variable.
//We'll use this as a time variable so as to prevent frequent robberies.
CMD:brob(playerid,params[]) //Creating the command using zcmd.
{
if(Time[playerid] == 1) //Detecting if the player has robbed before or not.
{ //If yes,
SendClientMessage(playerid, 0xFF0000, "You have just done a robbery. Please wait for sometime."); //Messaging to wait for sometime for next robbery.
} //Closing and if not robbed,
new interior; //Creating a variable as interior.
interior = GetPlayerInterior(playerid); //Using the variable to detect player's interior.
if(interior == 0) //Checking whether the detected interior is 0. 0 here used is the interior id of the bank.
//You can get more id's on wiki samp.
{ //If player is in that interior.
GivePlayerMoney(playerid,100000); //Giving player money to regard that he robbed.
Time[playerid]=1; //Changing the time variable to 1 so it'll be that the player has robbed.
SendClientMessage(playerid, 0xFF0000, "You have successfully robbed a bank."); //A message to player regarding his successful robbery.
SetTimerEx("disabletime", 900000,false,"d",playerid); //Creating a timer for 15 minutes which can disable the time variable so that the player can rob after 15 minutes.
} //Closing the opened brackets.
else //Using else statement to switch that if player is not in the correct interior,
{ //Opening brackets to execute function.
SendClientMessage(playerid, 0xFF0000, "You must be in a bank to use this command."); //Giving a message that player should be in a bank to use this command.
} //Closing the brackets.
return 1; //Returning functions.
} //Closing command.
forward disabletime() //Forwarding our timer.
public disabletime(playerid) //Creating disabletime function which we've used in the time.
{ //Opening brackets to execute function.
Time[playerid]=0; //After 15 mins, player will be able to rob because his Time array is set to 0.
return 1; //returning function.
} //Closing brackets