Loop Through Lines and Delete One?
#1

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?
Reply
#2

What file saving are you using for it?
Reply
#3

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,
Reply
#4

show us your code... maybe use mysql/sqlite
Reply
#5

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.
Reply
#6

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.
Reply
#7

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.
Reply
#8

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.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)