Problem with sscanf -
bustern - 04.09.2013
When i try to use my command:
PHP код:
CMD:akill(playerid,params[])
{
if(sscanf(params,"u",ID)) return SendClientMessage(playerid,COLOR_GREY,"USAGE: /akill [playerid / Partofname]");
if(!IsPlayerConnected(ID)) return SendClientMessage(playerid,COLOR_RED,"ERROR: This user is not connected!");
GetPlayerName(playerid,Nam,sizeof(Nam));
GetPlayerName(ID,pname,sizeof(pname));
format(str,sizeof(str),"Administrator %s has killed you",Nam);
SendClientMessage(ID,COLOR_ORANGE,str);
format(str,sizeof(str),"You have admin killed %s",pname);
SendClientMessage(playerid,COLOR_ORANGE,str);
SetPlayerHealth(ID,0);
return 1;
}
It always says :
"USAGE: /akill [playerid / Partofname]"
Server CMD:
sscanf erorystem not intialised
I am using the latest version of sscanf !
Re: Problem with sscanf -
Misiur - 04.09.2013
Make sure that:
1. In plugins folder you have sscanf.dll/sscanf.so (choose file accordingly to your OS)
2. In server.cfg you have sscanf/sscanf.so line (choose file accordingly to your OS)
3. In pawno/include there is file sscanf2.inc
If the problem persists, redownload latest package (
https://sampforum.blast.hk/showthread.php?tid=120356 )
Re: Problem with sscanf -
FabianoC - 04.09.2013
Make sure you use the correct amount of parameters for the correct amount of letters you provide your script to read.
Re: Problem with sscanf -
Dragonsaurus - 04.09.2013
pawn Код:
CMD:akill(playerid,params[])
{
new Name[MAX_PLAYER_NAME], pname[MAX_PLAYER_NAME], str[128];
new ID = ReturnUser(params));
if(sscanf(params,"u",ID)) return SendClientMessage(playerid,COLOR_GREY,"USAGE: /akill [playerid / Partofname]");
if(!IsPlayerConnected(ID)) return SendClientMessage(playerid,COLOR_RED,"ERROR: This user is not connected!");
GetPlayerName(playerid,Name,sizeof(Name));
GetPlayerName(ID,pname,sizeof(pname));
format(str,sizeof(str),"Administrator %s has killed you",Nam);
SendClientMessage(ID,COLOR_ORANGE,str);
format(str,sizeof(str),"You have admin killed %s",pname);
SendClientMessage(playerid,COLOR_ORANGE,str);
SetPlayerHealth(ID,0);
return 1;
}
Also you are going to need this stock (Put it at the end of your script):
pawn Код:
ReturnUser(text[], playerid = INVALID_PLAYER_ID)
{
new pos = 0;
while (text[pos] < 0x21)
{
if (text[pos] == 0) return INVALID_PLAYER_ID;
pos++;
}
new userid = INVALID_PLAYER_ID;
if (IsNumeric(text[pos]))
{
userid = strval(text[pos]);
if (userid >=0 && userid < MAX_PLAYERS)
{
if(!IsPlayerConnected(userid))
{
if (playerid != INVALID_PLAYER_ID) SendClientMessage(playerid, 0xFF0000AA, "User not connected");
userid = INVALID_PLAYER_ID;
}
else return userid;
}
else
{
if (playerid != INVALID_PLAYER_ID) SendClientMessage(playerid, 0xFF0000AA, "Invalid user ID");
userid = INVALID_PLAYER_ID;
}
return userid;
}
new len = strlen(text[pos]);
new count = 0;
new name[MAX_PLAYER_NAME];
for (new i = 0; i < MAX_PLAYERS; i++)
{
if (IsPlayerConnected(i))
{
GetPlayerName(i, name, sizeof (name));
if (strcmp(name, text[pos], true, len) == 0)
{
if (len == strlen(name)) return i;
else
{
count++;
userid = i;
}
}
}
}
if (count != 1)
{
if (playerid != INVALID_PLAYER_ID)
{
if (count) SendClientMessage(playerid, 0xFF0000AA, "Multiple users found, please narrow earch");
else SendClientMessage(playerid, 0xFF0000AA, "No matching user found");
}
userid = INVALID_PLAYER_ID;
}
return userid;
}