Help - Save Cars Positions. -
[YKZ]Marcos[VP] - 24.11.2009
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?
Re: Help - Save Cars Positions. -
[YKZ]Marcos[VP] - 25.11.2009
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.
Re: Help - Save Cars Positions. -
[YKZ]Marcos[VP] - 26.11.2009
Anything?
Re: Help - Save Cars Positions. -
Jose 510 - 26.11.2009
Quote:
Originally Posted by MarcosRoberto
Anything?
|
Is your idea based on LS-RP?
Re: Help - Save Cars Positions. -
Joe Staff - 26.11.2009
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.
Re: Help - Save Cars Positions. -
LarzI - 26.11.2009
You forgot the respawn_delay argument in CreateVehicle
Re: Help - Save Cars Positions. -
Joe Staff - 26.11.2009
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.
Re: Help - Save Cars Positions. -
Toney - 26.11.2009
Well i use this FS made by ping
http://forum.sa-mp.com/index.php?topic=78765.0 Good luck.