Saving vehicle is creating 1999 files instead of one.
#1

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

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

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

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

That would be helpful thanks
Reply
#6

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

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

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

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


Forum Jump:


Users browsing this thread: 1 Guest(s)