05.01.2015, 13:40
(
Последний раз редактировалось nezo2001; 05.01.2015 в 18:57.
)
As every time i was searching for one and i didn't find so i decided to make it
First the includes
and define some colors
Now for the whole code that i will explain it line by line
Now for the explain
The command of course
Here, we store the id that the player will rob.
This line is very important, we use it to make random between 10 numbers
And you will know why later......
This line is used to check if the player wrote the command right or not and store the target id the player will rob
Check if the id that the player wrote connected or not and if not send to the player a message
Check if the target id that the player write equal to the player id who write the command if yes send him a message
Define the x , y, z position that will be used now
As i said we use this line to get the position of the target id
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
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”)
Store the targetid money
Do you rembember the random that i said that it is important now we use it if the random number equal 0 or 1......
We use these lines to get the player name and the targetid name and store them
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)
To subtract from the target id the amount of money that the player robbed
And all of these is messages you can do in it what do you want
Now another case if the random equal 2 or 4......
Also get the players name
Give the player money but after divide it on 20 this time
Also to subtract the money from the target id
And also all of these is messages you can do in it what do you want
Another case if the random equal 5 or 6
Also get the players name
Give the player who write the command money but after divide it on 5
Subtract the money from the target id
And also these is messages you can do in it what do you want
If the random equal another numbers
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
Rob Command
for Role-Play serversFirst the includes
PHP код:
#include <a_samp>
#include <zcmd>
#include <sscanf2>
PHP код:
#define COLOR_RED 0xFF0000AA
#define COLOR_GREEN 0x00FF00CE
#define COLOR_WHITE 0xFFFFFFAA
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;
}
PHP код:
CMD:rob(playerid, params[])
{
PHP код:
new targetid;
PHP код:
new rob = random(10);
And you will know why later......
PHP код:
if(sscanf(params, "u", targetid)) return SendClientMessage(playerid, COLOR_WHITE, "Usage: /rob [id]");
PHP код:
if(!IsPlayerConnected(targetid)) return SendClientMessage(playerid, COLOR_RED, "This player is not connected");
PHP код:
if(playerid == targetid) return SendClientMessage(playerid, COLOR_RED, “You can’t rob yourself”);
PHP код:
new Float:x, Float:y, Float:z;
PHP код:
GetPlayerPos(targetid, x, y, z);
PHP код:
if(!IsPlayerInRangeOfPoint(playerid, 5, x, y, z)) return SendClientMessage(playerid, COLOR_RED, "This player is too far away");
PHP код:
if(GetPlayerMoney(targetid) < 1000) return SendClientMessage(playerid, COLOR_RED, "This player doesn't have enough money");
PHP код:
new money = GetPlayerMoney(targetid);
PHP код:
if(rob == 0 || rob == 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));
PHP код:
GivePlayerMoney(playerid, money / 10);
PHP код:
GivePlayerMoney(targetid, -money / 10);
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);
}
PHP код:
else if(rob == 2 || rob == 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));
PHP код:
GivePlayerMoney(playerid, money / 20);
PHP код:
GivePlayerMoney(targetid, -money / 20);
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);
}
PHP код:
else if(rob == 5 || rob == 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));
PHP код:
GivePlayerMoney(playerid, money / 5);
PHP код:
GivePlayerMoney(targetid, -money / 5);
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);
}
PHP код:
else
{
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);
}
PHP код:
return 1;
}
End of the tutorial hope i will help you
Ahmed_Nezoo