PDA

View Full Version : Vehicle system problem


RTV
06/01/2015, 04:54 PM
I'm trying to get vehicle system with y_ini working,but nothing happens.

enum VehicleStatistics
{
SAMPID = 999,
FileID = 999,
ModelID,
Color1,
Color2,
Float: ParkX,
Float: ParkY,
Float: ParkZ,
Float: ParkAng,
Plate[MAX_NUMBER_PLATE]
}
new gVehicleStats[MAX_VEHICLES][VehicleStatistics];

forward LoadVehicleFromFile(i, name[], value[]);
public LoadVehicleFromFile(i, name[], value[])
{
INI_Int("ModelID", gVehicleStats[i][ModelID]);
INI_Int("Color1", gVehicleStats[i][Color1]);
INI_Int("Color2", gVehicleStats[i][Color2]);
INI_Float("ParkX", gVehicleStats[i][ParkX]);
INI_Float("ParkY", gVehicleStats[i][ParkY]);
INI_Float("ParkZ", gVehicleStats[i][ParkZ]);
INI_Float("ParkAng", gVehicleStats[i][ParkAng]);
INI_String("Plate", gVehicleStats[i][Plate], MAX_NUMBER_PLATE);
return 0;
}

stock LoadVehicle(i)
{
new path[32];
format(path, sizeof(path), "userveh/%d.ini", i);

if(fexist(path))
{
INI_ParseFile(path, "LoadVehicleFromFile", .bExtra = true, .extra = i);
gVehicleStats[i][SAMPID] = GetAvailableVehicleID();
gVehicleStats[i][FileID] = i;
gVehicleStats[i][SAMPID] = AddStaticVehicleEx(gVehicleStats[i][ModelID], gVehicleStats[i][ParkX], gVehicleStats[i][ParkY], \
gVehicleStats[i][ParkZ], gVehicleStats[i][ParkAng], gVehicleStats[i][Color1], gVehicleStats[i][Color2], 36000);
SetVehicleNumberPlate(gVehicleStats[i][SAMPID], gVehicleStats[i][Plate]);
SetVehicleToRespawn(gVehicleStats[i][SAMPID]);
printf("[Vehicle System]: Loaded Vehicle %d successfully!", i);
}
}

stock LoadSavedVehicles()
{
for(new i; i<MAX_VEHICLES; i++)
{
LoadVehicle(i);
}
}

stock SaveVehicle(i)
{
new path[32];

if(gVehicleStats[i][FileID] == 999)
{
gVehicleStats[i][FileID] = GetAvailableFileID();
}

format(path, sizeof(path), "userveh/%s.ini", gVehicleStats[i][FileID]);

new INI:handle = INI_Open(path);
INI_WriteInt(handle, "ModelID", gVehicleStats[i][ModelID]);
INI_WriteInt(handle, "Color1", gVehicleStats[i][Color1]);
INI_WriteInt(handle, "Color2", gVehicleStats[i][Color2]);
INI_WriteFloat(handle, "ParkX", gVehicleStats[i][ParkX]);
INI_WriteFloat(handle, "ParkY", gVehicleStats[i][ParkY]);
INI_WriteFloat(handle, "ParkZ", gVehicleStats[i][ParkZ]);
INI_WriteFloat(handle, "ParkAng", gVehicleStats[i][ParkAng]);
INI_WriteString(handle, "Plate", gVehicleStats[i][Plate]);
INI_Close(handle);
}

stock SaveAllVehicles()
{
for(new i; i<MAX_VEHICLES; i++)
{
SaveVehicle(i);
}
}

stock GetAvailableVehicleID()
{
for(new i; i<MAX_VEHICLES; i++)
{
if(gVehicleStats[i][SAMPID] == 999)
{
return i;
}
}
return 0;
}

stock GetAvailableFileID()
{
new path[32];

for(new i; i<MAX_VEHICLES; i++)
{
format(path, sizeof(path), "userveh/%s.ini", i);
if(!fexist(path))
{
return i;
}
}
return 0;
}

LoadSavedVehicles is in OnGameModeIinit and SaveAllVehicles is in OnGameModeExit.
It even won't write in server window how many are loaded (printf("[Vehicle System]: Loaded Vehicle %d successfully!", i); )

Only one car in map userveh,any help?