[Tutorial] Robbable ATMs
#1

Hello everybody,

This here is something I took out of my server and made it in a simple form for you to create and maybe edit more if you want to, only 6-steps guide, you won't need any downloads, only a command processor. for me I use ZCMD.

ZCMD Download link: https://sampforum.blast.hk/showthread.php?tid=91354

What we will cover:
Code:
1) Creating ATM object and 3D Textlabel.
2) Detect when player is close to ATM.
3) Robbing the ATM with a timer.
1) Here we go, first; we create the variable we're going to use
PHP Code:
new ATMRobbery[MAX_PLAYERS]; //Robbery Timer 
2) If you have a ResetVariable public, post this under that, if not, post this under OnPlayerSpawn
PHP Code:
ATMRobbery[playerid] =0//Setting robbery timer to zero 
3) Now under OnGameModeInIt, we're going to create the objects(atm next to four dragons casino LV) and 3Dtext label, and also a one second timer
PHP Code:
CreateObject(2942  ,2023.4000000,997.9000200,10.5000000,0.0000000,0.0000000,90.0000000); //object(cj_slot_propg) (1)  //ATM Object creation
    
Create3DTextLabel("ATM"0xFFFFFFAA2023.4000000,997.9000200,11.8030.000); //ATM 3Dtext above it
        
        
SetTimer("PlayerOneSecondVariables",1000,1);     //Skip this line if you already have a one second timer. 
4) Now we have to create a stock to detect whenever player is near ATM
PHP Code:
stock IsNearATM(playerid)
{
    new 
bool:IsClose false;
    for(new 
i=0MAX_PLAYERSi++)
    {
        if(
IsPlayerInRangeOfPoint(i5.02023.4000000,997.9000200,9.80))  //Checking if player close to first/only ATm we created.
        
{
            
IsClose true
        }
    }
    return 
IsClose;

5) Now we have to create the command.
PHP Code:
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(playeridCOLOR_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(playeridCOLOR_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(playeridstring,2000,5); //Sending game text to player
      
return 1;
   }
   return 
1;

6) Final step! the one second timer, If you already have one, post this under it
PHP Code:
public PlayerOneSecondVariables()
{
     for(new 
i=0i<MAX_PLAYERSi++)
    {
      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] > && !IsNearATM(i)) //if robbery timer is more than 1, and player isn't near ATM
    
{
       
ATMRobbery[i] =0//Setting robbery timer to zero.
       
SendClientMessage(iCOLOR_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(istring,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(iGetPlayerScore(i)+1); //Setting player score to +1, edit it the way you want
       
GivePlayerMoney(imrand); //Giving the player money.
       
GetPlayerName(ipnamesizeof(pname)); //Getting player name
       
format(string,sizeof(string), "[ROBBERY] You've successfully robbed the ATM, and got away with $%d",mrand);
       
SendClientMessage(i,COLOR_GREENstring); //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_REDstring); //Sending robbery news to all players online.
       
ATMRobbery[i] =0//Setting player variable (robbery timer) to zero again.
    

This is what it will look like!


Thats it! I hope this helped you a little.
More tutorials are up to come!


NOTE: The idea can be used in any other commands like /deposit or /withdraw, use IsNearATM as the key.

Also please post your feedback.

Best Regards,
Vanter
Owner and Developer
San Andreas Cops and Criminals
Reply
#2

Very nice, good job.
Reply
#3

The default value of the variable is 0, not need to state "var = 0".
Reply
#4

Quote:
Originally Posted by ALiScripter
View Post
The default value of the variable is 0, not need to state "var = 0".
If you want to maintain a non-buggy server, you have to assure the variables are correctly set.
Also, keep in mind that this is a tutorial.
Reply
#5

Good job, rep!
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)