[Weired]STRFIND a bit bugged - 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: [Weired]STRFIND a bit bugged (
/showthread.php?tid=189778)
[Weired]STRFIND a bit bugged -
DRIFT_HUNTER - 13.11.2010
Ok what i need is to allow my admin's join gang without invite (just with cmd /agangjoin [NAME])
So i need to find ID from name for gang(gang chat FS)
And i haved much problems now i solved it for a bit but there is still BIG problem
What happening is next
I create gang's
Test
Drift
LOOL
Test2
Test3
and if i search ID's for Drift,LOOL and Test2 it return me correct ID
But! if i search for Test ID it return me Test3 ID
Any idea why these happen and how to fix these?
Here is how i check for ID
pawn Код:
for(id = 0; id < MAX_GANGS; id++)
{
if(strfind(gangNames[id], params, true) != -1)
gangnum = id;
}
Re: [Weired]STRFIND a bit bugged -
iggy1 - 13.11.2010
Do you not think it would be better using strcmp? It would probably be more reliable than strfind.
EDIT: something like
pawn Код:
for(id = 0; id < MAX_GANGS; id++)
{
if(!strcmp(gangNames[id], params, true))
{
gangnum = id;
return 1;
}
}
SendClientMessage(playerid, 0xff0000FF, "Gang not found");
Re: [Weired]STRFIND a bit bugged -
Retardedwolf - 13.11.2010
pawn Код:
for(id = 0; id < MAX_GANGS; id++)
{
if ( !strcmp ( gangNames [ id ], params ) )
{
//...
}
}
Re: [Weired]STRFIND a bit bugged -
DRIFT_HUNTER - 13.11.2010
Gona try it...
Re: [Weired]STRFIND a bit bugged -
DRIFT_HUNTER - 13.11.2010
Quote:
Originally Posted by ******
You are searching for the string "Test" in the string "Test3" and is returning true - I'm not sure what the problem is. "Test3" contains the string you want.
|
Yes...but i need 100% match...any idea?
Re: [Weired]STRFIND a bit bugged -
Hal - 13.11.2010
Quote:
Originally Posted by Retardedwolf
pawn Код:
for(id = 0; id < MAX_GANGS; id++) { if ( !strcmp ( gangNames [ id ], params ) ) { //... } }
|
Thanks, only if someone could have helped me with that last night :P
Does this check if its the full match, or just part? so if the input was 560 would it find the string "560 - sultan"
Re: [Weired]STRFIND a bit bugged -
iggy1 - 13.11.2010
Quote:
Originally Posted by Hal
Thanks, only if someone could have helped me with that last night :P
Does this check if its the full match, or just part? so if the input was 560 would it find the string "560 - sultan"
|
Strcmp doesn't find a string it compares two strings.
strcmp
EDIT: You can also use the "length" parameter to make it match part of a string.
Re: [Weired]STRFIND a bit bugged -
Retardedwolf - 13.11.2010
Quote:
Originally Posted by Hal
Thanks, only if someone could have helped me with that last night :P
Does this check if its the full match, or just part? so if the input was 560 would it find the string "560 - sultan"
|
It only does full match checks, I would just recommend you to remove those numbers and '-' infront of the vehicle names and do something like that.
pawn Код:
for(id = 0; id < 211; id++) //Does a loop to check the veh models.
{
if ( !strcmp ( vehicleNames [ id ], params ) ) //If it matches with a vehicle.
{
//...
}
}
You could use break to get out of a loop when you find a vehicle and be able to retrieve the id.