First things first, you aren't grouping your conditions.
Lua Code:
elseif event == 'PLAYER_ALIVE' and UnitIsGhost('player') or event == 'PLAYER_ENTERING_WORLD' and UnitIsGhost('player')
Should be written like this using parentheses to group statements that should be evaluated together
Lua Code:
elseif (event == 'PLAYER_ALIVE' or event == 'PLAYER_ENTERING_WORLD') and UnitIsGhost('player')
I would personally replace
Lua Code:
if event == 'PLAYER_ENTERING_WORLD' and UnitInVehicle('player') or event == 'UNIT_ENTERED_VEHICLE' or event == 'UNIT_ENTERING_VEHICLE' then
hcur, hmax = UnitHealth('vehicle'), UnitHealthMax('vehicle')
elseif event == 'PLAYER_ENTERING_WORLD' or 'UNIT_EXITING_VEHICLE' or 'UNIT_EXITED_VEHICLE' then
hcur, hmax = UnitHealth('player'), UnitHealthMax('player')
elseif event == 'UNIT_HEALTH' then
hcur = UnitHealth('player') or UnitHealth('vehicle')
hmax = UnitHealthMax('player') or UnitHealthMax('vehicle')
end
with something like this, since checking what event is firing doesn't really matter here
Lua Code:
local unit = UnitInVehicle('player') and 'vehicle' or 'player'
local hcur, hmax = UnitHealth(unit), UnitHealthMax(unit)
The main time you would want to check the event is if you're watching something like UNIT_HEALTH_FREQUENT which fires very frequently and want to reduce how much you're doing in response to that event.