[Weired]STRFIND a bit bugged
#1

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

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");
Reply
#3

pawn Код:
for(id = 0; id < MAX_GANGS; id++)
{
    if ( !strcmp ( gangNames [ id ], params ) )
    {
     //...
    }
}
Reply
#4

Gona try it...
Reply
#5

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

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"
Reply
#7

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

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


Forum Jump:


Users browsing this thread: 1 Guest(s)