Car system freezes pawno
#1

So I've made this with some help of a tut.
pawn Код:
stock CreateVehicleEx(modelid, Float:x, Float:y, Float:z, Float:angle, color1, color2, respawntime, ownername[MAX_PLAYER_NAME], factioncar, noobcar)
{
    new carid = GetFreeVehicleSlot();
    VehicleInfo[carid][vModel] = modelid;
    VehicleInfo[carid][vX] = x;
    VehicleInfo[carid][vY] = y;
    VehicleInfo[carid][vZ] = z;
    VehicleInfo[carid][vA] = angle;
    VehicleInfo[carid][vColor1] = color1;
    VehicleInfo[carid][vColor2] = color2;
    VehicleInfo[carid][vRespawn] = respawntime;
    VehicleInfo[carid][vOwner] = ownername;
    VehicleInfo[carid][vFaction] = factioncar;
    VehicleInfo[carid][vNoob] = noobcar;
    validcar[carid] = true;
    CreateVehicle(modelid, x, y, z, angle, color1, color2, respawntime);
    return carid;
}

stock LoadVehicle(filename[36])
{
    INI:ini = INI_Open(filename);
    CreateVehicleEx(INI_Int(ini, "Model", VehicleInfo[vehicle][vModel]), INI_Float(ini, "vX", VehicleInfo[vehicle][vX]), INI_Float(ini, "vY", VehicleInfo[vehicle][vY]), INI_Float(ini, "vZ", VehicleInfo[vehicle][vZ]), INI_Float(ini, "vA", VehicleInfo[vehicle][vA]),INI_Int(ini, "Color1", VehicleInfo[vehicle][vColor1]), INI_Int(ini, "Color2", VehicleInfo[vehicle][vColor2]), INI_Int(ini, "Respawn", VehicleInfo[vehicle][vRespawn]), INI_String(ini, "Owner", VehicleInfo[vehicle][vOwner]), INI_Int(ini, "FactionCar", VehicleInfo[vehicle][vFaction]), INI_Int(ini, "NoobCar", VehicleInfo[vehicle][vNoob]));
    INI_Close(ini);
}
Only did he use Dini, and I decided to change it to Y_Ini, as it's much better. But what have I done wrong? When i compile this, Pawno freezes. And when i remove this, pawno compiles just fine.
Reply
#2

Dini to Y_INI can be a complicated process for beginners, but if you know how Y_INI works, you'll be fine. Just look at the y_ini thread and it will explain enough for you to be able to study it, so I'll just give you the code for now :P

pawn Код:
stock CreateVehicleEx(modelid, Float:x, Float:y, Float:z, Float:angle, color1, color2, respawntime, ownername[MAX_PLAYER_NAME], factioncar, noobcar)
{
    new carid = GetFreeVehicleSlot();
    validcar[carid] = true;
    new file[40];
    format(file, sizeof(file), "Vehicles/%d.ini", carid); //Change 'Vehicles/%d.ini' to the location of your vehicle file.
    new INI:carfile = INI_Open(file);
    INI_SetTag(carfile, "data");
    INI_WriteInt(carfile, "Model", modelid);
    INI_WriteFloat(carfile, "vX", x);
    INI_WriteFloat(carfile, "vY", y);
    INI_WriteFloat(carfile, "vZ", z);
    INI_WriteFloat(carfile, "vA", angle);
    INI_WriteInt(carfile, "Color1", color1);
    INI_WriteInt(carfile, "Color2", color2);
    INI_WriteInt(carfile, "Respawn", respawntime);
    INI_WriteString(carfile, "Owner", ownername);
    INI_WriteInt(carfile, "FactionCar", factioncar);
    INI_WriteInt(carfile, "NoobCar", noobcar);
    INI_Close(carfile);
    INI_ParseFile(file, "LoadVehicle_%s", .bExtra = true, .extra = carid);
    return CreateVehicle(modelid, x, y, z, angle, color1, color2, respawntime);
}

forward LoadVehicle_data(carid, name[], value[]);
public LoadVehicle_data(carid, name[], value[])
{
    INI_Int("Model", VehicleInfo[carid][vModel]);
    INI_Float("vX", VehicleInfo[carid][vX]);
    INI_Float("vY", VehicleInfo[carid][vY]);
    INI_Float("vZ", VehicleInfo[carid][vZ]);
    INI_Float("vA", VehicleInfo[carid][vA]);
    INI_Int("Color1", VehicleInfo[carid][vColor1]);
    INI_Int("Color2", VehicleInfo[carid][vColor2]);
    INI_Int("Respawn", VehicleInfo[carid][vRespawn]);
    INI_String("Owner", VehicleInfo[carid][vOwner], MAX_PLAYER_NAME);
    INI_Int("FactionCar", VehicleInfo[carid][vFaction]);
    INI_Int("NoobCar", VehicleInfo[carid][vNoob]);
}

stock LoadVehicle(carid)
{
    new file[40];
    format(file, sizeof(file), "Vehicles/%d.ini", carid); //Change 'Vehicles/%d.ini' to the location of your vehicle file.
    INI_ParseFile(file, "LoadVehicle_%s", .bExtra = true, .extra = carid);
    CreateVehicle(VehicleInfo[carid][vModel], VehicleInfo[carid][vX], VehicleInfo[carid][vY], VehicleInfo[carid][vZ], VehicleInfo[carid][vA], VehicleInfo[carid][vColor1], VehicleInfo[carid][vColor2], VehicleInfo[carid][vRespawn]);
    return 1;
}
This will load each car individually. You will need a loop under OnGameModeInit.
Reply
#3

Still quite hard to understand though :P. Also it gives text mismatch for those floats @ loadvehicle.

Also, could you explain why loadvehicle_date has _data? and why are tags so important? Also, these are good right?

pawn Код:
stock SaveVehicle(vehicle, filename[36])
{
    INI:ini = INI_Open(filename);
    INI_WriteInt(ini, "Model", VehicleInfo[vehicle][vModel]);
    INI_WriteFloat(ini, "vX", VehicleInfo[vehicle][vX]);
    INI_WriteFloat(ini, "vY", VehicleInfo[vehicle][vY]);
    INI_WriteFloat(ini, "vZ", VehicleInfo[vehicle][vZ]);
    INI_WriteFloat(ini, "vX", VehicleInfo[vehicle][vX]);
    INI_WriteInt(ini, "Color1", VehicleInfo[vehicle][vColor1]);
    INI_WriteInt(ini, "Color2", VehicleInfo[vehicle][vColor2]);
    INI_WriteInt(ini, "Respawn", VehicleInfo[vehicle][vRespawn]);
    INI_WriteString(ini, "Owner", VehicleInfo[vehicle][vOwner]);
    INI_WriteInt(ini, "FactionCar", VehicleInfo[vehicle][vFaction]);
    INI_WriteInt(ini, "NoobCar", VehicleInfo[vehicle][vNoob]);
    INI_Close(ini);
}

stock SaveAllVehicles()
{
    new saveindex = 0;
    new fname[36];
    for(new i = 0; i < MAX_VEHICLES; i ++)
    {
        if(validcar[i])
        {
            format(fname, sizeof(fname), "/Vehicles/%d.ini", saveindex);
            SaveVehicle(i, fname);
            saveindex ++;
        }
    }
}
Reply
#4

Aight, I made a loop under OnGameModeInit, yet it doesn't seem to spawn vehicles. while i made a command with createvehicleex wich creates and makes the files :$
pawn Код:
for(new i = 0; i < MAX_VEHICLES; i ++)
        {
            LoadVehicle(i);
        }
Reply
#5

Do you mind if I see your whole code? I don't mind doing this entire system completely for you. PM me a link to your script, if you don't want the public to see it.
Reply
#6

It's a GM I'm making from scratch though. But ima PM you all the parts from the vehicle system.
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)