[Lua] Newbie Lua scripting question (SOLVED) menu

User Tag List

Results 1 to 11 of 11
  1. #1
    Maybepie's Avatar Active Member
    Reputation
    25
    Join Date
    Aug 2008
    Posts
    147
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    [Lua] Newbie Lua scripting question (SOLVED)

    Everything bellow is solved thanks to the elite scripters of MMowned. :)
    Keeping the post as it is for others with similar issues.



    Not sure if anyone will read this, I don't want to spam the forum with another question thread so I'll just write my second question here and hope for an answer again. :)

    This is my try at creating a second phase, I want the mob to yell out TEXT2 at 80% health, what am I doing wrong this time?

    Code:
    function bossfight(pUnit, event)
        pUnit:SendChatMessage(14, 0, "Hm? You dare to challenge me?! Pfah!")
        pUnit:RegisterEvent("phase1", 5000, 0)
        pUnit:RegisterEvent("phase2", 1000, 0)
    end
    
    function phase1 (pUnit, event)
        if pUnit:GetHealthPct() < 95 then
        pUnit:RemoveEvents()
        pUnit:SetModel(27176)
        pUnit:SendChatMessage(14, 0, "TEXT1")
        pUnit:CastSpell(28498)
        end
    
    function phase2(pUnit, event)
        if pUnit:GetHealthPct() < 80 then
        pUnit:RemoveEvents()
        pUnit:SendChatMessage(14, 0, "TEXT2")
        end
    end
    
    RegisterUnitEvent(NPCID, 1, "bossfight")



    Oh hai!
    I recently found out about the wonderful world of LUA scripting and I decided to give it a try. I've been playing around in notepad for a hour or two now, just trying out the basics.
    But now I'm stuck! I can't seem to get my script running as I want to.
    Code:
    function Boss7_Test(pUnit, Event)
    pUnit:SendChatMessage(14, 1, "RANDOMTEXT")
    if pUnit:GetHealthPct() < 95 then
    pUnit:RemoveEvents();
    pUnit:SendChatMessage(14, 1, "RANDOMTEXT2")
    pUnit:SetModel(27176)
    end
    end
    
    RegisterUnitEvent(50007, 1, "Boss7_Test")
    I basically want the mob to first yell out RANDOMTEXT when pulled, and when he's at about 95% I want him to yell out RANDOMTEXT2 AS WELL as change his model to 27176.

    When I try it on my private server he only yells out the first text and then nothing happens, any idea how to fix this?

    There's obviously 2x+Rep cookies waiting to be eaten, if a decent answer is provided of course! :)
    Last edited by Maybepie; 04-16-2010 at 07:28 AM. Reason: Solved :D!
    Nyaa ~

    [Lua] Newbie Lua scripting question (SOLVED)
  2. #2
    alj03's Avatar Contributor
    Reputation
    91
    Join Date
    Feb 2008
    Posts
    1,103
    Thanks G/R
    0/1
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Now i am not pro at this but this is what i think:

    Wouldn't you use when he enters combat the function

    unit:SendChatMessage(14, 0, "RANDOMTEXT")
    end
    And then for the 2nd part have

    function transform(unit, Event)
    if unit:GetHealthPct() <=95 then
    unit:SendChatMessage(14, 0, "RANDOMTEXT2")
    unit:SetModel(27176
    end
    end
    Try tie this into the script, if it doesn't work, i'll leave it to the experts. :P
    Death to all but Metal.

  3. #3
    Ground Zero's Avatar ★ Elder ★
    Reputation
    1132
    Join Date
    Aug 2008
    Posts
    3,504
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You need to make it a seperate function, right now it's making him check if the HP is under 95% when he first starts combat.
    Code:
    function zzOnCombat(pUnit, event)
        pUnit:SendChatMessage(14, 0, "Text")
        pUnit:RegisterEvent("phase1", 3000, 0)
    end
    
    function phase1 (pUnit, event)
        if pUnit:GetHealthPct() < 95 then
        pUnit:RemoveEvents()
        pUnit:SetModel(ID)
        pUnit:SendChatMessage(14, 0, "BLAHBLAH"
        end
    end
    
    RegisterUnitEvent(NPCID, 1, "zzOnCombat")
    You need to register the next function in your current function, so as it is now it checks every 3 seconds to see if the npc is under 95% hp, when it is it will removeevents which means it will stop checking for phase1 and move into phase1 in which the npc will yell it's message. If you want to add extra phases just keep doing so using RegisterEvent and RemoveEvents. The 3000 in the register event stands for milliseconds, 3000 = 3 seconds. The 0 stands for how many times it checks, 0 = unlimited and of course 1,2,3 etc.
    Last edited by Ground Zero; 04-15-2010 at 08:10 AM.

  4. #4
    alj03's Avatar Contributor
    Reputation
    91
    Join Date
    Feb 2008
    Posts
    1,103
    Thanks G/R
    0/1
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I kind of got close? But yeah take GZ's advice. Mine was less thought out.
    Death to all but Metal.

  5. #5
    RyeRye's Avatar Contributor
    Reputation
    240
    Join Date
    Aug 2008
    Posts
    996
    Thanks G/R
    0/1
    Trade Feedback
    3 (100%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally Posted by Ground Zero View Post
    You need to make it a seperate function, right now it's making him check if the HP is under 95% when he first starts combat.
    Code:
    function zzOnCombat(pUnit, event)
        pUnit:SendChatMessage(14, 0, "Text")
        pUnit:RegisterEvent("phase1", 3000, 0)
    end
    
    function phase1 (pUnit, event)
        if pUnit:GetHealthPct() < 95 then
        pUnit:RemoveEvents()
        pUnit:SetModel(ID)
        pUnit:SendChatMessage(14, 0, "BLAHBLAH")
        end
    end
    
    RegisterUnitEvent(NPCID, 1, "zzOnCombat")

    GZ had it right, but he had 1 little error, and with 1 error the whole script won't work, so use this one, (GZ's with the fixed error).



  6. #6
    Ground Zero's Avatar ★ Elder ★
    Reputation
    1132
    Join Date
    Aug 2008
    Posts
    3,504
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally Posted by RyeRye View Post

    GZ had it right, but he had 1 little error, and with 1 error the whole script won't work, so use this one, (GZ's with the fixed error).
    You would have been right if you posted 7 mins ago. :3 Hehe already fixed it.

  7. #7
    RyeRye's Avatar Contributor
    Reputation
    240
    Join Date
    Aug 2008
    Posts
    996
    Thanks G/R
    0/1
    Trade Feedback
    3 (100%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Dang your on it! hahah.



  8. #8
    Maybepie's Avatar Active Member
    Reputation
    25
    Join Date
    Aug 2008
    Posts
    147
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Heh, thanks a lot for the quick answers!
    It works fine now, I didn't know I had to make it as a separate function, but I do now! :)

    EDIT:Rep cookies all around, sorry RyeRye gotta wait 24 hours until yours are ready. ( My rep oven is gettin' quite old you see. )
    Nyaa ~

  9. #9
    RyeRye's Avatar Contributor
    Reputation
    240
    Join Date
    Aug 2008
    Posts
    996
    Thanks G/R
    0/1
    Trade Feedback
    3 (100%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks bro .



  10. #10
    Ground Zero's Avatar ★ Elder ★
    Reputation
    1132
    Join Date
    Aug 2008
    Posts
    3,504
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Register phase2 in phase1, otherwise the RemoveEvents will cancel phase2 once it hits phase1

    It's always the same way, the previous phase registers the next phase.

  11. #11
    Maybepie's Avatar Active Member
    Reputation
    25
    Join Date
    Aug 2008
    Posts
    147
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally Posted by Ground Zero View Post
    Register phase2 in phase1, otherwise the RemoveEvents will cancel phase2 once it hits phase1

    It's always the same way, the previous phase registers the next phase.
    Ahh, I see what you mean. It's fixed now.
    Thanks once again Ground Zero, you rock! :)
    Nyaa ~

Similar Threads

  1. lua scripting question
    By deep6ixed in forum WoW EMU Questions & Requests
    Replies: 3
    Last Post: 08-08-2009, 06:31 AM
  2. Lua Scripting question.
    By gregzoid2 in forum World of Warcraft Emulator Servers
    Replies: 3
    Last Post: 07-06-2008, 02:45 PM
  3. LUA Script question.. [AI_Tick?]
    By Lakotaness in forum World of Warcraft Emulator Servers
    Replies: 2
    Last Post: 06-14-2008, 06:54 AM
  4. LUA script question
    By Zordin in forum World of Warcraft Emulator Servers
    Replies: 4
    Last Post: 06-08-2008, 06:24 AM
  5. LUA Script Question
    By abndrew82 in forum World of Warcraft Emulator Servers
    Replies: 0
    Last Post: 02-08-2008, 02:55 PM
All times are GMT -5. The time now is 07:00 AM. 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