[Tutorial] Rob Command
#1

As every time i was searching for one and i didn't find so i decided to make it
Rob Command
for Role-Play servers

First the includes
PHP код:
#include <a_samp>
#include <zcmd>
#include <sscanf2> 
and define some colors
PHP код:
#define COLOR_RED 0xFF0000AA
#define COLOR_GREEN 0x00FF00CE
#define COLOR_WHITE 0xFFFFFFAA 
Now for the whole code that i will explain it line by line
PHP код:
CMD:rob(playeridparams[])
{
new 
targetid;
new 
rob random(10);
if(
sscanf(params"u"targetid)) return SendClientMessage(playeridCOLOR_WHITE"Usage: /rob [id]");
if(!
IsPlayerConnected(targetid)) return SendClientMessage(playeridCOLOR_RED"This player is not connected");
new 
Float:xFloat:yFloat:z;
GetPlayerPos(targetidxyz);
if(!
IsPlayerInRangeOfPoint(playerid5xyz)) return SendClientMessage(playeridCOLOR_RED"This player is too far away");
if(
GetPlayerMoney(targetid) < 1000) return SendClientMessage(playeridCOLOR_RED"This player doesn't have enough money");
new 
money GetPlayerMoney(targetid);
if(
rob == || rob == 1)
{
new 
name[MAX_PLAYER_NAME], string[24+MAX_PLAYER_NAME];
GetPlayerName(playeridnamesizeof(name));
new 
name2[MAX_PLAYER_NAME], string1[24+MAX_PLAYER_NAME];
GetPlayerName(targetidname2sizeof(name2));
GivePlayerMoney(playeridmoney 10);
GivePlayerMoney(targetid, -money 10);
format(string,sizeof(string),"%s has robbed %s",namename2);
SendClientMessageToAll(COLOR_GREEN,string);
format(string,sizeof(string),"You robbed $%d"money/10);
SendClientMessage(playerid,COLOR_SILVER,string);
format(string,sizeof(string),"You got robbed and lost $%d"money/10);
SendClientMessage(targetid,COLOR_SILVER,string);
}
else if(
rob == || rob == 4)
{
new 
name[MAX_PLAYER_NAME], string[24+MAX_PLAYER_NAME];
GetPlayerName(playeridnamesizeof(name));
new 
name2[MAX_PLAYER_NAME], string1[24+MAX_PLAYER_NAME];
GetPlayerName(targetidname2sizeof(name2));
GivePlayerMoney(playeridmoney 20);
GivePlayerMoney(targetid, -money 20);
format(string,sizeof(string),"%s has robbed %s",namename2);
SendClientMessageToAll(COLOR_GREEN,string);
format(string,sizeof(string),"You robbed $%d"money/20);
SendClientMessage(playerid,COLOR_SILVER,string);
format(string,sizeof(string),"You got robbed and lost $%d"money/20);
SendClientMessage(targetid,COLOR_SILVER,string);
}
else if(
rob == || rob == 6)
{
new 
name[MAX_PLAYER_NAME], string[24+MAX_PLAYER_NAME];
GetPlayerName(playeridnamesizeof(name));
new 
name2[MAX_PLAYER_NAME], string1[24+MAX_PLAYER_NAME];
GetPlayerName(targetidname2sizeof(name2));
GivePlayerMoney(playeridmoney 5);
GivePlayerMoney(targetid, -money 5);
format(string,sizeof(string),"%s has robbed %s",namename2);
SendClientMessageToAll(COLOR_GREEN,string);
format(string,sizeof(string),"You robbed $%d"money/5);
SendClientMessage(playerid,COLOR_SILVER,string);
format(string,sizeof(string),"You got robbed and lost $%d"money/5);
SendClientMessage(targetid,COLOR_SILVER,string);
}
else
{
new 
name[MAX_PLAYER_NAME], string[24+MAX_PLAYER_NAME];
GetPlayerName(playeridnamesizeof(name));
new 
name2[MAX_PLAYER_NAME], string1[24+MAX_PLAYER_NAME];
GetPlayerName(targetidname2sizeof(name2));
format(string,sizeof(string),"%s noticed you, Run away or he can kill you !"name2);
SendClientMessage(playeridCOLOR_REDstring);
format(string,sizeof(string), "%s tried to rob you and failed you can now kill him !"name);
SendClientMessage(targetidCOLOR_REDstring);
format(string1,sizeof(string1),"%s tried to rob %s and failed"namename2);
SendClientMessageToAll(COLOR_GREEN,string1);
}
return 
1;

Now for the explain
PHP код:
CMD:rob(playeridparams[])

The command of course
PHP код:
new targetid
Here, we store the id that the player will rob.
PHP код:
new rob random(10); 
This line is very important, we use it to make random between 10 numbers
And you will know why later......
PHP код:
if(sscanf(params"u"targetid)) return SendClientMessage(playeridCOLOR_WHITE"Usage: /rob [id]"); 
This line is used to check if the player wrote the command right or not and store the target id the player will rob
PHP код:
 if(!IsPlayerConnected(targetid)) return SendClientMessage(playeridCOLOR_RED"This player is not connected"); 
Check if the id that the player wrote connected or not and if not send to the player a message
PHP код:
if(playerid == targetid) return SendClientMessage(playeridCOLOR_RED“You can’t rob yourself”); 
Check if the target id that the player write equal to the player id who write the command if yes send him a message
PHP код:
new Float:xFloat:yFloat:z
Define the x , y, z position that will be used now
PHP код:
GetPlayerPos(targetidxyz); 
As i said we use this line to get the position of the target id
PHP код:
if(!IsPlayerInRangeOfPoint(playerid5xyz)) return SendClientMessage(playeridCOLOR_RED"This player is too far away"); 
Also this line is importnat because it check if the player who wrote the command is near to the player who he wrote his id or not if not send to him a message
PHP код:
if(GetPlayerMoney(targetid) < 1000) return SendClientMessage(playeridCOLOR_RED"This player doesn't have enough money"); 
This line to check if the player money is more than 1000 or not if not send him a message “You can change it as you want”)
PHP код:
new money GetPlayerMoney(targetid); 
Store the targetid money
PHP код:
if(rob == || rob == 1)

Do you rembember the random that i said that it is important now we use it if the random number equal 0 or 1......
PHP код:
new name[MAX_PLAYER_NAME], string[24+MAX_PLAYER_NAME];
GetPlayerName(playeridnamesizeof(name));
new 
name2[MAX_PLAYER_NAME], string1[24+MAX_PLAYER_NAME];
GetPlayerName(targetidname2sizeof(name2)); 
We use these lines to get the player name and the targetid name and store them
PHP код:
GivePlayerMoney(playeridmoney 10); 
Give the player who wrote the command the targetid money that we stored it before after divide it on 10 (This is in the case if the random equal 0 or 1)
PHP код:
GivePlayerMoney(targetid, -money 10); 
To subtract from the target id the amount of money that the player robbed
PHP код:
format(string,sizeof(string),"%s has robbed %s",namename2);
SendClientMessageToAll(COLOR_GREEN,string);
format(string,sizeof(string),"You robbed $%d"money/10);
SendClientMessage(playerid,COLOR_SILVER,string);
format(string,sizeof(string),"You got robbed and lost $%d"money/10);
SendClientMessage(targetid,COLOR_SILVER,string);

And all of these is messages you can do in it what do you want
PHP код:
else if(rob == || rob == 4)

Now another case if the random equal 2 or 4......
PHP код:
new name[MAX_PLAYER_NAME], string[24+MAX_PLAYER_NAME];
GetPlayerName(playeridnamesizeof(name));
new 
name2[MAX_PLAYER_NAME], string1[24+MAX_PLAYER_NAME];
GetPlayerName(targetidname2sizeof(name2)); 
Also get the players name
PHP код:
GivePlayerMoney(playeridmoney 20); 
Give the player money but after divide it on 20 this time
PHP код:
GivePlayerMoney(targetid, -money 20); 
Also to subtract the money from the target id
PHP код:
format(string,sizeof(string),"%s has robbed %s",namename2);
SendClientMessageToAll(COLOR_GREEN,string);
format(string,sizeof(string),"You robbed $%d"money/20);
SendClientMessage(playerid,COLOR_SILVER,string);
format(string,sizeof(string),"You got robbed and lost $%d"money/20);
SendClientMessage(targetid,COLOR_SILVER,string);

And also all of these is messages you can do in it what do you want
PHP код:
else if(rob == || rob == 6)

Another case if the random equal 5 or 6
PHP код:
new name[MAX_PLAYER_NAME], string[24+MAX_PLAYER_NAME];
GetPlayerName(playeridnamesizeof(name));
new 
name2[MAX_PLAYER_NAME], string1[24+MAX_PLAYER_NAME];
GetPlayerName(targetidname2sizeof(name2)); 
Also get the players name
PHP код:
GivePlayerMoney(playeridmoney 5); 
Give the player who write the command money but after divide it on 5
PHP код:
GivePlayerMoney(targetid, -money 5); 
Subtract the money from the target id
PHP код:
format(string,sizeof(string),"%s has robbed %s",namename2);
SendClientMessageToAll(COLOR_GREEN,string);
format(string,sizeof(string),"You robbed $%d"money/5);
SendClientMessage(playerid,COLOR_SILVER,string);
format(string,sizeof(string),"You got robbed and lost $%d"money/5);
SendClientMessage(targetid,COLOR_SILVER,string);

And also these is messages you can do in it what do you want
PHP код:
else

If the random equal another numbers
PHP код:
new name[MAX_PLAYER_NAME], string[24+MAX_PLAYER_NAME];
GetPlayerName(playeridnamesizeof(name));
new 
name2[MAX_PLAYER_NAME], string1[24+MAX_PLAYER_NAME];
GetPlayerName(targetidname2sizeof(name2));
format(string,sizeof(string),"%s noticed you, Run away or he can kill you !"name2);
SendClientMessage(playeridCOLOR_REDstring);
format(string,sizeof(string), "%s tried to rob you and failed you can now kill him !"name);
SendClientMessage(targetidCOLOR_REDstring);
format(string1,sizeof(string1),"%s tried to rob %s and failed"namename2);
SendClientMessageToAll(COLOR_GREEN,string1);

Get the player name and inform the players what happen and don’t give or subtract money from any one (The robbery fail !)
PHP код:
return 1;

The end of the command

End of the tutorial hope i will help you
Ahmed_Nezoo
Reply
#2

nice tut
Reply
#3

Thank you
Reply
#4

When im met u, u were nub at scripting xD.

But now, i'm impressed. Good job.
Reply
#5

Thank you xD
Reply
#6

This will give errors:
- You forgot to #include <sscanf2>
- You used some color-defines in the command that you did not define at the top of the script.
Reply
#7

Ok thank you i will edit it
Reply
#8

Nice tutorial...
Reply
#9

Good job mate
Reply
#10

Thank you all
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)