Loop trough a folder of files
#1

Hi everyone!

What i'm trying to do here, is when a police officer types /checkplate [plate] that the scripts starts looping trough my vehicle folder, and selects the [plate] the officer gave.

Is there any possibility in doing this?
(i did use search, but i didn't find something that solved my problem)
Reply
#2

you can use gl_common function :

pawn Код:
LoadStaticVehiclesFromFile(const filename[])
dont forget to use

pawn Код:
#include gl_common
Reply
#3

Quote:
Originally Posted by James Coral
Посмотреть сообщение
you can use gl_common function :

pawn Код:
LoadStaticVehiclesFromFile(const filename[])
dont forget to use

pawn Код:
#include gl_common
thanks, but how should i use this?
I never worked with gl_common before..
Reply
#4

@James Coral: That's not what he is asking for.

----

Does your vehicles save as IDs in your folder?

Like:
Код:
/scriptfiles/vehicles/1.ini
/scriptfiles/vehicles/2.ini
/scriptfiles/vehicles/3.ini
.....
/scriptfiles/vehicles/1000.ini
Reply
#5

Quote:
Originally Posted by iPLEOMAX
Посмотреть сообщение
@James Coral: That's not what he is asking for.

----

Does your vehicles save as IDs in your folder?

Like:
Код:
/scriptfiles/vehicles/1.ini
/scriptfiles/vehicles/2.ini
/scriptfiles/vehicles/3.ini
.....
/scriptfiles/vehicles/1000.ini
Yes, it saves like this
Reply
#6

You just have to create a loop and check if a vehicle at that index matches the plate number.


Something like this, UNTESTED.

pawn Код:
stock GetVehicleIDFromPlate(Plate[])
{
    new vehiclefile[64], readstring[24];

    for(new i = 0; i < MAX_VEHICLES; i++)
    {
        format(vehiclefile, sizeof vehiclefile, "/vehicles/%i.ini", i);
        if(fexist(vehiclefile))
        {
            INI_GetString(vehiclefile, "platenumber", readstring, sizeof readstring);
            //INI_GetString is just an example, use your file system library to get the string.
            //vehiclefile: Path of the file, "platenumber" is the ini key, readstring is a buffer string to read
           
            if(!strcmp(readstring, Plate, false)) return i;
        }
    }
   
    return 0;
}
Reply
#7

I'm sorry, but i can't get this to work.. I will post what I have now, and maybe you could help me..

This is the line where it saves:
pawn Код:
format(line, sizeof(line), "NumberPlate=%s\r\n", VehicleNumberPlate[vehicleid]); fwrite(handle, line);
This is the CMD:
pawn Код:
CMD:trackplate(playerid,params[]
{
    GetVehicleIDFromPlate(params)
    return 1;
}
Now, i have no clue how to get this to work.. (BTW, I use mademan's AVS system)
Reply
#8

sorry, little bump... could someone help me please?
Reply
#9

Post the whole problem code not just one line. Post your loop and where you name the files ect.
Reply
#10

That's the problem, that what i posted, is all i've got, i had that code from IPLEOMAX, but i don't know what to do with it...
The only thing i actually need, is that loop function, and that it reads from the file that holds the given plate...

it uses this to load the vehicles
pawn Код:
else if(strcmp(line, "NumberPlate=", false, 12) == 0) strmid(VehicleNumberPlate[i], line, 12, sizeof(line));
It uses this to save:
pawn Код:
format(line, sizeof(line), "NumberPlate=%s\r\n", VehicleNumberPlate[vehicleid]); fwrite(handle, line);
And, maybe also handy, i use Mademan's AVS system..

idk what i can give more on information..
Reply


Forum Jump:


Users browsing this thread: 5 Guest(s)