SA-MP Forums Archive
Loop through a file, see if string matches then get ID. - 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)
+--- Thread: Loop through a file, see if string matches then get ID. (/showthread.php?tid=283657)



Loop through a file, see if string matches then get ID. - Jack_Leslie - 16.09.2011

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.


Re: Loop through a file, see if string matches then get ID. - MisterTickle - 16.09.2011

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?