SA-MP Forums Archive
Loop Through Lines and Delete One? - 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 Lines and Delete One? (/showthread.php?tid=338077)



Loop Through Lines and Delete One? - ReneG - 28.04.2012

Hello, I've been working on a dynamic vehicle system, I've got the writing, and loading done fine, but now I need the deleting part to get down. So how would I loop through all the files, and delete one? I've thought about writing a string such as a name, but that would get hectic if the name already existed. Any ideas?


Re: Loop Through Lines and Delete One? - The DeLuca - 28.04.2012

What file saving are you using for it?


Re: Loop Through Lines and Delete One? - Jonny5 - 28.04.2012

Quote:
Originally Posted by The DeLuca
Посмотреть сообщение
What file saving are you using for it?
sounds like a raw file..



@V
i think this will prove to be hard,
if it was me i would have a unique ID for each line.

im having the same trouble with sqlite,
i try to keep the id's aligned with the veh id's but if i delete 1 it
changes my alignment.

sorry my post did not have anything useful,

gl,


Re: Loop Through Lines and Delete One? - Crazymax - 28.04.2012

show us your code... maybe use mysql/sqlite


Re: Loop Through Lines and Delete One? - The DeLuca - 28.04.2012

Well I just save my files to a directory within the script files. For instance Vehicles. And create files through script that save v1.ini and v2.ini and so forth. Then you can loop through every file with MAX_VEHICLES and delete ones that already exist. I use this for dynamic vehicles, houses, businesses, and everything else. It works flawlessly.


Re: Loop Through Lines and Delete One? - ReneG - 28.04.2012

I could do what you said above, but it wouldn't really be practical to have a file per car. I'll figure it out. I'm using sscanf, and the default file functions.


Re: Loop Through Lines and Delete One? - The DeLuca - 28.04.2012

Well it works if you save paint colors, mods, owners of the vehicle and such to it. If it's just the coordinates then it might not be as helpful. I just used it for dynamic faction vehicles.


Re: Loop Through Lines and Delete One? - admantis - 28.04.2012

It depends, if you save your vehicles as IDs (Vehicle_1.ini, and so on; that's what I recommend) and not by owner (it will limit you to owning only 1 vehicle), this code should be easy for you to understand.
You really do not require any loops but this:
pawn Код:
stock DeleteOwnedVehicle( key )
{
    new file_path[32];
    format( file_path, 32, "Vehicle_%d.ini", key ); // this is an example
    fremove( file_path );
    vehicleinfo[key][owned] = 0; // if your vehicle enum had the element 'owned' and your array 'vehicleinfo'
}
Quote:
Originally Posted by VincentDunn
Посмотреть сообщение
I could do what you said above, but it wouldn't really be practical to have a file per car. I'll figure it out. I'm using sscanf, and the default file functions.
It is practical. It is more organized than one file with the owner name, and all the data for all the vehicles inside it.

Otherwise, if you save all the cars in one single file, check this:
Quote:
Originally Posted by SAMP Wiki
Reading Line-by-Line
pawn Код:
public OnPlayerConnect(playerid)
{
    new string[64]; // Create the string to store the read text in
    new File:example = fopen("Startup.txt", io_read); // Open the file
    while(fread(example, string)) //reads the file line-by-line
    {
        if(strcmp(string, "Ban", true) == 0) //if any of the lines in the file say "Ban" the system will ban the player
        {
            Ban(playerid); //bans the player
        }
    }
    fclose(example);
    return 1;
}
Modify it as you require.