10.03.2013, 20:14
This is a rough outline I came up with. This is only an example to follow and shows the loading of the vehicles. You are responsible of creating the writing and saving of them, which shouldn't be very hard, it would be very similar to this. Note this is not tested - not even compiled.
iniGetKey and iniGetValue functions can be found around the forums, search for them.
Note (assuming you follow my example closely) that "VehID_" is just the symbol to search for if there is a vehicle to load. At the end, you add number the vehicle is in the file. The example of how the file might help clear what I'm saying:
This could be done much easier using Y_INI, as it does support tags, but I'm unfamiliar with the system.
pawn Код:
// OnPlayerConnect
enum E_VEHLOAD
{
model,
Float: x,
Float: y,
Float: z,
Float: a
};
new File: hFile, file[MAX_PLAYER_NAME+11], name[MAX_PLAYER_NAME], buffer[128], key[30], bool: loading, tmpData[E_VEHLOAD];
GetPlayerName(playerid, name, MAX_PLAYER_NAME);
format(file, sizeof(file), "Vehs/%s.ini", name);
if(fexist(file))
{
hFile = fopen(file, io_read);
while(fread(hFile, buffer))
{
if(strfind(buffer, "[VehID_"))
{
// found a vehicle, check if there is already one loaded
// if there is, create that vehicle and zero the memory in the tmpData array
if(loading == true)
{
CreateVehicle(tmpData[model], tmpData[x], tmpData[y], tmpData[z], -1, -1);
tmpData[model] = 0;
// etc
}
// else, this is the first vehicle found, so set the loading value
loading = true;
}
else
{
if(!loading) continue;
key = iniGetKey(buffer);
if(!strcmp(key, "VehModel", true))
tmpData[model] = iniGetValue(buffer);
else if(!strcmp(key, "VehX", true))
tmpData[model] = iniGetValue(buffer);
// etc
}
}
fclose(hFile);
}
Note (assuming you follow my example closely) that "VehID_" is just the symbol to search for if there is a vehicle to load. At the end, you add number the vehicle is in the file. The example of how the file might help clear what I'm saying:
Код:
[VehID_0] VehModel=400 VehX=4.00 VehY=49.99 VehZ=59.84 VehA=582.9 [VehID_1] VehModel=400 VehX=4.00 VehY=49.99 VehZ=59.84 VehA=582.9