SSCANF and DCMD on 0.3 -
virspector - 19.10.2009
I tried to make my own PM function, the code is like this:
pawn Код:
dcmd_pm(playerid, params[])
{
new string[128];
new id;
new message;
new namax[MAX_PLAYERS];
new namax2[MAX_PLAYERS];
if(sscanf(params,"us",id,message))
{
SendClientMessage(playerid, COLOR_ERROR, "<~> Wrong Usage! Correct Usage: /pm <playerid> <message> <~>");
}
else if(id == INVALID_PLAYER_ID)
{
SendClientMessage(playerid, COLOR_ERROR, "<~> Player doesn't exist <~>");
}
else
{
GetPlayerName(playerid, namax, sizeof(namax));
GetPlayerName(id, namax2, sizeof(namax2));
format(string, sizeof(string), "[PM %s (%i) -> %s (%i)] %s", namax, playerid, namax2, id, message);
SendClientMessage(l_green,playerid, string);
format(string, sizeof(string), "[PM %s (%i) <- %s {%i)] %s", namax, id, namax2, playerid, message);
SendClientMessage(l_green,id,string);
}
return 1;
}
And i got no error when compiling.
Now, when i typed
/pm [id] TEST in Game, there is nothing happened.
Why this doesn't work. Pleaze helpz, z0r!
Re: SSCANF and DCMD on 0.3 -
Andom - 19.10.2009
Not SA:MP 0.3's fault, but yours:
Код:
dcmd_pm(playerid, params[])
{
new string[128];
new namax[MAX_PLAYER_NAME];
new namax2[MAX_PLAYER_NAME];
new id, message[128];
if(sscanf(params,"ds",id,message))
{
SendClientMessage(playerid, COLOR_ERROR, "<~> Wrong Usage! Correct Usage: /pm <playerid> <message> <~>");
}
else if(id == INVALID_PLAYER_ID)
{
SendClientMessage(playerid, COLOR_ERROR, "<~> Player doesn't exist <~>");
}
else
{
GetPlayerName(playerid, namax, sizeof(namax));
GetPlayerName(id, namax2, sizeof(namax2));
format(string, sizeof(string), "[PM %s (%i) -> %s (%i)] %s", namax, playerid, namax2, id, message);
SendClientMessage(l_green,playerid, string);
format(string, sizeof(string), "[PM %s (%i) <- %s {%i)] %s", namax, id, namax2, playerid, message);
SendClientMessage(l_green,id,string);
}
return 1;
}
You forgot to make a string of new massage;
It had to be: new message[128];
And you used too big arrays for namax & namax.
Can an admin please move this to ''Scripting discussion''?
Re: SSCANF and DCMD on 0.3 - Zeex - 19.10.2009
Change
pawn Код:
SendClientMessage(l_green,id,string);
SendClientMessage(l_green,playerid, string);
to
pawn Код:
SendClientMessage(id,l_green,string);
SendClientMessage(playerid,l_green,string);
Re: SSCANF and DCMD on 0.3 -
virspector - 19.10.2009
Thanks, z0r! Now, it works...!
PS: I am soo stupid... i already knows lots of ADVANCED codes of PAWNO scripting, but i forgot the BASIC