[HELP] DCMD & sscanf
#1

i just started to understand sscanf and i was wondering

https://sampwiki.blast.hk/wiki/Fast_Comm...mple_revisited

Код:
public OnPlayerCommandText(playerid, cmdtext[])
{
	dcmd(heal, 4, cmdtext);
	return 0;
}
 
dcmd_heal(playerid, params[])
{
	new
		id;
	if (sscanf(params, "u", id)) SendClientMessage(playerid, 0xFF0000AA, "Usage: \"/heal <playerid>\"");
	else if (id == INVALID_PLAYER_ID) SendClientMessage(playerid, 0xFF0000AA, "Player not found");
	else
	{
		SetPlayerHealth(id, 100.0);
		SendClientMessage(id, 0x00FF00AA, "You have been healed");
		SendClientMessage(playerid, 0x00FF00AA, "Player healed");
	}
	return 1;
}
from this example i put in a script

i tested ingame with friend and /heal always resulted to id 0

how can this be?, and how can i fix this?
sorry if u don't understand my typing

Thanks
Reply
#2

Well for one thing, you don't need sscanf if you only have one parameter. It's normally used for multiple parameters. And when using it, there is a certain format. In this part if (sscanf(params, "u", id)) the u should either be a d or an i which represent integers. You could just do this.

pawn Код:
dcmd_heal(playerid, params[])
{
    if(!params[0])//Checks if he didn't type anything for a paramter
        return SendClientMessage(playerid, 0xFF0000AA, "Usage: \"/heal <playerid>\"");

    new id = strval(params);//Convert the parameters(string) to an integer
    if (!IsPlayerConnected(id))//Is the id connected?
        return SendClientMessage(playerid, 0xFF0000AA, "Usage: \"/heal <playerid>\"");

    SetPlayerHealth(id, 100.0);
    SendClientMessage(id, 0x00FF00AA, "You have been healed");
    SendClientMessage(playerid, 0x00FF00AA, "Player healed");
    return 1;
}
Reply
#3

Quote:
Originally Posted by Backwardsman97
Well for one thing, you don't need sscanf if you only have one parameter. It's normally used for multiple parameters. And when using it, there is a certain format. In this part if (sscanf(params, "u", id)) the u should either be a d or an i which represent integers. You could just do this.
You are wrong here. Parameter 'u' is like returnuser and not just casual integer, so defenitely needed for such a command.
And I suggest you to use zcmd instead of dcmd since it's newer and faster method (and easier) -> http://forum.sa-mp.com/index.php?topic=116240.0
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)