[LUA] Check a Spawned unit's HP? Is it possible? menu

Shout-Out

User Tag List

Results 1 to 8 of 8
  1. #1
    controlsx2's Avatar Member
    Reputation
    16
    Join Date
    Jun 2007
    Posts
    223
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    [LUA] Check a Spawned unit's HP? Is it possible?

    Is it possible in LUA to check an Ads HP. I spawn the Ad at 20% and make my boss invincible is there anyway to then check that Ad's HP so that when the ad is on 10% i can make my boss able to attack again?

    I was thinking maybe this, but not sure if it would work

    AD = Unit:SpawnCreature (ADENTRYID, x, y, z, o, 14, 60000);

    function BOSS_CHECKAD(pUnit, Event)
    if AD:GetHealthPct() <= 10 then
    //Write in here
    end
    end


    Would that work, if not is it possible

    P.S On normal LUA engine

    [LUA] Check a Spawned unit's HP? Is it possible?
  2. #2
    stoneharry's Avatar Moderator Harry


    Reputation
    1618
    Join Date
    Sep 2007
    Posts
    4,564
    Thanks G/R
    151/150
    Trade Feedback
    0 (0%)
    Mentioned
    4 Post(s)
    Tagged
    0 Thread(s)
    Do it this way.

    Code:
    local ThisNpc -- Need this here to prevent bugs
    
    RegisterUnitEvent(id, 18, "define_OnSpawn")
    
    function define_OnSpawn(pUnit, event)
            ThisNpc = pUnit -- this npc is now a variable (only this one, not all of that id)
    end
    
    -- wheee loads of the boss script bla bla bla
    
    -- ok the boss function where you want to check adds hp
    
    function CheckAdd(pUnit, Event)
     if ThisNpc:GetHealthPct() <= 10 then
        pUnit:RemoveEvents()
        pUnit:SetFaction(20) -- hostile?
        pUnit:StopMovement(0) -- enable movment if you disabled
        pUnit:SetCombatCapable(1) -- allow it to attack
        pUnit:RemoveAura(1) -- If you gave it an aura like invicnible you can remove it with this
        end
    end

    Ask if you don't understand

  3. #3
    AngelSandy's Avatar Member
    Reputation
    19
    Join Date
    Jan 2009
    Posts
    330
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I think you made a mistake Harry.

    pUnit:SetCombatCapeable()

    Works a "Reversed" kinda way. It needs 1 for Not being able to attack, and 0 for being able to attack.

  4. #4
    controlsx2's Avatar Member
    Reputation
    16
    Join Date
    Jun 2007
    Posts
    223
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally Posted by stoneharry View Post
    Do it this way.

    Code:
    local ThisNpc -- Need this here to prevent bugs
    
    RegisterUnitEvent(id, 18, "define_OnSpawn")
    
    function define_OnSpawn(pUnit, event)
            ThisNpc = pUnit -- this npc is now a variable (only this one, not all of that id)
    end
    
    -- wheee loads of the boss script bla bla bla
    
    -- ok the boss function where you want to check adds hp
    
    function CheckAdd(pUnit, Event)
     if ThisNpc:GetHealthPct() <= 10 then
        pUnit:RemoveEvents()
        pUnit:SetFaction(20) -- hostile?
        pUnit:StopMovement(0) -- enable movment if you disabled
        pUnit:SetCombatCapable(1) -- allow it to attack
        pUnit:RemoveAura(1) -- If you gave it an aura like invicnible you can remove it with this
        end
    end

    Ask if you don't understand
    I think i get it what is 18 for then, when you use the Spawn Command? Also what if i was tracking 2 or 3 Ads

    would i have to do it like this?
    local ThisNpc
    local ThisNpc2

    RegisterUnitEvent(id, 18, "define_OnSpawn")

    function define_OnSpawn(pUnit, event)
    ThisNpc = pUnit -- this npc is now a variable (only this one, not all of that id)
    Unit:RemoveEvents()
    RegisterUnitEvent(id, 18, "define_OnSpawn2")

    ==Spawn Code Her
    end

    function define_OnSpawn2(pUnit, event)
    ThisNpc2 = pUnit -- this npc is now a variable (only this one, not all of that id)

    end

  5. #5
    stoneharry's Avatar Moderator Harry


    Reputation
    1618
    Join Date
    Sep 2007
    Posts
    4,564
    Thanks G/R
    151/150
    Trade Feedback
    0 (0%)
    Mentioned
    4 Post(s)
    Tagged
    0 Thread(s)
    Yup, then once the npc is defined as a variable you can use it anywhere else in that script. For example:
    Code:
    ThisNpc1:SendChatMessage(12, 0, "where are you?")
    ThisNpc2:SendChatMessage(12, 0, "Boo!")

  6. #6
    controlsx2's Avatar Member
    Reputation
    16
    Join Date
    Jun 2007
    Posts
    223
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Also one thing how would i do a timer, like if i wanted to spawn and then wait 10seconds and do somethign else, is there a sleep command or something?

  7. #7
    AngelSandy's Avatar Member
    Reputation
    19
    Join Date
    Jan 2009
    Posts
    330
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Code:
    function Spawn_Lawl(pUnit, event)
         pUnit:Spawncreature(blablabla)
         pUnit:RegisterEvent("Spawn_Lawlz",10000,1)
    end
    Could this be a suggestion?

  8. #8
    stoneharry's Avatar Moderator Harry


    Reputation
    1618
    Join Date
    Sep 2007
    Posts
    4,564
    Thanks G/R
    151/150
    Trade Feedback
    0 (0%)
    Mentioned
    4 Post(s)
    Tagged
    0 Thread(s)
    What AngelSandy said, you just register another event for on a timer, then when you function the next event RemoveEvents() to make it not repeat.

Similar Threads

  1. lua check if target is player
    By Thomja in forum WoW UI, Macros and Talent Specs
    Replies: 6
    Last Post: 01-22-2014, 08:47 AM
  2. LUA check Battleground status
    By Iaccidentallytwink in forum WoW UI, Macros and Talent Specs
    Replies: 7
    Last Post: 09-18-2012, 04:24 AM
  3. Check whether the unit is in visual range?
    By zys924 in forum WoW Memory Editing
    Replies: 8
    Last Post: 10-06-2010, 05:44 AM
  4. [LUA HELP] Boss spawning npc when he dies
    By Moaradin in forum WoW EMU Questions & Requests
    Replies: 12
    Last Post: 04-19-2009, 11:03 AM
  5. lua guide on spawning mobs after death
    By runiker in forum WoW EMU Guides & Tutorials
    Replies: 2
    Last Post: 03-10-2008, 01:57 AM
All times are GMT -5. The time now is 06:27 PM. Powered by vBulletin® Version 4.2.3
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved. User Alert System provided by Advanced User Tagging (Pro) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
Google Authenticator verification provided by Two-Factor Authentication (Free) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
Digital Point modules: Sphinx-based search