[Tutorial] How to make a robbery system
#1

Hi guyz am superrobot48 and this is my first tutorial on sa-mp , so lets begin

PART 1- variables

So first lets include this on top

pawn Code:
#include <a_samp>
#include <streamer>
#include <zcmd>
pawn Code:
new CP_tatoo; // The name of the checkpoint add whatever you want :)

Adding some Colors
pawn Code:
#define COLOR_RED 0xFF0000AA
#define COLOR_BLUE 0x0000FFAA
#define COLOR_WHITE 0xFFFFFFAA
#define COLOR_YELLOW 0xFFFF00AA
#define COLOR_GREEN 0x33AA33AA
#define COL_WHITE "{FFFFFF}"
#define COL_RED "{F81414}"
#define COL_GREEN "{00FF22}"
#define COL_LIGHTBLUE "{00CED1}"
#define COLOR_ORANGE 0xFFA500AA
-add it on top of the script

Adding some more variables
pawn Code:
new ROBBING_TATOO[MAX_PLAYERS]; //used when you rob
new tatoorobbedrecently =0; // to make the players wait before robbing more
PART 2 - Checkpoint


In on Onplayerspawn or on OnplayerConnect add this
pawn Code:
CP_tatoo = CreateDynamicCP(-201.2237,-42.7339,1002.2734, 2.0, .interiorid = 3); // creating the checkpoint CP_tatoo
You can create any checkpoint using the format
Code:
CreateDynamicCP(Float:x, Float:y, Float:z, Float:size,  .interiorid = the id);
and dont forget to add a variable to it .
Now lets tell player to type a command when in the checkpoint .
pawn Code:
public OnPlayerEnterDynamicCP(playerid, checkpointid) //Add this anywhere
{

   if(checkpointid == CP_tatoo) //Checking if player is in the checkpoint "Tatoo"
   {
    SendClientMessage(playerid, COLOR_RED, "Start robbery by typing /robthis"); //Sending message so that player knows that to rob. he must type this command
   }
   return 1;
}
Now lets make the /robthis command
PART 3

pawn Code:
CMD:robthis(playerid, params[])
{
    #pragma unused params // we dont need the params
    if(IsPlayerInDynamicCP(playerid, CP_tatoo)) // Checking if player is in the checkpoint
    {
        if(tatoorobbedrecently >=1) //checking if tatoo shop has been robbed recently
        {
            SendClientMessage(playerid, COLOR_RED, "Tatoo Shop has been robbed recently"); // sending error message
                return 1;
        }
        ROBBING_TATOO[playerid] = 60; // setting the robbery timer
        tatoorobbedrecently =180; // Time the players needs to wait for starting an another robbery in the same place
    }
    return 1;
}
PART 4
now lets make the timers (we are just using 1 timer for lots of robberies )
lets forward the timer first
pawn Code:
forward ServerRobbery();
then on OnGamemodeinit
pawn Code:
SetTimer("ServerRobbery",1000,1);// Ticks every 1 second
Lets now make the public command
pawn Code:
public ServerRobbery()
{
        for(new i=0; i<MAX_PLAYERS; i++)
        {
            if(IsPlayerConnected(i)) // checking if player connected
            {
                //ROBBERIES
                if(ROBBING_TATOO[i] > 1) // Checking if robbery time is above 1
                {
                    ROBBING_TATOO[i] --; // Decreasing time
                    new time[20]; //adding time variable
                        format(time,sizeof(time),"Robbery Time: %d",ROBBING_TATOO[i]);
                        GameTextForPlayer(i,time,500,3); //shows gametext showing the time remaining for the robbery
                }
                if(ROBBING_TATOO[i] == 1) // IF the timer reached 1
                {
                                        new string[64], pName[MAX_PLAYER_NAME];// getting player name
                            GetPlayerName(i,pName,MAX_PLAYER_NAME);
                    SendClientMessage(i, COLOR_GREEN, "Robbery Complete"); //sending message to the player that robbery was complete
                    SetPlayerWantedLevel(i, GetPlayerWantedLevel(i) + 1); //giving player 1 wanted level
                    ROBBING_TATOO[i] =0; // RESET timer
                    new mrand =random(50000);
                            GivePlayerScore(i,1);
                    format(string,sizeof(string),"[ROBBERY] %s(%d) has robbed a total of $%d from the tatoo shop! LOL!",pName,i,mrand);
                    SendClientMessageToAll(COLOR_RED,string);
                    GivePlayerMoney(i, mrand);
                }
            }
        }
        return 1;
}
that's it now for the final part.
Now if the player left the checkpoint the robbery must be cancelled so
add
pawn Code:
public OnPlayerLeaveDynamicCP(playerid, checkpointid)
{
    if(checkpointid == CP_tatoo) // checking if the player is leaving the CP tatoo
    {
        if(ROBBING_TATOO[playerid] >= 1) //checking if the person was robbing and his robbery timer was above 1
        {
            SendClientMessage(playerid, COLOR_RED, "[ERROR]Robbery Failed"); //Error message that he failed
            ROBBING_TATOO[playerid] =0; // Setting Robbing_tatoo to 0. to stop the counter
            return 1;
        }
    }
    return 1;
}
That's it you have learned how to make a robbery ! Well Enjoy thanks for reading
If you have any doubts please ask below
Reply
#2

Not bad.
Reply
#3

This is good, Very useful
for new scripters, repped
Reply
#4

Thanks guys
Reply
#5

Oh and btw in part 4 this
pawn Code:
ROBBING_SEXSHOP[playerid] =0;
Should Be
pawn Code:
ROBBING_TATOO[playerid] =0;
Reply
#6

ah yes sorry did not see that while copying from my gamemode thanks
Reply
#7

Code:
C:\Users\Owner\Downloads\Server (1) (1)\Server (1)\The_Server\gamemodes\Rob_System.pwn(59) : error 021: symbol already defined: "SetTimer"
C:\Users\Owner\Downloads\Server (1) (1)\Server (1)\The_Server\gamemodes\Rob_System.pwn(83) : error 017: undefined symbol "GivePlayerScore"
Pawn compiler 3.2.3664	 	 	Copyright © 1997-2006, ITB CompuPhase


2 Errors.
how do i fix this?
Reply
#8

Not bad
Reply
#9

I am not sure if i was able to fix my earlyer problem(i probly did a mistake) but now it compiles. My question is where defuq is the tatoo shop? XD
Reply
#10

good attempt but its some how misleading e.g: new time[20]; //adding time variable
this actually is declaring an array to be used as string which will be used to display a message. So better to write it like //declaring a string to send a message or something like that.

ROBBING_TATOO[playerid] =0; // RESET THE TIMER
well timer is quite different thing. It is more like a counter variable or a variable to be used as counter unless it reach specific value.

Therefore it need some improved explanations at many points.
Thats just few things to spot for now but it has to be improved.
Reply
#11

Quote:
Originally Posted by ThatThoseTheThy
View Post
I am not sure if i was able to fix my earlyer problem(i probly did a mistake) but now it compiles. My question is where defuq is the tatoo shop? XD
would be nice if someone could answer this.
Reply
#12

Quote:
Originally Posted by ThatThoseTheThy
View Post
I am not sure if i was able to fix my earlyer problem(i probly did a mistake) but now it compiles. My question is where defuq is the tatoo shop? XD
just add new or different location's Coordinates...
Reply
#13

Quote:
Originally Posted by ThatThoseTheThy
View Post
would be nice if someone could answer this.
nice 1 . its added to the default tatoo interior
Reply
#14

Quote:
Originally Posted by Niko_boy
View Post
good attempt but its some how misleading e.g: new time[20]; //adding time variable
this actually is declaring an array to be used as string which will be used to display a message. So better to write it like //declaring a string to send a message or something like that.

ROBBING_TATOO[playerid] =0; // RESET THE TIMER
well timer is quite different thing. It is more like a counter variable or a variable to be used as counter unless it reach specific value.

Therefore it need some improved explanations at many points.
Thats just few things to spot for now but it has to be improved.
Thanks i'll add it and sorry
Reply
#15

Quote:
Originally Posted by ThatThoseTheThy
View Post
Code:
C:\Users\Owner\Downloads\Server (1) (1)\Server (1)\The_Server\gamemodes\Rob_System.pwn(59) : error 021: symbol already defined: "SetTimer"
C:\Users\Owner\Downloads\Server (1) (1)\Server (1)\The_Server\gamemodes\Rob_System.pwn(83) : error 017: undefined symbol "GivePlayerScore"
Pawn compiler 3.2.3664	 	 	Copyright © 1997-2006, ITB CompuPhase


2 Errors.
how do i fix this?
add this somewhere
pawn Code:
stock GivePlayerScore( playerid, score ) SetPlayerScore( playerid, GetPlayerScore( playerid ) + score );
u can give player score using this stock anytime
Reply
#16

Not really. This is a copy paste from SFCRRPG gamemode. You just changed that cp to dynamiccp.
Reply
#17

lol , they not got money lol
Reply
#18

pawn Code:
GivePlayerMoney(i, mrand);
check if u have this
Reply
#19

It's good for beginners, but there is a more neater way of creating a robbery system.

Although, good job.
Reply
#20

yes i have its , but my money not increase after the robbery can you help ?
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)