• 🏆 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 Adding locust ability

Status
Not open for further replies.
Level 4
Joined
Dec 26, 2021
Messages
45
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?
 
Level 4
Joined
Dec 26, 2021
Messages
45
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 :(
 
Level 39
Joined
Feb 27, 2007
Messages
5,033
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.
 
Level 4
Joined
Dec 26, 2021
Messages
45
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.
 

Uncle

Warcraft Moderator
Level 64
Joined
Aug 10, 2018
Messages
6,583
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

  • Locust Example.w3m
    16 KB · Views: 1
Level 4
Joined
Dec 26, 2021
Messages
45
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.
Top