SA-MP Forums Archive
Saving vehicles positions - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Saving vehicles positions (/showthread.php?tid=610243)



Saving vehicles positions - ivibeserro - 21.06.2016

Код:
public OnPlayerExitVehicle(playerid, vehicleid)
{
	if(GetPlayerVehicleID(playerid) > 3)
	{
    GetVehiclePos(vehicleid,Float:vx,Float:vy,Float:vz);
	GetVehicleZAngle(vehicleid,Float:va);
	for(new i = 0; i < sizeof(Vehicle); i++)
    {
        Vehicle[i][Positionx] = vx;
        Vehicle[i][Positiony] = vy;
        Vehicle[i][Positionz] = vz;
        SaveThings();
    }
    }
	return 1;
}
I'm trying to script that when a person exits from an owned vehicle, its position is saved. Because if I don't do that all vehicles would spawn at the authorised dealership in Grotti, even the bought ones. But, this code has a bug, when I exit from a vehicle, all vehicles will spawn there in the next restar, not just the one that I exited from. Can somebody help to fix it? Please I would really appreciate it.


Re: Saving vehicles positions - ATGOggy - 21.06.2016

Disable the respawn timer of the vehicle by setting it's value to -1 so that the vehicle won't respawn and it stays at the same position.

https://sampwiki.blast.hk/wiki/AddStaticVehicleEx
See the second last parameter of this function "respawn_delay", set it to -1 to prevent the vehicle from respawning.


Re: Saving vehicles positions - ivibeserro - 21.06.2016

You didn't understand me... I mean, all cars respawn in the last position where I exited a vehicle from when I restart the server.


Re: Saving vehicles positions - jlalt - 21.06.2016

here you go sir:

PHP код:
public OnPlayerExitVehicle(playeridvehicleid)
{
    if(
vehicleid 3)
    {
        
GetVehiclePos(vehicleid,Float:vx,Float:vy,Float:vz);
        
GetVehicleZAngle(vehicleid,Float:va);
        
Vehicle[vehicleid][Positionx] = vx;
        
Vehicle[vehicleid][Positiony] = vy;
        
Vehicle[vehicleid][Positionz] = vz;
        
SaveThings();
    }
    return 
1;




Re: Saving vehicles positions - TwinkiDaBoss - 21.06.2016

Use OnPlayerStateChange since its way more reliable
PHP код:
new OldCar[MAX_PLAYERS];
public 
OnPlayerStateChange(playeridnewstateoldstate) {
    if(
oldstate == PLAYER_STATE_ONFOOT && newstate == PLAYER_STATE_DRIVER// Player entered a vehicle as a driver
    
{
        if(
GetPlayerVehicleID(playerid) <= 3) return true;
        
OldCar[playerid] = GetPlayerVehicleID(playerid);
    }
    if(
oldstate == PLAYER_STATE_DRIVER && newstate == PLAYER_STATE_ONFOOT) {
        
GetVehiclePos(OldCar[playerid],Float:vx,Float:vy,Float:vz);
        
GetVehicleZAngle(OldCar[playerid],Float:va);
        
Vehicle[OldCar[playerid]][Positionx] = vx;
        
Vehicle[OldCar[playerid]][Positiony] = vy;
        
Vehicle[OldCar[playerid]][Positionz] = vz;
    }
    return 
1;

From wiki about OnPlayerExitVehicle
Quote:

Not called if the player falls off a bike or is removed from a vehicle by other means such as using SetPlayerPos.

EDIT: Forgot the > 3


Re: Saving vehicles positions - ATGOggy - 22.06.2016

Quote:
Originally Posted by ivibeserro
Посмотреть сообщение
You didn't understand me... I mean, all cars respawn in the last position where I exited a vehicle from when I restart the server.
To save the positions of the cars even after restart, you need to save the details of the cars in your database. Use Y_INI or MYSQL


Re: Saving vehicles positions - ivibeserro - 22.06.2016

It doesn't work because a vehicle ID on the server doesn't match with the owned car, there are also cars on the gamemode, three at the moment.

I don't need Y_INI neither MYSQL, cars saved well.