Jump to content

select specific elements from table


Cronoss

Recommended Posts

Hello again, I'm having a problem to understand how the tables work... I want to get ALL players inside a vehicle and get their health but I don't know how to make the table select every player and get their different healths

This is 

function vhDam(loss)
	local playersLossHP = getVehicleOccupants(source)
	local setLossToPlayers = getElementHealth(#playersLossHP) --------- how could I get every player's health?
---------------blablabla
end
addEventHandler("onVehicleDamage", root, vhDam)

 

Link to comment

try using it like this

function vhDam(loss)
   local playersLossHP = getVehicleOccupants(source) -- getVehicleOccupants returns a table
   for seat, player in pairs(playersLossHP) do --put this table in for loop
      local playerHealth = getElementHealth(player)  --get the hp of the player inside the vehicle
      outputDebugString("Seat ID: "..seat.." Player Health: "..playerHealth) --print seat id and player's health
   end
end
addEventHandler("onVehicleDamage", root, vhDam)
Edited by Burak5312
  • Thanks 1
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...