01.04.2016, 20:23
(
Last edited by Vanter; 05/04/2016 at 11:13 AM.
)
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:
1) Here we go, first; we create the variable we're going to use
2) If you have a ResetVariable public, post this under that, if not, post this under OnPlayerSpawn
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
4) Now we have to create a stock to detect whenever player is near ATM
5) Now we have to create the command.
6) Final step! the one second timer, If you already have one, post this under it
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
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.
PHP Code:
new ATMRobbery[MAX_PLAYERS]; //Robbery Timer
PHP Code:
ATMRobbery[playerid] =0; //Setting robbery timer to zero
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", 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.
PHP Code:
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;
}
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(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;
}
PHP Code:
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.
}
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