Help - Save Cars Positions.
#1

Hello.
I wonder how do I get when
I close the server it save the positions of all
vehicles and when the server starts it creates all vehicles saved in positions that he saved.

I've tried several ways but could not.
Can anyone help?
Reply
#2


Thank you.
I'm looking for something when the player buys the vehicle and park it elsewhere
save the position of the vehicle at that location, and when he gets back on the server the vehicle is in the position in which he left, even if the server is closed.
Reply
#3

Anything?
Reply
#4

Quote:
Originally Posted by MarcosRoberto
Anything?
Is your idea based on LS-RP?
Reply
#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
#6

You forgot the respawn_delay argument in CreateVehicle
Reply
#7

Quote:
Originally Posted by lrZ^ aka LarzI
You forgot the respawn_delay argument in CreateVehicle
Yeah and I messed up my strmid, it works now.
Reply
#8

Well i use this FS made by ping http://forum.sa-mp.com/index.php?topic=78765.0 Good luck.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)