SA-MP Forums Archive
Making /park cmd - 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: Making /park cmd (/showthread.php?tid=560330)



Making /park cmd - Arxalan - 28.01.2015

Hello , i have a dialog option . When player stand on pickup a dialog appears . And he can set any vehicle in his house . But i want to have a function that player can only save the vehicle in which he is . Following is the code of setting any vehicle to house . How to convert it to a function that he can save only that vehicle in which he is by /park.
PHP Code:
if(!strlen(inputtext)) return ShowPlayerDialog(playeridHOUSE_DIAG+18DIALOG_STYLE_INPUT"{"#B>"}House Settings - {"#G>"}House Vehicles", "{"#R>"}ERROR: You must enter a vehicle name or model id!\n\n{"#W>"}Enter a vehicle name or model id to continue", "Set", "Cancel");
                
new vehid GetVehicleModel2(inputtext);
                if(!
IsValidVehicle(vehid) || !IsAllowedVehicle(vehid)) return ShowPlayerDialog(playeridHOUSE_DIAG+18DIALOG_STYLE_INPUT"{"#B>"}House Settings - {"#G>"}House Vehicles", "{"#R>"}ERROR: This vehicle is either not allowed or does not exist!\n\n{"#W>"}Enter a vehicle name or model id to continue", "Set", "Cancel");
                
new key[20];
                new 
houseid HOUSEID(playerid);
                new 
vehslot GetPVarInt(playerid"HVehSlot");
                
format(hfilesizeof(hfile), HOUSE_FILEhouseid);
                
format(keysizeof(key), "VSlot%dModel"vehslot);
                
dini_IntSet(hfilekeyvehid);
                
hVeh[houseid][vehslot][ModelID] = vehid;
                
NotifyDialog(playerid"{"#B>"}House Settings - {"#G>"}House Vehicles", "House vehicle model was successfully changed!"); 



Respuesta: Making /park cmd - Trevor Gin - 28.01.2015

this cmd work 100%100
Code:
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);
				}
				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);
				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;
}
Or try this.
Code:
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);
				}
				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);
				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: Making /park cmd - Arxalan - 28.01.2015

You just copied the code . Every script have different enums e.g. your script have PlayerInfo[playerid][pLockCar] but mine have different and this don't work because this is just copied .