Bug in this command - Printable Version
+- SA-MP Forums Archive (
https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (
https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (
https://sampforum.blast.hk/forumdisplay.php?fid=12)
+---- Forum: Help Archive (
https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: Bug in this command (
/showthread.php?tid=94535)
Bug in this command -
_ERO_ - 30.08.2009
Hello... i have bug here.
Код:
dcmd_givecash(playerid,params[])
{
new tmp[256], idx;
tmp = strtok(params,idx);
if(!strlen(tmp))
{
SendClientMessage(playerid, COLOUR_RED, "Use: /givecash [playerid] [amount]");
return true;
}
new pid = strval(tmp);
if(!IsPlayerConnected(pid))
{
SendClientMessage(playerid, COLOUR_RED, "Incorrect playerid.");
return true;
}
tmp = strtok(params,idx);
if(!strlen(tmp))
{
SendClientMessage(playerid, COLOUR_RED, "Use: /givecash [playerid] [amount]");
return true;
}
new amount = strval(tmp), string[256], string1[256], pname2[MAX_PLAYER_NAME];
GetPlayerName(playerid, pname2, sizeof(pname2));
format(string, sizeof(string), "%s sent you $%d", pname2, amount);
format(string1, sizeof(string1), "You sent %s, $%d", pname2, amount);
SendClientMessage(pid,COLOUR_GREEN, string);
SendClientMessage(playerid,COLOUR_GREEN, string1);
GivePlayerMoney(pid, amount);
GivePlayerMoney(playerid, -amount);
return true;
}
How i tyoe /givecash (id) 100 i send to player 100$ no? is works, but i type /givecash (id) -100 i steal to the other player 100$
How i can fixed this?
Help me please
Re: Bug in this command -
Andom - 30.08.2009
Use strsscanf, not strtok.
Re: Bug in this command -
Correlli - 30.08.2009
Make an if statement and check if amount is > than 0.
Re: Bug in this command -
Vince - 30.08.2009
Here you go, a working code. Fixed also a couple of other small errors.
pawn Код:
dcmd_givecash(playerid,params[])
{
new
targetid,
amount;
if(sscanf(params, "ui", targetid, amount))
{
SendClientMessage(playerid, COLOUR_RED, "Use: /givecash [playerid] [amount]");
return true;
}
if(!IsPlayerConnected(targetid))
{
SendClientMessage(playerid, COLOUR_RED, "Incorrect playerid.");
return true;
}
if(amount < 1)
{
SendClientMessage(playerid, COLOUR_RED, "Invalid transaction amount");
return 1;
}
new
string[128],
pname[MAX_PLAYER_NAME],
pname2[MAX_PLAYER_NAME];
GetPlayerName(playerid, pname, sizeof(pname));
GetPlayerName(targetid, pname2, sizeof(pname2));
format(string, sizeof(string), "%s sent you $%d", pname, amount);
SendClientMessage(targetid,COLOUR_GREEN, string);
format(string, sizeof(string), "You sent %s, $%d", pname2, amount);
SendClientMessage(playerid,COLOUR_GREEN, string);
GivePlayerMoney(targetid, amount);
GivePlayerMoney(playerid, -amount);
return true;
}