help with /pay cmd -
bustern - 05.09.2013
PHP код:
CMD:pay(playerid, params[])
{
new otherid,cash,string[128],namez[MAX_PLAYER_NAME],names[MAX_PLAYER_NAME];
if (sscanf(params, "dd", otherid, cash)) SendClientMessage(playerid, COLOR_RED, "Usage: /pay [ID] [Cash]");
if(otherid == playerid) SendClientMessage(playerid, COLOR_RED, "It is pointless to pay yourself..");
else
{
if(GetPlayerMoney(playerid) < cash) SendClientMessage(playerid, COLOR_RED, "You don't have that much!");
else if(!IsPlayerConnected(otherid)) SendClientMessage(playerid, COLOR_RED, "That PlayerID is not connected!");
else
{
GivePlayerMoney(playerid, -cash);
GetPlayerName(otherid,names,sizeof(namez));
format(string,sizeof(string),"You gave $%d to %s",cash,names);
SendClientMessage(otherid,COLOR_BLUE,string);
}
{
GivePlayerMoney(otherid, cash);
GetPlayerName(playerid,namez,sizeof(namez));
format(string,sizeof(string),"%s gave you $%d",cash,namez);
SendClientMessage(otherid,COLOR_BLUE,string);
}
}
return 1;
}
Can someone help me ?When i try to pay to myself the error msg shows two times...And i want when you give cash to someone to show you a msg:You gave [] to[] and player who get cash to get msg:[]Gave you[]
Re: help with /pay cmd -
bustern - 06.09.2013
BUMP
Re: help with /pay cmd -
dusk - 06.09.2013
pawn Код:
format(string,sizeof(string),"You gave $%d to %s",cash,names);
SendClientMessage(otherid,COLOR_BLUE,string);
You should send this message to the player that called the function, "playerid".
Re: help with /pay cmd -
AaronKillz - 06.09.2013
Код:
CMD:pay(playerid, params[])
{
new otherid, cash, string[128], namez[MAX_PLAYER_NAME], names[MAX_PLAYER_NAME];
if(sscanf(params, "ud", otherid, cash)) return SendClientMessage(playerid, COLOR_RED, "Usage: /pay [ID] [Cash]");
if(!IsPlayerConnected(otherid)) return SendClientMessage(playerid, COLOR_RED, "That PlayerID is not connected!");
if(otherid == playerid) return SendClientMessage(playerid, COLOR_RED, "It is pointless to pay yourself..");
if(GetPlayerMoney(playerid) < cash) return SendClientMessage(playerid, COLOR_RED, "You don't have that much!");
GivePlayerMoney(playerid, -cash);
format(string, sizeof(string), "You gave $%d to %s", cash, GetPlayersName(names));
SendClientMessage(playerid, COLOR_BLUE, string);
GivePlayerMoney(otherid, cash);
format(string, sizeof(string), "%s gave you $%d", cash, GetPlayersName(namez));
SendClientMessage(otherid, COLOR_BLUE, string); //send the message to the other player
return 1;
}
GetPlayersName(playerid) //with this you don't always have to add "GetPlayerName" in every command
{
new playersName[MAX_PLAYER_NAME];
GetPlayerName(playerid, playersName, MAX_PLAYER_NAME);
return playersName;
}
I hope this is easier to understand.
You should indent and add a space after commas, it's easier to read.
Re: help with /pay cmd -
Dragonsaurus - 06.09.2013
I still see some minor mistakes:
pawn Код:
GetPlayerName(otherid, names, sizeof(namez)); // Name is assigned to "names" and sizeof is taken from "namez"...
format(string, sizeof(string), "%s gave you $%d", cash, namez); // "%s" assigned for cash and "$%d" assigned to the name...
Dusk and AaronKillz already gave you a solution, but here is the final code:
pawn Код:
CMD:pay(playerid, params[])
{
new otherid, cash, string[128], namez[MAX_PLAYER_NAME], names[MAX_PLAYER_NAME];
if (sscanf(params, "dd", otherid, cash)) SendClientMessage(playerid, COLOR_RED, "Usage: /pay [ID] [Cash]");
if(!IsPlayerConnected(otherid)) return SendClientMessage(playerid, COLOR_RED, "That PlayerID is not connected!");
if(otherid == playerid) return SendClientMessage(playerid, COLOR_RED, "It is pointless to pay yourself..");
if(GetPlayerMoney(playerid) < cash) return SendClientMessage(playerid, COLOR_RED, "You don't have that much!");
GivePlayerMoney(playerid, -cash);
GetPlayerName(otherid, names, sizeof(names));
format(string, sizeof(string), "You gave $%d to %s", cash, names);
SendClientMessage(playerid, COLOR_BLUE, string);
GivePlayerMoney(otherid, cash);
GetPlayerName(playerid, namez, sizeof(namez));
format(string, sizeof(string), "%s gave you $%d", namez, cash);
SendClientMessage(otherid, COLOR_BLUE, string);
return 1;
}
Re: help with /pay cmd -
bustern - 06.09.2013
Now i cant pay, if i use /pay it returns:its poitness to pay to yourself..
Re: help with /pay cmd -
Dragonsaurus - 06.09.2013
EDIT: Oh I found it: You should add a "return" after sscanf(...).
pawn Код:
if(sscanf(params, "ud", otherid, cash)) return SendClientMessage(...).
Important: Always use "u" specifier for player ids in sscanf!
Re: help with /pay cmd -
bustern - 06.09.2013
Nope, when i just use /pay or /pay 8 100(i am not ID

it return this value
Re: help with /pay cmd -
Dragonsaurus - 06.09.2013
Read my edited post above.
Re: help with /pay cmd -
AaronKillz - 06.09.2013
Look at my code again, seems like I've overlooked that.