Loop trough a folder of files -
Jstylezzz - 28.04.2012
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)
Re: Loop trough a folder of files -
James Coral - 28.04.2012
you can use gl_common function :
pawn Код:
LoadStaticVehiclesFromFile(const filename[])
dont forget to use
Re: Loop trough a folder of files -
Jstylezzz - 28.04.2012
Quote:
Originally Posted by James Coral
you can use gl_common function :
pawn Код:
LoadStaticVehiclesFromFile(const filename[])
dont forget to use
|
thanks, but how should i use this?
I never worked with gl_common before..
Re: Loop trough a folder of files -
iPLEOMAX - 28.04.2012
@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
Re: Loop trough a folder of files -
Jstylezzz - 28.04.2012
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
Re: Loop trough a folder of files -
iPLEOMAX - 28.04.2012
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;
}
Re: Loop trough a folder of files -
Jstylezzz - 28.04.2012
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)
Re: Loop trough a folder of files -
Jstylezzz - 29.04.2012
sorry, little bump... could someone help me please?
Re: Loop trough a folder of files -
iggy1 - 29.04.2012
Post the whole problem code not just one line. Post your loop and where you name the files ect.
Re: Loop trough a folder of files -
Jstylezzz - 29.04.2012
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..