Rob Command -
nezo2001 - 05.01.2015
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(playerid, params[])
{
new targetid;
new rob = random(10);
if(sscanf(params, "u", targetid)) return SendClientMessage(playerid, COLOR_WHITE, "Usage: /rob [id]");
if(!IsPlayerConnected(targetid)) return SendClientMessage(playerid, COLOR_RED, "This player is not connected");
new Float:x, Float:y, Float:z;
GetPlayerPos(targetid, x, y, z);
if(!IsPlayerInRangeOfPoint(playerid, 5, x, y, z)) return SendClientMessage(playerid, COLOR_RED, "This player is too far away");
if(GetPlayerMoney(targetid) < 1000) return SendClientMessage(playerid, COLOR_RED, "This player doesn't have enough money");
new money = GetPlayerMoney(targetid);
if(rob == 0 || rob == 1)
{
new name[MAX_PLAYER_NAME], string[24+MAX_PLAYER_NAME];
GetPlayerName(playerid, name, sizeof(name));
new name2[MAX_PLAYER_NAME], string1[24+MAX_PLAYER_NAME];
GetPlayerName(targetid, name2, sizeof(name2));
GivePlayerMoney(playerid, money / 10);
GivePlayerMoney(targetid, -money / 10);
format(string,sizeof(string),"%s has robbed %s",name, name2);
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 == 2 || rob == 4)
{
new name[MAX_PLAYER_NAME], string[24+MAX_PLAYER_NAME];
GetPlayerName(playerid, name, sizeof(name));
new name2[MAX_PLAYER_NAME], string1[24+MAX_PLAYER_NAME];
GetPlayerName(targetid, name2, sizeof(name2));
GivePlayerMoney(playerid, money / 20);
GivePlayerMoney(targetid, -money / 20);
format(string,sizeof(string),"%s has robbed %s",name, name2);
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 == 5 || rob == 6)
{
new name[MAX_PLAYER_NAME], string[24+MAX_PLAYER_NAME];
GetPlayerName(playerid, name, sizeof(name));
new name2[MAX_PLAYER_NAME], string1[24+MAX_PLAYER_NAME];
GetPlayerName(targetid, name2, sizeof(name2));
GivePlayerMoney(playerid, money / 5);
GivePlayerMoney(targetid, -money / 5);
format(string,sizeof(string),"%s has robbed %s",name, name2);
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(playerid, name, sizeof(name));
new name2[MAX_PLAYER_NAME], string1[24+MAX_PLAYER_NAME];
GetPlayerName(targetid, name2, sizeof(name2));
format(string,sizeof(string),"%s noticed you, Run away or he can kill you !", name2);
SendClientMessage(playerid, COLOR_RED, string);
format(string,sizeof(string), "%s tried to rob you and failed you can now kill him !", name);
SendClientMessage(targetid, COLOR_RED, string);
format(string1,sizeof(string1),"%s tried to rob %s and failed", name, name2);
SendClientMessageToAll(COLOR_GREEN,string1);
}
return 1;
}
Now for the explain
PHP код:
CMD:rob(playerid, params[])
{
The command of course
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(playerid, COLOR_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(playerid, COLOR_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(playerid, COLOR_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:x, Float:y, Float:z;
Define the x , y, z position that will be used now
PHP код:
GetPlayerPos(targetid, x, y, z);
As i said we use this line to get the position of the target id
PHP код:
if(!IsPlayerInRangeOfPoint(playerid, 5, x, y, z)) return SendClientMessage(playerid, COLOR_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(playerid, COLOR_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 == 0 || 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(playerid, name, sizeof(name));
new name2[MAX_PLAYER_NAME], string1[24+MAX_PLAYER_NAME];
GetPlayerName(targetid, name2, sizeof(name2));
We use these lines to get the player name and the targetid name and store them
PHP код:
GivePlayerMoney(playerid, money / 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",name, name2);
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 == 2 || rob == 4)
{
Now another case if the random equal 2 or 4......
PHP код:
new name[MAX_PLAYER_NAME], string[24+MAX_PLAYER_NAME];
GetPlayerName(playerid, name, sizeof(name));
new name2[MAX_PLAYER_NAME], string1[24+MAX_PLAYER_NAME];
GetPlayerName(targetid, name2, sizeof(name2));
Also get the players name
PHP код:
GivePlayerMoney(playerid, money / 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",name, name2);
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 == 5 || rob == 6)
{
Another case if the random equal 5 or 6
PHP код:
new name[MAX_PLAYER_NAME], string[24+MAX_PLAYER_NAME];
GetPlayerName(playerid, name, sizeof(name));
new name2[MAX_PLAYER_NAME], string1[24+MAX_PLAYER_NAME];
GetPlayerName(targetid, name2, sizeof(name2));
Also get the players name
PHP код:
GivePlayerMoney(playerid, money / 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",name, name2);
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
If the random equal another numbers
PHP код:
new name[MAX_PLAYER_NAME], string[24+MAX_PLAYER_NAME];
GetPlayerName(playerid, name, sizeof(name));
new name2[MAX_PLAYER_NAME], string1[24+MAX_PLAYER_NAME];
GetPlayerName(targetid, name2, sizeof(name2));
format(string,sizeof(string),"%s noticed you, Run away or he can kill you !", name2);
SendClientMessage(playerid, COLOR_RED, string);
format(string,sizeof(string), "%s tried to rob you and failed you can now kill him !", name);
SendClientMessage(targetid, COLOR_RED, string);
format(string1,sizeof(string1),"%s tried to rob %s and failed", name, name2);
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 !)
The end of the command
End of the tutorial hope i will help you
Ahmed_Nezoo
Re: Rob Command -
Cyber123 - 05.01.2015
nice tut
Re: Rob Command -
nezo2001 - 05.01.2015
Thank you
Re: Rob Command -
Glossy42O - 05.01.2015
When im met u, u were nub at scripting xD.
But now, i'm impressed. Good job.
Re: Rob Command -
nezo2001 - 05.01.2015
Thank you
xD
Re: Rob Command -
Schneider - 05.01.2015
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.
Re: Rob Command -
nezo2001 - 05.01.2015
Ok thank you i will edit it
Re: Rob Command -
TheRaGeLord - 06.01.2015
Nice tutorial...
Re: Rob Command -
Arastair - 06.01.2015
Good job mate
Re: Rob Command -
nezo2001 - 06.01.2015
Thank you all