View Single Post
02-28-14, 09:31 AM   #2
semlar
A Pyroguard Emberseer
 
semlar's Avatar
AddOn Author - Click to view addons
Join Date: Sep 2007
Posts: 1,060
First things first, you aren't grouping your conditions.
Lua Code:
  1. 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:
  1. elseif (event == 'PLAYER_ALIVE' or event == 'PLAYER_ENTERING_WORLD') and UnitIsGhost('player')

I would personally replace
Lua Code:
  1. if event == 'PLAYER_ENTERING_WORLD' and UnitInVehicle('player') or event == 'UNIT_ENTERED_VEHICLE' or event == 'UNIT_ENTERING_VEHICLE' then
  2.     hcur, hmax = UnitHealth('vehicle'), UnitHealthMax('vehicle')
  3. elseif event == 'PLAYER_ENTERING_WORLD' or 'UNIT_EXITING_VEHICLE' or 'UNIT_EXITED_VEHICLE' then
  4.     hcur, hmax = UnitHealth('player'), UnitHealthMax('player')
  5. elseif event == 'UNIT_HEALTH' then
  6.     hcur = UnitHealth('player') or UnitHealth('vehicle')
  7.     hmax = UnitHealthMax('player') or UnitHealthMax('vehicle')
  8. end
with something like this, since checking what event is firing doesn't really matter here
Lua Code:
  1. local unit = UnitInVehicle('player') and 'vehicle' or 'player'
  2. 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.
  Reply With Quote