Smooth periodics - turning off

Cokemonkey11

New Member
Reaction score
18
As I noted in this thread - http://www.thehelper.net/forums/showthread.php?t=107530

I turned .1 second wait action into a more final draft of every .03 game seconds.

Here is my code currently.

JASS:
globals
unit centerUnit
unit rifleAttacker
unit footAttacked
integer i
endglobals

function moveInCircle takes nothing returns nothing
    local location posCenter = GetUnitLoc(centerUnit)
    local location posCenterOff
    local real posRifleOffX
    local real posRifleOffY
    local location posCenterOff2
    local real posFootOffX
    local real posFootOffY
    set i = i+1
    set posCenterOff = PolarProjectionBJ(posCenter,512,i)
    set posRifleOffX = GetLocationX(posCenterOff)
    set posRifleOffY = GetLocationY(posCenterOff)
    set posCenterOff2 = PolarProjectionBJ(posCenter,450,i)
    set posFootOffX = GetLocationX(posCenterOff2)
    set posFootOffY = GetLocationY(posCenterOff2)
    call SetUnitX(rifleAttacker,posRifleOffX)
    call SetUnitY(rifleAttacker,posRifleOffY)
    call SetUnitX(footAttacked,posFootOffX)
    call SetUnitY(footAttacked,posFootOffY)
endfunction

function Trig_dummyCenter_Actions takes nothing returns nothing
    local timer time = CreateTimer()
    set centerUnit = CreateUnitAtLoc(Player(0),'hfoo',GetRectCenter(GetPlayableMapRect()),270)
    set rifleAttacker = CreateUnitAtLoc(Player(15),'hrif',PolarProjectionBJ(GetRectCenter(GetPlayableMapRect()),512,0),270)
    set footAttacked = CreateUnitAtLoc(Player(15),'hfoo',PolarProjectionBJ(GetRectCenter(GetPlayableMapRect()),390,0),270)
    call IssueTargetOrder(rifleAttacker,"attack",footAttacked)
    set i = 0
    call TimerStart(time,.03,true,function moveInCircle)
endfunction

function InitTrig_movingCircleFast takes nothing returns nothing
    set gg_trg_movingCircleFast = CreateTrigger()
    call TriggerRegisterTimerEvent(gg_trg_movingCircleFast,2,false)
    call TriggerAddAction(gg_trg_movingCircleFast, function Trig_dummyCenter_Actions)
endfunction


My question is - how do I stop the rotation from running without just "masking" it. I want the trigger to actually stop calling every .03 seconds.
Maybe an if then that says after 360 degrees cancel timer or something.

My other question is - You will see in this video http://www.xfire.com/video/30a05/ of my trigger running that the rifleman starts to attack the footman but after awhile he just stops and they both start trying to "walk" back to their original placed position. Is there any simple way of avoiding this? I think I could just put order rifle to attack footman at the loop every time, but then again maybe that won't work.

AFTER these questions I will be interested in ways of cleaning up/making better my trigger. But please don't just say DO THIS DO THAT, I'd like an explanation of whats changing and why it's better.
 

Dr.Jack

That's Cap'n to you!
Reaction score
109
My question is - how do I stop the rotation from running without just "masking" it. I want the trigger to actually stop calling every .03 seconds.

Assuming I understood you properly if you want to make the unit stop rotating after a while use ticks. Here you make the rifleman more 1 degree at a time, meaning it takes him 360 times runs to complete a round. So set ticks = 360. Pass the information to the callback function and reduce it by 1 each run until ticks == 0. Then destroy the timer and the rifleman will stop rotating after one round. Clear I hope?

> My other question is - You will see in this video http://www.xfire.com/video/30a05/ of my trigger running that the rifleman starts to attack the footman but after awhile he just stops and they both start trying to "walk" back to their original placed position

Mind rephrasing?

> AFTER these questions I will be interested in ways of cleaning up/making better my trigger. But please don't just say DO THIS DO THAT, I'd like an explanation of whats changing and why it's better.

You got several leaks here I strongly suggest you read some leak removing tutorials. Also I suggest you use natives rather then BJs. If you need anymore assistance in this area let us know!
 

Cokemonkey11

New Member
Reaction score
18
I think I get what you mean by ticks - its just like in a loop when you say exitwhen n = 500 and then do set n = n+1 right?

If i implemented ticks +1 each time and i wanted it to stop at 360, what would the code be after that to stop the trigger?


If you watch the video you will see the rifleman is attacking the footman. But after a short while, they just stop and begin playing their walk animation trying to walk back to their starting position (?)

leaks I need to work on, and is there any specific BJ you see that should be replaced with a native? (I've read a few tutorials on making clean code) I know I should ideally make every BJ into native code, but is there any one I'm using in particular you think I should change?
 

quraji

zap
Reaction score
144
JASS:
globals
    integer counter = 0
endglobals

function runthrice takes nothing returns nothing
    local timer t = GetExpiredTimer()

    set counter  = counter + 1

    if counter == 3 then
        call PauseTimer(t)
        call DestroyTimer(t)
        set t = null
        return
    endif

endfunction

function startit takes nothing returns nothing
    local timer t = CreateTimer()

    call TimerStart(t, .03, true, function runthrice)

endfunction


Obviously not multi-instanceable. Use gamecache with(out) structs, or an attachment system to achieve this..ask if you need an example.
 

AdamGriffith

You can change this now in User CP.
Reaction score
69
JASS:
scope MoveInCircle initializer Init     //Seeing as you are using vJASS you might aswell take advantage of scopes.

globals     //It is just 'convention' to use block capitals for global names.
    unit CENTERUNIT
    unit RIFLEATTACKER
    unit FOOTATTACKED
    integer I = 0
endglobals

private function Move takes nothing returns nothing
    local real x1 = GetUnitX(CENTERUNIT)
    local real y1 = GetUnitY(CENTERUNIT)
    local real x2
    local real y2
    local real x3
    local real y3
    local timer t = GetExpiredTimer()

    set I = I + 1
    set x2 = x1 + 512.0 * Cos(I * bj_DEGTORAD)      //Use reals instead of locations. Faster? And then dont need to be cleaned.
    set y2 = y1 + 512.0 * Sin(I * bj_DEGTORAD)
    set x3 = x1 + 384.0 * Cos(I * bj_DEGTORAD)
    set y3 = y1 + 384.0 * Sin(I * bj_DEGTORAD)
    call SetUnitPosition(RIFLEATTACKER, x2, y2)     //Better than setting x and y seperately.
    call SetUnitPosition(FOOTATTACKED, x3, y3)      //Better than setting x and y seperately.
    if I == 360 then        //This is to stop everything at 360 degrees.
        set I = 0
        call PauseTimer(t)
        call DestroyTimer(t)
    else
    endif
    
    set t = null        //Cleaning our ONE handle leak. <img src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" class="smilie smilie--sprite smilie--sprite1" alt=":)" title="Smile    :)" loading="lazy" data-shortname=":)" />
endfunction

private function Actions takes nothing returns nothing      //This is now private so it can just be called actions.
    local timer t = CreateTimer()
    set CENTERUNIT = CreateUnit(Player(0), &#039;hfoo&#039;, 0.0, 0.0, 270.0)       //Lets use reals instead of locations.
    set RIFLEATTACKER = CreateUnit(Player(15), &#039;hrif&#039;, 512.0, 0.0, 270.0)       //Just changed to use reals.
    set FOOTATTACKED = CreateUnit(Player(15), &#039;hfoo&#039;, 384.0, 0.0, 270.0)        //Just changed to use reals.
    call IssueTargetOrder(RIFLEATTACKER, &quot;attack&quot;, FOOTATTACKED)        //Are you sure this is what you meant to do?
    call TimerStart(t, 0.03, true, function Move)
    set t = null
endfunction

private function Init takes nothing returns nothing     //This can now just be called init because it is inside of the scope.
    local trigger t = CreateTrigger()       //Make this local.
    call TriggerRegisterTimerEvent(t,2.0,false)
    call TriggerAddAction(t, function Actions)
endfunction

endscope    //End of the scope.


Quick jobbie. Tell me if there is a problem.

EDIT:
Also this is not MUI.

And for the walk animation thing, I think you are going to have to order the units to stop each time the timer runs.
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Staff online

      • Ghan
        Administrator - Servers are fun

      Members online

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top