making wisp moving in a blade-like circle

jig7c

Stop reading me...-statement
Reaction score
123
I need help..

I have created this script.. which is suppose to create a total of 22 wisp...
and move then around in a circle...

not an O circle... but more like a blade ... kinda like

-, /, -, \, -, /, -, \ like two blades of a fan opposite each other..... also like two spokes of a wheel... but of equal length and equal speed

anyways...
here is the script, i'm sure it has tons of errors in it.. can someone help me fix it


what i have done is combine two things into one script, (probably not so smart of me) but local trigger t stuff creates the wisp, and local trigger a makes the wisps move in circle every .03 seconds..

JASS:
scope StartCircle initializer Init
    globals
        constant integer dummy = 'e002'                         //wisp unit-id
        unit array wisp                                      //the actual wisp to be created
        constant location l = GetRectCenter(gg_rct_Rect_096)    //center of wisp circle
    endglobals

    private function Cond1 takes nothing returns boolean
        return ((GetUnitTypeId(GetTriggerUnit()) == 'H007')  or (GetUnitTypeId(GetTriggerUnit()) == 'H009')  or (GetUnitTypeId(GetTriggerUnit()) == 'H008')  or (GetUnitTypeId(GetTriggerUnit()) == 'H00A') == true)
    endfunction

    private function levelcheck takes nothing returns boolean
        return (udg_Level_Start == true ) 
    endfunction

    private function CreateActions takes nothing returns nothing
        local integer i = 1                                    //for the loop
        local location l                                       //wisp's starting location
       
        if ( levelcheck ) then
            call DisableTrigger( gg_trg_Spin_Wisps )
            loop
                exitwhen i > 22
                if ( i > 11 ) then
                    set l = PolarProjectionBJ(l, ( 75.00 * (i - 11.00 )), 0)
                    set wisp<i> = CreateUnitAtLoc(Player(11), dummy, l, 90)
                    call RemoveLocation(l)
                else
                    set l = PolarProjectionBJ(l, ( 75.00 * i), 0)
                    set wisp<i> = CreateUnitAtLoc(Player(11), dummy, l, 90)
                    call RemoveLocation(l)
                endif
                set i = i + 1
            endloop
            call EnableTrigger( a ) //error
        endif
    endfunction
    
    //moving wisp in circle...
        
    private function Actions takes nothing returns nothing
        local real angle = 1
        local integer wloop = 1
        local location wisppoint
        set angle = angle + 1.50
        loop
            exitwhen wloop == 22
            if (wloop &gt; 22) then
                set wisppoint = PolarProjectionBJ(l, ( 75.00 * ( wloop - 11.00 ) ), angle)
                call SetUnitPositionLoc( wisp[wloop], wisppoint )
                call RemoveLocation(wisppoint)
            else
                set wisppoint = PolarProjectionBJ(l, ( 75.00 * wloop ), angle)
                call SetUnitPositionLoc( wisp[wloop], wisppoint )
                call RemoveLocation(wisppoint)
            endif
            set wloop = wloop + 1
        endloop
        call RemoveLocation(l)
    endfunction


    //===========================================================================
    private function Init takes nothing returns nothing
        local trigger t = CreateTrigger ()
        local trigger a = CreateTrigger ()
        call TriggerRegisterEnterRectSimple( t, gg_rct_Block_1_Start_Copy_Copy )
        call TriggerAddCondition( t, Condition( function Cond1) )
        call TriggerAddAction( t, function CreateActions )
        
    
        call DisableTrigger( gg_trg_Spin_Wisps_Ice_Copy )
        call TriggerRegisterTimerEventPeriodic(a, 0.03 )
        call TriggerAddAction(a, function Actions )
    endfunction
    
endscope
</i></i>
 

Jedi

New Member
Reaction score
63
Circle movement with coordinates.
JASS:
private function Actions takes nothing returns nothing
        //If your center point isn&#039;t constant, save it everytime but I think it is.
        local real angle
        local real distance
        local integer loopi = 1
        local real x
        local real y
        loop
            exitwhen loopi &gt; 22 //wisp count
            set x = GetUnitX(wisp[loopi])
            set y = GetUnitX(wisp[ loopi])
            set distance = SquareRoot((x - CenterX) * (x - CenterX) + (y - CenterY) * (y - CenterY)
            set angle = (bj_RADTODEG * Atan2(y - CenterY, x - CenterX)) + 2.5 //This 2.5 is important, trust me <img src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" class="smilie smilie--sprite smilie--sprite1" alt=":)" title="Smile    :)" loading="lazy" data-shortname=":)" /> If they are moving too fast, decrease this 2.5
            call SetUnitX(wisp[loopi], CenterX + distance * Cos(angle * bj_DEGTORAD) //PolarX
            call SetUnitY(wisp[loopi], CenterY + distance * Sin(angle * bj_DEGTORAD)  //PolarY
            set loopi = loopi + 1
endfunction
 

Sevion

The DIY Ninja
Reaction score
413
That would be the traditional wisp wheel. But I'm not quite sure what he meant. Because he said "Not like a Circle" ._.

This also confused me: -/-\-/-\ like two blades of a fan opposite each other..... also like two spokes of a wheel... but of equal length and equal speed
 

jig7c

Stop reading me...-statement
Reaction score
123
sorry to be confusing fellas.. i did a bad job of explaining

sevion, your picture is exactly what i want.. where the spokes of the wheel is, is where i want my wisp to be...except, only 2 equally opposite spokes...

the wisp will move around in a circle, with a constant center point...
all of the wisp will be in a straight line, and with the most middle wisp staying in one place and the rest moving around it...

if you put your hands up, perpendicular to your body, but to towards the sides... and spin around, thats how I want the wisp to be spinning arounds

i tried looking for pictures.. but couldn't find it.. so here goes a snapshot

inside a region i want the wisp, designated by (o) to move around

Code:
1____________________________
|                    o     |
|                 o        | 
|              o           |
|           o              |
|         o                |
|___o______________________|

2________________________
|              o          |
|              o          | 
|              o          |
|              o          |
|              o          |
|______________o__________|

3_________________________
|   o                     |
|       o                 | 
|            o            |
|                 o       |
|                    o    |
|________________________o|

bad pictures, i know
and so on...
there will be 11 wisps on each side, moving 75 units every .03 seconds...
 

Sevion

The DIY Ninja
Reaction score
413
Ah. I see what you mean now. Did you want a wisp in the middle then? That'd be 23 total wisps with 22 spinning.

This should work:

JASS:
library WispWheel
    globals
        private constant integer WISP = &#039;ewsp&#039;
        private constant integer NUM_OF_WISPS = 22
        private constant real    DISTANCE = 70
        private constant boolean ADD_LOCUST = true
        private constant integer LOCUST = &#039;Aloc&#039;
    endglobals
    
    struct Wheel
        unit array Wisps[NUM_OF_WISPS]
        unit Center
        real CenterX
        real CenterY
        real Speed
        
        implement T32x
        
        method periodic takes nothing returns nothing
            local integer i = NUM_OF_WISPS
            local real angle
            local real x
            local real y
            
            set this.CenterX = GetUnitX(this.Center)
            set this.CenterY = GetUnitY(this.Center)
            
            set angle = Atan2(GetUnitY(this.Wisps<i>) - this.CenterY, GetUnitX(this.Wisps<i>) - this.CenterX) + this.Speed
            
            loop
                set x = GetUnitX(this.Wisps<i>)
                set y = GetUnitY(this.Wisps<i>)
                call SetUnitX(this.Wisps<i>, this.CenterX + (i - NUM_OF_WISPS / 2) * DISTANCE * Cos(angle))
                call SetUnitY(this.Wisps<i>, this.CenterY + (i - NUM_OF_WISPS / 2) * DISTANCE * Sin(angle))
                set i = i - 1
                exitwhen i == NUM_OF_WISPS / 2
            endloop
            
            set angle = Atan2(GetUnitY(this.Wisps<i>) - this.CenterY, GetUnitX(this.Wisps<i>) - this.CenterX) + this.Speed
            
            loop
                set x = GetUnitX(this.Wisps<i>)
                set y = GetUnitY(this.Wisps<i>)
                call SetUnitX(this.Wisps<i>, this.CenterX + i * DISTANCE * Cos(angle))
                call SetUnitY(this.Wisps<i>, this.CenterY + i * DISTANCE * Sin(angle))
                set i = i - 1
                exitwhen i == 0
            endloop
        endmethod
        
        static method create takes player owner, real x, real y, real speed returns thistype
            local thistype this = thistype.allocate()
            local integer i = NUM_OF_WISPS
            
            set this.Center = CreateUnit(owner, WISP, x, y, 0)
            set this.CenterX = x
            set this.CenterY = y
            static if ADD_LOCUST then
                call UnitAddAbility(this.Center, LOCUST)
            endif
            set this.Speed = speed * T32_PERIOD
            
            loop
                set this.Wisps<i> = CreateUnit(owner, WISP, x + (i - NUM_OF_WISPS / 2) * DISTANCE, y, 0)
                static if ADD_LOCUST then
                    call UnitAddAbility(this.Wisps<i>, LOCUST)
                endif
                set i = i - 1
                exitwhen i == NUM_OF_WISPS / 2
            endloop
            
            loop
                set this.Wisps<i> = CreateUnit(owner, WISP, x + -i * DISTANCE, y, 0)
                static if ADD_LOCUST then
                    call UnitAddAbility(this.Wisps<i>, LOCUST)
                endif
                set i = i - 1
                exitwhen i == 0
            endloop
            
            return this
        endmethod
    endstruct
endlibrary</i></i></i></i></i></i></i></i></i></i></i></i></i></i></i></i>


To test:

JASS:
scope Test initializer init
    private function init takes nothing returns nothing
        local Wheel dat = Wheel.create(Player(0), 0, 0, 1)
        call dat.startPeriodic()
    endfunction
endscope
 

Sevion

The DIY Ninja
Reaction score
413
You don't need events.

In your actions function, just do

JASS:
local Wheel dat = Wheel.create(Player(0), 0, 0, 1)
call dat.startPeriodic()


Edit:

So basically, it'd be:

JASS:
scope StartCircle initializer Init
    globals
        private boolexpr True
    endglobals
    
    private function Cond1 takes nothing returns boolean
        return ((GetUnitTypeId(GetTriggerUnit()) == &#039;H007&#039;)  or (GetUnitTypeId(GetTriggerUnit()) == &#039;H009&#039;)  or (GetUnitTypeId(GetTriggerUnit()) == &#039;H008&#039;)  or (GetUnitTypeId(GetTriggerUnit()) == &#039;H00A&#039;) == true)
    endfunction
    
    private function TrueFunc takes nothing returns boolean
        return true
    endfunction

    private function CreateActions takes nothing returns nothing
        local Wheel NewWheel
       
        if ( udg_level_Start ) then
            //call DisableTrigger( gg_trg_Spin_Wisps ) Wtf are you doing here?
            set NewWheel = Wheel.create(GetOwningPlayer(GetTriggerPlayer()), GetRectCenterX(gg_rct_Rect_096), GetRectCenterY(gg_rct_Rect_096), 1.5)
            call NewWheel.startPeriodic()
        endif
    endfunction


    //===========================================================================
    private function Init takes nothing returns nothing
        local trigger t = CreateTrigger ()
        set True = Filter(function TrueFunc)
        call TriggerRegisterEnterRectSimple( t, gg_rct_Block_1_Start_Copy_Copy )
        call TriggerAddCondition( t, Condition( function Cond1) )
        call TriggerAddAction( t, function CreateActions )
    endfunction
    
endscope
 

Jedi

New Member
Reaction score
63
Group enumeration functions caused a memory leak before patch 1.24 if null was used as the boolexpr argument. To avoid this, a coder would often resort to creating a garbage boolexpr function that returns true, to be used instead of null.

This no longer applies since Blizzard fixed this issue in patch 1.24. You may now input null as a boolexpr argument freely without worry of a memory leak.

@Helper.nerWiki

http://wiki.thehelper.net/wc3/jass/common.j/boolexpr
 

Sevion

The DIY Ninja
Reaction score
413
TBH, I looked over my code, and it's not even used. Just take it out.

Edit: Noticed another thing. I did GetOwningPlayer(GetTriggerPlayer()), should be GetOwningPlayer(GetTriggerUnit())
 

jig7c

Stop reading me...-statement
Reaction score
123
actually in my code, it needs to be Player(11)... it creates wisp for the enemies :)
 
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