70% done spell - 30% help from you please?

warden13

New Member
Reaction score
32
Hello I am trying to make a spell that creates guardians arround you and moves them with you. I have done this so far:

JASS:
function Trig_AS_Actions takes nothing returns nothing
    
    local unit u = GetTriggerUnit()
    local real array x
    local real array y
    local unit array d
    local integer DUMMY = 'h001'
    local integer ABI = 'A000'
    local integer lvl = GetUnitAbilityLevel(u, ABI)
    local integer count = lvl + 2
    local real dur = 30
    local real range = 250
    local integer i = 0
    local integer j = 0
    local integer l = 0
    local real angle = 0
    local real angle2 = 0
    local player p = GetOwningPlayer(u)
    local boolean boo = true
    
    set x[0] = GetUnitX(u)
    set y[0] = GetUnitY(u)
    set boo = true

    
    loop
        exitwhen i == count
        set i = i + 1
        set angle = angle + (360/count)
        set x<i> = x[0] + range * Cos(angle * bj_DEGTORAD)
        set y<i> = y[0] + range * Sin(angle * bj_DEGTORAD)
        set d<i> = CreateUnit(p, DUMMY, x<i>, y<i>, 0)
    endloop
        
    loop
        exitwhen boo == false
        set j = j + 1
        set l = ModuloInteger(j, i) + 1
        set angle2 = angle2 + (360/count)
        set x[0] = GetUnitX(u)
        set y[0] = GetUnitY(u)
        set x[l] = x[0] + range * Cos(angle2 * bj_DEGTORAD)
        set y[l] = y[0] + range * Sin(angle2 * bj_DEGTORAD)
        call SetUnitX(d[l], x[l])
        call SetUnitY(d[l], y[l])
        call SetUnitAnimationByIndex(d[l], 2)
        call SetUnitFacing(d[l], GetUnitFacing(u))
        call TriggerSleepAction(0)
    endloop
endfunction
    
    
    
    function Trig_AS_Conditions takes nothing returns boolean
    return GetSpellAbilityId() == &#039;A000&#039;
endfunction

function InitTrig_AS takes nothing returns nothing
    local trigger AS = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( AS, EVENT_PLAYER_UNIT_SPELL_EFFECT )
    call TriggerAddCondition( AS, Condition( function Trig_AS_Conditions ) )
    call TriggerAddAction( AS, function Trig_AS_Actions )
endfunction</i></i></i></i></i>


What I need is:

1-) After (dur)30 seconds, boo must be false.
2-) TriggerSleepAction sux. And I don't know how to make the loop faster.
3-) That's all. Maybe you can fix leaks.
 

LurkerAspect

Now officially a Super Lurker
Reaction score
118
To make an interval of less than 0.2 seconds (the lowest TriggerSleepAction allows), you need to use structs.

Seeming as you haven't used scopes or private functions, my guess is that you're a beginner, so let's help each other, hey? :p

To make the loop faster, you need to use a timer action, and you can use structs to allocate your units and values to a leakless, MUI system. Like this:
(This uses Cohadar's ABC system)
JASS:
struct HopperStruct
    unit hopper
    location start
    location end
    real height
    real distance
    real step
    real angle
    effect hopeffect
    method onDestroy takes nothing returns nothing
        set .hopper = null
        call RemoveLocation(.start)
        call RemoveLocation(.end)
    endmethod
endstruct

public function GetParabolaZ takes real x,real d,real h returns real
    return 4 * h * x * (d - x) / (d * d)
endfunction

private function callback takes nothing returns nothing
    local timer t = GetExpiredTimer()
    local HopperStruct a = GetTimerStructA(t)
    local real MaxHeight = 300.00
    local location offset = null
    if a.step &gt;= a.distance then
        call SetUnitFlyHeight(a.hopper, GetUnitDefaultFlyHeight(a.hopper), 0.)
        call SetUnitPathing(a. hopper, true)
        call PauseUnit(a.hopper, false)
        call PauseTimer(t)
        call DestroyTimer(t)
        call DestroyEffect(a.hopeffect)
        call ClearTimerStructA(t)
        call a.destroy()
    else
        set offset = PolarProjectionBJ(a.start, a.step, a.angle)
        set a.height = GetParabolaZ(a.step, a.distance, MaxHeight)
        call UnitAddAbility(a.hopper, &#039;Amrf&#039;)
        call UnitRemoveAbility(a.hopper, &#039;Amrf&#039;)
        call SetUnitPositionLoc(a.hopper, offset)
        call SetUnitFlyHeight(a.hopper, a.height, 0.)
        call RemoveLocation(offset)
        set a.step = a.step + 10.00
    endif
    set t = null
    call RemoveLocation(offset)
endfunction        

private function HopActions takes nothing returns nothing
    local timer t = CreateTimer()
    local HopperStruct a = HopperStruct.create()
    set a.hopper = GetTriggerUnit()
    set a.start = GetUnitLoc(a.hopper)
    set a.end = GetSpellTargetLoc()
    set a.distance = DistanceBetweenPoints(a.start, a.end)
    set a.angle = AngleBetweenPoints(a.start, a.end)
    set a.step = 10.00
    set a.hopeffect = AddSpecialEffectTarget(&quot;Abilities\\Weapons\\ChimaeraAcidMissile\\ChimaeraAcidMissile.mdl&quot;, a.hopper, &quot;chest&quot;)
    call PauseUnit(a.hopper, true)
    call SetUnitPathing(a.hopper, false)
    call SetTimerStructA(t, a)
    call TimerStart(t, 0.02, true, function callback)
    set t = null
endfunction

private function HopConditions takes nothing returns boolean
    return GetSpellAbilityId() == &#039;A00D&#039;
endfunction

private function Init takes nothing returns nothing
    local trigger t = CreateTrigger()
    call TriggerRegisterAnyUnitEventBJ(t, EVENT_PLAYER_UNIT_SPELL_CAST)
    call TriggerAddCondition(t, Filter(function HopConditions))
    call TriggerAddAction(t, function HopActions)
endfunction

endscope

If you look at this trigger, you will see what I mean. Although it's a bit leaky, just remember to never use locations, only X's and Y's for unit positions.
To make the spell stop, add this to the timer callback function:
JASS:
private function callback takes nothing returns nothing
     local real timeleft
     set timeleft = timeleft + (your real timer interval)

I'm sorry I can't be more specific, but I'm afraid I don't know how to explain it to you in any other way :(
 

warden13

New Member
Reaction score
32
It is hard to understand this way. Is this vJass? Can someone implement this thing to my code? Is this ABC system requires a code on header or like this?
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      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