/givecookie bug
#1

I was updating my JMTDM script to new version and when I scripted this /givecookie CMD it bugged. When I type integer reason then it works good... Else if it's string then it bugs me with SERVER: Unknown command! Help me to fix that!

Код:
CMD:givecookie(playerid, params[]) // CMD for giving somebody a cookie
{
	new pid;
	new reason;
	new str[128];
	if(sscanf(params, "us", pid, reason)) return SendClientMessage(playerid, COLOR_WHITE, "USAGE: /givecookie [Player ID] [Reason]");
	if(!IsPlayerConnected(pid)) return SendClientMessage(playerid, COLOR_RED, "PlayerID is not connected.");
	if (PlayerInfo[playerid][pAdmin]>=4)
	{
	 format(str, sizeof(str), "%s have been granted a cookie by %s. Reason: %s", GetName(pid), GetName(playerid), reason);
	 SendClientMessageToAll(COLOR_RED, str);
	 format(str, sizeof(str), "You just gave a cookie to %s.", GetName(pid));
	 SendClientMessage(playerid, COLOR_RED, str);
	 PlayerInfo[playerid][pCookies]=PlayerInfo[playerid][pCookies]+1;
	}
	else SendClientMessage(playerid, COLOR_RED, "You must be an admin to use that command!");
 	return 1;
}
Reply
#2

pawn Код:
if(sscanf(params, "us[128]", pid..........
i think
Reply
#3

100 percent bug is in 2 lines i quess in those
pawn Код:
new str[144];
if(sscanf(params, "us[144]", pid, reason)) return SendClientMessage(playerid, COLOR_WHITE, "USAGE: /givecookie [Player ID] [Reason]");
Maybe this will work...Just dont add that variable for string!
Reply
#4

Yeah it bugs somewhere in the line
Код:
if(sscanf(params, "us", pid, reason))...
because it writes that it's unknown command and nothing happens.
I'll try to make s[128] as you suggested.
Reply
#5

More I found: If I type one letter, then it works. Why it doesn't work with 2+ letters?
Reply
#6

sscanf needs for string "s[value]". Also, you have to define reason as a string with array.
pawn Код:
CMD:givecookie(playerid, params[]) // CMD for giving somebody a cookie
{
    new pid;
    new reason[128];
    new str[128];
    if(sscanf(params, "us[128]", pid, reason)) return SendClientMessage(playerid, COLOR_WHITE, "USAGE: /givecookie [Player ID] [Reason]");
    if(!IsPlayerConnected(pid)) return SendClientMessage(playerid, COLOR_RED, "PlayerID is not connected.");
    if (PlayerInfo[playerid][pAdmin]>=4)
    {
     format(str, sizeof(str), "%s have been granted a cookie by %s. Reason: %s", GetName(pid), GetName(playerid), reason);
     SendClientMessageToAll(COLOR_RED, str);
     format(str, sizeof(str), "You just gave a cookie to %s.", GetName(pid));
     SendClientMessage(playerid, COLOR_RED, str);
     PlayerInfo[pid][pCookies] ++; // ++ -> x = x + 1
    }
    else SendClientMessage(playerid, COLOR_RED, "You must be an admin to use that command!");
    return 1;
}
Reply
#7

Let me check it..
Reply
#8

This works for now. Thanks.
Reply
#9

Also, I edited. That
pawn Код:
PlayerInfo[playerid][pCookies] ++;
should be
pawn Код:
PlayerInfo[pid][pCookies] ++;
Because it will give the cookie to the Admin and not at the pid!
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)