SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Scripting Help > Tutorials

Reply
 
Thread Tools Display Modes
Old 01/04/2016, 08:23 PM   #1
Vanter
Huge Clucker
 
Vanter's Avatar
 
Join Date: Jul 2013
Posts: 391
Reputation: 16
Thumbs up Robbable ATMs

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: http://forum.sa-mp.com/showthread.php?t=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

Last edited by Vanter; 05/04/2016 at 11:13 AM.
Vanter is offline   Reply With Quote
Old 02/04/2016, 06:55 PM   #2
LeeZhang
Little Clucker
 
Join Date: Feb 2015
Posts: 9
Reputation: 0
Default Re: Robbable ATMs

Very nice, good job.
LeeZhang is offline   Reply With Quote
Old 03/04/2016, 06:39 AM   #3
Logic_
Banned
 
Join Date: Jun 2015
Posts: 1,506
Reputation: 305
Default Re: Robbable ATMs

The default value of the variable is 0, not need to state "var = 0".
Logic_ is offline   Reply With Quote
Old 03/04/2016, 11:43 AM   #4
Vanter
Huge Clucker
 
Vanter's Avatar
 
Join Date: Jul 2013
Posts: 391
Reputation: 16
Default Re: Robbable ATMs

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.
Vanter is offline   Reply With Quote
Old 04/04/2016, 04:55 PM   #5
N0FeaR
High-roller
 
N0FeaR's Avatar
 
Join Date: Nov 2011
Location: Sweden
Posts: 2,308
Reputation: 167
Default Re: Robbable ATMs

Good job, rep!
__________________
Here is my discord server https://discord.gg/ucVpDkJ
N0FeaR is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
[FilterScript] ATMs GTA V style (textdraws and objects) adri1 Filterscripts 16 19/07/2014 07:51 AM
Dynamic ATMs not working correctly[MySQL]. ikbenremco Scripting Help 13 26/01/2014 04:54 PM
How to add buildings and how to make them robbable chrism11 Help Archive 1 23/10/2010 09:34 PM


All times are GMT. The time now is 02:55 AM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.