• Check out the results of the Techtree Contest #19!
  • Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.
  • Create a void inspired texture for Warcraft 3 and enter Hive's 34th Texturing Contest: Void! Click here to enter!
  • The Hive's 22nd Icon Contest: Creep Abilities is now concluded, time to vote for your favourite set of icons! Click here to vote!

[Solved] LUA Adding locust ability

Status
Not open for further replies.
Level 4
Joined
Dec 26, 2021
Messages
47
Hello, just starting off LUA and i think there's some differences to Jass with ability and unit codes, i see something about FourCC but i can't seem to get this to work.
currently trying to add to a GUI "for each unit in unit group do action(s): via custom script
  • Unit Group - Pick every unit in myUG and do (Actions)
    • Loop - Actions
      • Custom script: UnitAddAbility(GetEnumUnit(), FourCC("Aloc"))
I also tried just 'Aloc', and multiple other combinations, also setting picked unit to a variable and then running udg_myunitvariable instead of GetEnumUnit() but still no luck.

Can someone please point out my mistake?
 
Is there a compile error or just nothing is having locust added to it? Is your map actually set to use Lua, or is it still in JASS? Scenario > Map Options > Script Language.
No compiler error in any scenario i have tried, only that locust is not added. Yes it is set to use LUA, everything else i am doing in LUA is working just issues with ability codes :(
 
I'm unfamiliar because I don't generally program in Lua but it appears that Blizzard's FourCC implementation is broken in some ways. This is explained in detail in this thread, which contains a replacement function you can try instead.
Lua:
function unreforgedFourCC(str)
    local n = 0
    local len = #str
    for i = len, 1, -1 do
        n = n + (str:byte(i,i) << 8*(len-i)) -- shift by 0,8,16,24
    end
    return n
end
Put that in your map's "custom script" header and then use that function instead in your custom script line.
 
I'm unfamiliar because I don't generally program in Lua but it appears that Blizzard's FourCC implementation is broken in some ways. This is explained in detail in this thread, which contains a replacement function you can try instead.
Lua:
function unreforgedFourCC(str)
    local n = 0
    local len = #str
    for i = len, 1, -1 do
        n = n + (str:byte(i,i) << 8*(len-i)) -- shift by 0,8,16,24
    end
    return n
end
Put that in your map's "custom script" header and then use that function instead in your custom script line.
thanks, I have added to the header, updated the call as below but still no luck.. Tried the below so far:

UnitAddAbility(GetEnumUnit(), unreforgedFourCC('Aloc'))
UnitAddAbility(udg_myUnitVar, unreforgedFourCC('Aloc'))
UnitAddAbility(GetEnumUnit(), FourCC('Aloc'))
UnitAddAbility(myUnitVar, FourCC('Aloc'))
UnitAddAbility(GetEnumUnit(), 'Aloc')
UnitAddAbility(myUnitVar, 'Aloc')
Also tried the above 4 combinations with "Aloc" instead of 'Aloc'

very confusing as it works fine on jass using the last 2..
 
Hello, just starting off LUA and i think there's some differences to Jass with ability and unit codes, i see something about FourCC but i can't seem to get this to work.
currently trying to add to a GUI "for each unit in unit group do action(s): via custom script
  • Unit Group - Pick every unit in myUG and do (Actions)
    • Loop - Actions
      • Custom script: UnitAddAbility(GetEnumUnit(), FourCC("Aloc"))
I also tried just 'Aloc', and multiple other combinations, also setting picked unit to a variable and then running udg_myunitvariable instead of GetEnumUnit() but still no luck.

Can someone please point out my mistake?
Can you post the whole script and let your trigger print some messages to the screen to know that the trigger executes and reached the end. Lua silently crashs current running code, when it encounters errors.
 
This works fine for me:
  • Untitled Trigger 001
    • Events
      • Time - Elapsed game time is 1.00 seconds
    • Conditions
    • Actions
      • Unit Group - Pick every unit in (Units in (Playable map area)) and do (Actions)
        • Loop - Actions
          • Custom script: local u = GetEnumUnit()
          • Custom script: UnitAddAbility(u, FourCC('Aloc'))
I'm on the latest patch (1.34).
 

Attachments

No I figured it out thanks to the above 2 posts; i was adding locust to units which were hidden which resulted in them becoming invulnerable but still selectable and controllable. Locust was level 1 for these but i could still control them etc... (The issue was the units were already invulnerable so i could not see this).

solution is to add locust only when unit is not hidden.

How toggling hide/unhide for locust unit works is my next set of investigation
 
Status
Not open for further replies.
Back
Top