GetElementHealth: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
mNo edit summary
mNo edit summary
Line 1: Line 1:
{{Server client function}}
{{Server client function}}
__NOTOC__
__NOTOC__
This function returns a float that contains the current health for the specified [[element]]. This can be a [[player]] or a [[vehicle]].
This function returns the current health for the specified [[element]]. This can be a [[player]] or a [[vehicle]].


==Syntax==
==Syntax==

Revision as of 01:13, 17 September 2007

This function returns the current health for the specified element. This can be a player or a vehicle.

Syntax

Click to collapse [-]
Server and client
float getElementHealth ( element theElement )

Required Arguments

  • theElement: The player or vehicle whose health you want to check.

Returns

Returns a float indicating the element's health, or false if invalid arguments were passed.

Example

Click to collapse [-]
Clientside example

This example outputs the health of the player who enters the command 'showhealth', and their vehicle's health.

function showLocalHealth()
	-- get the player's health and output it
	local playerHealth = getElementHealth ( getLocalPlayer() )
	outputChatBox ( "Your health: " .. playerHealth )

	-- get the player's vehicle: if he is in one, output its health as well
	local playerVehicle = getPlayerOccupiedVehicle ( getLocalPlayer() )
	if playerVehicle then
		local vehicleHealth = getElementHealth ( playerVehicle )
		outputChatBox ( "Your vehicle's health: " .. vehicleHealth )
	end
end
addCommandHandler ( "showhealth", showLocalHealth )

See Also

Shared