This is actually really easy...
WARNING: The following code is untested, use at your own risk LOL
Revised and tested, works to 80% of satisfaction
Issues: Vehicles spawn before players have time to load the land, so vehicles fall through the ground and appear in a nearby position.
Fix: Add to the 'tmpz' when creating the vehicle
pawn Code:
#include <a_samp>
public OnGameModeInit()
{
new File:tfile=fopen("savedvehicles.sav",io_read);
new Float:tmpx,Float:tmpy,Float:tmpz,Float:tmpa,tmpm,tmpstr[128],tmpstr2[10],tmpint; //tmpstr2 to accomodate for strval and floatstr's small buffersize
for(new o;o<MAX_VEHICLES;o++)
{
fread(tfile,tmpstr);
//Model
tmpint=strfind(tmpstr,",");
strmid(tmpstr2,tmpstr,0,tmpint);
tmpm=strval(tmpstr2);
strdel(tmpstr,0,tmpint+1);
//X
tmpint=strfind(tmpstr,",");
strmid(tmpstr2,tmpstr,0,tmpint);
tmpx=floatstr(tmpstr2);
strdel(tmpstr,0,tmpint+1);
//Y
tmpint=strfind(tmpstr,",");
strmid(tmpstr,tmpstr2,0,tmpint);
tmpy=floatstr(tmpstr2);
strdel(tmpstr,0,tmpint+1);
//Z
tmpint=strfind(tmpstr,",");
strmid(tmpstr2,tmpstr,0,tmpint);
tmpz=floatstr(tmpstr2);
strdel(tmpstr,0,tmpint+1);
//Angle
tmpint=strlen(tmpstr);
strmid(tmpstr2,tmpstr,0,tmpint);
tmpa=floatstr(tmpstr2);
//Creating Vehicle
CreateVehicle(tmpm,tmpx,tmpy,tmpz,tmpa,-1,-1,60000);
}
fclose(tfile);
}
public OnGameModeExit()
{
new File:tfile = fopen("savedvehicles.sav",io_write);
new Float:tmpx,Float:tmpy,Float:tmpz,Float:tmpa,tmpm,tmpstr[128];
for(new o; o<MAX_VEHICLES;o++)
{
tmpm=GetVehicleModel(o);
if(tmpm)
{
GetVehiclePos(o,tmpx,tmpy,tmpz);
GetVehicleZAngle(o,tmpa);
format(tmpstr,sizeof(tmpstr),"%d,%f,%f,%f,%f\n",tmpm,tmpx,tmpy,tmpz,tmpa);
fwrite(tfile,tmpstr);
}
}
fclose(tfile);
}
Only problem with this is if you have a vehicle system of any kind, it may collide.