Making A Circle

WolfieeifloW

WEHZ Helper
Reaction score
372
I figured this out in GUI easy, but I can't in JASS.
JASS:
scope PeonCircle initializer PCInit
    
    globals
        private constant integer PCID = 'A000'
    endglobals
    
    private function Conditions takes nothing returns boolean
        return GetSpellAbilityId() == PCID
    endfunction
    
    private function Actions takes nothing returns nothing
        local unit Caster = GetTriggerUnit()
        local unit u
        local integer zz = 0
        local integer z = 0
        local real x
        local real y
        
        loop
        exitwhen z == 10
            //set x = PolarProjectionBJ(GetUnitLoc(Caster), 300, I2R((i * 36)))
            set x = GetLocationX(GetUnitLoc(Caster)) + 300 * Cos((z * 36) * bj_DEGTORAD)
            //set y = PolarProjectionBJ(GetUnitLoc(Caster), 300, I2R((i * 36)))
            set y = GetLocationY(GetUnitLoc(Caster)) + 300 * Sin((z * 36) * bj_DEGTORAD)
            loop
            exitwhen zz == GetUnitAbilityLevel(Caster, PCID)
                set u = CreateUnit(GetOwningPlayer(Caster), 'o000', x, y, GetUnitFacing(Caster))
                call IssuePointOrder(u, "attack", x, y)
                call UnitApplyTimedLife(u, 'BTLF', (2 + I2R(GetUnitAbilityLevel(Caster, PCID))))
                set u = null
                set zz = zz + 1
            endloop
            set z = z + 1
        endloop
        set Caster = null
    endfunction
    
//====================================================================================================
    private function PCInit takes nothing returns nothing
        local trigger t = CreateTrigger()
        local integer i = 0
        
        loop
            call TriggerRegisterPlayerUnitEvent(t, Player(i), EVENT_PLAYER_UNIT_SPELL_EFFECT, null)
            set i = i + 1
        exitwhen i == bj_MAX_PLAYER_SLOTS
        endloop
        call TriggerAddCondition(t, Condition(function Conditions))
        call TriggerAddAction(t, function Actions)
    endfunction

endscope

It creates X Peons around the hero for X seconds;
Where X depends on the level of the spell.

The problem?
It only creates 1 single peon at 0 degrees.
 

RaiJin

New Member
Reaction score
40
in the first loop your doing

also try removing bj_DEGTORAD because it already gives it in Radians IM GUESSING

EDIT re read that part anyhow as i said try removing bj_DEGTORAD
 

WolfieeifloW

WEHZ Helper
Reaction score
372
Yes, I know it's (0 * 36) the first run through.
It should be.
But when it runs through the second and third time;
(1 * 36), (2 * 36), etc. all the way up to (10 * 36) which would be 360, the end of the circle.

EDIT: Removing bj_DEGTORAD did nothing.
 

RaiJin

New Member
Reaction score
40
ya i accidentally misinterpreted it but try removing bj_DEGTORAD

edit: really.. hmm ill look again

edit2: shouldnt a local unit variable be nulled after its use?
 

WolfieeifloW

WEHZ Helper
Reaction score
372
I'm like 95% sure it has something to do with the x/y.
I was never good with Cos/Sin and that :eek: .
Never really been able to use them in WC3 either.
 
Reaction score
91
A loop in a loop is really, really bad. Avoid it as much as possible.
Why the hell do you need zz when you can just
JASS:
call UnitApplyTimedLife(u, 'BTLF', (2 + I2R(GetUnitAbilityLevel(Caster, PCID))))

You're not using it anywhere, just doing some pointless loop.

JASS:

set x = GetLocationX(GetUnitLoc(Caster)) + 300 * Cos((z * 36) * bj_DEGTORAD)

You're leaking a location. Just remove GetLocationX() and use GetUnitX() instead (as well as GetUnitY()).

This should be fine now:
JASS:

scope PeonCircle initializer PCInit
    
    globals
        private constant integer PCID = 'A000'
    endglobals
    
    private function Conditions takes nothing returns boolean
        return GetSpellAbilityId() == PCID
    endfunction
    
    private function Actions takes nothing returns nothing
        local unit Caster = GetTriggerUnit()
        local unit u
        local integer zz = 0
        local integer z = 0
        local real x
        local real y
        loop
        exitwhen z == 10
            set x = GetUnitX(Caster) + 300 * Cos((z * 36) * bj_DEGTORAD)
            set y = GetUnitY(Caster) + 300 * Sin((z * 36) * bj_DEGTORAD)
            set u = CreateUnit(GetOwningPlayer(Caster), 'o000', x, y, GetUnitFacing(Caster))
            call IssuePointOrder(u, "attack", x, y)
            call UnitApplyTimedLife(u, 'BTLF', (2 + I2R(GetUnitAbilityLevel(Caster, PCID))))
            set u = null
            set z = z + 1
        endloop
        set Caster = null
    endfunction
    
//====================================================================================================
    private function PCInit takes nothing returns nothing
        local trigger t = CreateTrigger()
        local integer i = 0
        
        loop
            call TriggerRegisterPlayerUnitEvent(t, Player(i), EVENT_PLAYER_UNIT_SPELL_EFFECT, null)
            set i = i + 1
        exitwhen i == bj_MAX_PLAYER_SLOTS
        endloop
        call TriggerAddCondition(t, Condition(function Conditions))
        call TriggerAddAction(t, function Actions)
    endfunction

endscope
 

WolfieeifloW

WEHZ Helper
Reaction score
372
The second loop is for creating the X number of units.
Here's the spells description:
Learn Peon Circle said:
Creates multiple Peons in a circle around the caster to defend him for several seconds. Number of Peons and duration increase with level.

Level 1 - 1 Peon, 3 seconds.
Level 2 - 2 Peons, 4 seconds.
Level 3 - 3 Peons, 5 seconds.
Level 4 - 4 Peons, 6 seconds.

Cooldown: 20/18/16/14 seconds.
Fixed the location leak, thank you.
Here's the new trigger, still not working:
JASS:
scope PeonCircle initializer PCInit
    
    globals
        private constant integer PCID = 'A000'
    endglobals
    
    private function Conditions takes nothing returns boolean
        return GetSpellAbilityId() == PCID
    endfunction
    
    private function Actions takes nothing returns nothing
        local unit Caster = GetTriggerUnit()
        local unit u
        local integer zz = 0
        local integer z = 0
        local real x
        local real y
        
        loop
        exitwhen z == 10
            set x = GetUnitX(Caster) + 300 * Cos((z * 36) * bj_DEGTORAD)
            set y = GetUnitY(Caster) + 300 * Sin((z * 36) * bj_DEGTORAD)
            loop
            exitwhen zz == GetUnitAbilityLevel(Caster, PCID)
                set u = CreateUnit(GetOwningPlayer(Caster), 'o000', x, y, GetUnitFacing(Caster))
                call IssuePointOrder(u, "attack", x, y)
                call UnitApplyTimedLife(u, 'BTLF', (2 + I2R(GetUnitAbilityLevel(Caster, PCID))))
                set u = null
                set zz = zz + 1
            endloop
            set z = z + 1
        endloop
        set Caster = null
    endfunction
    
//====================================================================================================
    private function PCInit takes nothing returns nothing
        local trigger t = CreateTrigger()
        local integer i = 0
        
        loop
            call TriggerRegisterPlayerUnitEvent(t, Player(i), EVENT_PLAYER_UNIT_SPELL_EFFECT, null)
            set i = i + 1
        exitwhen i == bj_MAX_PLAYER_SLOTS
        endloop
        call TriggerAddCondition(t, Condition(function Conditions))
        call TriggerAddAction(t, function Actions)
    endfunction

endscope
 

WolfieeifloW

WEHZ Helper
Reaction score
372
Wow...
Such an easy fix.

Although, some of the unit's don't attack.
Any reason for that, or just the sheer amount of Peon's being created makes some of them not attack?

EDIT: Nevermind, fixed.
Peon's were set to attack their own spawn point, not the Caster's point.
Fixed it though:
JASS:
scope PeonCircle initializer PCInit
    
    globals
        private constant integer PCID = 'A000'
    endglobals
    
    private function Conditions takes nothing returns boolean
        return GetSpellAbilityId() == PCID
    endfunction
    
    private function Actions takes nothing returns nothing
        local unit Caster = GetTriggerUnit()
        local unit u
        local integer zz = 0
        local integer z = 0
        local real x
        local real y
        
        loop
        exitwhen z == 8
            set x = GetUnitX(Caster) + 300 * Cos((z * 45) * bj_DEGTORAD)
            set y = GetUnitY(Caster) + 300 * Sin((z * 45) * bj_DEGTORAD)
            loop
            exitwhen zz == GetUnitAbilityLevel(Caster, PCID)
                set u = CreateUnit(GetOwningPlayer(Caster), 'o000', x, y, GetUnitFacing(Caster))
                call IssuePointOrder(u, "attack", GetUnitX(Caster), GetUnitY(Caster))
                call UnitApplyTimedLife(u, 'BTLF', (2 + I2R(GetUnitAbilityLevel(Caster, PCID))))
                set u = null
                set zz = zz + 1
            endloop
            set z = z + 1
            set zz = 0
        endloop
        set Caster = null
    endfunction
    
//====================================================================================================
    private function PCInit takes nothing returns nothing
        local trigger t = CreateTrigger()
        local integer i = 0
        
        loop
            call TriggerRegisterPlayerUnitEvent(t, Player(i), EVENT_PLAYER_UNIT_SPELL_EFFECT, null)
            set i = i + 1
        exitwhen i == bj_MAX_PLAYER_SLOTS
        endloop
        call TriggerAddCondition(t, Condition(function Conditions))
        call TriggerAddAction(t, function Actions)
    endfunction

endscope
 

AceHart

Your Friendly Neighborhood Admin
Reaction score
1,494
Add a short "wait" to the inner loop.
If it works, there's too many of them too quickly.

Peon? Or try with something that isn't a worker. They don't like attacking things.
 

WolfieeifloW

WEHZ Helper
Reaction score
372
I would've liked it to spawn one group at a time, one after another;
Not all at once.
But TSA's are inaccurate and I haven't learned timers yet :eek: .
 

Gwypaas

hook DoNothing MakeGUIUsersCrash
Reaction score
50
Creating a nova is easy...

JASS:
local real diffBetween = 360/Amount of Units In Nova
local real currAngle = 0
local integer i = 0
loop
exitwhen i >= Amount of units in nova
call CreateUnit(...... CenterX+ 300*Cos(currAngle * bj_DEGTORAD), CenterY+ 300*Sin(currAngle * bj_DEGTORAD)) // Change "300" to the radius you want.
set currAngle = currAngle + diffBetween
set i = i + 1
endloop

Note - This code is working in degrees but you could convert it to radians by changing 360 to a whole circle with radians which I belive is 2PI and remove the bj_DEGTORAD's.

You can also do the exitwhen like this:
JASS:
exitwhen currAngle >= 359 // (359 to avoids conflicts with decimals being trunced)
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      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