SA-MP Forums Archive
Saving vehicle is creating 1999 files instead of 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: Saving vehicle is creating 1999 files instead of one. (/showthread.php?tid=351866)



Saving vehicle is creating 1999 files instead of one. - Vero - 17.06.2012

Hello, yeah I tried making a vehicle saving system. This is my first attempt:

pawn Код:
command(savevehicle, playerid, params[])
{
    if(PlayerInfo[playerid][Admin] >= 4)
    {
        if(IsPlayerInAnyVehicle(playerid))
        {
            new vehicle, Float:vx, Float:vy, Float:vz, Float:vr;
            GetPlayerPos(playerid, vx, vy, vz );
            GetPlayerFacingAngle(playerid, vr);
            vehicle = GetPlayerVehicleID(playerid);
            for(new i = 0; i < MAX_VEHICLES; i++)
            {
                new Vehiclefile[256];
                format(Vehiclefile, sizeof(Vehiclefile), "vehicles/Vehicle_%d.ini", i);
                dini_Create(Vehiclefile);
                {
                    dini_IntSet(Vehiclefile, "VID", vehicle);
                    dini_FloatSet(Vehiclefile, "Posvx", Float:vx);
                    dini_FloatSet(Vehiclefile, "Posvy", Float:vy);
                    dini_FloatSet(Vehiclefile, "Posvz", Float:vz);
                    dini_FloatSet(Vehiclefile, "Posvr", Float:vr);
                    dini_IntSet(Vehiclefile, "FactionID", 0);
                    SendClientMessage(playerid, COLOUR_ADMIN, "[ADMIN NOTE] You have successfully saved the vehicle. /vfaction to change car faction." );
                    SpawnedVehicles++;
                }
            }
        }
    }
    return 1;
}
But the problem is that it keeps creating the same file 1999 times, the Max vehicle limit. Can someone help?


Re: Saving vehicle is creating 1999 files instead of one. - milanosie - 17.06.2012

pawn Код:
for(new i = 0; i < MAX_VEHICLES; i++)
            {
AKA, your saving the file for every number smaller than Max_vehicles


Re: Saving vehicle is creating 1999 files instead of one. - Vero - 17.06.2012

Thanks for the response, what should I change it to to prevent this?


Re: Saving vehicle is creating 1999 files instead of one. - Kindred - 17.06.2012

Why do you have a loop? If you're saving a single vehicle file, why not just save the current vehicle id itself.

I don't have an example right now, but could post one if no one else does.


Re: Saving vehicle is creating 1999 files instead of one. - Vero - 17.06.2012

That would be helpful thanks


Re: Saving vehicle is creating 1999 files instead of one. - RoboN1X - 17.06.2012

try to change like this:
pawn Код:
for(new i = 1; i <= MAX_VEHICLES; i++)
i think its because the first vehicle's id is 1 and MAX_VEHICLES defined 2000


Re: Saving vehicle is creating 1999 files instead of one. - Vero - 17.06.2012

Quote:
Originally Posted by Robo_N1X
Посмотреть сообщение
try to change like this:
pawn Код:
for(new i = 1; i <= MAX_VEHICLES; i++)
i think its because the first vehicle's id is 1 and MAX_VEHICLES defined 2000
This gives me a warning.


Re: Saving vehicle is creating 1999 files instead of one. - Kindred - 17.06.2012

pawn Код:
command(savevehicle, playerid, params[])
{
    if(PlayerInfo[playerid][Admin] >= 4)
    {
        if(IsPlayerInAnyVehicle(playerid))
        {
            new vehicle, Float:vx, Float:vy, Float:vz, Float:vr;
            GetPlayerPos(playerid, vx, vw, vz);
            GetPlayerFacingAngle(playerid, vr);
            vehicle = GetPlayerVehicleID(playerid);
            new Vehiclefile[246];
            format(Vehiclefile, sizeof(Vehiclefile), "vehicles/Vehicle_%d.ini", SpawnedVehicles);
            dini_Create(Vehiclefile);
            dini_IntSet(Vehiclefile, "VID", vehicle);
            dini_FloatSet(Vehiclefile, "Posvx", Float:vx);
            dini_FloatSet(Vehiclefile, "Posvy", Float:vy);
            dini_FloatSet(Vehiclefile, "Posvz", Float:vz);
            dini_FloatSet(Vehiclefile, "Posvr", Float:vr);
            dini_IntSet(Vehiclefile, "FactionID", 0);
            SendClientMessage(playerid, COLOUR_ADMIN, "[ADMIN NOTE] You have successfully saved the vehicle. /vfaction to change car faction." );
            SpawnedVehicles++;
        }
    }
    return 1;
}
Untested, haven't done anything like this in a while.

What I was planning for it to do is to set the name of the file to the current value of SpawnedVehicles, create the file and save it. It then increases so that you can save another one, and it won't overlap the other value.

Hope I helped.


Re: Saving vehicle is creating 1999 files instead of one. - Vero - 17.06.2012

Thanks, however it saves the vehicle ID as 1 not 465 (for example) and also if the server goes down it restarts at file 0 again.