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.
  • WildTurkey WildTurkey:
    is there a stephen green in the house?
    +1
  • The Helper The Helper:
    What is up WildTurkey?
  • The Helper The Helper:
    Looks like Google fixed whatever mistake that made the recipes on the site go crazy and we are no longer trending towards a recipe site lol - I don't care though because it motivated me to spend alot of time on the site improving it and at least now the content people are looking at is not stupid and embarrassing like it was when I first got back into this like 5 years ago.
  • The Helper The Helper:
    Plus - I have a pretty bad ass recipe collection now! That section of the site is 10 thousand times better than it was before
  • The Helper The Helper:
    We now have a web designer at my job. A legit talented professional! I am going to get him to redesign the site theme. It is time.
  • Varine Varine:
    I got one more day of community service and then I'm free from this nonsense! I polished a cop car today for a funeral or something I guess
  • Varine Varine:
    They also were digging threw old shit at the sheriff's office and I tried to get them to give me the old electronic stuff, but they said no. They can't give it to people because they might use it to impersonate a cop or break into their network or some shit? idk but it was a shame to see them take a whole bunch of radios and shit to get shredded and landfilled
  • The Helper The Helper:
    whatever at least you are free
  • Monovertex Monovertex:
    How are you all? :D
    +1
  • 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 Discord

      Staff online

      Members online

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top