• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • 🏆 Hive's 6th HD Modeling Contest: Mechanical is now open! Design and model a mechanical creature, mechanized animal, a futuristic robotic being, or anything else your imagination can tinker with! 📅 Submissions close on June 30, 2024. Don't miss this opportunity to let your creativity shine! Enter now and show us your mechanical masterpiece! 🔗 Click here to enter!

[Solved] [LUA] Need a little help

Status
Not open for further replies.
Level 8
Joined
Jun 16, 2008
Messages
333
So i am trying to remove every unit of Demon Hunter(Edem) of player slot that is unused. I know this can easily be done in the gui trigger but I am trying to learn LUA.
Lua:
function HelloWorld()
    CheckPlayers3()
    CheckPlayers()  
    print("Hello World")
end
function CheckPlayers3()
    print("checking3")
end
function CheckPlayers()
    print("checking...")
    local playerUnit = GetUnitsOfTypeIdAll("Edem")
    local playerSlot = GetPlayerSlotState(GetOwningPlayer(GetEnumUnit()))
    print(playerUnit)
    ForGroupBJ(playerUnit, HeroKill(playerUnit))
  
end
function HeroKill(x)
if playerSlot == FASLE then
    print("var var 2")
        print(x)
        RemoveUnit(x)
  
end
end
I get all the print and group number/id, whatever it is. However, non of the units gets removed.
 
Last edited:
I see but it didn't help... are there any good tutorials or documentation on LUA for warcraft 3? I couldn't find any...

Any standard Lua tutorial should apply to Warcraft III as well. You can look at the common.j if you don't know how various natives work.

Your code doesn't make sense in many places. I figure you are basically trying to do this:

Lua:
function CheckPlayers()
    ForGroup(GetUnitsOfTypeIdAll(FourCC("Edem")), HeroKill)
end

function HeroKill()
    local x = GetEnumUnit()
    local playerSlot = GetPlayerSlotState(GetOwningPlayer(x))
    if playerSlot == PLAYER_SLOT_STATE_EMPTY then
        RemoveUnit(x)
    end
end
 
Level 8
Joined
Jun 16, 2008
Messages
333
Any standard Lua tutorial should apply to Warcraft III as well. You can look at the common.j if you don't know how various natives work.

Your code doesn't make sense in many places. I figure you are basically trying to do this:

Lua:
function CheckPlayers()
    ForGroup(GetUnitsOfTypeIdAll(FourCC("Edem")), HeroKill)
end

function HeroKill()
    local x = GetEnumUnit()
    local playerSlot = GetPlayerSlotState(GetOwningPlayer(x))
    if playerSlot == PLAYER_SLOT_STATE_EMPTY then
        RemoveUnit(x)
    end
end
I was just plugging in different things to see if it worked....

But thanks, it worked! Ill do some more studying
 
Status
Not open for further replies.
Top