I never bothered with IsObjectAlive(). If the player is dead, then GetCharacterUnit() returns nil. Some of the functions accept nils as arguments and some crash when given nils. I never bothered to memorize which ones do which, so I always do a nil check before hand:
Code: Select all
local unit = GetCharacterUnit(player)
If unit == nil then return end --the function ends here if the player is dead
--player is alive if the code reaches this point
or
Code: Select all
local unit = GetCharacterUnit(player)
if unit ~= nil then
--player is alive, do something here
else
--player is dead here
end
--player is alive or dead here
I don't recommend storing units in an alive or dead table if it can be avoided. It's probably safe, but we don't know enough about the game's internal threading design. When a unit dies does OnCharacterDeath get called instantly or might some of our other code run beforehand (in which case you'll have a dead player in your alive table). Does a spawned player leaving the server trigger an OnCharacterDeath()? But those are only issues you need to think about if you're trying to make a very high quality map. It's safer to loop through all the units on a team as then you don't have those issues, but I never ran benchmarks and it can depend on what your map is doing.
Lua tables:
http://lua-users.org/wiki/TablesTutorial
If you want to see what something returns, just print it out. Almost everything will print out without crashing the game. There's a couple unicode strings that crash the game if you print them.
print("team member", GetTeamMember(1,2));
print("it's unit", GetCharacterUnit(GetTeamMember(1,2));
If you want to look at a table and have v1.3 installed use: uf_print( <table>, <true to print out nested table, else false for just the top level>, <starting depth number (for easier output reading only)> )
If you want to see everything available to you at that point print out Lua's global table (will freeze the game for a couple minutes while it prints everything): uf_print(_G, true, 0)