Commands crash server - 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)
+--- Thread: Commands crash server (
/showthread.php?tid=615128)
Commands crash server -
LennyBE - 17.08.2016
Hi!
Both of the commands below crash the server when used and I don't see any problem with them.
Код:
CMD:armor(playerid, params[])
{
static Armor;
if(pData[playerid][Rank] < 1) return SendErrorMessage(playerid, "You must be atleast a Recruit to do this.");
if(sscanf(params, "i", Armor)) return SendSyntaxMessage(playerid, "/armor [value]");
if(Armor < 0 || Armor > 125) return SendErrorMessage(playerid, "Invalid amount.");
SetPlayerArmour(playerid, Armor);
CommandMsg(COLOR_RED, "%s (%d) has set their armor to %d.", ReturnName(playerid, 0), playerid, Armor);
SendClientMessageEx(playerid, -1, "You have set your armor to %d.", Armor);
return 1;
}
Код:
CMD:hp(playerid, params[])
{
static hp;
if(pData[playerid][Rank] < 1) return SendErrorMessage(playerid, "You must be atleast a Recruit to do this.");
if(sscanf(params, "i", hp)) return SendSyntaxMessage(playerid, "/hp [value]");
if(hp < 0 || hp > 125) return SendErrorMessage(playerid, "Invalid amount.");
SetPlayerHealth(playerid, hp);
CommandMsg(COLOR_RED, "%s (%d) has set their health to %d.", ReturnName(playerid, 0), playerid, hp);
SendClientMessageEx(playerid, -1, "You have set your health to %d.", hp);
return 1;
}
Would appreciate any help.
EDIT: Commenting the 'CommandMsg' function worked, doesn't crash anymore.
I use it on other functions too and it doesn't crash though, is there anything wrong?
Код:
forward CommandMsg(color, message[]);
public CommandMsg(color, message[])
{
new string[128];
format(string, sizeof(string), "%s", message);
for(new i = 0; i < MAX_PLAYERS; i++)
{
if(IsPlayerConnected(i))
{
if(pData[i][Rank] >= 6)
{
SendClientMessage(i, color, string);
}
}
}
}
Re: Commands crash server -
Konstantinos - 17.08.2016
Ignoring warnings results to such things. You definitely got warning 202: number of arguments does not match definition and the cause of the crash is specifiers in client messages.
So you have three options:
1) Format and sending the message to those players whose rank is >= 6 (the standard way).
2) Use y_va (from YSI)
3) Wait for somebody with knowledge of #emit.