Saving vehicles positions
#1

Код:
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.
Reply
#2

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

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

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;

Reply
#5

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
Reply
#6

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

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


Forum Jump:


Users browsing this thread: 1 Guest(s)