• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.
  • The Hive's 22nd Icon Contest: Creep Abilities is now concluded, time to vote for your favourite set of icons! Click here to vote!
  • ✅ The POLL for Hive's Texturing Contest #34 is OPEN! Vote for the TOP 3 SKINS! 🔗Click here to cast your vote!
  • ✅ The POLL for Hive's Techtree Contest #20 is OPEN! Vote for the TOP 3 FACTIONS! 🔗Click here to cast your vote!

[JASS] call SetUnitPosition

Status
Not open for further replies.
Level 6
Joined
Jul 18, 2009
Messages
199
I wanted my unit to move behind the attacked unit. this is what i got in the math.
JASS:
local real r =  GetUnitLoc( u ) - 128 * Cos( AngleBetweenPoints( GetUnitLoc( t ), GetUnitLoc( u ) ) )
But i wanted to use
JASS:
call SetUnitPosition

//ChaosKnight :wink:
 
Dont use Locs. Simple as that. Also, Angle Between Points returns degrees, not radians (I think), so you have to use Atan2.

JASS:
local real angle = Atan2(GetUnitY(u) - GetUnitY(t), GetUnitX(u) - GetUnitX(t))
local real x = GetUnitX(u) + Cos(angle) * DISTANCE
local real y = GetUnitY(u) + Sin(angle) * DISTANCE
call SetUnitPosition(u, x, y)

Im not sure which units are u and t, so you can figure out the rest. That should work somewhat though.
 
Okay, i got it work. But now my trigger's messed up instead.
JASS:
scope MovingStrike initializer Init
// +-------------------------------------------------------------------------------+
// |     Possession - Created by Chaos_Knight.  Requires a vJass preprocessor!     |   
// +-------------------------------------------------------------------------------+
// | Gives a small chance to permanently change control of the target unit         |
// | to the owner of the attacker.                                                 |
// +-------------------------------------------------------------------------------+
// | How to Import:                                                                |
// |  - Create a new trigger                                                       |
// |  - Convert it to Custom text (Edit > Convert to Custom Text)                  |
// |  - Replace everything there with this code                                    |
// |  - Change the constants to suit yourself                                      |
// |  - Enjoy!                                                                     |
// +-------------------------------------------------------------------------------+

// |-------------|
// | Constants:  |
// |-------------|
    globals
        // The effect created on the target when it is being possessed:
        private constant string EFFECT = "Abilities\\Weapons\\PhoenixMissile\\Phoenix_Missile_mini.mdl"
        // Which is attached to the targets:
        private constant string EFFECT_POSITION = "weapon,left"
        private constant string EFFECTPOSITION = "weapon,right"
        private constant integer DUMMYSPELLID = 'Q009'
        
        // The Raw code of the ability
        private constant integer ID = 'A008'
    endglobals
    
    private constant function CHANCE takes integer level returns integer
    // The chance of a unit being possessed. "level" is the level of the ability.
        return level * 3
    endfunction
    
// |------------------|
// | End of Constants |
// |------------------|

// DO NOT EDIT BELOW THIS LINE!

    private function True takes nothing returns boolean
        return true
    endfunction
    
    private function Cons takes nothing returns boolean
        return IsPlayerEnemy(GetOwningPlayer(GetTriggerUnit()), GetOwningPlayer(GetAttacker())) and GetRandomInt(0, 100) <= CHANCE(GetUnitAbilityLevel(GetAttacker(), ID)) and IsUnitType(GetTriggerUnit(), UNIT_TYPE_HERO) == false and GetUnitAbilityLevel(GetAttacker(), ID) > 0
    endfunction
    
    private function Move takes nothing returns nothing
        local unit u = GetAttacker()
        local unit t = GetTriggerUnit()
        local real x1 = GetUnitX( u )
        local real y1 = GetUnitY( u )
        local real x2 = GetUnitX( t )
        local real y2 = GetUnitY( t )
        local real angle = Atan2(y2 - y1, x2 - x1)
        
        call SetUnitX( u , x2 + 128 * Cos(angle))
        call SetUnitY( u , y2 + 128 * Sin(angle))
        set u = null
        set t = null
    endfunction
    
    private function Attack takes nothing returns nothing
        local unit u = GetAttacker()
        local unit t = GetTriggerUnit()
        local real x1 = GetUnitX( u )
        local real y1 = GetUnitY( u )
        local real x2 = GetUnitX( t )
        local real y2 = GetUnitY( t )
        local real angle = Atan2(y2 - y1, x2 - x1)
        
        call CreateUnit( GetTriggerPlayer(), 'u000' , Cos(angle) , Sin(angle) , 128 )
        call SetUnitPathing( GetLastCreatedUnit() , false )
        call UnitApplyTimedLife( GetLastCreatedUnit() , 'BTLF' , 5. )
        call UnitAddAbility( GetLastCreatedUnit() , DUMMYSPELLID )
        call IssueTargetOrder( GetLastCreatedUnit() , "stormbolt" , t )
    endfunction
    
    private function Moving takes nothing returns nothing
        local unit u = GetAttacker()
        local unit t = GetTriggerUnit()
        call DestroyEffect(AddSpecialEffectTarget(EFFECT, u, EFFECT_POSITION))
        call DestroyEffect(AddSpecialEffectTarget(EFFECT, u, EFFECTPOSITION))
        call Move()
        call Attack()
        set u = null
        set t = null
    endfunction
    
    private function Init takes nothing returns nothing
        local trigger t = CreateTrigger()
        local integer i = 0
        loop
            exitwhen i > 15
                call TriggerRegisterPlayerUnitEvent(t, Player(i), EVENT_PLAYER_UNIT_ATTACKED, Filter(function True))
            set i = i + 1
        endloop
        call TriggerAddCondition(t, Filter(function Cons))
        call TriggerAddAction(t, function Moving)
    endfunction

endscope
call Move() works.
call Attack() doesnt work.
 
GetLastCreatedUnit() wont do anything if you're not using CreateUnitBJ.

Try this.

JASS:
    private function Attack takes nothing returns nothing
        local unit u = GetAttacker()
        local unit t = GetTriggerUnit()
        local real x1 = GetUnitX( u )
        local real y1 = GetUnitY( u )
        local real x2 = GetUnitX( t )
        local real y2 = GetUnitY( t )
        local real angle = Atan2(y2 - y1, x2 - x1)
        local unit u2 = CreateUnit( GetTriggerPlayer(), 'u000' , Cos(angle) , Sin(angle) , 128 )
        call SetUnitPathing( u2 , false )
        call UnitApplyTimedLife( u2 , 'BTLF' , 5. )
        call UnitAddAbility( u2, DUMMYSPELLID )
        call IssueTargetOrder( u2 , "stormbolt" , t )
        //Dont forget to null all handle variables!
        set u = null
        set t = null
        set u2 = null
    endfunction
 
Dang it. Wont work.
JASS:
scope MovingStrike initializer Init
// +-------------------------------------------------------------------------------+
// |     Possession - Created by Chaos_Knight.  Requires a vJass preprocessor!     |   
// +-------------------------------------------------------------------------------+
// | Gives a small chance to permanently change control of the target unit         |
// | to the owner of the attacker.                                                 |
// +-------------------------------------------------------------------------------+
// | How to Import:                                                                |
// |  - Create a new trigger                                                       |
// |  - Convert it to Custom text (Edit > Convert to Custom Text)                  |
// |  - Replace everything there with this code                                    |
// |  - Change the constants to suit yourself                                      |
// |  - Enjoy!                                                                     |
// +-------------------------------------------------------------------------------+

// |-------------|
// | Constants:  |
// |-------------|
    globals
        // The effect created on the target when it is being possessed:
        private constant string EFFECT = "Abilities\\Weapons\\PhoenixMissile\\Phoenix_Missile_mini.mdl"
        // Which is attached to the targets:
        private constant string EFFECT_POSITION = "weapon,left"
        private constant string EFFECTPOSITION = "weapon,right"
        private constant integer DUMMYSPELLID = 'Q009'
        
        // The Raw code of the ability
        private constant integer ID = 'A008'
    endglobals
    
    private constant function CHANCE takes integer level returns integer
    // The chance of a unit being possessed. "level" is the level of the ability.
        return level * 3
    endfunction
    
// |------------------|
// | End of Constants |
// |------------------|

// DO NOT EDIT BELOW THIS LINE!

    private function True takes nothing returns boolean
        return true
    endfunction
    
    private function Cons takes nothing returns boolean
        return IsPlayerEnemy(GetOwningPlayer(GetTriggerUnit()), GetOwningPlayer(GetAttacker())) and GetRandomInt(0, 100) <= CHANCE(GetUnitAbilityLevel(GetAttacker(), ID)) and IsUnitType(GetTriggerUnit(), UNIT_TYPE_HERO) == false and GetUnitAbilityLevel(GetAttacker(), ID) > 0
    endfunction
    
    private function Move takes nothing returns nothing
        local unit u = GetAttacker()
        local unit t = GetTriggerUnit()
        local real x1 = GetUnitX( u )
        local real y1 = GetUnitY( u )
        local real x2 = GetUnitX( t )
        local real y2 = GetUnitY( t )
        local real angle = Atan2(y2 - y1, x2 - x1)
        
        call SetUnitX( u , x2 + 128 * Cos(angle))
        call SetUnitY( u , y2 + 128 * Sin(angle))
        set u = null
        set t = null
    endfunction
    
    private function Attack takes nothing returns nothing
        local unit u = GetAttacker()
        local unit t = GetTriggerUnit()
        local real x1 = GetUnitX( u )
        local real y1 = GetUnitY( u )
        local real x2 = GetUnitX( t )
        local real y2 = GetUnitY( t )
        local real angle = Atan2(y2 - y1, x2 - x1)
        local unit dummy = CreateUnit( GetTriggerPlayer(), 'u000' , GetUnitX(GetTriggerUnit()) , GetUnitY(GetTriggerUnit()) , 128 )
        call SetUnitPathing( dummy , false )
        call UnitApplyTimedLife( dummy , 'BTLF' , 1 )
        call UnitAddAbility( dummy , DUMMYSPELLID )
        call IssueTargetOrder( dummy , "stormbolt" , t )
    endfunction
    
    private function Moving takes nothing returns nothing
        local unit u = GetAttacker()
        local unit t = GetTriggerUnit()
        call DestroyEffect(AddSpecialEffectTarget(EFFECT, u, EFFECT_POSITION))
        call DestroyEffect(AddSpecialEffectTarget(EFFECT, u, EFFECTPOSITION))
        call Move()
        call Attack()
        set u = null
        set t = null
    endfunction
    
    private function Init takes nothing returns nothing
        local trigger t = CreateTrigger()
        local integer i = 0
        loop
            exitwhen i > 15
                call TriggerRegisterPlayerUnitEvent(t, Player(i), EVENT_PLAYER_UNIT_ATTACKED, Filter(function True))
            set i = i + 1
        endloop
        call TriggerAddCondition(t, Filter(function Cons))
        call TriggerAddAction(t, function Moving)
    endfunction

endscope
 
Oh, and somthing i found out, you can replace this
JASS:
        loop
            exitwhen i > 15
                call TriggerRegisterPlayerUnitEvent(t, Player(i), EVENT_PLAYER_UNIT_ATTACKED, Filter(function True))
            set i = i + 1
        endloop
with
JASS:
               call TriggerRegisterPlayerUnitEvent(t, GetLocalPlayer(), EVENT_PLAYER_UNIT_ATTACKED, Filter(function True))

Edit: Shouldn't
JASS:
       call IssueTargetOrder( dummy , "stormbolt" , t )
Be replaced with
JASS:
       call IssueTargetOrder( dummy , "charm" , t )
?

and
JASS:
 call TriggerRegisterPlayerUnitEvent(t, Player(i), EVENT_PLAYER_UNIT_ATTACKED, Filter(function True))
can be abused by spamming the stop order.
 
Make sure that the dummy spell works. To do this, give it to a normal unit, cast it on something, and make sure it does whatever it is supposed to do, otherwise that is where the problem lies. Also make sure your dummy has enough mana/time to cast it. (Make sure that the follow through time/channel/casting time is 0, and mana cost is 0)

Also, be sure you are adding the right spell and also be sure that you are using the correct order string. =)

you can replace this with:
JASS:
call TriggerRegisterPlayerUnitEvent(t, GetLocalPlayer(), EVENT_PLAYER_UNIT_ATTACKED, Filter(function True))

I used to think the same thing, and I tried using it as an alternative. However, when you use this, it will make the actions be performed locally too, which is why the loop as actually needed. =) [else it will do all the actions for one player, and will thus increase the chances of a desync]

@ChaosKnight: Also, you can just remove:
JASS:
    private function True takes nothing returns boolean
        return true
    endfunction

And replace the Filter(function True) with null as that leak no longer exists as of 1.24 or so.
 
You had a "Get Triggering Player" in there, when there is no event that gets a triggering player. I've also cleaned up your spell quite a bit.

JASS:
scope MovingStrike initializer Init
// +-------------------------------------------------------------------------------+
// |     Possession - Created by Chaos_Knight.  Requires a vJass preprocessor!     |
// +-------------------------------------------------------------------------------+
// | Gives a small chance to permanently change control of the attacked unit       |
// | to the owner of the attacker.                                                 |
// +-------------------------------------------------------------------------------+
// | How to Import:                                                                |
// |  - Create a new trigger                                                       |
// |  - Convert it to Custom text (Edit > Convert to Custom Text)                  |
// |  - Replace everything there with this code                                    |
// |  - Change the globals to suit yourself                                        |
// |  - Enjoy!                                                                     |
// +-------------------------------------------------------------------------------+
 
// |-------------|
    globals     //
// |-------------|
 
        private constant string FX = "Abilities\\Weapons\\PhoenixMissile\\Phoenix_Missile_mini.mdl"
        private constant string attachA = "weapon,left"
        private constant string attachB = "weapon,right"
            // Modify the above three variables to add a unique effect to the attacker whenever
            // a unit is possessed.
 
        private constant integer SPELL_ID = 'A008'
            // The ability carried by the attacking unit that enables it to possess its target.
         private constant integer CHANCE = 3
            // CHANCE is multiplied by the level of SPELL_ID to weigh the odds of a possession.
 
        private constant integer DUMMY_ID = 'Q009'
            // Can change DUMMY_ID to be any offensive spell to cast on the attacked unit.
         private constant integer ORDER_ID = OrderId("stormbolt")
            // The ORDER_ID string needs to match the order id string of the DUMMY_ID spell.
 
        private constant unit dum = CreateUnit(Player(15),'u000',0.,0.,0.)
            // Make sure the model path of the dummy unit is "none".  Player(15) is the
            // neutral passive player, so changing that isn't so great.
 
// |-------------|
    endglobals  //
// |-------------|
 
 
    private function Actions takes player p,unit u,unit t returns nothing
        local real x2 = GetUnitX(t)
        local real y2 = GetUnitY(t)
        local real angle = Atan2(y2 - GetUnitY(u), x2 - GetUnitX(u))
 
    // apply primary effects:
        call DestroyEffect(AddSpecialEffectTarget(FX,u,attachA))
        call DestroyEffect(AddSpecialEffectTarget(FX,u,attachB))
        call SetUnitX(u,x2 + 128. * Cos(angle))
        call SetUnitY(u,y2 + 128. * Sin(angle))
        call SetUnitOwner(t,p,true)
 
    // setup dummy:
        call SetUnitX(dum,x2)
        call SetUnitY(dum,y2)
        call SetUnitOwner(dum,p,false)
        call IssueTargetOrderById(dum,ORDER_ID,t)
        call TriggerSleepAction(2.)
        if GetUnitCurrentOrder(dum) != ORDER_ID then
            call SetUnitOwner(dum,Player(15),false)
        endif
    endfunction
 
    private function Conditions takes nothing returns nothing
        local unit u = GetAttacker()
        local unit t = GetTriggerUnit()
        local player p = GetOwningPlayer(u)
        local integer spid = GetUnitAbilityLevel(u,SPELL_ID)
        if (IsUnitEnemy(t,p) and spid > 0 and GetRandomInt(0,100) <= spid * CHANCE and not IsUnitType(t,UNIT_TYPE_HERO)) then
            call Actions(p,u,t)
        endif
        set u = null
        set t = null
    endfunction
 
    private function Init takes nothing returns nothing
        local trigger t = CreateTrigger()
        call TriggerAddAction(t,function Conditions)
        call TriggerRegisterAnyUnitEventBJ(t,EVENT_PLAYER_UNIT_ATTACKED)
        call SetUnitPathing(dum,false)
        call UnitAddAbility(dum,DUMMY_ID)
    endfunction
 
endscope
 
Last edited:
I tested it and from my results GetTriggerPlayer() works fine when responding even to player unit events. Weird eh? But I guess it can make sense for the player part of player-unit. (I just did I2S(GetPlayerId(GetTriggerPlayer())) and it worked fine [yeah, I tested it for other players as well]) =)

Don't ask me why everyone (including me) uses GetOwningPlayer(), it is mostly just a matter of preference I guess. (But some don't know in general, so yeah) I'll try to run some benchmarks to see which is faster.
 
I tested it and from my results GetTriggerPlayer() works fine when responding even to player unit events. Weird eh? But I guess it can make sense for the player part of player-unit. (I just did I2S(GetPlayerId(GetTriggerPlayer())) and it worked fine [yeah, I tested it for other players as well]) =)

Don't ask me why everyone (including me) uses GetOwningPlayer(), it is mostly just a matter of preference I guess. (But some don't know in general, so yeah) I'll try to run some benchmarks to see which is faster.
Well, in that case, his Triggering Player was the unit that was attacked... not such a good idea since the player in consideration needs to be the owner of the attacking unit. But, nice catch. Triggering Player works for these... this could make for some interesting coding somewhere in the future... =)
 
I rmoved the dummy part, and it worked. +rep to both of you.
this is the code i got :P
JASS:
scope MovingStrike initializer Init
// +-------------------------------------------------------------------------------+
// |     Possession - Created by Chaos_Knight.  Requires a vJass preprocessor!     |   
// +-------------------------------------------------------------------------------+
// | Gives a small chance to permanently change control of the target unit         |
// | to the owner of the attacker.                                                 |
// +-------------------------------------------------------------------------------+
// | How to Import:                                                                |
// |  - Create a new trigger                                                       |
// |  - Convert it to Custom text (Edit > Convert to Custom Text)                  |
// |  - Replace everything there with this code                                    |
// |  - Change the constants to suit yourself                                      |
// |  - Enjoy!                                                                     |
// +-------------------------------------------------------------------------------+

// |-------------|
// | Constants:  |
// |-------------|
    globals
        // The effect created on the target when it is being possessed:
        private constant string EFFECT = "Abilities\\Weapons\\PhoenixMissile\\Phoenix_Missile_mini.mdl"
        private constant string EFFECT2 = "Abilities\\Weapons\\PhoenixMissile\\Phoenix_Missile.mdl"
        // Which is attached to the targets:
        private constant string EFFECT_POSITION = "weapon,left"
        private constant string EFFECTPOSITION = "weapon,right"
        private constant integer DUMMYSPELLID = 'Q009'
        
        // The Raw code of the ability
        private constant integer ID = 'A008'
    endglobals
    
    private constant function CHANCE takes integer level returns integer
    // The chance of a unit being possessed. "level" is the level of the ability.
        return level * 2
    endfunction
    
// |------------------|
// | End of Constants |
// |------------------|

// DO NOT EDIT BELOW THIS LINE!

    private function True takes nothing returns boolean
        return true
    endfunction
    
    private function Cons takes nothing returns boolean
        return IsPlayerEnemy(GetOwningPlayer(GetTriggerUnit()), GetOwningPlayer(GetAttacker())) and GetRandomInt(0, 100) <= CHANCE(GetUnitAbilityLevel(GetAttacker(), ID)) and IsUnitType(GetTriggerUnit(), UNIT_TYPE_HERO) == false and GetUnitAbilityLevel(GetAttacker(), ID) > 0
    endfunction
    
    private function Move takes nothing returns nothing
        local unit u = GetAttacker()
        local unit t = GetTriggerUnit()
        local real x1 = GetUnitX( u )
        local real y1 = GetUnitY( u )
        local real x2 = GetUnitX( t )
        local real y2 = GetUnitY( t )
        local real angle = Atan2(y2 - y1, x2 - x1)
        
        call SetUnitX( u , x2 + 128 * Cos(angle))
        call SetUnitY( u , y2 + 128 * Sin(angle))
        set u = null
        set t = null
    endfunction
    
    private function Attack takes nothing returns nothing
        local unit u = GetAttacker()
        local unit t = GetTriggerUnit()
        local real dmg = 25 * GetUnitAbilityLevel( u ,ID )
        call UnitDamageTarget( u , t , dmg , true , true , ATTACK_TYPE_CHAOS , DAMAGE_TYPE_FIRE , WEAPON_TYPE_WHOKNOWS )
    endfunction
    
    
    private function Moving takes nothing returns nothing
        local unit u = GetAttacker()
        local unit t = GetTriggerUnit()
        local real dmg = 25 * GetUnitAbilityLevel( u , ID )
        local texttag TT = CreateTextTag()
        call SetTextTagText( TT , "You have dealt " + R2S(dmg) + " Damage" , 100 )
        call SetTextTagColor( TT , 200 , 125 , 255 , 255 )
        call SetTextTagPos( TT , GetUnitX(u) , GetUnitY(u) , 100 )
        call SetTextTagVisibility( TT , true )
        call SetTextTagLifespan( TT, 5 )
        call DestroyEffect(AddSpecialEffectTarget(EFFECT, u, EFFECT_POSITION))
        call DestroyEffect(AddSpecialEffectTarget(EFFECT2, u, EFFECTPOSITION))
        call Move()
        call Attack()
        set u = null
        set t = null
    endfunction
    
    private function Init takes nothing returns nothing
        local trigger t = CreateTrigger()
        local integer i = 0
        loop
            exitwhen i > 15
                call TriggerRegisterPlayerUnitEvent(t, Player(i), EVENT_PLAYER_UNIT_ATTACKED, Filter(function True))
            set i = i + 1
        endloop
        call TriggerAddCondition(t, Filter(function Cons))
        call TriggerAddAction(t, function Moving)
    endfunction

endscope
 
Well, in that case, his Triggering Player was the unit that was attacked... not such a good idea since the player in consideration needs to be the owner of the attacking unit. But, nice catch. Triggering Player works for these... this could make for some interesting coding somewhere in the future... =)

D'oh, silly me. I forget to consider the purposes of the code. =P

Anyway, I've tested it and here are my results:

attachment.php

About ~11% benefit

JASS:
library Benchmark initializer OnInit
    ///////////////////////////////////////////////
    // Native declarations for stopwatch natives //
    //  - Requires no modified common.j import   //
    ///////////////////////////////////////////////
    native StopWatchCreate  takes nothing returns integer
    native StopWatchMark    takes integer stopwatch returns real
    native StopWatchDestroy takes integer stopwatch returns nothing
    
    /////////////////////////
    // Benchmarking script //
    /////////////////////////
    
    // Initialisation
    globals
        // ...
    endglobals
    
    private function Init takes nothing returns nothing
        // things required to be performed once before your test
    endfunction
    
    // Tests
    globals
    private constant string TITLE_A="GetOwningPlayer"
    //! textmacro Benchmark__TestA
        call GetOwningPlayer(null)
        call GetOwningPlayer(null)
        call GetOwningPlayer(null)
        call GetOwningPlayer(null)
        call GetOwningPlayer(null)
        call GetOwningPlayer(null)
        call GetOwningPlayer(null)
        call GetOwningPlayer(null)
        call GetOwningPlayer(null)
        call GetOwningPlayer(null)
    //! endtextmacro
    private constant string TITLE_B="GetTriggerPlayer"
    //! textmacro Benchmark__TestB
        call GetTriggerPlayer()
        call GetTriggerPlayer()
        call GetTriggerPlayer()
        call GetTriggerPlayer()
        call GetTriggerPlayer()
        call GetTriggerPlayer()
        call GetTriggerPlayer()
        call GetTriggerPlayer()
        call GetTriggerPlayer()
        call GetTriggerPlayer()
    //! endtextmacro
    endglobals
    
    // execution
    private function TestA1000 takes nothing returns nothing
        local integer i=100 // hence 1,000 execs
        loop
            exitwhen i==0
            set i=i-1
            // Repeat x10
            //! runtextmacro Benchmark__TestA() // 1
            //! runtextmacro Benchmark__TestA() // 2
            //! runtextmacro Benchmark__TestA() // 3
            //! runtextmacro Benchmark__TestA() // 4
            //! runtextmacro Benchmark__TestA() // 5
            //! runtextmacro Benchmark__TestA() // 6
            //! runtextmacro Benchmark__TestA() // 7
            //! runtextmacro Benchmark__TestA() // 8
            //! runtextmacro Benchmark__TestA() // 9
            //! runtextmacro Benchmark__TestA() // 10
        endloop
    endfunction
    private function TestB1000 takes nothing returns nothing
        local integer i=100
        loop
            exitwhen i==0 // hence 1,000 execs
            set i=i-1
            // Repeat x10
            //! runtextmacro Benchmark__TestB() // 1
            //! runtextmacro Benchmark__TestB() // 2
            //! runtextmacro Benchmark__TestB() // 3
            //! runtextmacro Benchmark__TestB() // 4
            //! runtextmacro Benchmark__TestB() // 5
            //! runtextmacro Benchmark__TestB() // 6
            //! runtextmacro Benchmark__TestB() // 7
            //! runtextmacro Benchmark__TestB() // 8
            //! runtextmacro Benchmark__TestB() // 9
            //! runtextmacro Benchmark__TestB() // 10
        endloop
    endfunction
    
    private function OnEsc takes nothing returns nothing
        local integer sw
        local integer i
        
        set i=0
        set sw=StopWatchCreate()
        loop
            set i=i+1
            call TestA1000.evaluate() // x10 - 10,000 executions altogether.
            exitwhen i==10
        endloop
        call BJDebugMsg("|cff66ddff"+TITLE_A+" : "+R2S(StopWatchMark(sw)*100)+"|r")
        call StopWatchDestroy(sw)
        
        set i=0
        set sw=StopWatchCreate()
        loop
            set i=i+1
            call TestB1000.evaluate() // x10 - 10,000 executions altogether.
            exitwhen i==10
        endloop
        call BJDebugMsg("|cffddff66"+TITLE_B+" : "+R2S(StopWatchMark(sw)*100)+"|r")
        call StopWatchDestroy(sw)
    endfunction
    
    ///////////////////////////////
    // Registers the OnEsc event //
    ///////////////////////////////
    private function OnInit takes nothing returns nothing
        local trigger t=CreateTrigger()
        call TriggerRegisterPlayerEvent(t,Player(0),EVENT_PLAYER_END_CINEMATIC)
        call TriggerAddAction(t,function OnEsc)
        call Init()
    endfunction
endlibrary
It might not be most accurate to use GetOwningPlayer(null) though, with an actual unit input it is:
attachment.php

About ~33% benefit
JASS:
library Benchmark initializer OnInit
    ///////////////////////////////////////////////
    // Native declarations for stopwatch natives //
    //  - Requires no modified common.j import   //
    ///////////////////////////////////////////////
    native StopWatchCreate  takes nothing returns integer
    native StopWatchMark    takes integer stopwatch returns real
    native StopWatchDestroy takes integer stopwatch returns nothing
    
    /////////////////////////
    // Benchmarking script //
    /////////////////////////
    
    // Initialisation
    globals
        // ...
        unit u = CreateUnit(Player(15),'hfoo',1000,1000,0)
    endglobals
    
    private function Init takes nothing returns nothing
        // things required to be performed once before your test
    endfunction
    
    // Tests
    globals
    private constant string TITLE_A="GetOwningPlayerU"
    //! textmacro Benchmark__TestA
        call GetOwningPlayer(u)
        call GetOwningPlayer(u)
        call GetOwningPlayer(u)
        call GetOwningPlayer(u)
        call GetOwningPlayer(u)
        call GetOwningPlayer(u)
        call GetOwningPlayer(u)
        call GetOwningPlayer(u)
        call GetOwningPlayer(u)
        call GetOwningPlayer(u)
    //! endtextmacro
    private constant string TITLE_B="GetTriggerPlayer"
    //! textmacro Benchmark__TestB
        call GetTriggerPlayer()
        call GetTriggerPlayer()
        call GetTriggerPlayer()
        call GetTriggerPlayer()
        call GetTriggerPlayer()
        call GetTriggerPlayer()
        call GetTriggerPlayer()
        call GetTriggerPlayer()
        call GetTriggerPlayer()
        call GetTriggerPlayer()
    //! endtextmacro
    endglobals
    
    // execution
    private function TestA1000 takes nothing returns nothing
        local integer i=100 // hence 1,000 execs
        loop
            exitwhen i==0
            set i=i-1
            // Repeat x10
            //! runtextmacro Benchmark__TestA() // 1
            //! runtextmacro Benchmark__TestA() // 2
            //! runtextmacro Benchmark__TestA() // 3
            //! runtextmacro Benchmark__TestA() // 4
            //! runtextmacro Benchmark__TestA() // 5
            //! runtextmacro Benchmark__TestA() // 6
            //! runtextmacro Benchmark__TestA() // 7
            //! runtextmacro Benchmark__TestA() // 8
            //! runtextmacro Benchmark__TestA() // 9
            //! runtextmacro Benchmark__TestA() // 10
        endloop
    endfunction
    private function TestB1000 takes nothing returns nothing
        local integer i=100
        loop
            exitwhen i==0 // hence 1,000 execs
            set i=i-1
            // Repeat x10
            //! runtextmacro Benchmark__TestB() // 1
            //! runtextmacro Benchmark__TestB() // 2
            //! runtextmacro Benchmark__TestB() // 3
            //! runtextmacro Benchmark__TestB() // 4
            //! runtextmacro Benchmark__TestB() // 5
            //! runtextmacro Benchmark__TestB() // 6
            //! runtextmacro Benchmark__TestB() // 7
            //! runtextmacro Benchmark__TestB() // 8
            //! runtextmacro Benchmark__TestB() // 9
            //! runtextmacro Benchmark__TestB() // 10
        endloop
    endfunction
    
    private function OnEsc takes nothing returns nothing
        local integer sw
        local integer i
        
        set i=0
        set sw=StopWatchCreate()
        loop
            set i=i+1
            call TestA1000.evaluate() // x10 - 10,000 executions altogether.
            exitwhen i==10
        endloop
        call BJDebugMsg("|cff66ddff"+TITLE_A+" : "+R2S(StopWatchMark(sw)*100)+"|r")
        call StopWatchDestroy(sw)
        
        set i=0
        set sw=StopWatchCreate()
        loop
            set i=i+1
            call TestB1000.evaluate() // x10 - 10,000 executions altogether.
            exitwhen i==10
        endloop
        call BJDebugMsg("|cffddff66"+TITLE_B+" : "+R2S(StopWatchMark(sw)*100)+"|r")
        call StopWatchDestroy(sw)
    endfunction
    
    ///////////////////////////////
    // Registers the OnEsc event //
    ///////////////////////////////
    private function OnInit takes nothing returns nothing
        local trigger t=CreateTrigger()
        call TriggerRegisterPlayerEvent(t,Player(0),EVENT_PLAYER_END_CINEMATIC)
        call TriggerAddAction(t,function OnEsc)
        call Init()
    endfunction
endlibrary

All-in-all, if you were to use GetTriggerPlayer() vs. getting the owning player of a null unit it would be about an 11% or so benefit, but realistically if you were to use GetTriggerPlayer() vs. getting the player of an actual unit there would be about a ~33% benefit, more or less. The difference isn't outstanding (and you won't notice it in game obviously) but based on whether my results are accurate or not, GetTriggerPlayer() should be pretty much faster in most if not all cases. =)


EDIT: I actually should've created the unit on init rather than in the globals block, but whatever, I'll test it again. =P

EDIT2:

Ok, I've tested it with a unit created on init, and here are my results:
attachment.php

JASS:
library Benchmark initializer OnInit
    ///////////////////////////////////////////////
    // Native declarations for stopwatch natives //
    //  - Requires no modified common.j import   //
    ///////////////////////////////////////////////
    native StopWatchCreate  takes nothing returns integer
    native StopWatchMark    takes integer stopwatch returns real
    native StopWatchDestroy takes integer stopwatch returns nothing
    
    /////////////////////////
    // Benchmarking script //
    /////////////////////////
    
    // Initialisation
    globals
        // ...
        unit u 
    endglobals
    
    private function Init takes nothing returns nothing
        set u = CreateUnit(Player(15),'hfoo',1000,1000,0)
        // things required to be performed once before your test
    endfunction
    
    // Tests
    globals
    private constant string TITLE_A="GetOwningPlayerU"
    //! textmacro Benchmark__TestA
        call GetOwningPlayer(u)
        call GetOwningPlayer(u)
        call GetOwningPlayer(u)
        call GetOwningPlayer(u)
        call GetOwningPlayer(u)
        call GetOwningPlayer(u)
        call GetOwningPlayer(u)
        call GetOwningPlayer(u)
        call GetOwningPlayer(u)
        call GetOwningPlayer(u)
    //! endtextmacro
    private constant string TITLE_B="GetTriggerPlayer"
    //! textmacro Benchmark__TestB
        call GetTriggerPlayer()
        call GetTriggerPlayer()
        call GetTriggerPlayer()
        call GetTriggerPlayer()
        call GetTriggerPlayer()
        call GetTriggerPlayer()
        call GetTriggerPlayer()
        call GetTriggerPlayer()
        call GetTriggerPlayer()
        call GetTriggerPlayer()
    //! endtextmacro
    endglobals
    
    // execution
    private function TestA1000 takes nothing returns nothing
        local integer i=100 // hence 1,000 execs
        loop
            exitwhen i==0
            set i=i-1
            // Repeat x10
            //! runtextmacro Benchmark__TestA() // 1
            //! runtextmacro Benchmark__TestA() // 2
            //! runtextmacro Benchmark__TestA() // 3
            //! runtextmacro Benchmark__TestA() // 4
            //! runtextmacro Benchmark__TestA() // 5
            //! runtextmacro Benchmark__TestA() // 6
            //! runtextmacro Benchmark__TestA() // 7
            //! runtextmacro Benchmark__TestA() // 8
            //! runtextmacro Benchmark__TestA() // 9
            //! runtextmacro Benchmark__TestA() // 10
        endloop
    endfunction
    private function TestB1000 takes nothing returns nothing
        local integer i=100
        loop
            exitwhen i==0 // hence 1,000 execs
            set i=i-1
            // Repeat x10
            //! runtextmacro Benchmark__TestB() // 1
            //! runtextmacro Benchmark__TestB() // 2
            //! runtextmacro Benchmark__TestB() // 3
            //! runtextmacro Benchmark__TestB() // 4
            //! runtextmacro Benchmark__TestB() // 5
            //! runtextmacro Benchmark__TestB() // 6
            //! runtextmacro Benchmark__TestB() // 7
            //! runtextmacro Benchmark__TestB() // 8
            //! runtextmacro Benchmark__TestB() // 9
            //! runtextmacro Benchmark__TestB() // 10
        endloop
    endfunction
    
    private function OnEsc takes nothing returns nothing
        local integer sw
        local integer i
        
        set i=0
        set sw=StopWatchCreate()
        loop
            set i=i+1
            call TestA1000.evaluate() // x10 - 10,000 executions altogether.
            exitwhen i==10
        endloop
        call BJDebugMsg("|cff66ddff"+TITLE_A+" : "+R2S(StopWatchMark(sw)*100)+"|r")
        call StopWatchDestroy(sw)
        
        set i=0
        set sw=StopWatchCreate()
        loop
            set i=i+1
            call TestB1000.evaluate() // x10 - 10,000 executions altogether.
            exitwhen i==10
        endloop
        call BJDebugMsg("|cffddff66"+TITLE_B+" : "+R2S(StopWatchMark(sw)*100)+"|r")
        call StopWatchDestroy(sw)
    endfunction
    
    ///////////////////////////////
    // Registers the OnEsc event //
    ///////////////////////////////
    private function OnInit takes nothing returns nothing
        local trigger t=CreateTrigger()
        call TriggerRegisterPlayerEvent(t,Player(0),EVENT_PLAYER_END_CINEMATIC)
        call TriggerAddAction(t,function OnEsc)
        call Init()
    endfunction
endlibrary

lol, anywhere from about a 67%-90% benefit, albeit that is still not that dramatic (as in, it won't alter whether or not your map will lag) but that shows that it is a little more optimal to use GetTriggerPlayer() when the event warrants it. Interesting. =)
 

Attachments

  • BenchTrigPvsOwn.jpg
    BenchTrigPvsOwn.jpg
    141 KB · Views: 205
  • BenchPlayer2.jpg
    BenchPlayer2.jpg
    141.2 KB · Views: 204
  • BenchPlayer3.jpg
    BenchPlayer3.jpg
    144.8 KB · Views: 213
Status
Not open for further replies.
Back
Top