Jump to content

Why is this other code not working?


Recommended Posts

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

	-- get the player's vehicle: if he is in one, output its health as well
	local playerVehicle = getPedOccupiedVehicle ( localPlayer )
	if playerVehicle then
		local vehicleHealth = getElementHealth ( playerVehicle ) / 10  -- Divide this by 10, as default the denominator is 1000
		outputChatBox ( "Your vehicle's health: " .. vehicleHealth )
	end
end
addCommandHandler ( "showhealth", showLocalHealth )

I copied this one directly from the MTA Wiki and it doesn't work. I receive no message. Why? And how to fix it?

Link to comment
49 minutes ago, DNL291 said:

It should work, I see no errors by looking at the code. Make sure to set it as client-side in meta.xml and type the command correctly.

(sou português, mas não sei se posso falar português aqui)

It was on a server-side script, that was the problem.

Anyways I can make it into a server-side?

 

And could you take answer me some small questions please?

Link to comment
  • Moderators

Se quiser postar em português use a seção Portuguesa, aqui: Portuguese / Português

 

Server-side version:

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

	-- get the player's vehicle: if he is in one, output its health as well
	local playerVehicle = getPedOccupiedVehicle ( thePlayer )
	if playerVehicle then
		local vehicleHealth = getElementHealth ( playerVehicle ) / 10  -- Divide this by 10, as default the denominator is 1000
		outputChatBox ( "Your vehicle's health: " .. vehicleHealth, thePlayer )
	end
end
addCommandHandler ( "showhealth", showLocalHealth )

 

Link to comment
On 22/01/2019 at 19:27, DNL291 said:

Se quiser postar em português use a seção Portuguesa, aqui: Portuguese / Português

 

Server-side version:


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

	-- get the player's vehicle: if he is in one, output its health as well
	local playerVehicle = getPedOccupiedVehicle ( thePlayer )
	if playerVehicle then
		local vehicleHealth = getElementHealth ( playerVehicle ) / 10  -- Divide this by 10, as default the denominator is 1000
		outputChatBox ( "Your vehicle's health: " .. vehicleHealth, thePlayer )
	end
end
addCommandHandler ( "showhealth", showLocalHealth )

 

Thanks!!

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...