Stupid Locust..

Exide

I am amazingly focused right now!
Reaction score
448
Hi.
I made another thread about this, in the GUI-section, and there I decided to make a trigger that checks the points of all locust units of a certain type, and then compare it to the point where the "hero unit" is.
So I made it in JASS. Surprisingly, it actually saved the map and was able to start it (I was expecting a crash or two,) but not-so-surprisingly it doesn't work.

EDIT: Right, what the trigger is supposed to do:
Whenever one of these Locust-units comes within 70 range of the Hero-unit, the Hero-unit recieves 50hp damage, and the Locust-unit is removed from the game.


So here's my trigger: (It's Initially Off, but is Turned On, using another trigger.)
JASS:

function Trig_Setting_Points_Actions takes nothing returns nothing
    local location array checkloc
    local location heroloc
    local unit hero
    local group locustgroup
    local integer loopstart
    local integer loopend
    
    set hero = udg_Hero
    set heroloc = GetUnitLoc(hero)
    set locustgroup = GetUnitsOfTypeIdAll('h00W')
    set loopend = CountUnitsInGroup(locustgroup)
    set loopstart = 1
    
    loop
        exitwhen loopstart > loopend 
        set checkloc[loopstart] = GetUnitLoc(GetEnumUnit())
        if ( DistanceBetweenPoints(heroloc, checkloc[loopstart]) < 71.00 ) then
                    call UnitDamageTargetBJ( GetEnumUnit(), hero, 50.00, ATTACK_TYPE_CHAOS, DAMAGE_TYPE_LIGHTNING )
                    call AddSpecialEffectLoc( "Abilities\\Spells\\Human\\Thunderclap\\ThunderClapCaster.mdl", heroloc)
                    set udg_SpecialFX = bj_lastCreatedEffect
                    call TriggerExecute( gg_trg_Special_Effect_Destruction )
                    call RemoveUnit( GetEnumUnit() )
            else
            endif
        set loopstart = loopstart + 1
    endloop
    
    set loopstart = 1
    
    loop
        exitwhen loopstart > loopend
        call RemoveLocation(checkloc[loopstart])
        set checkloc[loopstart] = null
        set loopstart = loopstart + 1
    endloop

    call DestroyGroup(locustgroup)
    call RemoveLocation(heroloc)
    set heroloc = null
    set hero = null
    
endfunction

//===========================================================================
function InitTrig_Setting_Points takes nothing returns nothing
    set gg_trg_Setting_Points = CreateTrigger(  )
    call TriggerRegisterTimerEventPeriodic( gg_trg_Setting_Points, 0.50 )
    call TriggerAddAction( gg_trg_Setting_Points, function Trig_Setting_Points_Actions )
endfunction


Any ideas?
(Oh, and as a "bonus", how would I get rid of that BJ in 'UnitDamageTargetBJ'? -according to JassCraft, UnitDamageTarget has a lot more "settings".)

Thank you. :)
/Exide.
 

darkbeer

Beer is Good!
Reaction score
84
hm, one mistake lies here:

JASS:
set checkloc[loopstart] = GetUnitLoc(GetEnumUnit())


GetEnumUnit is only used in ForGroup Actions, it will return null here.

other suggestion loop through the group:

JASS:
function Trig_Setting_Points_Actions takes nothing returns nothing
    local location checkloc
    local unit hero = udg_Hero
    local location heroloc = GetUnitLoc(hero)
    local group locustgroup = GetUnitsOfTypeIdAll('h00W')
    local unit first
    
    loop
        set first = FirstOfGroup(locustgroup)
        exitwhen first == null
        set checkloc = GetUnitLoc(first)
        if ( DistanceBetweenPoints(heroloc, checkloc[loopstart]) < 71.00 ) then
                    call UnitDamageTargetBJ( GetEnumUnit(), hero, 50.00, ATTACK_TYPE_CHAOS, DAMAGE_TYPE_LIGHTNING )
                    call AddSpecialEffectLoc( "Abilities\\Spells\\Human\\Thunderclap\\ThunderClapCaster.mdl", heroloc)
                    set udg_SpecialFX = bj_lastCreatedEffect
                    call TriggerExecute( gg_trg_Special_Effect_Destruction )
                    call GroupRemoveUnit(locustgroup,first )
         endif
         call RemoveLocation(checkloc)
    endloop

.......
 

PurgeandFire

zxcvmkgdfg
Reaction score
509
GetEnumUnit() is null. You'll have to use "ForGroup" and use GetEnumUnit in the callback.

Or you can just use "FirstOfGroup(locustgroup)"

Damn... Beat to the post... I spent too long trying to optimize the code but I just gave up. :p
 

Exide

I am amazingly focused right now!
Reaction score
448
So this is how it turned out:

JASS:

function Trig_Setting_Points_Actions takes nothing returns nothing
    local location checkloc
    local location heroloc = GetUnitLoc(udg_Hero)
    local unit hero = udg_Hero
    local group locustgroup = GetUnitsOfTypeIdAll('h00W')
    local unit first
    
    loop
        set first = FirstOfGroup(locustgroup)
        exitwhen first == null
        set checkloc = GetUnitLoc(first)
        if ( DistanceBetweenPoints(heroloc, checkloc) < 71.00 ) then
                    call UnitDamageTargetBJ( GetEnumUnit(), hero, 50.00, ATTACK_TYPE_CHAOS, DAMAGE_TYPE_LIGHTNING )
                    call AddSpecialEffectLoc( "Abilities\\Spells\\Human\\Thunderclap\\ThunderClapCaster.mdl", heroloc)
                    set udg_SpecialFX = bj_lastCreatedEffect
                    call TriggerExecute( gg_trg_Special_Effect_Destruction )
                    call GroupRemoveUnit(locustgroup,first )
            endif
    endloop

    call DestroyGroup(locustgroup)
    call RemoveLocation(checkloc)
    call RemoveLocation(heroloc)
    set checkloc = null
    set heroloc = null
    set hero = null
    
endfunction

//===========================================================================
function InitTrig_Setting_Points takes nothing returns nothing
    set gg_trg_Setting_Points = CreateTrigger(  )
    call TriggerRegisterTimerEventPeriodic( gg_trg_Setting_Points, 0.50 )
    call TriggerAddAction( gg_trg_Setting_Points, function Trig_Setting_Points_Actions )
endfunction


It nearly worked.
There was no damage dealt to the Hero, and the Lightning Bolt just went right past. However, the special effect showed at like 50% of the times a lightning bolt passed by the hero. There was also heavy lag.
-Maybe I did something wrong?
 

PurgeandFire

zxcvmkgdfg
Reaction score
509

Exide

I am amazingly focused right now!
Reaction score
448
Yea, I figured GetEnumUnit() in the 'UnitDamageTargetBJ' function was the damage problem. -I doubt that will solve the lag, though. :(
Oh, and I'm not quite sure what 'GroupRemoveUnit' does. Sounds like 'remove *unit* from *group*'. -When I want to remove the unit from the game.

The special effect was the only thing that worked. :p So no need going on about that, but here's the trigger, just for the heck of it:

Code:
Special Effect Destruction
    Events
    Conditions
    Actions
        Custom script:   local effect tempEffect
        Custom script:   set tempEffect = udg_SpecialFX
        Wait 7.00 game-time seconds
        Custom script:   set udg_SpecialFX = tempEffect
        Special Effect - Destroy SpecialFX
 

PurgeandFire

zxcvmkgdfg
Reaction score
509
It is probably the 7 seven second wait. You wait like 7 seconds every .5 seconds. :p Why not just destroy it automatically? The thunder clap only lasts a few seconds so you can destroy it automatically.

;) And it is not MUI (your trig) so it will probably miss some sfx.
 

Exide

I am amazingly focused right now!
Reaction score
448
So how do I remove the unit that comes within range of Hero?

EDIT:
Instead of cleaning up the Special Effect automatically, I decided to completely remove it. So I removed these two functions:
JASS:

     set udg_SpecialFX = AddSpecialEffectLoc( "Abilities\\Spells\\Human\\Thunderclap\\ThunderClapCaster.mdl", heroloc)
    call TriggerExecute( gg_trg_Special_Effect_Destruction )


And it STILL lags..
 

darkbeer

Beer is Good!
Reaction score
84
okay. completely optimized:

JASS:
function Trig_Setting_Points_Actions takes nothing returns nothing
    local location checkloc
    local location heroloc = GetUnitLoc(udg_Hero)
    local unit hero = udg_Hero
    local group locustgroup = GetUnitsOfTypeIdAll('h00W')
    local unit first
    
    loop
        set first = FirstOfGroup(locustgroup)
        exitwhen first == null
        set checkloc = GetUnitLoc(first)
        if ( DistanceBetweenPoints(heroloc, checkloc) < 71.00 ) then
                    call UnitDamageTargetBJ( first, hero, 50.00, ATTACK_TYPE_CHAOS, DAMAGE_TYPE_LIGHTNING )
                    call DestroyEffect( AddSpecialEffectLoc("Abilities\\Spells\\Human\\Thunderclap\\ThunderClapCaster.mdl", heroloc))
                    call GroupRemoveUnit(locustgroup,first )
                    call RemoveUnit(first) // <-- will remove locust unit
        endif
        call RemoveLocation(checkloc)
    endloop

    call DestroyGroup(locustgroup)
    call RemoveLocation(heroloc)
    set checkloc = null
    set heroloc = null
    set hero = null
    set locustgroup = null
    
endfunction

//===========================================================================
function InitTrig_Setting_Points takes nothing returns nothing
    local trigger t = CreateTrigger(  )
    call TriggerRegisterTimerEventPeriodic( t, 0.50 )
    call TriggerAddAction( t, function Trig_Setting_Points_Actions )
    set t = null
endfunction


How many locust units do you have in your map?
 

Exide

I am amazingly focused right now!
Reaction score
448
I don't know how many I have. They're spawned every X and are removed when they reach their final area.

JASS:

function Trig_Spawn_Lightning_Bolts_Actions takes nothing returns nothing
    local location array spawnloc
    local integer loopstart
    local integer loopend
    local integer startloop

    set spawnloc[1] = GetRectCenter(gg_rct_Trap_loc1)
    set spawnloc[2] = GetRectCenter(gg_rct_Trap_loc3)
    set spawnloc[3] = GetRectCenter(gg_rct_Trap_loc5)
    set spawnloc[4] = GetRectCenter(gg_rct_Trap_loc7)
    set spawnloc[5] = GetRectCenter(gg_rct_Trap_loc9)
    set spawnloc[6] = GetRectCenter(gg_rct_Trap_loc11)
    set spawnloc[7] = GetRectCenter(gg_rct_Trap_loc13)
    set spawnloc[8] = GetRectCenter(gg_rct_Trap_loc15)

    set loopstart = 1
    set loopend = GetRandomInt(5, 10)
    loop
        exitwhen loopstart > loopend
        call CreateNUnitsAtLoc( 1, 'h00W', Player(2), spawnloc[GetRandomInt(1, 8)], 270.00 )
        set loopstart = loopstart + 1
    endloop

    set startloop = 1
    loop
        exitwhen startloop > 8
        call RemoveLocation(spawnloc[startloop])
        set spawnloc[startloop] = null
        set startloop = startloop + 1
    endloop

endfunction

//===========================================================================
function InitTrig_Spawn_Lightning_Bolts takes nothing returns nothing
    set gg_trg_Spawn_Lightning_Bolts = CreateTrigger(  )
    call DisableTrigger( gg_trg_Spawn_Lightning_Bolts )
    call TriggerRegisterTimerEventPeriodic( gg_trg_Spawn_Lightning_Bolts, GetRandomReal(2.00, 3.50) )
    call TriggerAddAction( gg_trg_Spawn_Lightning_Bolts, function Trig_Spawn_Lightning_Bolts_Actions )
endfunction


How can this work:
JASS:

call DestroyEffect( AddSpecialEffectLoc("Abilities\\Spells\\Human\\Thunderclap\\ThunderClapCaster.mdl", heroloc))

?

I will try your trigger now and see what happens.

EDIT: Tried it, and it's still laggy (maybe a tiny bit less lag now), and the locust unit still don't get removed. :(
 

PurgeandFire

zxcvmkgdfg
Reaction score
509
Here it is, this is pretty much as optimized as possible. GroupAddGroupEnum is a BJ, but since all ForGroups follow the same line, it is fine in that case.

So yeah, here it is. I don't think there are any BJs (A lot were BJs, but just didn't have BJ at the end)
JASS:
function Setting_Points_Actions takes nothing returns nothing
    local real cx
    local real cy
    local unit hero = udg_Hero
    local real hx = GetUnitX(hero)
    local real hy = GetUnitY(hero)
    local group locustgroup = CreateGroup()
    local group g = CreateGroup()
    local unit first
    local integer i = 0
    local real dist
    
    loop
        call GroupClear(g)
        call GroupEnumUnitsOfPlayer(g,Player(i),filterGetUnitsOfTypeIdAll)
        set bj_groupAddGroupDest = locustgroup 
        call ForGroup(g,function GroupAddGroupEnum)
        set i = i + 1
        exitwhen i == 16
    endloop
    call DestroyGroup(g)
    set g = null
    
    loop
        set first = FirstOfGroup(locustgroup)
        exitwhen first == null
        set cx = GetUnitX(first)
        set cy = GetUnitY(first)
        set dist = (cx-hx*cx-hx+cy-hy*cy-hy)
        if dist < 71 then
            call UnitDamageTarget(first,hero,50,true,false,ATTACK_TYPE_CHAOS,DAMAGE_TYPE_LIGHTNING,WEAPON_TYPE_WHOKNOWS)
            call DestroyEffect(AddSpecialEffect("Abilities\\Spells\\Human\\Thunderclap\\ThunderClapCaster.mdl",hx,hy))
            call RemoveUnit(first)
        endif
        call GroupRemoveUnit(locustgroup,first)
    endloop
    
    call DestroyGroup(locustgroup)
    set first = null
    set hero = null
endfunction


See if that works. It has a lot more lines, but technically, it has less lines and is faster. :p
 

Exide

I am amazingly focused right now!
Reaction score
448
JASS:

set dist = (cx-hx*cx-hx+cy-hy*cy-hy)


Wow. :p

I really appriciate all the effort you put into helping me, both of you.

Too bad this one didn't work either.
There was no lag this time, but also no damage and no special effect and still no locust unit removes.

What about a different way of approaching this?
Could I, using the spawn trigger (see post #11), set variables to each spawned Locust Units, and check whenever a unit comes within X of *Variable_unit*?
 

PurgeandFire

zxcvmkgdfg
Reaction score
509
This should cover it :p
JASS:
function Trig_In_Range_Conditions takes nothing returns boolean
    return GetUnitTypeId(GetTriggerUnit()) == 'h00W'
endfunction

function True takes nothing returns boolean
    return true //dummy filter, possible hazards of nulling boolexpr arguement as far as I know
endfunction

function Trig_In_Range_Actions takes nothing returns nothing
    local real x = GetUnitX(GetTriggerUnit())
    local real y = GetUnitY(GetTriggerUnit())
    call DestroyEffect(AddSpecialEffect("Abilities\\Spells\\Human\\Thunderclap\\ThunderClapCaster.mdl",x,y)
    call RemoveUnit(GetTriggerUnit())
endfunction

//==== Init Trigger NewTrigger ====
function InitTrig_In_Range takes nothing returns nothing
    set gg_trg_In_Range = CreateTrigger()
    call TriggerRegisterUnitInRange(gg_trg_In_Range,udg_Hero,71,Condition(function True))
    call TriggerAddCondition(gg_trg_In_Range, Condition(function Trig_In_Range_Conditions))
    call TriggerAddAction(gg_trg_In_Range, function Trig_In_Range_Actions)
endfunction
 

Exide

I am amazingly focused right now!
Reaction score
448
I'm quite sure that:
JASS:

function Trig_In_Range_Conditions takes nothing returns boolean
    return GetUnitTypeId(GetTriggerUnit()) == 'h00W'
endfunction

doesn't work if 'h00W' has the Locust ability.

EDIT: If I'm wrong, I misunderstood your trigger.
 

PurgeandFire

zxcvmkgdfg
Reaction score
509
I added Locust to a footman, then did this trigger:
JASS:
function Trig_TRIG_Actions takes nothing returns nothing
    local integer i = GetUnitTypeId(udg_Foot)
    if GetUnitTypeId(udg_Foot) == 'hfoo' then
        call BJDebugMsg(I2S(i))
    endif
endfunction

//===========================================================================
function InitTrig_TRIG takes nothing returns nothing
    set gg_trg_TRIG = CreateTrigger(  )
    call TriggerRegisterTimerEventSingle( gg_trg_TRIG, 3.00 )
    call TriggerAddAction( gg_trg_TRIG, function Trig_TRIG_Actions )
endfunction


And it worked fine. It displayed the message.

Basically, my trigger checks if there is a unit within 71.00 of udg_Hero. If there is, it will add the effect then remove the locust unit. ;)
 

Exide

I am amazingly focused right now!
Reaction score
448
I copied your trigger like this:

JASS:

function Trig_In_Range_Conditions takes nothing returns boolean
    return GetUnitTypeId(GetTriggerUnit()) == 'h00W'
endfunction

function True takes nothing returns boolean
    return true //dummy filter, possible hazards of nulling boolexpr arguement as far as I know
endfunction

function Trig_In_Range_Actions takes nothing returns nothing
    local real x = GetUnitX(GetTriggerUnit())
    local real y = GetUnitY(GetTriggerUnit())
    call DestroyEffect(AddSpecialEffect("Abilities\\Spells\\Human\\Thunderclap\\ThunderClapCaster.mdl",x,y))
    call RemoveUnit(GetTriggerUnit())
endfunction

//==== Init Trigger NewTrigger ====
function InitTrig_In_Range takes nothing returns nothing
    set gg_trg_In_Range = CreateTrigger()
    call TriggerRegisterUnitInRange(gg_trg_In_Range,udg_Hero,71,Condition(function True))
    call TriggerAddCondition(gg_trg_In_Range, Condition(function Trig_In_Range_Conditions))
    call TriggerAddAction(gg_trg_In_Range, function Trig_In_Range_Actions)
endfunction


and it still don't work.
Could you upload a test map where these triggers work, so I can see for myself? (I might be (probably) misunderstanding you here.)
 

PurgeandFire

zxcvmkgdfg
Reaction score
509
I don't know. When doing the "Units in Range" it didn't even register. Did any of your triggers register? Then it could probably be of use. ;)
 
General chit-chat
Help Users
  • No one is chatting at the moment.
  • Ghan Ghan:
    Howdy
  • Ghan Ghan:
    Still lurking
    +3
  • The Helper The Helper:
    I am great and it is fantastic to see you my friend!
    +1
  • The Helper The Helper:
    If you are new to the site please check out the Recipe and Food Forum https://www.thehelper.net/forums/recipes-and-food.220/
  • Monovertex Monovertex:
    How come you're so into recipes lately? Never saw this much interest in this topic in the old days of TH.net
  • Monovertex Monovertex:
    Hmm, how do I change my signature?
  • tom_mai78101 tom_mai78101:
    Signatures can be edit in your account profile. As for the old stuffs, I'm thinking it's because Blizzard is now under Microsoft, and because of Microsoft Xbox going the way it is, it's dreadful.
  • The Helper The Helper:
    I am not big on the recipes I am just promoting them - I use the site as a practice place promoting stuff
    +2
  • Monovertex Monovertex:
    @tom_mai78101 I must be blind. If I go on my profile I don't see any area to edit the signature; If I go to account details (settings) I don't see any signature area either.
  • The Helper The Helper:
    You can get there if you click the bell icon (alerts) and choose preferences from the bottom, signature will be in the menu on the left there https://www.thehelper.net/account/preferences
  • The Helper The Helper:
    I think I need to split the Sci/Tech news forum into 2 one for Science and one for Tech but I am hating all the moving of posts I would have to do
  • The Helper The Helper:
    What is up Old Mountain Shadow?
  • The Helper The Helper:
    Happy Thursday!
    +1
  • Varine Varine:
    Crazy how much 3d printing has come in the last few years. Sad that it's not as easily modifiable though
  • Varine Varine:
    I bought an Ender 3 during the pandemic and tinkered with it all the time. Just bought a Sovol, not as easy. I'm trying to make it use a different nozzle because I have a fuck ton of Volcanos, and they use what is basically a modified volcano that is just a smidge longer, and almost every part on this thing needs to be redone to make it work
  • Varine Varine:
    Luckily I have a 3d printer for that, I guess. But it's ridiculous. The regular volcanos are 21mm, these Sovol versions are about 23.5mm
  • Varine Varine:
    So, 2.5mm longer. But the thing that measures the bed is about 1.5mm above the nozzle, so if I swap it with a volcano then I'm 1mm behind it. So cool, new bracket to swap that, but THEN the fan shroud to direct air at the part is ALSO going to be .5mm to low, and so I need to redo that, but by doing that it is a little bit off where it should be blowing and it's throwing it at the heating block instead of the part, and fuck man
  • Varine Varine:
    I didn't realize they designed this entire thing to NOT be modded. I would have just got a fucking Bambu if I knew that, the whole point was I could fuck with this. And no one else makes shit for Sovol so I have to go through them, and they have... interesting pricing models. So I have a new extruder altogether that I'm taking apart and going to just design a whole new one to use my nozzles. Dumb design.
  • Varine Varine:
    Can't just buy a new heatblock, you need to get a whole hotend - so block, heater cartridge, thermistor, heatbreak, and nozzle. And they put this fucking paste in there so I can't take the thermistor or cartridge out with any ease, that's 30 dollars. Or you can get the whole extrudor with the direct driver AND that heatblock for like 50, but you still can't get any of it to come apart
  • Varine Varine:
    Partsbuilt has individual parts I found but they're expensive. I think I can get bits swapped around and make this work with generic shit though
  • Ghan Ghan:
    Heard Houston got hit pretty bad by storms last night. Hope all is well with TH.
  • The Helper The Helper:
    Power back on finally - all is good here no damage
    +2
  • V-SNES V-SNES:
    Happy Friday!
    +1

      The Helper Discord

      Staff online

      Members online

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top