01.07.2012, 08:21
hello,
I made a dini car system with some help from a tutorial.
But it doesn't wanna load my cars, can anyone help?
Hope someone can help
I made a dini car system with some help from a tutorial.
But it doesn't wanna load my cars, can anyone help?
pawn Код:
new bool:validcar[MAX_VEHICLES];
public OnGameModeInit()
{
LoadAllVehicles();
return 1;
}
stock GetFreeVehicleSlot()
{
for(new i = 0; i < sizeof(validcar); i ++)
{
if(!validcar[i]) return i;
}
return -1;
}
stock CreateVehicleEx(modelid, Float:x, Float:y, Float:z, Float:angle, color1, color2, group)
{
//now put all the data into the array
//To get the index, use the first free slot with the function before
new carid = GetFreeVehicleSlot();
Vehicle[carid][Model] = modelid;
Vehicle[carid][xspawn] = x;
Vehicle[carid][yspawn] = y;
Vehicle[carid][zspawn] = z;
Vehicle[carid][anglespawn] = angle;
Vehicle[carid][Col1] = color1;
Vehicle[carid][Col2] = color2;
Vehicle[carid][Group] = group;
//... you can just add any data you like
//dont forget to mark the carslot as used in the validcar array
validcar[carid] = true;
//At last create the vehicle in the game
AddStaticVehicle(modelid, x, y, z, angle, color1, color2);
return carid; //Make the function return the carid/array index. This is not necessarily needed, but good style
}
stock SaveExistingVehicle(carid)
{
new string[36];
format(string, sizeof(string), "Vehicles/%d.ini", carid);
if(fexist(string))
{
dini_IntSet(string, "Model", Vehicle[carid][Model]);
dini_FloatSet(string, "XSpawn", Vehicle[carid][xspawn]);
dini_FloatSet(string, "YSpawn", Vehicle[carid][yspawn]);
dini_FloatSet(string, "ZSpawn", Vehicle[carid][zspawn]);
dini_FloatSet(string, "AngleSpawn", Vehicle[carid][anglespawn]);
dini_IntSet(string, "Color1", Vehicle[carid][Col1]);
dini_IntSet(string, "Color2", Vehicle[carid][Col2]);
dini_IntSet(string, "Group", Vehicle[carid][Group]);
}
return 1;
}
stock SaveVehicle(vehicle, filename[36])
{
new carid = GetFreeVehicleSlot();
format(string, sizeof(string), "Vehicles/%d.ini", carid);
if(!fexist(string))
{
dini_Create(string);
dini_IntSet(string, "Model", Vehicle[carid][Model]);
dini_FloatSet(string, "XSpawn", Vehicle[carid][xspawn]);
dini_FloatSet(string, "YSpawn", Vehicle[carid][yspawn]);
dini_FloatSet(string, "ZSpawn", Vehicle[carid][zspawn]);
dini_FloatSet(string, "AngleSpawn", Vehicle[carid][anglespawn]);
dini_IntSet(string, "Color1", Vehicle[carid][Col1]);
dini_IntSet(string, "Color2", Vehicle[carid][Col2]);
dini_IntSet(string, "Group", Vehicle[carid][Group]);
}
else
{
SendClientMessage(playerid, WHITE, "This car File already exist");
}
return 1;
}
stock LoadVehicle(filename[36])
{
new carid = GetFreeVehicleSlot();
format(filename, sizeof(filename), "Vehicles/%d.ini", carid);
if(fexist(filename))
{
Vehicle[carid][Model] = dini_Int(filename, "Model");
Vehicle[carid][xspawn] = dini_Float(filename, "XSpawn");
Vehicle[carid][yspawn] = dini_Float(filename, "YSpawn");
Vehicle[carid][zspawn] = dini_Float(filename, "ZSpawn");
Vehicle[carid][anglespawn] = dini_Float(filename, "AngleSpawn");
Vehicle[carid][Col1] = dini_Int(filename, "Color1");
Vehicle[carid][Col2] = dini_Int(filename, "Color2");
Vehicle[carid][Group] = dini_Int(filename, "Group");
AddStaticVehicle(Vehicle[carid][Model], Vehicle[carid][xspawn], Vehicle[carid][yspawn], Vehicle[carid][zspawn], Vehicle[carid][anglespawn], Vehicle[carid][Col1], Vehicle[carid][Col2]);
}
else
{
printf("[ERROR] Vehicle %d cannot be spawned.", carid);
}
return 1;
}
stock LoadAllVehicles()
{
new fname[36];
format(fname, sizeof(fname), "Vehicles/%d.ini", fname);
while(fexist(fname))
{
LoadVehicle(fname);
}
}