Don't save a bike [+1 Rep]
#1

When I buy a motorcycle and get out to the server, again enter the Server but the bike can not preserve.

pawn Код:
forward SaveBike(motorid);
public SaveBike(motorid)
{
    new car[32];
    format(car, 32, "/Motori/%d.ini", motorid);
    if(fexist(car))
    {
        djSetInt(car, "Model", MotorInfo[motorid][mModel]);
        djSetFloat(car, "LocX", MotorInfo[motorid][LocX]);
        djSetFloat(car, "LocY", MotorInfo[motorid][LocY]);
        djSetFloat(car, "LocZ", MotorInfo[motorid][LocZ]);
        djSetFloat(car, "Kut", MotorInfo[motorid][Kut]);
        djSetInt(car, "Boja1", MotorInfo[motorid][mBoja1]);
        djSetInt(car, "Boja2", MotorInfo[motorid][mBoja2]);
        djSet(car, "Vlasnik", MotorInfo[motorid][mVlasnik]);
        djSetInt(car, "Cena", MotorInfo[motorid][mCena]);
        djSetInt(car, "ImaVlasnika", MotorInfo[motorid][mKupljeno]);
        djSetInt(car, "Lock", MotorInfo[motorid][mZakljucano]);
        djSetInt(car, "Prodano", MotorInfo[motorid][mProdano]);
    }
    return 1;
}
pawn Код:
stock ReloadBike(motorid)
{
    new car[32];
    format(car, 32, "/Motori/%d.ini", motorid);
    if(fexist(car))
    {
        MotorInfo[motorid][mModel] = djInt(car, "Model");
        MotorInfo[motorid][LocX] = djInt(car, "LocX");
        MotorInfo[motorid][LocY] = djInt(car, "LocY");
        MotorInfo[motorid][LocZ] = djInt(car, "LocZ");
        MotorInfo[motorid][Kut] = djInt(car, "Kut");
        MotorInfo[motorid][mBoja1] = djInt(car, "Boja1");
        MotorInfo[motorid][mBoja2] = djInt(car, "Boja2");
        format(MotorInfo[motorid][mVlasnik], MAX_PLAYER_NAME, "%s", dj(car, "Vlasnik"));
        MotorInfo[motorid][mCena] = djInt(car, "Cena");
        MotorInfo[motorid][mKupljeno] = djInt(car, "ImaVlasnika");
        MotorInfo[motorid][mZakljucano] = djInt(car, "Lock");
        MotorInfo[motorid][mProdano] = djInt(car, "Prodano");
        new motor = AddStaticVehicleEx(MotorInfo[motorid][mModel],MotorInfo[motorid][LocX],MotorInfo[motorid][LocY],MotorInfo[motorid][LocZ]+1.0,MotorInfo[motorid][Kut],MotorInfo[motorid][mBoja1],MotorInfo[motorid][mBoja2], 1200000);
        Cmotor[motor] = 1;
    }
    return 1;
}
What's wrong?
Reply
#2

Try removing "fexist" from SaveBike
Reply
#3

Also try to find a different way to save your vehicles (don't use the vehicleid).

Let's assume you have no vehicles in your gamemode and you create a bike.
It gets saved as "Motori\1.ini".

Then your server gets restarted and you don't login again.
Since you had a fresh server-restart, your server has no vehicles.

Someone else logs in and creates another vehicle.
This one gets vehicleid 1.

Now you login, loading 1.ini, which may load fine, but it creates your bike with vehicleid 2.
Then you logout again.
Then your bike gets saved again but now has the filename "Motori\2.ini".

When you login again, there will be 2 bikes at the same location since you have 1.ini and 2.ini.


Soon you'll have 100 identical bikes at the same location and you'll have problems.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)