1) Creating ATM object and 3D Textlabel. 2) Detect when player is close to ATM. 3) Robbing the ATM with a timer.
new ATMRobbery[MAX_PLAYERS]; //Robbery Timer
ATMRobbery[playerid] =0; //Setting robbery timer to zero
CreateObject(2942 ,2023.4000000,997.9000200,10.5000000,0.0000000,0.0000000,90.0000000); //object(cj_slot_propg) (1) //ATM Object creation
Create3DTextLabel("ATM", 0xFFFFFFAA, 2023.4000000,997.9000200,11.80, 30.0, 0, 0); //ATM 3Dtext above it
SetTimer("PlayerOneSecondVariables",1000,1); //Skip this line if you already have a one second timer.
stock IsNearATM(playerid)
{
new bool:IsClose = false;
for(new i=0; i < MAX_PLAYERS; i++)
{
if(IsPlayerInRangeOfPoint(i, 5.0, 2023.4000000,997.9000200,9.80)) //Checking if player close to first/only ATm we created.
{
IsClose = true;
}
}
return IsClose;
}
CMD:robatm(playerid,params[])
{
#pragma unused params
new frand =random(10); //Possibility for player to fail/succeed in robbing the ATM
new string[256];
/*if(gTeam[playerid] != TEAM_CIVIL) //Checking if player is Civilian // Clear this or edit it the way it suits you
{
SendClientMessage(playerid,COLOR_RED,"[ERROR] You must be a civilian in order to rob.");
return 1;
}*/
if(!IsNearATM(playerid)) //If player is not close to ATM
{
SendClientMessage(playerid, COLOR_RED, "[ERROR] You must be near an atm first in order to use this command.");
return 1;
}
if(IsNearATM(playerid)) //Player is near ATM
{
if(frand <= 2) //If fail possibility is 2 or less.
{
SendClientMessage(playerid, COLOR_RED, "[ROBBERY] You've attempted to rob the ATM, but failed.");
//SetPlayerWantedLevel(playerid, 4); //edit it the way you want
return 1;
}
//If fail possibility isn't 2 or less. = success
new torand =random(10); //Timer random, you can make it default by skipping this line and removing torand from the following line
ATMRobbery[playerid] =torand+15; //Setting timer to (0/10) + 15
//SetPlayerWantedLevel(playerid, 6); //setting wanted level to 6
format(string,sizeof(string),"~r~ROBBERY IN PROGRESS~n~~w~%d ~g~remaining",ATMRobbery[playerid]); //Formatting game text to show to player
GameTextForPlayer(playerid, string,2000,5); //Sending game text to player
return 1;
}
return 1;
}
public PlayerOneSecondVariables()
{
for(new i=0; i<MAX_PLAYERS; i++)
{
new string[228]; //creating string to use
new pname[MAX_PLAYER_NAME]; //creating player name
GetPlayerName(i,pname,sizeof(pname)); //Creating player name
//Now thats the work
if(ATMRobbery[i] > 1 && !IsNearATM(i)) //if robbery timer is more than 1, and player isn't near ATM
{
ATMRobbery[i] =0; //Setting robbery timer to zero.
SendClientMessage(i, COLOR_RED, "You've left your position while robbing, robbery failed.");
return 1;
}
if(ATMRobbery[i] > 1) //If ATM robbery timer is more than 1.
{
format(string,sizeof(string),"~r~ROBBERY IN PROGRESS~n~~w~%d ~g~remaining~n~~p~DO NOT MOVE",ATMRobbery[i]); //Showing robbery timer for player
GameTextForPlayer(i, string,1000,5);
ATMRobbery[i] --; //decreasing robbery timer by 1 every one second.
}
if(ATMRobbery[i] == 1) //When robbery timer is 1.
{
new mrand =30000+random(30000); //Creating random robbery cash, 30000 default + (0/30000)
SetPlayerScore(i, GetPlayerScore(i)+1); //Setting player score to +1, edit it the way you want
GivePlayerMoney(i, mrand); //Giving the player money.
GetPlayerName(i, pname, sizeof(pname)); //Getting player name
format(string,sizeof(string), "[ROBBERY] You've successfully robbed the ATM, and got away with $%d",mrand);
SendClientMessage(i,COLOR_GREEN, string); //Sending player a message
format(string,sizeof(string), "[ROBBERY] {FFFFFF}%s(%d) {F81414}has robbed the ATM {FFFFFF},{F81414} and got away with {FFFFFF}$%d",pname,i,mrand);
SendClientMessageToAll(COLOR_RED, string); //Sending robbery news to all players online.
ATMRobbery[i] =0; //Setting player variable (robbery timer) to zero again.
}
The default value of the variable is 0, not need to state "var = 0".
|