SA-MP Forums Archive
[help] strfind + sscanf. - 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)
+---- Forum: Help Archive (https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: [help] strfind + sscanf. (/showthread.php?tid=132139)



[help] strfind + sscanf. - Martin_M - 06.03.2010

Hey.
Is there any tutoliar about sscanf using strfind.
For example i have a command:

Код:
new Player;
if(sscanf(params,"u",Player)) return SendClientMessage(playerid,COLOR,"Kick player: [ /kick player ]");
if(Player == INVALID_PLAYER_ID) return SendClientMessage(playerid,COLOR,"Player is not online.");
Kick(Player);
In this situation, i must to write player's name from left to right without missing any letter.
If my name
Quote:

Martin_Miller

So i must to write:
Quote:

/kick mart

But if i write like this:
Quote:

/kick in_Miller

It says like people is offline.
I think you got what i want to.

Thanks for help.


Re: [help] strfind + sscanf. - ¤Adas¤ - 06.03.2010

Try this:

pawn Код:
stock GetCharsCount(const string[], ...)
{
new Count, num = numargs();
for(new n = 1; n<num; n++) for(new i; i<strlen(string); i++) if(getarg(n, 0) && string[i] == getarg(n, 0)) Count++;
return Count;
}

stock GetNumericCharsCount(const string[]) return GetCharsCount(string, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57);

stock bool:GetNumericPartOfString(const string[], output[], &index)
{
new lenght = strlen(string);
if(!lenght || !GetNumericCharsCount(string)) return false;
while(index < lenght && !IsNumericChar(string[index])) index++;
new offset = index;
while(index < lenght && IsNumericChar(string[index])) output[index - offset] = string[index], index++;
return true;
}

stock GetPlayerID(const name[], bool:ignorecase = false)
{
new output[5], index;
for(new i; i<GetMaxPlayers(); i++) if(IsPlayerConnected(i)) if(strfind(Name(i), name, ignorecase) != -1) return i;
if(IsNumeric(name) && IsPlayerConnected(strval(name))) return strval(name);
if(GetNumericPartOfString(name, output, index)) if(IsPlayerConnected(strval(output))) return strval(output);
return INVALID_PLAYER_ID;
}
I hope, it will help you. HAND.


Re: [help] strfind + sscanf. - Martin_M - 06.03.2010

Quote:
Originally Posted by ¤Adas¤
Try this:

pawn Код:
stock GetCharsCount(const string[], ...)
{
new Count, num = numargs();
for(new n = 1; n<num; n++) for(new i; i<strlen(string); i++) if(getarg(n, 0) && string[i] == getarg(n, 0)) Count++;
return Count;
}

stock GetNumericCharsCount(const string[]) return GetCharsCount(string, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57);

stock bool:GetNumericPartOfString(const string[], output[], &index)
{
new lenght = strlen(string);
if(!lenght || !GetNumericCharsCount(string)) return false;
while(index < lenght && !IsNumericChar(string[index])) index++;
new offset = index;
while(index < lenght && IsNumericChar(string[index])) output[index - offset] = string[index], index++;
return true;
}

stock GetPlayerID(const name[], bool:ignorecase = false)
{
new output[5], index;
for(new i; i<GetMaxPlayers(); i++) if(IsPlayerConnected(i)) if(strfind(Name(i), name, ignorecase) != -1) return i;
if(IsNumeric(name) && IsPlayerConnected(strval(name))) return strval(name);
if(GetNumericPartOfString(name, output, index)) if(IsPlayerConnected(strval(output))) return strval(output);
return INVALID_PLAYER_ID;
}
I hope, it will help you. HAND.
Thank You. Just can you show me an example?


Re: [help] strfind + sscanf. - ¤Adas¤ - 06.03.2010

new Player = GetPlayerID(params, true);

And you don't have to use SSCANF for that.


Re: [help] strfind + sscanf. - Martin_M - 06.03.2010

Ok. I will try that. Thank You.


Re: [help] strfind + sscanf. - Martin_M - 06.03.2010

Nop. I don't like that.
Maybe someone have other ideas?


Re: [help] strfind + sscanf. - ¤Adas¤ - 06.03.2010

Why you don't like that


Re: [help] strfind + sscanf. - Martin_M - 06.03.2010

Quote:
Originally Posted by ¤Adas¤
Why you don't like that
Firstable: I don't know why, but it's starts to show errors.
Secondy: It's will be better, if it include sscanf.


Re: [help] strfind + sscanf. - ¤Adas¤ - 06.03.2010

Errors? Then your compiler is dumb.


Re: [help] strfind + sscanf. - ¤Adas¤ - 06.03.2010

Quote:
Originally Posted by Seif_
Quote:
Originally Posted by ¤Adas¤
Errors? Then your compiler is dumb.
No, you're not giving him the functions needed for this.
Oh, I am so sorry! I hope, here are all functions already.

pawn Код:
stock GetCharsCount(const string[], ...)
{
new Count, num = numargs();
for(new n = 1; n<num; n++) for(new i; i<strlen(string); i++) if(getarg(n, 0) && string[i] == getarg(n, 0)) Count++;
return Count;
}

stock GetNumericCharsCount(const string[]) return GetCharsCount(string, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57);

stock bool:IsNumericChar(character) return character > 46 && character < 58;

stock bool:IsNumeric(const string[]) return GetNumericCharsCount(string) == strlen(string);

stock bool:GetNumericPartOfString(const string[], output[], &index)
{
new lenght = strlen(string);
if(!lenght || !GetNumericCharsCount(string)) return false;
while(index < lenght && !IsNumericChar(string[index])) index++;
new offset = index;
while(index < lenght && IsNumericChar(string[index])) output[index - offset] = string[index], index++;
return true;
}

stock GetPlayerID(const name[], bool:ignorecase = false)
{
new output[5], index;
for(new i; i<GetMaxPlayers(); i++) if(IsPlayerConnected(i)) if(strfind(Name(i), name, ignorecase) != -1) return i;
if(IsNumeric(name) && IsPlayerConnected(strval(name))) return strval(name);
if(GetNumericPartOfString(name, output, index) && IsPlayerConnected(strval(output))) return strval(output);
return INVALID_PLAYER_ID;
}