/GIVECASH PROBLEM -
AwokenNeoX - 31.10.2015
Hello guys,
I made a /givecash command for my script. I want this:
/givecash Player1 100
If I send a player money I see in the chat:
* You sent $100 to player1
and the player see in the chat:
* You have received $100 from player2
If I dont have amount money:
* Sorry, invalid transaction... you dont have $100.
If I try to give myself money:
* Sorry, you cannot give cash to yourself!
If I typed the command wrong:
** Usage: /givecash <PlayerID/PlayerName> <MoneyAmount>
* Gives the specified amount of your money to the player specified.
My Command:
Код:
CMD:givecash(playerid, params[])
{
new player, amount,name1[24], name2[24], string[128];
if(!sscanf(params, "ui",player,amount))
{
if(playerid != player)
{
if(GetPlayerMoney(playerid) >= amount)
{
GetPlayerName(playerid, name1, 24);
GetPlayerName(player, name2, 24);
format(string, sizeof(string), "* You send $%d to %s",amount,name2);
SendClientMessage(playerid, COLOR_GREY2, string);
format(string, sizeof(string), "* You have received $%d from %s", amount, name1);
SendClientMessage(player, COLOR_GREY2, string);
GivePlayerMoney(playerid, -amount);
GivePlayerMoney(player, amount);
}
else return
format(string, sizeof(string), "* Sorry, invalid transaction... you dont have $%d!",amount);
SendClientMessage(playerid, COLOR_ERROR_YELLOW, string);
}
else return SendClientMessage(playerid, COLOR_ERROR_YELLOW,"* Sorry, you cannot give cash to yourself!");
}
else return
SendClientMessage(playerid, COLOR_ERROR_YELLOW,"** Usage: /givecash <PlayerID/PlayerName> <MoneyAmount>");
SendClientMessage(playerid, COLOR_ERROR_YELLOW,"* Gives the specified amount of your money to the player specified.");
return 1;
}
There is only a problem with the SendClientMessages.
AW: /GIVECASH PROBLEM -
AwokenNeoX - 31.10.2015
Код:
else return
SendClientMessage(playerid, COLOR_ERROR_YELLOW,"** Usage: /givecash <PlayerID/PlayerName> <MoneyAmount>");
SendClientMessage(playerid, COLOR_ERROR_YELLOW,"* Gives the specified amount of your money to the player specified.");
return 1;
Is it allowed to write 2 SendClientMessage under else return `?
Re: /GIVECASH PROBLEM -
thaKing - 31.10.2015
PHP код:
ReturnName(playerid, underscore=1) // by Emmet_
{
static
name[MAX_PLAYER_NAME + 1];
GetPlayerName(playerid, name, sizeof(name));
if (!underscore) {
for (new i = 0, len = strlen(name); i < len; i ++) {
if (name[i] == '_') name[i] = ' ';
}
}
return name;
}
CMD:givecash(playerid, params[])
{
new userid, amount, str[128];
if (!sscanf(params, "ui", userid, armount))
return SendClientMessage(playerid, -1, "usage: /givecash [playerid/name] [amount]");
if (userid == playerid || !IsPlayerConnected(userid) || !IsPlayerConnected(playerid))
return SendClientMessage(playerid, -1, "error: You have entered an invalid playerid/name!");
if (amount < 0 || amount > GetPlayerMoney(playerid))
return SendClientMessage(playerid, -1, "error: You have entered an invalid amount!");
GivePlayerMoney(playerid, -amount);
GivePlayerMoney(userid, amount);
format(str, sizeof(str), "info: You have received $%i from %s.", amount, ReturnName(playerid, 0));
SendClientMessage(userid, -1, str);
format(str, sizeof(str), "info: You have given $%i from %s.", amount, ReturnName(userid, 0));
SendClientMessage(playerid, -1, str);
retrun 1;
}
AW: /GIVECASH PROBLEM -
AwokenNeoX - 31.10.2015
No, my Command is working but he shows all SendClientMessages.
Re: /GIVECASH PROBLEM -
Matess - 31.10.2015
PHP код:
CMD:givecash(playerid, params[])
{
new player, amount,name1[24], name2[24], string[128];
if(!sscanf(params, "ui",player,amount))
{
if(playerid != player)
{
if(GetPlayerMoney(playerid) >= amount)
{
GetPlayerName(playerid, name1, 24);
GetPlayerName(player, name2, 24);
format(string, sizeof(string), "* You send $%d to %s",amount,name2);
SendClientMessage(playerid, COLOR_GREY2, string);
format(string, sizeof(string), "* You have received $%d from %s", amount, name1);
SendClientMessage(player, COLOR_GREY2, string);
GivePlayerMoney(playerid, -amount);
GivePlayerMoney(player, amount);
return 1;
}
else {
format(string, sizeof(string), "* Sorry, invalid transaction... you dont have $%d!",amount);
return SendClientMessage(playerid, COLOR_ERROR_YELLOW, string);}
}
else return SendClientMessage(playerid, COLOR_ERROR_YELLOW,"* Sorry, you cannot give cash to yourself!");
}
else {
SendClientMessage(playerid, COLOR_ERROR_YELLOW,"** Usage: /givecash <PlayerID/PlayerName> <MoneyAmount>");
return SendClientMessage(playerid, COLOR_ERROR_YELLOW,"* Gives the specified amount of your money to the player specified.");}
}
AW: /GIVECASH PROBLEM -
AwokenNeoX - 31.10.2015
Finally, it's perfect. Thank you so much
(REP+)