In need of a way to keep this MUI

Kenny

Back for now.
Reaction score
202
I can't seem to figure out a way to keep this MUI.

Basically i need a way to limit the amount of units created by this spell to a certain amount per level.

Heres how it works:

- Every X distance, unit is created.
- Unit is constantly given orders (crappy AI).
- Unit eventually dies.

However if you move a far distance, too many units are created.

The only half-decent way i know is to group units of a specific player on the map, but that would only be MPI.

So yeah, any way to limit the amount of units?

Script:

JASS:
scope SoulTrail initializer Init

globals
    private constant integer Abil_id = 'A001'
    private constant integer IS_stat_id = 'A007'
    private constant integer Damage_id = 'A008'
    private constant integer Attackspeed_id = 'A009'
    private constant integer Dummy_id = 'u001'
    private constant real Interval = 0.04
    private constant real Distance = 150.00
    private constant string Sfx = "Abilities\\Spells\\Items\\AIil\\AIilTarget.mdl"
    private constant string Point = "origin"
endglobals

//=======================================================================
private function Maxdist takes integer lvl returns real
    return 1800.00-(200.00*lvl)
endfunction

private function MaxDuration takes integer lvl returns real
    return 10.00
endfunction

private function LeashRange takes integer lvl returns real
    return 1000.00
endfunction

private function Radius takes integer lvl returns real
    return 600.00
endfunction

//=======================================================================
private keyword Data
private keyword Atad

globals
    private Data array D
    private Atad array A
    private integer DT = 0                   
    private integer AT = 0
    private timer Timer = null
    private boolexpr Truefilt = null
    private boolexpr Enemyfilt = null
    private constant integer Order_stop = 851972
    private constant integer Order_smart = 851971
    private constant integer Order_attack = 851983
endglobals

//=======================================================================
private function DistanceXY takes real x1, real y1, real x2, real y2 returns real
    return SquareRoot((x2-x1)*(x2-x1) + (y2-y1)*(y2-y1))
endfunction

//=======================================================================
private function EnemyFilt takes nothing returns boolean
    return GetWidgetLife(GetFilterUnit()) > 0.405
endfunction

//=======================================================================
private struct Data
    unit cast
    real castx
    real casty
    real dist
endstruct

private struct Atad
    unit cast
    unit dum
    real time
    integer lvl
    integer alpha
    
    private method onDestroy takes nothing returns nothing
        call ShowUnit(.dum,false)
        call KillUnit(.dum)
        
        set .cast = null
        set .dum = null
    endmethod
endstruct

//=======================================================================
private function Update takes nothing returns nothing
    local Atad a = 0
    local real x = 0.00
    local real y = 0.00
    local real dist = 0.00
    local integer lvl = 0
    local integer steplvl = 0
    local integer i = 1
    local unit u = null
    
    loop
        exitwhen i > DT
        
        set x = GetUnitX(D<i>.cast)
        set y = GetUnitY(D<i>.cast)
        set dist = DistanceXY(D<i>.castx,D<i>.casty,x,y)
        set lvl = GetUnitAbilityLevel(D<i>.cast,Abil_id)
        set steplvl = GetUnitAbilityLevel(D<i>.cast,IS_stat_id)
    
        set D<i>.dist = D<i>.dist + dist
    
        if D<i>.dist &gt;= Maxdist(lvl) then
            call DestroyEffect(AddSpecialEffectTarget(Sfx,D<i>.cast,Point))
            set a = Atad.create()
            set a.cast = D<i>.cast
            set a.dum = CreateUnit(GetOwningPlayer(D<i>.cast),Dummy_id,x,y,GetUnitFacing(D<i>.cast))
            set a.alpha = 255
            set a.time = 0.00
            set a.lvl = lvl
            call SetUnitMoveSpeed(a.dum,GetUnitMoveSpeed(D<i>.cast))
            call SetUnitVertexColor(a.dum,255,255,255,a.alpha)
            call SetUnitPathing(a.dum,false)
            
            if steplvl &gt; 0 then
                call UnitAddAbility(a.dum,Damage_id)
                call UnitAddAbility(a.dum,Attackspeed_id)
                call SetUnitAbilityLevel(a.dum,Damage_id,steplvl)
                call SetUnitAbilityLevel(a.dum,Attackspeed_id,steplvl)
            endif
            
            set AT = AT + 1
            set A[AT] = a
            
            set D<i>.dist = 0.00
        endif
    
        set D<i>.castx = x
        set D<i>.casty = y
        
        set i = i + 1
    endloop

    set i = 1
    
    loop
        exitwhen i &gt; AT
        
        
        set x = GetUnitX(A<i>.cast)
        set y = GetUnitY(A<i>.cast)
        set steplvl = GetUnitAbilityLevel(A<i>.cast,IS_stat_id)
        
        if A<i>.time &gt;= MaxDuration(A<i>.lvl) or GetWidgetLife(A<i>.cast) &lt; 0.406 then
            call A<i>.destroy()
            set A<i> = A[AT]
            set AT = AT - 1
            set i = i - 1
        else
            call SetUnitVertexColor(A<i>.dum,255,255,255,A<i>.alpha)
            
            if steplvl &gt; 0 then
                if GetUnitAbilityLevel(A<i>.dum,Damage_id) == 0 then
                    call UnitAddAbility(A<i>.dum,Damage_id)
                    call UnitAddAbility(A<i>.dum,Attackspeed_id)
                endif
                call SetUnitAbilityLevel(A<i>.dum,Damage_id,steplvl)
                call SetUnitAbilityLevel(A<i>.dum,Attackspeed_id,steplvl)
            else
                if GetUnitAbilityLevel(A<i>.dum,Damage_id) &gt; 0 then 
                    call UnitRemoveAbility(A<i>.dum,Damage_id)
                    call UnitRemoveAbility(A<i>.dum,Attackspeed_id)
                endif
            endif
            
            if not IsUnitInRange(A<i>.dum,A<i>.cast,LeashRange(A<i>.lvl)) then
                call SetUnitX(A<i>.dum,x + Distance * Cos(GetRandomReal(0.00,360.00) * bj_DEGTORAD))
                call SetUnitY(A<i>.dum,y + Distance * Sin(GetRandomReal(0.00,360.00) * bj_DEGTORAD))
                call IssuePointOrderById(A<i>.dum,Order_attack,x + Distance * Cos(GetRandomReal(0.00,360.00) * bj_DEGTORAD),y + Distance * Sin(GetRandomReal(0.00,360.00) * bj_DEGTORAD))
            else
                if GetUnitCurrentOrder(A<i>.cast) == Order_attack or GetUnitCurrentOrder(A<i>.cast) == Order_smart then
                    set u = GetOrderTargetUnit()
                    if u != null then 
                        if IsUnitEnemy(u,GetOwningPlayer(A<i>.cast)) == true then
                            call IssueTargetOrderById(A<i>.dum,Order_attack,u)
                        else
                            call IssuePointOrderById(A<i>.dum,Order_attack,x + Distance * Cos(GetRandomReal(0.00,360.00) * bj_DEGTORAD),y + Distance * Sin(GetRandomReal(0.00,360.00) * bj_DEGTORAD))
                        endif
                    else
                        if GetUnitCurrentOrder(A<i>.dum) != Order_attack then
                            call IssuePointOrderById(A<i>.dum,Order_attack,x + Distance * Cos(GetRandomReal(0.00,360.00) * bj_DEGTORAD),y + Distance * Sin(GetRandomReal(0.00,360.00) * bj_DEGTORAD))
                        endif
                    endif
                else                
                    if GetUnitCurrentOrder(A<i>.dum) != Order_attack then
                        call IssuePointOrderById(A<i>.dum,Order_attack,x + Distance * Cos(GetRandomReal(0.00,360.00) * bj_DEGTORAD),y + Distance * Sin(GetRandomReal(0.00,360.00) * bj_DEGTORAD))
                    endif
                endif
            endif
            
            set u = null
            set A<i>.alpha = A<i>.alpha - 1
            set A<i>.time = A<i>.time + Interval
        endif
        
        set i = i + 1
    endloop        
endfunction

//=======================================================================
private function Actions takes nothing returns nothing
    local unit cast = GetTriggerUnit()
    local Data d = 0
    
    if GetLearnedSkill() == Abil_id and GetUnitAbilityLevel(cast,Abil_id) == 1 and IsUnitIllusion(cast) == false then
        set d = Data.create()
        
        set d.cast = cast
        set d.castx = GetUnitX(d.cast)
        set d.casty = GetUnitY(d.cast)
        set d.dist = 0.00
        
        set DT = DT + 1
        if DT == 1 and AT == 0 then
            call TimerStart(Timer,Interval,true,function Update)
        endif
        set D[DT] = d
    endif
    
    set cast = null
endfunction

//=======================================================================
private function TrueFilt takes nothing returns boolean
    return true
endfunction

//=======================================================================
private function Init takes nothing returns nothing
    local trigger trig = CreateTrigger()
    local integer i = 0
    local unit dum = null
    
    set Timer = CreateTimer()
    set Truefilt = Filter(function TrueFilt)
    set Enemyfilt = Filter(function EnemyFilt)
    
    loop
        call TriggerRegisterPlayerUnitEvent(trig,Player(i),EVENT_PLAYER_HERO_SKILL,Truefilt)
        set i = i + 1
        exitwhen i == bj_MAX_PLAYER_SLOTS
    endloop

    call TriggerAddAction(trig,function Actions)
    
    set dum = CreateUnit(Player(PLAYER_NEUTRAL_PASSIVE),Dummy_id,0.00,0.00,0.00)
    call UnitAddAbility(dum,Damage_id)
    call UnitAddAbility(dum,Attackspeed_id)
    call ShowUnit(dum,false)
    call KillUnit(dum)
    
    set dum = null
    set trig = null
endfunction

endscope</i></i></i></i></i></i></i></i></i></i></i></i></i></i></i></i></i></i></i></i></i></i></i></i></i></i></i></i></i></i></i></i></i></i></i></i></i></i></i></i></i></i></i></i></i></i></i></i></i></i></i></i></i></i>
 

Viikuna

No Marlo no game.
Reaction score
265
Cant you just store the number of units created to your struct? If too many is created then stop creating them?
 

Kenny

Back for now.
Reaction score
202
Oops, sorry. Well the units can also die, so how would i keep track of them within the same struct when they die?
 

quraji

zap
Reaction score
144
If they're attackable and can be killed, then you just have to either make a trigger to track them (unit death event), or group them and check for dead ones. This, in conjunction with capping the max number of them.

I guess. I haven't looked at the actual code :p
 

Viikuna

No Marlo no game.
Reaction score
265
You have a timer running there, so I guess you could just keep checking if they are alive constantly.

Have a group member in Data struct. When you create a a.dum add it to that group.

edit. Btw, there is a pretty neat way to recycle groups for structs.

Vexorian uses this for hes xecollider.
JASS:
              if(.lastSeen &lt; integer(xc)) then //with this I do group recycling 
      set .lastSeen = integer(xc)
       set xc.seen = CreateGroup()
endif


That is from xecolliders create method. .lastSeen is a static integer
xc is the new allocated xecollider instance.
 

Kenny

Back for now.
Reaction score
202
make a trigger to track them (unit death event)

That would requires me to transfer data using globals or something, and with my knowledge it wouldnt end up working.

group them and check for dead ones.

The only way i know to group them all successfully is to groupenumunitsofplayer, and that isnt MUI.

So im not exactly sure where to go with it.
 

Kenny

Back for now.
Reaction score
202
> Like this :)

Firstly, im not too great at this stuff, so even when its spelt out for me ill still probably have a hard time :p.

So basically, i created a group for each unit using the spell (within the Data struct), then whenever a unit is created add it to that group, then next time a unit is going to be created, check whether CountUnitsInGroup() > MaxUnits, if not, created the unit.

But how do i check if the unit is alive within the Data struct and not the other one which holds the information about the unit? Thats where im a little confused.
 

Viikuna

No Marlo no game.
Reaction score
265
JASS:
// Try something like this
local unit u=null
local integer livingGuys=0
loop
    set u=FirstOfGroup(.unitGroup)
    exitwhen u==null
    if GetWidgetLife(u)&gt;0.405 then
        set livingGuys=livingGuys+1 // we found a living unit
        call GroupAddUnit(TempG,u) // store living units to a global group 
    endif
    call GroupRemoveUnit(u,.unitGroup)
endloop
// Now you need to move living units from TempG back to .unitGroup
call GroupAddGroup(TempG,.unitGroup)
 

Viikuna

No Marlo no game.
Reaction score
265
So, in short words, FirstOfGroup might be null, because that unit might be removed from the game because some time is passed since those units were grouped and this everything might cause this fail.

And this can be fixxed by using Griffens GroupRefresh function.

Neat stuff.
 

Sooda

Diversity enchants
Reaction score
318
> So yeah, any way to limit the amount of units?

Keep count of "Shadow Trail" units created for caster, if limit is reached kill last trail or just don't create new one. Requires additional struct variable.

JASS:
set steplvl = GetUnitAbilityLevel(A<i>.cast,IS_stat_id)</i>

Sure you need to check caster ability level periodically after 0.04 seconds?

Does so far made code even works as you like?
 

Kenny

Back for now.
Reaction score
202
Thanks Viikuna, ill give that a try. I had a similar idea in my head, i just didnt know how to implement it, plus yours seems a bit easier than what i was thinking.

Sure you need to check caster ability level periodically after 0.04 seconds?

That ability constantly changes depending on how far the caster moved in the last X seconds.

Does so far made code even works as you like?

Yes the code works almost exactly as i like except for capping units.


EDIT:

I couldnt get that group thing to work (the one viikuna suggested). I mucked around with it for a bit and got nothing. The integer to count living units was always 1 and didnt increase.
 
General chit-chat
Help Users
  • No one is chatting at the moment.
  • 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 The Helper:
    New recipe is another summer dessert Berry and Peach Cheesecake - https://www.thehelper.net/threads/recipe-berry-and-peach-cheesecake.194169/

      The Helper Discord

      Members online

      No members online now.

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top