several issues about vehicles
#1

Well I'm trying to make a vehicle system and for some reasons they aren't loading/saving maybe I've messed something up or something, well first of all..
The vehicle creates fine ingame but when the gamemode exits/loads it doesn't save to the file or loads.

pawn Код:
public LoadCars_data(idx, name[], value[])
{
        INI_Int("vModel",cInfo[idx][vModel]);
        INI_Float("vX",cInfo[idx][vX]);
        INI_Float("vY",cInfo[idx][vY]);
        INI_Float("vZ",cInfo[idx][vZ]);
        INI_Float("vA",cInfo[idx][vA]);
        INI_Int("vCol2",cInfo[idx][vCol1]);
        INI_Int("vCol1",cInfo[idx][vCol2]);
        INI_String("vOwner",cInfo[idx][vOwner],25);
        INI_Int("vLocked",cInfo[idx][vLocked]);
        INI_Int("vOwned",cInfo[idx][vOwned]);
       
        return 1;
}
public SaveCar(id)
{
    new file4[40];
    format(file4, sizeof(file4),CPATH, id);
    new INI:File = INI_Open(file4);
    INI_SetTag(File,"data");
    INI_WriteInt(File,"vModel",cInfo[id][vModel]);
    INI_WriteFloat(File,"vX",cInfo[id][vX]);
    INI_WriteFloat(File,"vY",cInfo[id][vY]);
    INI_WriteFloat(File,"vZ",cInfo[id][vZ]);
    INI_WriteFloat(File,"vA",cInfo[id][vA]);
    INI_WriteInt(File,"vCol1",cInfo[id][vCol1]);
    INI_WriteInt(File,"vCol2",cInfo[id][vCol2]);
    INI_WriteString(File,"vOwner",cInfo[id][vOwner]);
    INI_WriteInt(File,"vLocked",cInfo[id][vLocked]);
    INI_WriteInt(File,"vOwned",cInfo[id][vOwned]);
        INI_Close(File);
    return 1;
}
// OnGMinIt
    new strb[40]
    for(new idx = 1; idx < sizeof(cInfo); idx++)
    {
        format(strb, sizeof(strb), CPATH, idx);
        INI_ParseFile(strb, "LoadCars_%s", .bExtra = true, .extra = idx );
        vCreate(cInfo[idx][vModel],cInfo[idx][vX],cInfo[idx][vY],cInfo[idx][vZ],cInfo[idx][vA],cInfo[idx][vCol1],cInfo[idx][vCol2]);
// exit
    for(new id = 1; id < sizeof(cInfo); id++)
    {
        if(cInfo[id][vModel] == 0) break;
        SaveCar(id);
    }
    }
Any help is appreciated, thank you.
Reply
#2

Okay I managed to fix it up now it's loading and saving fine but why is the number of the vehicle is the latest vehicle ID available.

E.G:

if my MAX_VEHICLES is 600 the ID will be 599 and if I create one more it wont create because maximum amount of vehicle has reached while it's not.
pawn Код:
case DIALOG_DEALERSHIP:
        {
            if(response)
            {
                if(listitem == 0)
                {
                    new cid = GetFreeSlot();
                    MSG(playerid,-1,"Move your car away from the dealership and park it away as soon as possible!");
                    cInfo[cid][vModel] = 445;
                    cInfo[cid][vX] = -2087.3484;
                    cInfo[cid][vY] = -2244.3879;
                    cInfo[cid][vZ] = 31.1463;
                    cInfo[cid][vA] = 317.7882;
                    cInfo[cid][vCol1] = random(225);
                    cInfo[cid][vCol2] = random(225);
                    cInfo[cid][vOwner] = sendername(playerid);
                    cInfo[cid][vLocked] = 0;
                    cInfo[cid][vOwned] = 1;
                    vCreate(cInfo[cid][vModel],cInfo[cid][vX],cInfo[cid][vY],cInfo[cid][vZ],cInfo[cid][vA],cInfo[cid][vCol1],cInfo[cid][vCol2]);
                    //(modelid,Float:x,Float:y,Float:z,Float:angle,color1,color2)
                    validcar[cid] = true;
                    SaveCar(cid);
                }
            }
        }
img
Reply
#3

Try to use INI_Save
Reply
#4

Please don't reply if you don't know what you're talking about.
Reply
#5

bump.
Reply
#6

new cid = GetFreeSlot();

Show GetFreeSlot please bud.
Reply
#7

I've tried to debug that GetFreeSlot stock and it always returns 599 why so?


pawn Код:
stock GetFreeSlot()
{
    for(new i = 0; i < sizeof(validcar); i ++)
    {
        if(!validcar[i]) return i;
    }
    return -1;
}
Reply
#8

MAX_VEHICLES = 600 elements.

1st element = MAX_VEHICLES[0].
2nd element = MAX_VEHICLES[1].
3rd element = MAX_VEHICLES[2].
.
.
MAX_VEHICLES element = MAX_VEHICLES[MAX_VEHICLES - 1].
- if MAX_VEHICLES is 600 -
600th element = MAX_VEHICLES[599].
Reply
#9

Okay I got the problem for some reasons it seems every vehicle ID's validcar variable is TRUE so I tried making a looping which changes all that to false and it worked now on the GameModeInit how would I do that? if anyone can give me any example/explain I'd be thankful.
Reply
#10

Nevermind fixed it.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)