Help - Save Cars Positions.
#5

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.
Reply


Messages In This Thread
Help - Save Cars Positions. - by [YKZ]Marcos[VP] - 24.11.2009, 21:02
Re: Help - Save Cars Positions. - by [YKZ]Marcos[VP] - 25.11.2009, 04:13
Re: Help - Save Cars Positions. - by [YKZ]Marcos[VP] - 26.11.2009, 02:18
Re: Help - Save Cars Positions. - by Jose 510 - 26.11.2009, 02:58
Re: Help - Save Cars Positions. - by Joe Staff - 26.11.2009, 05:21
Re: Help - Save Cars Positions. - by LarzI - 26.11.2009, 05:26
Re: Help - Save Cars Positions. - by Joe Staff - 26.11.2009, 05:33
Re: Help - Save Cars Positions. - by Toney - 26.11.2009, 08:09

Forum Jump:


Users browsing this thread: 4 Guest(s)