Question sscanf "u" - 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: Question sscanf "u" (
/showthread.php?tid=375986)
Question sscanf "u" -
andrew2695 - 08.09.2012
When using the "u" parameter of sscanf, We can use the part of a name but it's only if we use the first letters...
Example: If someone is named SAMPForums and we do /command forum, it will return invalid player. We need to use /command SAMP. Do you know any way how to make the first method to work?
Re: Question sscanf "u" -
SuperViper - 08.09.2012
pawn Код:
GetPlayerWithPartName(part[])
{
if(part[0] >= '0' && part[0] <= '9')
{
return strval(part);
}
new playersName[MAX_PLAYER_NAME];
for(new i = 0; i < MAX_PLAYERS; i++)
{
if(IsPlayerConnected(i))
{
GetPlayerName(i, playersName, MAX_PLAYER_NAME);
if(strfind(playersName, part, true) > -1)
{
return i;
}
}
}
return INVALID_PLAYER_ID;
}
Usage:
pawn Код:
CMD:killplayer(playerid, params[])
{
new targetID = GetPlayerWithPartName(params);
if(targetID == INVALID_PLAYER_ID)
{
return SendClientMessage(playerid, -1, "Invalid player specified.");
}
SetPlayerHealth(targetID, 0.0);
return 1;
}
Re: Question sscanf "u" -
Opah - 08.09.2012
add this somewhere in ur script
pawn Код:
SSCANF:player_name(string[]) {
new foundplayer = INVALID_PLAYER_ID, name[MAX_PLAYER_NAME];
new bool:numeric = true;
for (new i = 0, c; (c = string[i]); i++) {
if (c < '0' || c > '9') {
numeric = false;
break;
}
}
if (numeric) {
foundplayer = strval(string);
if (IsPlayerConnected(foundplayer))
return foundplayer;
else
foundplayer = INVALID_PLAYER_ID;
}
foreach(new playerid : Player) {
GetPlayerName(playerid, name, sizeof(name));
if (strfind(name, string, true) != -1) {
if (foundplayer != INVALID_PLAYER_ID)
return INVALID_PLAYER_ID; // Multiple matches
else
foundplayer = playerid;
}
}
return foundplayer;
}
Credits Come Back To Slice
And Replace The
With
Re: Question sscanf "u" -
Babul - 08.09.2012
have a look at my "fingerprint" include:
http://forum.sa-mp.com/showthread.ph...59#post1880259
...it contains a custom "u" specifier ( k<who> ) aswell - feel free to modify it ofc