[help] strfind + sscanf.
#1

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.
Reply
#2

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.
Reply
#3

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?
Reply
#4

new Player = GetPlayerID(params, true);

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

Ok. I will try that. Thank You.
Reply
#6

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

Why you don't like that
Reply
#8

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.
Reply
#9

Errors? Then your compiler is dumb.
Reply
#10

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;
}
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)