Have Problem please help - 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: Have Problem please help (
/showthread.php?tid=359476)
Have Problem please help -
rumen98 - 14.07.2012
Hey people tried to do a check command but it did nothing to try it on another player shows my stats I need for an RP I'm doing
PHP код:
CMD:check(playerid, params[])
{
new gamer;
new atext[128];
new atext2[128];
new nivo = PlayerInfo[playerid][Hungry];
new nivo2 = PlayerInfo[gamer][Hungry];
if(!IsPlayerAdmin(playerid))
return SendClientMessage(playerid, COLOR_RED, "Достъп отказан.");
if (sscanf(params, "u", gamer)) SendClientMessage(playerid, COLOR_RED, "Използвай: \"/check <Играч>");
else if (gamer == INVALID_PLAYER_ID) SendClientMessage(playerid, COLOR_RED, "Играча на е намерен");
else
{
format (atext, sizeof(atext), "Hungry on player:%d",nivo);
format (atext2, sizeof(atext2), "Hungry on player:%d",nivo2);
SendClientMessage(playerid, COLOR_PURPLE, atext2);
SendClientMessage(playerid, COLOR_PURPLE, atext);
}
return 1;
}
Re: Have Problem please help -
AndreT - 14.07.2012
Let me show you what you do here:
pawn Код:
new gamer;
new nivo2 = PlayerInfo[gamer][Hungry];
if(sscanf(params, "u", gamer)) // ...
The problem here is that you get the value of PlayerInfo[gamer][Hungry] before you even know what the gamer is supposed to be. So it always takes the Hungry value of player 0 (new variables are initialized with a 0 value).
What you need to do instead is:
pawn Код:
new gamer;
if(sscanf(params, "u", gamer))
{
// ...
}
new nivo2 = PlayerInfo[gamer][Hungry];
This way, nivo2 will have a proper value.
Also what you do here:
pawn Код:
format (atext, sizeof(atext), "Hungry on player:%d",nivo);
format (atext2, sizeof(atext2), "Hungry on player:%d",nivo2);
SendClientMessage(playerid, COLOR_PURPLE, atext2);
SendClientMessage(playerid, COLOR_PURPLE, atext);
This uses 2 arrays to send these text lines, you could instead use only one:
pawn Код:
format(atext, sizeof(atext), "Hungry on player: %d", nivo);
SendClientMessage(playerid, COLOR_PURPLE, atext);
format(atext, sizeof(atext), "Hungry on player: %d", nivo2);
SendClientMessage(playerid, COLOR_PURPLE, atext);
Re: Have Problem please help -
rumen98 - 14.07.2012
Quote:
Originally Posted by AndreT
Let me show you what you do here:
pawn Код:
new gamer; new nivo2 = PlayerInfo[gamer][Hungry];
if(sscanf(params, "u", gamer)) // ...
The problem here is that you get the value of PlayerInfo[gamer][Hungry] before you even know what the gamer is supposed to be. So it always takes the Hungry value of player 0 (new variables are initialized with a 0 value).
What you need to do instead is:
pawn Код:
new gamer; if(sscanf(params, "u", gamer)) { // ... } new nivo2 = PlayerInfo[gamer][Hungry];
This way, nivo2 will have a proper value.
Also what you do here:
pawn Код:
format (atext, sizeof(atext), "Hungry on player:%d",nivo); format (atext2, sizeof(atext2), "Hungry on player:%d",nivo2); SendClientMessage(playerid, COLOR_PURPLE, atext2); SendClientMessage(playerid, COLOR_PURPLE, atext);
This uses 2 arrays to send these text lines, you could instead use only one:
pawn Код:
format(atext, sizeof(atext), "Hungry on player: %d", nivo); SendClientMessage(playerid, COLOR_PURPLE, atext); format(atext, sizeof(atext), "Hungry on player: %d", nivo2); SendClientMessage(playerid, COLOR_PURPLE, atext);
|
thanks i will try it