Angle Error

Expelliarmus

Where to change the sig?
Reaction score
48
JASS:
scope IllusoryOrb 

globals
    private constant integer AbilID = 'A002' 
    private constant integer DummyID = 'h001' 
    private constant real IORadius = 225.00 
    private constant real IORange = 1400.00 
    private constant real IOInterval = 0.0375 
    private constant real IOMissilespeed = 500 
endglobals

constant function IOIntervalex takes nothing returns real
    return  (IOMissilespeed * IOInterval)
endfunction

constant function IODamage takes integer level returns real
    return (level * 70.00)
endfunction

struct IO
    real x
    real y
    real xx
    real yy
    real dist
    timer IOtimer    
    group damaged
    real distance
    unit dummy
    unit caster
    location loc
    real dummyx
    real dummyy
    real angle 
    
static method create takes nothing returns IO
    local IO io = IO.allocate() 
    
    set io.loc= GetSpellTargetLoc()
    set io.xx = GetLocationX(io.loc)
    set io.yy = GetLocationY(io.loc)
    set io.caster = GetTriggerUnit()
    set io.x = GetUnitX(io.caster)
    set io.y = GetUnitY(io.caster)
    set io.dist = IOIntervalex()
    call RemoveLocation(io.loc)
    set io.loc = null
    set io.angle = Atan2(io.yy - io.y, io.xx - io.x) * bj_DEGTORAD
    return io
endmethod

 private method onDestroy takes nothing returns nothing
        call ReleaseTimer(.IOtimer)
        call GroupClear(.damaged)
        call RemoveUnit(.dummy)
        set .caster = null
        set .dummy = null
        call BJDebugMsg("Struct Clear")
        call ClearTimerStructA(.IOtimer)
        call DestroyGroup( .damaged)
endmethod                      
endstruct

private function GetEnumFilter takes nothing returns boolean
    return IsUnitEnemy(GetFilterUnit(), GetOwningPlayer(GetTriggerUnit())) != true and GetWidgetLife(GetFilterUnit())>.405 and IsUnitType(GetFilterUnit(),UNIT_TYPE_STRUCTURE) != true and GetFilterUnit() != GetTriggerUnit()
endfunction

private function Conditions takes nothing returns boolean    
    return GetSpellAbilityId() == AbilID
endfunction

private function IOTimeout takes nothing returns nothing
      local IO io = GetTimerStructA(GetExpiredTimer())
      local unit u
      local group damage = CreateGroup()
      
      local integer level = GetUnitAbilityLevel(io.caster, AbilID)
      local real polarx = io.dummyx + IOIntervalex() * Cos(io.angle)
      local real polary =io.dummyy + IOIntervalex() * Sin(io.angle )
      
      call GroupEnumUnitsInRange(damage, io.dummyx, io.dummyy, IORadius, Condition( function GetEnumFilter))
    loop
        set u = FirstOfGroup(damage)
        exitwhen u == null      
        if  IsUnitInGroup(u, io.damaged) == false then
        call GroupAddUnit(io.damaged, u)
        call GroupRemoveUnit( damage, u)
        call UnitDamageTarget(io.caster, u, IODamage(level) , false, false,  ATTACK_TYPE_HERO, DAMAGE_TYPE_MAGIC, WEAPON_TYPE_CLAW_LIGHT_SLICE)
        endif      
        set u = null
        call DestroyGroup(damage)
     endloop       
        call SetUnitPosition(io.dummy, polarx, polary)
        if io.dist  <=IORange then
        set io.dist = io.dist + IOIntervalex()
        call BJDebugMsg( R2S(io.dist))
        set io.dummyx = GetUnitX(io.dummy)
        set io.dummyy = GetUnitY(io.dummy)
        else 
        call io.destroy()
        call BJDebugMsg( "Struct Destroyed1")
    endif
endfunction

private function Actions takes nothing returns nothing
    local IO io = IO.create()
    call BJDebugMsg("Dummy")
    set io.IOtimer = NewTimer()
    set io.dummy = CreateUnit(GetOwningPlayer(io.caster), DummyID, io.x, io.y, io.angle)
    
    call SetTimerStructA(io.IOtimer, io)
    
    call TimerStart(io.IOtimer, IOInterval, true, function IOTimeout)
    
    
endfunction
//__________________________________________________________________________________________

public function InitTrig takes nothing returns nothing
    local trigger trig = CreateTrigger(  )
        call TriggerRegisterAnyUnitEventBJ( trig, EVENT_PLAYER_UNIT_SPELL_EFFECT )
        call TriggerAddCondition( trig, Condition( function Conditions ) )
        call TriggerAddAction( trig, function Actions )
endfunction

endscope

2 things happen when I cast this spell:
- dummy gets created at where the previous dummy left off (from previous cast); how did the data get passed to the next cast
- dummy always travel to the right, I know something is wrong

What works:
- dummy created
- max distance
- speed of missile
- damage (to correct units)

Please hint me optimization tips
Also, is this MUI/ Leakless? Just wanted to know :D

Thanks in Advance
 

Artificial

Without Intelligence
Reaction score
326
JASS:
set io.angle = Atan2(io.yy - io.y, io.xx - io.x) * bj_DEGTORAD
Remove the * bj_DEGTORAD part and the angle should be right. Atan2 already returns the value in radians.

Please hint me optimization tips
As you wish. x)

Why is loc a struct member? It could just be a local variable.

JASS:
set .caster = null
set .dummy = null
No need to null global variables.

Also as your interval is so small, you could use a single timer (or use TT), and you could also recycle the groups.

dummy gets created at where the previous dummy left off
Are you sure it gets created there? I'd guess it gets created to the right place, but just gets moved to the place where the previous one was, as you're not setting dummyx and dummyy. Also I can't understand why they are struct members, as there's no need for that (local real dummyX = GetUnitX(io.dummy) and the same for y).

JASS:
local real polarx = io.dummyx + IOIntervalex() * Cos(io.angle)
local real polary =io.dummyy + IOIntervalex() * Sin(io.angle)
IOIntervalex() * Cos(io.angle) and IOIntervalex() * Sin(io.angle) are going to remain the same during a spell cast, right? Then why always recalculate them? Calculate them when the spell is casted and store them into struct members. Then just do
JASS:
local real polarx = GetUnitX(io.dummy) + io.xIncrease
local real polary = GetUnitY(io.dummy) + io.yIncrease


You're also having 2 struct members for distance: dist and distance. :D

JASS:
call GroupRemoveUnit( damage, u)
You might want to move that outside the if statement. If a unit already is in the struct member group, it won't be removed from the group and the loop will keep running for that unit until the game stops the execution.
 

Expelliarmus

Where to change the sig?
Reaction score
48
Remove the * bj_DEGTORAD part and the angle should be right. Atan2 already returns the value in radians.
Saved the whole code. Thanks +rep!
I thought Atan2 returns in degrees because Atan2BJ calls Atan2 and converts it to Radian.
Are you sure it gets created there? I'd guess it gets created to the right place, but just gets moved to the place where the previous one was, as you're not setting dummyx and dummyy. Also I can't understand why they are struct members, as there's no need for that (local real dummyX = GetUnitX(io.dummy) and the same for y).
Yeah, It moves instantly to that location, not gets created there.I don't get what you mean by the bolded bit. I need their (x,y) for the other spell which basically sets the caster to the location of the dummy. Is it required?
Also as your interval is so small, you could use a single timer (or use TT), and you could also recycle the groups.
Yea, I was thinking of using TT, but I had to reassure my confidence in ABC. TT is like 10x easily to pass data to timer I believe. Recycle the groups as in the function in CSSafety? I can't compile that because I don't have the correct version of jasshelper. I'm not bothered to update it.
You're also having 2 struct members for distance: dist and distance.
lol, I wonder how that happened ^_^

Thanks again!
EDIT:
hmm... my dummy gets created like 600.00 distance away from the caster. The direction it goes is fine...
 

Expelliarmus

Where to change the sig?
Reaction score
48
JASS:
scope IllusoryOrb 

globals
    private constant integer AbilID = 'A002' 
    private constant integer DummyID = 'h001' 
    private constant real IORadius = 225.00 
    private constant real IORange = 1400.00 
    private constant real IOInterval = 0.0375 
    private constant real IOMissilespeed = 500 
endglobals

constant function IOIntervalex takes nothing returns real
    return  (IOMissilespeed * IOInterval)
endfunction

constant function IODamage takes integer level returns real
    return (level * 70.00)
endfunction

struct IO
    real x
    real y
    real xx
    real yy
    real dist
    timer IOtimer    
    group damaged
    unit dummy
    unit caster
    location loc
    real dummyx
    real dummyy
    real angle
    real xincrease
    real yincrease
    
static method create takes nothing returns IO
    local IO io = IO.allocate() 
    
    set io.loc= GetSpellTargetLoc()
    set io.xx = GetLocationX(io.loc)
    set io.yy = GetLocationY(io.loc)
    set io.caster = GetTriggerUnit()
    set io.x = GetUnitX(io.caster)
    set io.y = GetUnitY(io.caster)
    set io.dist = IOIntervalex()
    set io.loc = null
    set io.angle = Atan2(io.yy - io.y, io.xx - io.x)
    set io.xincrease = IOIntervalex() * Cos(io.angle)
    set io.yincrease = IOIntervalex() * Sin(io.angle)
    return io
endmethod

 private method onDestroy takes nothing returns nothing
        call ReleaseTimer(.IOtimer)
        call GroupClear(.damaged)
        call RemoveUnit(.dummy)
        call ClearTimerStructA(.IOtimer)
        call DestroyGroup( .damaged)
endmethod                      
endstruct

private function GetEnumFilter takes nothing returns boolean
    return IsUnitEnemy(GetFilterUnit(), GetOwningPlayer(GetTriggerUnit())) != true and GetWidgetLife(GetFilterUnit())>.405 and IsUnitType(GetFilterUnit(),UNIT_TYPE_STRUCTURE) != true and GetFilterUnit() != GetTriggerUnit()
endfunction

private function Conditions takes nothing returns boolean    
    return GetSpellAbilityId() == AbilID
endfunction

private function IOTimeout takes nothing returns nothing
      local IO io = GetTimerStructA(GetExpiredTimer())
      local unit u
      local group damage = CreateGroup()
      
      local integer level = GetUnitAbilityLevel(io.caster, AbilID)
      local real polarx = io.dummyx + io.xincrease
      local real polary =io.dummyy + io.yincrease
      
      call GroupEnumUnitsInRange(damage, io.dummyx, io.dummyy, IORadius, Condition( function GetEnumFilter))
    loop
        set u = FirstOfGroup(damage)
        exitwhen u == null      
        if  IsUnitInGroup(u, io.damaged) == false then
        call GroupAddUnit(io.damaged, u)
        call UnitDamageTarget(io.caster, u, IODamage(level) , false, false,  ATTACK_TYPE_HERO, DAMAGE_TYPE_MAGIC, WEAPON_TYPE_CLAW_LIGHT_SLICE)
        endif    
        call GroupRemoveUnit( damage, u)
        set u = null
        call DestroyGroup(damage)
     endloop       
        call SetUnitPosition(io.dummy, polarx, polary)
        if io.dist  <=IORange then
        set io.dist = io.dist + IOIntervalex()
        set io.dummyx = GetUnitX(io.dummy)
        set io.dummyy = GetUnitY(io.dummy)
        else 
        call io.destroy()
    endif
endfunction

private function Actions takes nothing returns nothing
    local location loc= GetSpellTargetLoc()
    local IO io = IO.create()
    call RemoveLocation(loc)
    set io.IOtimer = NewTimer()
    set io.dummy = CreateUnit(GetOwningPlayer(io.caster), DummyID, io.x, io.y, io.angle)
    
    call SetTimerStructA(io.IOtimer, io)
    
    call TimerStart(io.IOtimer, IOInterval, true, function IOTimeout)

    
    
endfunction
//__________________________________________________________________________________________

public function InitTrig takes nothing returns nothing
    local trigger trig = CreateTrigger(  )
        call TriggerRegisterAnyUnitEventBJ( trig, EVENT_PLAYER_UNIT_SPELL_EFFECT )
        call TriggerAddCondition( trig, Condition( function Conditions ) )
        call TriggerAddAction( trig, function Actions )
endfunction

endscope

Changed a few things from post #2.
 

Tukki

is Skeleton Pirate.
Reaction score
29
I'm not 100% sure, but you should change the following lines;
JASS:
      local real polarx = io.dummyx + io.xincrease
      local real polary =io.dummyy + io.yincrease

to
JASS:
      local real polarx = GetUnitX(io.dummy) + io.xincrease
      local real polary = GetUnitY(io.dummy) + io.yincrease


As they are never initialized before first timer execute. Also where are you using the "loc" variable in the Actions function, and removal isn't enough you must null it.
 

Expelliarmus

Where to change the sig?
Reaction score
48
I'm not 100% sure, but you should change the following lines;
Lol that fixed the range. Thankyou +rep
Also where are you using the "loc" variable in the Actions function
in the struct, I am setting xx and yy based from that. should I even have a variable for that or should i do that in xx and yy?
you must null it
lol? really, how about groups and special effects? do they need to be nulled?
And one last thing... when I shoot twice to the same unit, the second time the target unit doesn't take damage; it is already in the io.damaged on my second cast. Why is that??

Thank you for fixing my error!
 

Tukki

is Skeleton Pirate.
Reaction score
29
In the IOTimeout;
JASS:
      local IO io = GetTimerStructA(GetExpiredTimer())
      local unit u
      local group damage = CreateGroup() // We must null and destroy this.
      
      local integer level = GetUnitAbilityLevel(io.caster, AbilID)
      local real polarx = io.dummyx + io.xincrease
      local real polary =io.dummyy + io.yincrease
      
      call GroupEnumUnitsInRange(damage, io.dummyx, io.dummyy, IORadius, Condition( function GetEnumFilter))
    loop
        set u = FirstOfGroup(damage)
        exitwhen u == null      
        if  IsUnitInGroup(u, io.damaged) == false then
        call GroupAddUnit(io.damaged, u)
        call UnitDamageTarget(io.caster, u, IODamage(level) , false, false,  ATTACK_TYPE_HERO, DAMAGE_TYPE_MAGIC, WEAPON_TYPE_CLAW_LIGHT_SLICE)
        endif    
        call GroupRemoveUnit( damage, u)
     endloop       
        call SetUnitPosition(io.dummy, polarx, polary)
        if io.dist  <=IORange then
        set io.dist = io.dist + IOIntervalex()
        set io.dummyx = GetUnitX(io.dummy)
        set io.dummyy = GetUnitY(io.dummy)
        else 
        call io.destroy()
    endif
    call DestroyGroup(damage) // null and destroy.
    set damage = null


lol? really, how about groups and special effects?
groups and effects also needs to be nulled. But effects does not if you are doing something like this: "call DestroyEffect(AddSpecialEffect(...))".
 

Viikuna

No Marlo no game.
Reaction score
265
You could just use global group together with ClearGroup, it would save you from creating and destroying and nulling your group all the time.
 

Tukki

is Skeleton Pirate.
Reaction score
29
Yeah, but then you would need to revamp to most of your code to make it MUI.
 

Expelliarmus

Where to change the sig?
Reaction score
48
ok... that's just wierd. Now the damage doesn't work...
JASS:
scope IllusoryOrb 

globals
    private constant integer AbilID = 'A002' 
    private constant integer DummyID = 'h001' 
    private constant real IORadius = 225.00 
    private constant real IORange = 1400.00 
    private constant real IOInterval = 0.0375 
    private constant real IOMissilespeed = 500 
endglobals

constant function IOIntervalex takes nothing returns real
    return  (IOMissilespeed * IOInterval)
endfunction

constant function IODamage takes integer level returns real
    return (level * 70.00)
endfunction

struct IO
    real x
    real y
    real xx
    real yy
    real dist
    timer IOtimer    
    group damaged
    unit dummy
    unit caster
    location loc
    real dummyx
    real dummyy
    real angle
    real xincrease
    real yincrease
    
static method create takes nothing returns IO
    local IO io = IO.allocate() 
    
    set io.loc= GetSpellTargetLoc()
    set io.xx = GetLocationX(io.loc)
    set io.yy = GetLocationY(io.loc)
    set io.caster = GetTriggerUnit()
    set io.x = GetUnitX(io.caster)
    set io.y = GetUnitY(io.caster)
    set io.dist = IOIntervalex()
    set io.loc = null
    set io.angle = Atan2(io.yy - io.y, io.xx - io.x)
    set io.xincrease = IOIntervalex() * Cos(io.angle)
    set io.yincrease = IOIntervalex() * Sin(io.angle)
    return io
endmethod

 private method onDestroy takes nothing returns nothing
        call ReleaseTimer(.IOtimer)
        call GroupClear(.damaged)
        call RemoveUnit(.dummy)
        call ClearTimerStructA(.IOtimer)
        call DestroyGroup( .damaged)
        set .damaged = null
endmethod                      
endstruct

private function GetEnumFilter takes nothing returns boolean
    return IsUnitEnemy(GetFilterUnit(), GetOwningPlayer(GetTriggerUnit())) != true and GetWidgetLife(GetFilterUnit())>.405 and IsUnitType(GetFilterUnit(),UNIT_TYPE_STRUCTURE) != true and GetFilterUnit() != GetTriggerUnit()
endfunction

private function Conditions takes nothing returns boolean    
    return GetSpellAbilityId() == AbilID
endfunction

private function IOTimeout takes nothing returns nothing
      local IO io = GetTimerStructA(GetExpiredTimer())
      local unit u
      local group damage = CreateGroup()
      
      local integer level = GetUnitAbilityLevel(io.caster, AbilID)
      local real polarx = GetUnitX(io.dummy) + io.xincrease
      local real polary =GetUnitY(io.dummy) + io.yincrease
      
      call GroupEnumUnitsInRange(damage, io.dummyx, io.dummyy, IORadius, Condition( function GetEnumFilter))
    loop
        set u = FirstOfGroup(damage)
        call BJDebugMsg(GetUnitName(u))
        exitwhen u == null      
        if  IsUnitInGroup(u, io.damaged) == false then
        call GroupAddUnit(io.damaged, u)
        call UnitDamageTarget(io.caster, u, IODamage(level) , false, false,  ATTACK_TYPE_HERO, DAMAGE_TYPE_MAGIC, WEAPON_TYPE_CLAW_LIGHT_SLICE)
        endif    
        call GroupRemoveUnit( damage, u)
        set u = null
        
     endloop       
        call SetUnitPosition(io.dummy, polarx, polary)
        if io.dist  <=IORange then
        set io.dist = io.dist + IOIntervalex()
        set io.dummyx = GetUnitX(io.dummy)
        set io.dummyy = GetUnitY(io.dummy)
        else 
        call io.destroy()
    endif
    call DestroyGroup(damage)
    set damage = null
endfunction

private function Actions takes nothing returns nothing
    local location loc= GetSpellTargetLoc()
    local IO io = IO.create()
    
    call RemoveLocation(loc)
    set loc = null
    set io.IOtimer = NewTimer()
    set io.dummy = CreateUnit(GetOwningPlayer(io.caster), DummyID, io.x, io.y, io.angle)
    
    call SetTimerStructA(io.IOtimer, io)
    
    call TimerStart(io.IOtimer, IOInterval, true, function IOTimeout)

    
    
endfunction
//__________________________________________________________________________________________

public function InitTrig takes nothing returns nothing
    local trigger trig = CreateTrigger(  )
        call TriggerRegisterAnyUnitEventBJ( trig, EVENT_PLAYER_UNIT_SPELL_EFFECT )
        call TriggerAddCondition( trig, Condition( function Conditions ) )
        call TriggerAddAction( trig, function Actions )
endfunction

endscope

I think it's my condition...but I haven't touched the condition since it was working.
 

Tukki

is Skeleton Pirate.
Reaction score
29
Oh crap, hang on some minutes and I will post a alternative code..

EDIT: The GetEnumFilter is the thing that doesn't work.. <-- just so you know.

EDIT 2: Okey not it's independent of any systems and it compiles for me (but it's not tested..)
JASS:
scope IllusoryOrb initializer InitTrig

globals
    private constant integer AbilID  = &#039;A002&#039; 
    private constant integer DummyID = &#039;h001&#039; 
    private constant real IORadius   = 225.00 
    private constant real IORange    = 1400.00 
    private constant real IOInterval = 0.0375 
    private constant real IOMissilespeed = 500 
endglobals

// Really not needed..
//constant function IOIntervalex takes nothing returns real
//    return  (IOMissilespeed * IOInterval)
//endfunction 

//============================================================================================
constant function IODamage takes integer level returns real
    return (level * 70.00)
endfunction

//============================================================================================
private struct IO // private prefix.
    real x
    real y
    real xx
    real yy
    real dist  
    group damaged
    unit dummy
    unit caster
    real dummyx
    real dummyy
    real xTick
    real yTick
    real damage
    
    static method create takes nothing returns IO
     local IO io = IO.allocate() 
     local location l = GetSpellTargetLoc() 
     local real a = Atan2(io.yy - io.y, io.xx - io.x) 
        
        set io.xx = GetLocationX(l)
        set io.yy = GetLocationY(l)
        set io.caster = GetTriggerUnit()
        set io.x = GetUnitX(io.caster)
        set io.y = GetUnitY(io.caster)
        set io.dist = 0
        set io.xTick = (IOMissilespeed * IOInterval) * Cos(a)
        set io.yTick = (IOMissilespeed * IOInterval) * Sin(a)
        set io.dummy = CreateUnit(GetOwningPlayer(io.caster), DummyID, io.x, io.y, a * bj_RADTODEG) // facing is in degrees, Atan2 returns in radians
        set io.damage = IODamage(GetUnitAbilityLevel(io.caster, AbilID))
        set io.damaged = CreateGroup()
        
        call RemoveLocation(l)
        set l = null
        return io
    endmethod

    private method onDestroy takes nothing returns nothing
            call GroupClear(.damaged)
            call KillUnit(.dummy)
            call DestroyGroup( .damaged)
            //set .damaged = null // no need to null struct members.
    endmethod                      
endstruct

// This must we change as it does not work, see how we deal with it below
//============================================================================================
globals
    private unit TempUnit = null   // TempUnit for checking enuming.
    private group TempGroup = null // TempGroup for enuming.
    private timer Timer    = null  // Timer for running orbs and such..
    private boolexpr FILTER = null // Boolexpr for checking conditions with group.
    
    private integer array Datas    // Array for storing struct.
    private integer TopIndex = 0   // Index for retrieving struct.
endglobals

//============================================================================================
private function GetEnumFilter takes nothing returns boolean
    return IsUnitEnemy(GetFilterUnit(), GetOwningPlayer(TempUnit)) != true and GetWidgetLife(GetFilterUnit())&gt;.405 and IsUnitType(GetFilterUnit(),UNIT_TYPE_STRUCTURE) != true 
endfunction// Right now it will ONLY damage friendly, alive and non-structure units

//============================================================================================
private function IOTimeout takes nothing returns nothing
 local IO d      // &lt;-- our IO data.
 local integer i = TopIndex// &lt;-- integer for looping.
 local unit fog  // &lt;-- First of Group unit.
 local real x    // x movement
 local real y    // y movement
 
    loop
        exitwhen TopIndex &lt; 0
        set d = Datas<i>  //&lt;-- Get our struct.
        set x = GetUnitX(d.dummy) + d.xTick
        set y = GetUnitY(d.dummy) + d.yTick // y- and xTick are the movement per Interval
        set TempUnit = d.caster
        call GroupEnumUnitsInRange(TempGroup, x, y, IORadius, FILTER)
        loop
            set fog = FirstOfGroup(TempGroup)
            exitwhen fog == null
            call GroupRemoveUnit(TempGroup, fog)
            if not (IsUnitInGroup(fog, d.damaged)) then
                call GroupAddUnit(d.damaged, fog)
                call UnitDamageTarget(d.caster, fog, d.damage, false, false, ATTACK_TYPE_HERO, DAMAGE_TYPE_MAGIC, null)
                // Maybe create some nify SFX?
            endif
        endloop
        call SetUnitX(d.dummy, x)
        call SetUnitY(d.dummy, y)
        set d.dist = d.dist + IOMissilespeed * IOInterval
        if (d.dist &lt;= IORange) then
            set d.dummyx = x
            set d.dummyy = y
        else
            call d.destroy()
            set TopIndex = TopIndex - 1 // Lower the index.
            if (TopIndex &lt;= 0) then
                set TopIndex = 0
                call PauseTimer(Timer)
            else
                set Datas<i> = Datas[TopIndex] // Move the newest struct to the just cleared one.
            endif
        endif
        call GroupClear(TempGroup) // Clear the group from all units, if there are any?
        set i = i + 1
    endloop
endfunction

//============================================================================================
private function Actions takes nothing returns nothing
 local IO io = IO.create()

    if (TopIndex - 1 == 0) then
        call TimerStart(Timer, IOInterval, true, function IOTimeout)
    endif
endfunction

//============================================================================================
private function Conditions takes nothing returns boolean    
    return GetSpellAbilityId() == AbilID
endfunction

//============================================================================================
private function InitTrig takes nothing returns nothing // private as we uses initializer
 local trigger trig = CreateTrigger(  )
 
    set Timer = CreateTimer() // Create our timer..
    set TempGroup = CreateGroup() // Create our group..
    set FILTER = Condition(function GetEnumFilter)
    call TriggerRegisterAnyUnitEventBJ( trig, EVENT_PLAYER_UNIT_SPELL_EFFECT )
    call TriggerAddCondition( trig, Condition( function Conditions ) )
    call TriggerAddAction( trig, function Actions )
endfunction
endscope</i></i>
 

Expelliarmus

Where to change the sig?
Reaction score
48
Hmm.. I tried your code and...
What does work:
- Dummy gets created

What doesn't work:
- Movement of Dummy
- Damage

Besides that, wow! highly skilled vJass skills... awesome!
lol I tried to decipher it, but I got lost when you declared arrays ^_^
The GetEnumFilter is the thing that doesn't work.. <-- just so you know.
hmm.. is it just this that is the problem? How can you fix this?
 

Tukki

is Skeleton Pirate.
Reaction score
29
Heh, not strange why it doesn't work -- no struct attaching..

UPDATED CODE:
JASS:
scope IllusoryOrb initializer InitTrig

globals
    private constant integer AbilID  = &#039;A002&#039; 
    private constant integer DummyID = &#039;h001&#039; 
    private constant real IORadius   = 225.00 
    private constant real IORange    = 1400.00 
    private constant real IOInterval = 0.0375 
    private constant real IOMissilespeed = 500 
endglobals

// Really not needed..
//constant function IOIntervalex takes nothing returns real
//    return  (IOMissilespeed * IOInterval)
//endfunction 

//============================================================================================
constant function IODamage takes integer level returns real
    return (level * 70.00)
endfunction

//============================================================================================
private struct IO // private prefix.
    real x
    real y
    real xx
    real yy
    real dist  
    group damaged
    unit dummy
    unit caster
    real dummyx
    real dummyy
    real xTick
    real yTick
    real damage
    
    static method create takes nothing returns IO
     local IO io = IO.allocate() 
     local location l = GetSpellTargetLoc() 
     local real a = Atan2(io.yy - io.y, io.xx - io.x) 
        
        set io.xx = GetLocationX(l)
        set io.yy = GetLocationY(l)
        set io.caster = GetTriggerUnit()
        set io.x = GetUnitX(io.caster)
        set io.y = GetUnitY(io.caster)
        set io.dist = 0
        set io.xTick = (IOMissilespeed * IOInterval) * Cos(a)
        set io.yTick = (IOMissilespeed * IOInterval) * Sin(a)
        set io.dummy = CreateUnit(GetOwningPlayer(io.caster), DummyID, io.x, io.y, a * bj_RADTODEG) // facing is in degrees, Atan2 returns in radians
        set io.damage = IODamage(GetUnitAbilityLevel(io.caster, AbilID))
        set io.damaged = CreateGroup()
        
        call RemoveLocation(l)
        set l = null
        return io
    endmethod

    private method onDestroy takes nothing returns nothing
            call GroupClear(.damaged)
            call KillUnit(.dummy)
            call DestroyGroup( .damaged)
            //set .damaged = null // no need to null struct members.
    endmethod                      
endstruct

// This must we change as it does not work, see how we deal with it below
//============================================================================================
globals
    private unit TempUnit = null   // TempUnit for checking enuming.
    private group TempGroup = null // TempGroup for enuming.
    private timer Timer    = null  // Timer for running orbs and such..
    private boolexpr FILTER = null // Boolexpr for checking conditions with group.
    
    private integer array Datas    // Array for storing struct. As structs are integer we can store them in an array and retrieve them with a loop.
    private integer TopIndex = 0   // Max Index a.k.a How many structs there are being used.
endglobals

//============================================================================================
private function GetEnumFilter takes nothing returns boolean
    return IsUnitEnemy(GetFilterUnit(), GetOwningPlayer(TempUnit)) != true and GetWidgetLife(GetFilterUnit())&gt;.405 and IsUnitType(GetFilterUnit(),UNIT_TYPE_STRUCTURE) != true 
endfunction// Right now it will ONLY damage friendly, alive and non-structure units

//============================================================================================
private function IOTimeout takes nothing returns nothing
 local IO d      // &lt;-- our IO data.
 local integer i = TopIndex// &lt;-- integer for looping.
 local unit fog  // &lt;-- First of Group unit.
 local real x    // x movement
 local real y    // y movement
 
    loop
        exitwhen TopIndex &lt; 0
        set d = Datas<i>  //&lt;-- Get our struct.
        set x = GetUnitX(d.dummy) + d.xTick
        set y = GetUnitY(d.dummy) + d.yTick // y- and xTick are the movement per Interval
        set TempUnit = d.caster
        call GroupEnumUnitsInRange(TempGroup, x, y, IORadius, FILTER)
        loop
            set fog = FirstOfGroup(TempGroup)
            exitwhen fog == null
            call GroupRemoveUnit(TempGroup, fog)
            if not (IsUnitInGroup(fog, d.damaged)) then
                call GroupAddUnit(d.damaged, fog)
                call UnitDamageTarget(d.caster, fog, d.damage, false, false, ATTACK_TYPE_HERO, DAMAGE_TYPE_MAGIC, null)
                // Maybe create some nify SFX?
            endif
        endloop
        call SetUnitX(d.dummy, x)
        call SetUnitY(d.dummy, y)
        set d.dist = d.dist + IOMissilespeed * IOInterval
        if (d.dist &lt;= IORange) then
            set d.dummyx = x
            set d.dummyy = y
        else
            call d.destroy()
            set TopIndex = TopIndex - 1 // Lower the index.
            if (TopIndex &lt;= 0) then
                set TopIndex = 0
                call PauseTimer(Timer)
            else
                set Datas<i> = Datas[TopIndex] // Move the newest struct to the just cleared one.
            endif
        endif
        call GroupClear(TempGroup) // Clear the group from all units, if there are any?
        set i = i + 1
    endloop
endfunction

//============================================================================================
private function Actions takes nothing returns nothing
 local IO io = IO.create()

    set Datas[TopIndex] = io
    set TopIndex = TopIndex + 1
    
    if (TopIndex - 1 == 0) then
        call TimerStart(Timer, IOInterval, true, function IOTimeout)
    endif
endfunction

//============================================================================================
private function Conditions takes nothing returns boolean    
    return GetSpellAbilityId() == AbilID
endfunction

//============================================================================================
private function InitTrig takes nothing returns nothing // private as we are using an initializer
 local trigger trig = CreateTrigger(  )
 
    set Timer = CreateTimer() // Create our timer..
    set TempGroup = CreateGroup() // Create our group..
    set FILTER = Condition(function GetEnumFilter)
    call TriggerRegisterAnyUnitEventBJ( trig, EVENT_PLAYER_UNIT_SPELL_EFFECT )
    call TriggerAddCondition( trig, Condition( function Conditions ) )
    call TriggerAddAction( trig, function Actions )
endfunction
endscope</i></i>


hmm.. is it just this that is the problem? How can you fix this?
I'm using a global unit called TempUnit and sets it in the loop, right before I call the GroupEnumUnitsInRange(..) function. It's only MUI if you use it in a way like that as the code is updated in the same period, not called by multiple timers at different intervals.
 

Viikuna

No Marlo no game.
Reaction score
265
ye, Globals are usually MUI if you dont have any waits or timers or some other time taking thingies beetween your actions.
 

Tukki

is Skeleton Pirate.
Reaction score
29
I seriously need to test that code..

EDIT: Just real in-game testing left, found some really obvious bugs.

EDIT_2:
UPDATED CODE: (You must change AbilID and DummyID to your ids, though)
JASS:
scope IllusoryOrb initializer InitTrig

globals
    private constant integer AbilID  = &#039;AHtb&#039; 
    private constant integer DummyID = &#039;hpea&#039; 
    private constant real IORadius   = 225.00 
    private constant real IORange    = 1400.00 
    private constant real IOInterval = 0.0375 
    private constant real IOMissilespeed = 500 
endglobals

// Really not needed..
//constant function IOIntervalex takes nothing returns real
//    return  (IOMissilespeed * IOInterval)
//endfunction 

//============================================================================================
constant function IODamage takes integer level returns real
    return (level * 70.00)
endfunction

//============================================================================================
private struct IO // private prefix.
    real x
    real y
    real xx
    real yy
    real dist  
    group damaged
    unit dummy
    unit caster
    real dummyx
    real dummyy
    real xTick
    real yTick
    real damage
    
    static method create takes nothing returns IO
     local IO io = IO.allocate() 
     local location l = GetSpellTargetLoc() 
     local real a
        
        set io.xx = GetLocationX(l)
        set io.yy = GetLocationY(l)
        set io.caster = GetTriggerUnit()
        set io.x = GetUnitX(io.caster)
        set io.y = GetUnitY(io.caster)
        set io.dist = 0
        set a = Atan2(io.yy - io.y, io.xx - io.x) 
        set io.xTick = (IOMissilespeed * IOInterval) * Cos(a)
        set io.yTick = (IOMissilespeed * IOInterval) * Sin(a)
        set io.dummy = CreateUnit(GetOwningPlayer(io.caster), DummyID, io.x, io.y, a * bj_RADTODEG) // facing is in degrees, Atan2 returns in radians
        set io.damage = IODamage(GetUnitAbilityLevel(io.caster, AbilID))
        set io.damaged = CreateGroup()
        
        // call UnitAddAbility(io.dummy, &#039;Aloc&#039;) // Locust ability, it can&#039;t be detected by GroupEnumUnitsInRange(..) functions. Also it&#039;s now unaffected by pathing.
        
        call RemoveLocation(l)
        set l = null
        return io
    endmethod

    private method onDestroy takes nothing returns nothing
            call GroupClear(.damaged)
            call KillUnit(.dummy)
            call DestroyGroup( .damaged)
            //set .damaged = null // no need to null struct members.
    endmethod                      
endstruct

// This must we change as it does not work, see how we deal with it below
//============================================================================================
globals
    private unit TempUnit = null   // TempUnit for checking enuming.
    private group TempGroup = null // TempGroup for enuming.
    private timer Timer    = null  // Timer for running orbs and such..
    private boolexpr FILTER = null // Boolexpr for checking conditions with group.
    
    private integer array Datas    // Array for storing struct. As structs are integer we can store them in an array and retrieve them with a loop.
    private integer TopIndex = 0   // Max Index a.k.a How many structs there are being used.
endglobals

//============================================================================================
private function GetEnumFilter takes nothing returns boolean
    return IsUnitEnemy(GetFilterUnit(), GetOwningPlayer(TempUnit)) != true and GetWidgetLife(GetFilterUnit())&gt;.405 and IsUnitType(GetFilterUnit(),UNIT_TYPE_STRUCTURE) != true 
endfunction// Right now it will ONLY damage friendly, alive and non-structure units

//============================================================================================
private function IOTimeout takes nothing returns nothing
 local IO d      // &lt;-- our IO data.
 local integer i = TopIndex - 1// &lt;-- integer for looping. - 1 as we add +1 to the TotalIndex after the struct is attached, meaning wc3 belives that we have 1 additional struct.
 local unit fog  // &lt;-- First of Group unit.
 local real x    // x movement
 local real y    // y movement
 
    loop
        exitwhen i &lt; 0
        set d = Datas<i>  //&lt;-- Get our struct.
        set x = GetUnitX(d.dummy) + d.xTick
        set y = GetUnitY(d.dummy) + d.yTick // y- and xTick are the movement per Interval
        set TempUnit = d.caster
        call GroupEnumUnitsInRange(TempGroup, x, y, IORadius, FILTER)
        loop
            set fog = FirstOfGroup(TempGroup)
            exitwhen fog == null
            call GroupRemoveUnit(TempGroup, fog)
            if not (IsUnitInGroup(fog, d.damaged)) then
                call GroupAddUnit(d.damaged, fog)
                call UnitDamageTarget(d.caster, fog, d.damage, false, false, ATTACK_TYPE_HERO, DAMAGE_TYPE_MAGIC, null)
                // Maybe create some nify SFX?
            endif
        endloop
        call SetUnitX(d.dummy, x)
        call SetUnitY(d.dummy, y)
        set d.dist = d.dist + IOMissilespeed * IOInterval
        if (d.dist &lt;= IORange) then
            set d.dummyx = x
            set d.dummyy = y
        else
            call d.destroy()
            set TopIndex = TopIndex - 1 // Lower the index.
            if (TopIndex &lt; 0) then
                set TopIndex = 0
                call PauseTimer(Timer)
            else
                set Datas<i> = Datas[TopIndex] // Move the newest struct to the just cleared one.
            endif
        endif
        call GroupClear(TempGroup) // Clear the group from all units, if there are any?
        set i = i - 1
    endloop
endfunction

//============================================================================================
private function Actions takes nothing returns nothing
 local IO io = IO.create()

    set Datas[TopIndex] = integer(io)
    set TopIndex = TopIndex + 1
    
    if (TopIndex - 1 == 0) then
        call TimerStart(Timer, IOInterval, true, function IOTimeout)
    endif
endfunction

//============================================================================================
private function Conditions takes nothing returns boolean    
    return GetSpellAbilityId() == AbilID
endfunction

//============================================================================================
private function InitTrig takes nothing returns nothing // private as we are using an initializer
 local trigger trig = CreateTrigger(  )
 
    set Timer = CreateTimer() // Create our timer..
    set TempGroup = CreateGroup() // Create our group..
    set FILTER = Condition(function GetEnumFilter)
    call TriggerRegisterAnyUnitEventBJ( trig, EVENT_PLAYER_UNIT_SPELL_EFFECT )
    call TriggerAddCondition( trig, Condition( function Conditions ) )
    call TriggerAddAction( trig, function Actions )
endfunction
endscope</i></i>
 
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

      Members online

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top