[Eluna] [3.3.5a] [TrinityCore] Whats wrong with this LUA script? menu

User Tag List

Results 1 to 7 of 7
  1. #1
    Togggy's Avatar Member
    Reputation
    1
    Join Date
    May 2021
    Posts
    8
    Thanks G/R
    1/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    [Eluna] [3.3.5a] [TrinityCore] Whats wrong with this LUA script?

    local NPC_ID = 43285

    function OnDamageTaken(pUnit, event)
    if creature:GetHealthPct() < 75 then
    creature:RemoveEvents();
    creature:SendUnitSay( "TESTING TESTING 123", 0 )
    creature:RemoveEvents();
    end
    end

    RegisterUnitEvent(NPC_ID, 23, OnDamageTaken)

    [Eluna] [3.3.5a] [TrinityCore] Whats wrong with this LUA script?
  2. #2
    stoneharry's Avatar Moderator Harry

    Authenticator enabled
    Reputation
    1613
    Join Date
    Sep 2007
    Posts
    4,554
    Thanks G/R
    151/146
    Trade Feedback
    0 (0%)
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    Quite a few things:

    Eluna API

    RegisterUnitEvent is not a valid Eluna function - are you trying to use the ArcEmu API?

    I suspect you want: Global:RegisterCreatureEvent - Eluna

    CREATURE_EVENT_ON_DAMAGE_TAKEN = 9, // (event, creature, attacker, damage)

    Now this documents different parameters and parameter order to what you have specified.

    Also you have called a parameter pUnit but you are refering to 'creature' in your script. 'creature' is not defined anywhere, you need to rename one or the other.

    You are called RemoveEvents twice - why? RemoveEvents is when you want to remove all events that have been registered with the RegisterEvent function on the object.

    I suspect you want something more like:
    Code:
    local NPC_ID = 43285
    
    local function OnDamageTaken(event, creature, attacker, damage)
        if creature:GetHealthPct() < 75 then
            creature:SendUnitSay("TESTING TESTING 123", 0)
        end
    end
    
    RegisterCreatureEvent(NPC_ID, 9, OnDamageTaken)
    But this is going to happen every time the creature takes damage while the health is less than 75%. I suspect you want something more like:
    Code:
    local NPC_ID = 43285
    
    local function CheckHealthPct(_, _, _, creature)
        if creature:GetHealthPct() < 75 then
            creature:RemoveEvents()
            creature:SendUnitSay("TESTING TESTING 123", 0)
        end
    end
    
    local function CreatureEvents(event, creature)
        if event == 1 then
            pUnit:RegisterEvent(CheckHealthPct, 1000, 0)
        else
            pUnit:RemoveEvents()
        end
    end
    
    RegisterCreatureEvent(NPC_ID, 1, CreatureEvents) -- OnCreatureEnterCombat
    RegisterCreatureEvent(NPC_ID, 2, CreatureEvents) -- OnCreatureLeaveCombat
    RegisterCreatureEvent(NPC_ID, 4, CreatureEvents) -- OnCreatureDied

  3. #3
    Togggy's Avatar Member
    Reputation
    1
    Join Date
    May 2021
    Posts
    8
    Thanks G/R
    1/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It didnt seem to do anything.
    trying to get creature to talk - YouTube

  4. #4
    stoneharry's Avatar Moderator Harry

    Authenticator enabled
    Reputation
    1613
    Join Date
    Sep 2007
    Posts
    4,554
    Thanks G/R
    151/146
    Trade Feedback
    0 (0%)
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    Originally Posted by Togggy View Post
    It didnt seem to do anything.
    trying to get creature to talk - YouTube
    Have you checked your Eluna log file for any errors?

  5. #5
    Togggy's Avatar Member
    Reputation
    1
    Join Date
    May 2021
    Posts
    8
    Thanks G/R
    1/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally Posted by stoneharry View Post
    Code:
    local function CreatureEvents(event, creature)
        if event == 1 then
            pUnit:RegisterEvent(CheckHealthPct, 1000, 0)
        else
            pUnit:RemoveEvents()
        end
    end
    the pUnit in this section was showing as an error, I replaced both pUnits with creature and it work as intended now. Much thanks!

  6. #6
    Togggy's Avatar Member
    Reputation
    1
    Join Date
    May 2021
    Posts
    8
    Thanks G/R
    1/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    So now it looks like this
    Code:
    local NPC_ID = 43285
    
    local function CheckHealthPct(_, _, _, creature)
        if creature:GetHealthPct() < 75 then
            creature:RemoveEvents()
            creature:SendUnitSay("You are unable to change destiny.", 0)
        end
    end
    
    local function CreatureEvents(event, creature)
        if event == 1 then
            creature:RegisterEvent(CheckHealthPct, 1000, 0)
        else
            creature:RemoveEvents()
        end
    end
    
    RegisterCreatureEvent(NPC_ID, 1, CreatureEvents) -- OnCreatureEnterCombat
    RegisterCreatureEvent(NPC_ID, 2, CreatureEvents) -- OnCreatureLeaveComat
    RegisterCreatureEvent(NPC_ID, 4, CreatureEvents) -- OnCreatureDied
    Last edited by Togggy; 06-08-2021 at 05:50 PM. Reason: bad copy/paste

  7. #7
    stoneharry's Avatar Moderator Harry

    Authenticator enabled
    Reputation
    1613
    Join Date
    Sep 2007
    Posts
    4,554
    Thanks G/R
    151/146
    Trade Feedback
    0 (0%)
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    Originally Posted by Togggy View Post
    the pUnit in this section was showing as an error, I replaced both pUnits with creature and it work as intended now. Much thanks!
    Ok great, I've been using pUnit for so many years now that it's muscle memory. It's not a particularly good naming convention, 'pointer to a unit' is more hungarian notation which is not that popular in modern software.

Similar Threads

  1. Whats wrong with this LUA Script?
    By controlsx2 in forum WoW EMU Questions & Requests
    Replies: 1
    Last Post: 06-16-2009, 01:01 AM
  2. whats wrong with this LUA?
    By Envoke in forum WoW EMU Questions & Requests
    Replies: 5
    Last Post: 02-22-2009, 10:06 AM
  3. [helpzerz] What is wrong with this lua script?
    By w21froster in forum World of Warcraft Emulator Servers
    Replies: 8
    Last Post: 05-21-2008, 09:45 PM
  4. Whats wrong with this LUA Script?
    By controlsx2 in forum World of Warcraft Emulator Servers
    Replies: 1
    Last Post: 05-20-2008, 03:03 PM
All times are GMT -5. The time now is 02:15 PM. Powered by vBulletin® Version 4.2.3
Copyright © 2024 vBulletin Solutions, Inc. All rights reserved. User Alert System provided by Advanced User Tagging (Pro) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
Digital Point modules: Sphinx-based search