IsPlayerInVehicle: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
No edit summary
 
m (Visual improvement)
 
(5 intermediate revisions by 4 users not shown)
Line 1: Line 1:
__NOTOC__
__NOTOC__
This function returns true if a player is in a vehicle.
{{Server client function}}
{{Deprecated|isPedInVehicle}}
 
This function checks if a player is in a vehicle.


==Syntax==
==Syntax==
Line 6: Line 9:


===Required Arguments===
===Required Arguments===
*'''player''': The [[player]] you are checking.
*'''thePlayer''': The [[player]] element you are checking.


===Returns===
===Returns===
Returns true if a player is inside a vehicle.
Returns ''true'' if the player is inside a vehicle, ''false'' if he isn't or an invalid player was passed.


==Example==
==Example==
<syntaxhighlight lang="lua">if ( isPlayerInVehicle ( findPlayer ( "someGuy" ) ) then
This code defines an ''isinvehicle'' command which tells a player whether another player is in a vehicle or not.
  outputChatBox ( "Someguy is in a vehicle.", player )
<syntaxhighlight lang="lua">
end</syntaxhighlight>
-- we create our handler function, where sourcePlayer is the player who sent the command,
-- and checkedPlayerName is the player name specified.
function outputIsInVehicle ( sourcePlayer, commandName, checkedPlayerName )
-- we get the player element from the nick specified
local checkedPlayer = getPlayerFromNick ( checkedPlayerName )
-- if it exists,
if ( checkedPlayer ) then
-- if it's in a vehicle,
if isPlayerInVehicle ( checkedPlayer ) then
-- tell the source player
outputChatBox ( checkedPlayerName .. " is in a vehicle.", sourcePlayer )
-- if it's not in a vehicle,
else
-- tell the source player
outputChatBox ( checkedPlayerName .. " is not in a vehicle.", sourcePlayer )
end
-- if it doesn't exist,
else
-- tell the source player
outputChatBox ( "Invalid player name.", sourcePlayer )
end
end
 
-- define a handler for the isinvehicle command
addCommandHandler ( "isinvehicle", outputIsInVehicle )
</syntaxhighlight>


==See Also==
==See Also==
{{Player functions}}
{{Player functions}}

Latest revision as of 11:48, 26 June 2014

Emblem-important.png This function is deprecated. This means that its use is discouraged and that it might not exist in future versions.

Please use isPedInVehicle instead.


This function checks if a player is in a vehicle.

Syntax

bool isPlayerInVehicle ( player thePlayer )

Required Arguments

  • thePlayer: The player element you are checking.

Returns

Returns true if the player is inside a vehicle, false if he isn't or an invalid player was passed.

Example

This code defines an isinvehicle command which tells a player whether another player is in a vehicle or not.

-- we create our handler function, where sourcePlayer is the player who sent the command,
-- and checkedPlayerName is the player name specified.
function outputIsInVehicle ( sourcePlayer, commandName, checkedPlayerName )
	-- we get the player element from the nick specified
	local checkedPlayer = getPlayerFromNick ( checkedPlayerName )
	-- if it exists,
	if ( checkedPlayer ) then
		-- if it's in a vehicle,
		if isPlayerInVehicle ( checkedPlayer ) then
			-- tell the source player
			outputChatBox ( checkedPlayerName .. " is in a vehicle.", sourcePlayer )
		-- if it's not in a vehicle,
		else
			-- tell the source player
			outputChatBox ( checkedPlayerName .. " is not in a vehicle.", sourcePlayer )
		end
	-- if it doesn't exist,
	else
		-- tell the source player
		outputChatBox ( "Invalid player name.", sourcePlayer )
	end
end

-- define a handler for the isinvehicle command
addCommandHandler ( "isinvehicle", outputIsInVehicle )

See Also