SA-MP Forums Archive
Saving Vehicle Position - 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 Vehicle Position (/showthread.php?tid=473644)



Saving Vehicle Position - yancarlos4500 - 03.11.2013

Hello,

I need help with this.

my server dont save car position automatically.

you have to be in your vehicle and type /estacionar (/Park)

what i want is that when the player disconnect. saves all of the players cars position with out being in each car.

this is that command

PHP код:
CMD:estacionar(playeridparams[])
{
for(new 
MAX_PLAYERVEHICLESd++)
    {
        if(
IsPlayerInVehicle(playeridPlayerVehicleInfo[playerid][d][pvId]))
        {
            if(
GetPlayerState(playerid) != PLAYER_STATE_DRIVER) return SendClientMessageEx(playeridCOLOR_GREY"Tu debes ser el conductor.");
            new 
Float:xFloat:yFloat:zFloat:angleFloat:health;
            
GetVehicleHealth(PlayerVehicleInfo[playerid][d][pvId], health);
            
PlayerVehicleInfo[playerid][d][pvHealth] = health;
            if(
health 800) return SendClientMessageEx(playeridCOLOR_GREY" Tu vehiculo estб muy daсado para estacionarlo.");
            if(
Info[playerid][pLockCar] == GetPlayerVehicleID(playerid)) Info[playerid][pLockCar] = INVALID_VEHICLE_ID;
            
GetVehiclePos(PlayerVehicleInfo[playerid][d][pvId], xyz);
            
GetVehicleZAngle(PlayerVehicleInfo[playerid][d][pvId], angle);
            
SurfingCheck(GetPlayerVehicleID(playerid));
            
UpdatePlayerVehicleParkPosition(playeriddxyzanglehealth);
            
PutPlayerInVehicle(playeridPlayerVehicleInfo[playerid][d][pvId], 0);
            
SetPlayerArmedWeapon(playerid0);
            new 
string[30 + (MAX_PLAYER_NAME 2)];
            
format(stringsizeof(string), "%s estaciona su vehнculo."GetPlayerNameEx(playerid));
            
ProxDetector(30.0playeridstringCOLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE);
            
fVehSpeed[playerid] = 0.0;
            return 
1;
        }
    }
    
SendClientMessageEx(playeridCOLOR_GREY"Tu necesitas estar dentro de tu vehiculo para hacer esto.");
    return 
1;




Re: Saving Vehicle Position - Gogorakis - 03.11.2013

Try my /park cmd:
Код:
CMD:park(playerid, params[])
{
	if(PlayerInfo[playerid][pVehicleKeysFrom] != INVALID_PLAYER_ID)
	{
		new ownerid = PlayerInfo[playerid][pVehicleKeysFrom];
		if(IsPlayerConnected(ownerid))
		{
			new d = PlayerInfo[playerid][pVehicleKeys];
			if(IsPlayerInVehicle(playerid, PlayerVehicleInfo[ownerid][d][pvId]))
			{
			    if(GetPlayerState(playerid) != PLAYER_STATE_DRIVER) return SendClientMessageEx(playerid, COLOR_GREY, "You must be in the driver seat.");
				new Float:x, Float:y, Float:z, Float:angle, Float:health;
				GetVehicleHealth(PlayerVehicleInfo[ownerid][d][pvId], health);
				if(health < 800) return SendClientMessageEx(playerid, COLOR_GREY, " Your vehicle is too damaged to park it.");
				if(PlayerInfo[playerid][pLockCar] == GetPlayerVehicleID(playerid)) PlayerInfo[playerid][pLockCar] = INVALID_VEHICLE_ID;
				if(IsARC(GetPlayerVehicleID(playerid))) // RC Vehicles
				{
					new Float:vehPos[3];
					GetVehiclePos(GetPlayerVehicleID(playerid),vehPos[0], vehPos[1], vehPos[2]);
					SetPlayerPos(playerid,vehPos[0], vehPos[1]+0.5, vehPos[2]+0.5);
				}
				new vSeat[MAX_PLAYERS], newcar = GetPlayerVehicleID(playerid);
				GetVehiclePos(PlayerVehicleInfo[ownerid][d][pvId], x, y, z);
				GetVehicleZAngle(PlayerVehicleInfo[ownerid][d][pvId], angle);
				SurfingCheck(GetPlayerVehicleID(playerid));
				UpdatePlayerVehicleParkPosition(ownerid, d, x, y, z, angle, health);
				foreach(Player, i) {
				    vSeat[i] = 999;
				    if(IsPlayerInVehicle(i, newcar)) {
				        vSeat[i] = GetPlayerVehicleSeat(i);
					}
				}
				foreach(Player, i) {
				    if(vSeat[i] != 999) PutPlayerInVehicle(i, GetPlayerVehicleID(playerid), vSeat[i]);
				}
				PutPlayerInVehicle(playerid, GetPlayerVehicleID(playerid), 0);
			 	SetPlayerArmedWeapon(playerid, 0);

				new string[29 + (MAX_PLAYER_NAME * 2)];
				format(string, sizeof(string), "* %s has parked %s's vehicle.", GetPlayerNameEx(playerid), GetPlayerNameEx(ownerid));
				ProxDetector(30.0, playerid, string, COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE);
				return 1;
			}
		}
	}
	for(new d = 0 ; d < MAX_PLAYERVEHICLES; d++)
	{
		if(IsPlayerInVehicle(playerid, PlayerVehicleInfo[playerid][d][pvId]))
		{
			new Float:x, Float:y, Float:z, Float:angle, Float:health;
			GetVehicleHealth(PlayerVehicleInfo[playerid][d][pvId], health);
            if(GetPlayerState(playerid) != PLAYER_STATE_DRIVER) return SendClientMessageEx(playerid, COLOR_GREY, "You must be in the driver seat.");
			if(health < 800) return SendClientMessageEx(playerid, COLOR_GREY, " Your vehicle is too damaged to park it.");
			if(PlayerInfo[playerid][pLockCar] == GetPlayerVehicleID(playerid)) PlayerInfo[playerid][pLockCar] = INVALID_VEHICLE_ID;
			GetVehiclePos(PlayerVehicleInfo[playerid][d][pvId], x, y, z);
			GetVehicleZAngle(PlayerVehicleInfo[playerid][d][pvId], angle);
			SurfingCheck(GetPlayerVehicleID(playerid));
			UpdatePlayerVehicleParkPosition(playerid, d, x, y, z, angle, health);
			PutPlayerInVehicle(playerid, PlayerVehicleInfo[playerid][d][pvId], 0);
			SetPlayerArmedWeapon(playerid, 0);

			new string[30 + (MAX_PLAYER_NAME * 2)];
			format(string, sizeof(string), "* %s has parked their vehicle.", GetPlayerNameEx(playerid));
			ProxDetector(30.0, playerid, string, COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE);
			return 1;
		}
	}
	SendClientMessageEx(playerid, COLOR_GREY, "You need to be inside a vehicle that you own.");
	return 1;
}



Re: Saving Vehicle Position - yancarlos4500 - 03.11.2013

You dont understand

I want to park all of the players vehicle when get Disconnects


Re: Saving Vehicle Position - CJay9209 - 03.11.2013

well you need to have a decent file I/O setup in order to save the positions - which one are you using or is it custom built? Once we know how the filesystem is working then it's easier but the system you wanna make essentially means that you need to load all of the vehicles from external files or a database which is NOT SIMPLE AT ALL. Easy enough to manage once setup but it requires ALOT of setup.


Re: Saving Vehicle Position - yancarlos4500 - 03.11.2013

by filesystem you mean the way the server saves data


Re: Saving Vehicle Position - [ABK]Antonio - 03.11.2013

Probably just need this under OnPlayerDisconnect

pawn Код:
for(new d = 0 ; d < MAX_PLAYERVEHICLES; d++)
{
    new Float:x, Float:y, Float:z, Float:angle, Float:health;
    GetVehicleHealth(PlayerVehicleInfo[playerid][d][pvId], health);
    PlayerVehicleInfo[playerid][d][pvHealth] = health;
    GetVehiclePos(PlayerVehicleInfo[playerid][d][pvId], x, y, z);
    GetVehicleZAngle(PlayerVehicleInfo[playerid][d][pvId], angle);
    UpdatePlayerVehicleParkPosition(playerid, d, x, y, z, angle, health);
}
Assuming UpdatePlayerVehicleParkPosition saves it


Re: Saving Vehicle Position - yancarlos4500 - 03.11.2013

umm i am going to try it.

although would it save everything?


Re: Saving Vehicle Position - yancarlos4500 - 03.11.2013

Quote:
Originally Posted by [ABK]Antonio
Посмотреть сообщение
Probably just need this under OnPlayerDisconnect

pawn Код:
for(new d = 0 ; d < MAX_PLAYERVEHICLES; d++)
{
    new Float:x, Float:y, Float:z, Float:angle, Float:health;
    GetVehicleHealth(PlayerVehicleInfo[playerid][d][pvId], health);
    PlayerVehicleInfo[playerid][d][pvHealth] = health;
    GetVehiclePos(PlayerVehicleInfo[playerid][d][pvId], x, y, z);
    GetVehicleZAngle(PlayerVehicleInfo[playerid][d][pvId], angle);
    UpdatePlayerVehicleParkPosition(playerid, d, x, y, z, angle, health);
}
Assuming UpdatePlayerVehicleParkPosition saves it
Thanks men it worked