Find a name inside all existing files
#1

I'm trying to load a name, looping all files which exists. I know how to do it, but since my files are numerated like: 0, 1, 2, 3, 4 ... Then I need to know which file of these one the name have been loaded.

pawn Code:
public OnPlayerConnect(playerid)
{
    static str[128];
    Loop(h, MAX_VEHICLES)
    {
       format(file,sizeof(file),local,h);
       if(dini_Exists(file)) // I'm using dini in this cas
       {
           if(!strcmp(GetMyName(playerid), dini_Get(file,"Name"), true)) // Would search on all files
           {
                format(str,sizeof(str),""#red"[CAR SYSTEM]: "#green"Hello %s. You own a vehicle model %i. Your vehicle ID is: %i", // I didn't end here yet.
                Player[playerid][Owner] = 1;
           }
        }
    }
    return 1;
}
So, how can I know what file the name have been loaded from?
Reply
#2

Add a break statement after 'Player[playerid][Owner] = 1;'. This will jump straight out of the loop once the item is found, and your 'file' variable will still be usable. Assuming that each player can only own 1 car.
Reply
#3

I mean: the loop will search on all files on that folder for the name of the player which has connected. But I want to know the file number which has found this player name, since the files are like: 0,1,2,3,4,5,6..
Reply
#4

Anyone?
Reply
#5

pawn Code:
public OnPlayerConnect(playerid)
{
    static str[128];
    Loop(h, MAX_VEHICLES)
    {
        format(file,sizeof(file),local,h);
        if(dini_Exists(file)) // I'm using dini in this cas
        {
            if(!strcmp(GetMyName(playerid), dini_Get(file,"Name"), true)) // Would search on all files
            {
                format(str,sizeof(str),""#red"[CAR SYSTEM]: "#green"Hello %s. You own a vehicle model %i. Your vehicle ID is: %i", // I didn't end here yet.
                Player[playerid][Owner] = 1;
                //Just add your code here, the variable which stores the number is h
            }
        }
    }
    return 1;
}
Reply
#6

Use SQLite or MySQL. Files aren't meant to be used like that.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)