Loop through a file, see if string matches then get ID.
#1

Hey guys.
So I'm having trouble with this code, that Jeffrey made for me. It's meant to loop through, see if the two strings match anywhere then return the ID of where they matched.

pawn Код:
stock GetCarIDFromPlayer(playerid)
{
    new PlayersName[MAX_PLAYER_NAME];
    GetPlayerName(playerid, PlayersName, MAX_PLAYER_NAME);
    for(new i=0; i<sizeof(CarInfo); i++)
    {
        if(!strcmp(CarInfo[i][vOwner], PlayersName)) return i;  //Returns the Vehicle ID
    }
    return -1;
}
It keeps returning ID 1 though.
Reply
#2

I don't think this will make much of a difference but.. Try this.

Код:
stock GetCarIDFromPlayer(playerid)
{
    new PlayersName[MAX_PLAYER_NAME];
    GetPlayerName(playerid, PlayersName, MAX_PLAYER_NAME);
    for(new i=0; i<sizeof(CarInfo); i++)
    {
        if(!strcmp(CarInfo[i][vOwner], PlayersName, true)) return i;  //Returns the Vehicle ID
    }
    return -1;
}
Oh and are you sure its 1 not -1?
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)