This is a read only copy without any forum functionality of the old Modcraft forum.
If there is anything that you would like to have removed, message me on Discord via Kaev#5208.
Big thanks to Alastor for making this copy!

Menu

Author Topic: [LUA] Unit:GetHealthPct Not Working  (Read 1860 times)

Diemen

  • Registred Member
  • Race Changer
  • *****
  • Posts: 37
    • View Profile
[LUA] Unit:GetHealthPct Not Working
« on: March 08, 2013, 10:37:07 pm »
Hey Guys ,

I Made a Script but the problem is that when i use it ingame it Skips the Health Checks and Just proceeds to the next phase...
I tried everything i could find on the web but without any result...
Could it be that the Lua Engine i have in my server does not support this feature ? ( this could be the only thing i could think of at the moment.)

Well if some one could Check my Script for any bugs of have another solution , let me know !

Gr ,

Steve  

Ps. Scroll box for posting walls of Text not working or am i doing it wrong ? :P

Code: [Select]
---------------- Boss Fight  -----------------


-- Variables
local NPC_ID = 90016

--------------------- Combat States -------------------
function Lorean_OnEnterCombat(Unit, Event)
Unit:CastSpell(48469) -- MOTW
Unit:CastSpell(53307) -- Thorns
Unit:CastSpell(768) -- Catform
Unit:RegisterEvent("MangleCat", 1500, 0)
Unit:RegisterEvent("RakeCat", 2000, 0)
Unit:RegisterEvent("FerociousBite", 5000, 0)
Unit:RegisterEvent("TigersFury", 10000, 0)
Unit:SendChatMessage(14,0,"So you wish to challenge me !")
Unit:SendChatMessage(14,0,"Powers of the Ancestors I invoke the !")
Unit:RegisterEvent("Lorean_Phase1", 2000, 0) -- Phase begint na 2 seconden Zoals het moet.
Unit:SendChatMessage(14,0,"Fase 1 Gestart")
end

function Lorean_OnLeaveCombat(Unit, Event, player)
Unit:RemoveEvents()
end

function Lorean_OnKilledTarget(Unit, Event, player)
Unit:SendChatMessage(14,0,"You will not break this dream !")
end

function Lorean_OnDeath(Unit, Event, player)
Unit:SendChatMessage(14,0,"NOOOO !!!!")
Unit:RemoveEvents()
end


--------------- Phases -------------------

function Lorean_Phase1(Unit, Event)
if Unit:GetHealthPct() <= 90 then
Unit:RemoveEvents()
Unit:RegisterEvent("MoonkinForm", 1000, 1)
Unit:RegisterEvent("Roots", 6000, 0)
Unit:RegisterEvent("Moonfire", 2000, 0)
Unit:RegisterEvent("Starfire", 11000, 0)
Unit:RegisterEvent("Wrath", 2500, 0)
Unit:RegisterEvent("Hurricane", 15000, 0)
Unit:RegisterEvent("Lorean_Phase2", 1000, 0)
Unit:SendChatMessage(14,0,"Fase 2 Gestart")
end
end


function Lorean_Phase2(Unit, Event)
if Unit:GetHealthPct() <= 80 then
Unit:RemoveEvents()

Unit:RegisterEvent("Lorean_Phase3", 1000, 0)
Unit:SendChatMessage(14,0,"Fase 3 Gestart")
end
end

function Lorean_Phase3(Unit, Event, player)
Unit:SendChatMessage(14,0,"Fase 3 Gestart")
if Unit:GetHealthPct() <= 70 then
Unit:RemoveEvents()
Unit:RegisterEvent("Lorean_Phase4", 1000, 0)
end
end

function Lorean_Phase4(Unit, Event, player)
Unit:SendChatMessage(14,0,"Fase 4 Gestart")
if Unit:GetHealthPct() <= 50 then
Unit:RemoveEvents()
Unit:RegisterEvent("Lorean_Phase5", 1000, 0)
end
end

function Lorean_Phase5(Unit, Event, player)
Unit:SendChatMessage(14,0,"Fase 5 Gestart")
if Unit:GetHealthPct() <= 30 then
Unit:RemoveEvents()
Unit:RegisterEvent("Lorean_Phase6", 1000, 0)
end
end

function Lorean_Phase6(Unit, Event, player)
Unit:SendChatMessage(14,0,"Fase 6 Gestart")
if Unit:GetHealthPct() <= 10 then
Unit:RemoveEvents()
end
end
-------- Cat Spells -----
function Catform(Unit, Event)
Unit:CastSpell(768)
end
function MangleCat(Unit, Event, player)
Unit:CastSpellOnTarget(42389, Unit:GetMainTank())
end
function RakeCat(Unit, Event)
Unit:CastSpell(27638)
end
function TigersFury(Unit, Event)
Unit:CastSpell(9845)
end
function FerociousBite(Unit, Event)
Unit:CastSpell(27557)
end


-------- Bear Spells -----
function Bearform(Unit, Event)
Unit:CastSpell(9634)
end
function MangleBear(Unit, Event)
Unit:CastSpell(42389)
end
function Barkskin(Unit, Event)
Unit:CastSpell(22812)
end
function Demo_Roar(Unit, Event)
Unit:CastSpell(9898)
end
function FaerieFireFeral(Unit, Event)
Unit:CastSpell(16857)
end
function Bash(Unit, Event)
Unit:CastSpell(8983)
end
function FrenzyRegen(Unit, Event)
Unit:CastSpell(22842)
end

-------- Healing Spells -----
function Regrowth(Unit, Event)
Unit:CastSpell(48443)
end

-------- Attack Spells -----
function MoonkinForm(Unit, Event, player)
Unit:CastSpell(24858)
end
function Moonfire(Unit, Event)
Unit:CastSpell(48469)
end
function Roots(Unit, Event)
Unit:CastSpell(21331)
end
function Wrath(Unit, Event)
Unit:CastSpell(48461)
end
function Starfire(Unit, Event)
Unit:CastSpell(48465)
end
function Hurricane(Unit, Event)
Unit:CastSpell(48467)
end




RegisterUnitEvent(90016, 1, "Lorean_OnEnterCombat")
RegisterUnitEvent(90016, 2, "Lorean_OnLeaveCombat")
RegisterUnitEvent(90016, 3, "Lorean_OnKilledTarget")
RegisterUnitEvent(90016, 4, "Lorean_OnDeath")
« Last Edit: January 01, 1970, 01:00:00 am by Admin »

Diemen

  • Registred Member
  • Race Changer
  • *****
  • Posts: 37
    • View Profile
Re: [LUA] Unit:GetHealthPct Not Working
« Reply #1 on: March 14, 2013, 01:40:37 am »
60 views and no one who can  give me an answer ? ...
« Last Edit: January 01, 1970, 01:00:00 am by Admin »

schlumpf

  • Administrator
  • Creator of Worlds
  • *****
  • Posts: 2967
    • View Profile
Re: [LUA] Unit:GetHealthPct Not Working
« Reply #2 on: March 14, 2013, 08:59:17 am »
Quote
Could it be that the Lua Engine i have in my server does not support this feature ? ( this could be the only thing i could think of at the moment.)
yes, but you never said which server or engine you use instead of pasting al code that does not matter. Refer I their documentation.
« Last Edit: January 01, 1970, 01:00:00 am by Admin »

Ascathos

  • Moderators
  • Creator of Worlds
  • *****
  • Posts: 1129
    • View Profile
Re: [LUA] Unit:GetHealthPct Not Working
« Reply #3 on: March 14, 2013, 01:34:36 pm »
ArcEmu supports LUA. Not sure if the boss scripts do, though.

Trinity Core does not. I suggest looking into EventMap.
« Last Edit: January 01, 1970, 01:00:00 am by Admin »

Diemen

  • Registred Member
  • Race Changer
  • *****
  • Posts: 37
    • View Profile
Re: [LUA] Unit:GetHealthPct Not Working
« Reply #4 on: March 14, 2013, 07:36:58 pm »
I'm sorry for being not clear enough , i am indeed using  a arcemu Server.
i never had any trouble with Scripts like these on my old server btw.
ArcEmu is using LuaEngine  i didn't use LuaBridge
« Last Edit: January 01, 1970, 01:00:00 am by Admin »

schlumpf

  • Administrator
  • Creator of Worlds
  • *****
  • Posts: 2967
    • View Profile
Re: [LUA] Unit:GetHealthPct Not Working
« Reply #5 on: March 15, 2013, 01:42:58 am »
What is the behavior you expect? What is the behavior you get?
« Last Edit: January 01, 1970, 01:00:00 am by Admin »

Diemen

  • Registred Member
  • Race Changer
  • *****
  • Posts: 37
    • View Profile
Re: [LUA] Unit:GetHealthPct Not Working
« Reply #6 on: March 15, 2013, 04:00:00 am »
As i explained in my first post  i want the script to check the boss its hp %  
Under a certain amount i want to start the next phase.
In this case it is a Druid boss.
When she enters combat she has to buff herself with Motw and Thorns , then turn into a cat and start attacking till her hp is under 90%
Then she has to turn into a moonkin and continue fighting untill the next phase.

The problem is that the server does read the script but won't check the boss her hp.
She enters combat , buffs , turns into a cat , turn into a moonkin an then the script is done.
I added a say function to check wich phase she was , she yells  phase 1 gestart  and so on.
But she goes from start to the last phase in about 5 seconds.

I hope this is clear enough  :D
« Last Edit: January 01, 1970, 01:00:00 am by Admin »

schlumpf

  • Administrator
  • Creator of Worlds
  • *****
  • Posts: 2967
    • View Profile
Re: [LUA] Unit:GetHealthPct Not Working
« Reply #7 on: March 15, 2013, 09:51:33 am »
Try something called "debugging":
Code: [Select]
function enter_combat (Unit, Event)
  Unit:RegisterEvent ("health_check", 1000, 0)
end
function leave_combat (Unit, Event, player)
  Unit:RemoveEvents()
end

function health_check (Unit, Event)
  Unit:SendChatMessage (14, 0, "GetHealthPct: " .. Unit::GetHealthPct())
  if Unit:GetHealthPct() <= 50 then
    Unit:SendChatMessage (14, 0, "health below 50%")
  end
end

RegisterUnitEvent (90016, 1, "enter_combat")
RegisterUnitEvent (90016, 2, "leave_combat")
RegisterUnitEvent (90016, 4, "leave_combat")
« Last Edit: January 01, 1970, 01:00:00 am by Admin »