how can I use more "Unit"s in one LUA file menu

User Tag List

Results 1 to 6 of 6
  1. #1
    Gix85's Avatar Private
    Reputation
    1
    Join Date
    Feb 2011
    Posts
    10
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    how can I use more "Unit"s in one LUA file

    Hello!
    I've a problem with LUA scripting...I'll explain it with an example

    npc A (ID: 1)
    npc B (ID: 2)

    now....I'm working in A.lua and I want that ,when B's health is < 10%, then A has to begin "phase 2".. (I can work only in A.lua)
    so...

    function A_OnCombat(Unit (which is A's ID) , Unit1 (which is B's ID....theoretically), event)
    if Unit1:GetHealthPct() < 10 then
    Unit:RegisterEvent("A_phase2",500,0)
    end
    end

    RegisterUnitEvent(1,1,"A_OnCombat") <---- here I say that Unit is npc A

    but B???? how can I say that Unit1 is npc B??

    I thought to write a "local variable" on the top of the LUA file......but I don't know how use it...... "local Unit1 = NPCID(2)" ??............ I suppose that it's wrong (obviously)....So how I can solve this problem?

    I hope someone helps me!
    waiting for your answer!

    bye

    how can I use more &quot;Unit&quot;s in one LUA file
  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)
    local Unit1 = nil
    ^
    At top of script.

    function bla bla
    if health < 10 then
    register event

    Unit1 = pUnit:GetCreatureNearestCoords(x,y,z,id) -- fill this in, x,y,z of the npc you want to target and his entry ID

    end

  3. #3
    Gix85's Avatar Private
    Reputation
    1
    Join Date
    Feb 2011
    Posts
    10
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    so...should be
    "
    local Unit1 = nil

    function A_OnCombat(Unit, Unit1, event)
    Unit1 = Unit:GetCreatureNearestCoords(x,y,z,2)
    if Unit1:GetHealthPct() < 10 then
    Unit:RegisterEvent("A_phase2",500,0)
    end
    end "

    ?

    still not works

  4. #4
    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)
    you need to change the x,y,z of where the "Unit1" is. You've set his NPC ID to 2, which I doubt it is.

  5. #5
    Gix85's Avatar Private
    Reputation
    1
    Join Date
    Feb 2011
    Posts
    10
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    XD of course! in the real LUA, I've put the real coordinates x,y,z and the real ID of the creature! ......in the previous post,I've put 2 because it is B's ID in the example!
    anyway....still not works
    In the log, there's write that Unit1 is a nil value....

  6. #6
    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)
    Basically it's trying to find the creature and it can't, because it hasn't found the creature there.

    This method only checks within a small amount of X, Y and Z of the specified location, so the creature has to be more or less on it.

    Alternately, you can do this:
    Code:
    local Unit1 = nil
    
    function A_OnCombat(Unit, Unit1, event)
    if Unit1:GetHealthPct() < 10 then
    Unit:RegisterEvent("A_phase2",500,0)
    end
    end
    
    --- script stuff
    
    function Unit1_Spawns_SoWeDefine(pUnit, Event)
    Unit1 = pUnit
    end
    
    RegisterUnitEvent(npcid, 18, "Unit1_Spawns_SoWeDefine")

Similar Threads

  1. how can i bot more, with current hardware
    By critical88 in forum Diablo 3 Bots Questions & Requests
    Replies: 3
    Last Post: 07-26-2012, 11:04 PM
  2. How can I take more than 50k when I move realms?
    By neilneil123 in forum World of Warcraft General
    Replies: 9
    Last Post: 03-15-2011, 08:07 PM
  3. [Question] can't use more then 1 model??
    By AdR15 in forum WoW ME Questions and Requests
    Replies: 3
    Last Post: 07-15-2009, 11:00 PM
  4. [Question] How can I use C++ in Ascent?
    By dude891 in forum WoW EMU Questions & Requests
    Replies: 1
    Last Post: 08-27-2008, 07:59 AM
  5. How can i get more people to join my server properly ?
    By Wheeze201 in forum World of Warcraft Emulator Servers
    Replies: 2
    Last Post: 12-24-2007, 12:15 AM
All times are GMT -5. The time now is 01:40 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