A "Swap" system, needed ? (From a command in "DotA" ;))

Komaqtion

You can change this now in User CP.
Reaction score
469
Hello ! :D

I just saw a thread asking for such a system, and I remembered I "made" a system like it like half a year ago... XD
I also made a thread about it, but I lost interest in getting it to work, as it got quite messy :(

Anyways, I've taken up the challenge again, and I wanted to know what you think about it ? :eek:

Note: If you don't know what a "Swap" command is, it's like this:
  1. Every player picks their hero.
  2. I randomed a hero, and got someone I didn't want :(
  3. I see Player 2 (Blue) (Player(1) in Jass ;)) has a hero I really want.
  4. I type "-swap 2" to see if he wants to swap heroes with me. (Type "-swap 1" if I want to use Jass-player-id's and that constant is true)
  5. Player 2 (Blue) types "-swap 1", and thereby accepts my request to swap heroes.
  6. The system starts the swap, and depending on different constants this can look different, but the main thing is that each player's heroes switch owners, so I not have Player 2 (Blue)'s hero, and he has mine :D

Hope you got it :p

Here's the current code, but I haven't commented much and I would VERY much appreciate it if anyone would be so kind and test it in a small map online, or on LAN ! :D <3

JASS:
library SwapHeroes initializer Init requires SimError, TimerUtils, optional PlayerColors

    globals
        private constant boolean HEROES_ON_INIT = true      // Change this to true, if each player has a &#039;single&#039; hero at Map Init !
        
        private constant boolean SWAP_NEUTRALS = false      // If you want the players to be able to swap heroes with the &#039;neutral&#039; players (They don&#039;t have to write &quot;-swap ##&quot; back <img src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" class="smilie smilie--sprite smilie--sprite7" alt=":p" title="Stick Out Tongue    :p" loading="lazy" data-shortname=":p" />)
        
        private constant boolean SWAP_ALLIES_ONLY = true    // If you only want the players to be able to swap with their allies !
        
        private constant boolean SWITCH_POSITIONS = true    // If you want the swapped heroes to also swap positions <img src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" class="smilie smilie--sprite smilie--sprite8" alt=":D" title="Big Grin    :D" loading="lazy" data-shortname=":D" />
        
        private constant boolean REVIVE_IF_DEAD = true      // If you swap with a player, and it&#039;s currently dead, then if this is true it&#039;ll revive the unit also <img src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" class="smilie smilie--sprite smilie--sprite8" alt=":D" title="Big Grin    :D" loading="lazy" data-shortname=":D" />
        
        private constant boolean USE_GUI_PLAYER_IDS = false
        
        private constant boolean USE_PLAYERS_COLOR_ON_NAME = true
        
        private constant boolean RETAIN_PLAYER_COLORS = false
        
        private constant boolean ONE_SWAP_ONLY = false
        
        private constant boolean SWAP_TIME_LIMIT = true
        private constant real TIME_LIMIT = 30.
        
        private constant string SWAP_COMMAND = &quot;-swap &quot;
    endglobals
    
    native UnitAlive takes unit id returns boolean

    globals
        private group ENUM = CreateGroup()
        
        private integer tempInt = 0
    endglobals

    private struct SwapData extends array
        boolean hasSwapped
        
        unit swapUnit
        unit targetUnit
        
        player swapPlayer
        player targetPlayer
        
        timer resetTimer
        
        static method ResetSwapData takes nothing returns nothing
            local thistype this = GetTimerData( GetExpiredTimer() )
            
            set this.targetUnit = null
            set this.targetPlayer = null
            
            call ReleaseTimer( GetExpiredTimer() )
        endmethod
        
    endstruct
        
    private function SwapActions takes nothing returns boolean
        local player p
        local player pt
        local string s = GetEventPlayerChatString()
        local boolean conds
        local unit temp = null
        
        if SubString( s, 0, 6 ) == SWAP_COMMAND then
            set p = GetTriggerPlayer()
            
            if USE_GUI_PLAYER_IDS then
                set pt = Player( S2I( SubString( s, 6, StringLength( s ) ) ) - 1 )
            else
                set pt = Player( S2I( SubString( s, 6, StringLength( s ) ) ) )
            endif
            
            if SWAP_NEUTRALS then
                if USE_GUI_PLAYER_IDS then
                    set conds = GetPlayerId( pt ) &gt;= 17 or GetPlayerId( pt ) &lt; 0 or pt == null or SwapData[ GetPlayerId( pt ) ].swapPlayer != null or pt == p or ( SWAP_ALLIES_ONLY and IsPlayerEnemy( p, pt ) )
                else
                    set conds = GetPlayerId( pt ) &gt;= 16 or GetPlayerId( pt ) &lt; 0 or pt == null or SwapData[ GetPlayerId( pt ) ].swapPlayer != null or pt == p or ( SWAP_ALLIES_ONLY and IsPlayerEnemy( p, pt ) )
                endif
            else
                if USE_GUI_PLAYER_IDS then
                    set conds = GetPlayerId( pt ) &gt;= 13 or GetPlayerId( pt ) &lt; 0 or pt == null or SwapData[ GetPlayerId( pt ) ].swapPlayer != null or pt == p or ( SWAP_ALLIES_ONLY and IsPlayerEnemy( p, pt ) )
                else
                    set conds = GetPlayerId( pt ) &gt;= 12 or GetPlayerId( pt ) &lt; 0 or pt == null or SwapData[ GetPlayerId( pt ) ].swapPlayer != null or pt == p or ( SWAP_ALLIES_ONLY and IsPlayerEnemy( p, pt ) )
                endif
            endif
            
            // Make sure you type a valid player
            
            if conds then
                call SimError( p, &quot;You need to input a valid player-id !&quot; )
                
                return false
            endif
            
            // And also make sure you yourself have a valid hero to swap before starting <img src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" class="smilie smilie--sprite smilie--sprite2" alt=";)" title="Wink    ;)" loading="lazy" data-shortname=";)" />
            
            if SwapData[ GetPlayerId( p ) ].swapUnit == null then
                call SimError( p, &quot;You need to have a swap hero eligible yourself, before you can use the -swap command !&quot; )
                
                return false
            endif
            
            if SwapData[ GetPlayerId( p ) ].hasSwapped == true and ONE_SWAP_ONLY then
                call SimError( p, &quot;You have already swapped once, and can&#039;t swap again...&quot; )
                
                return false
            endif
            
            if SwapData[ GetPlayerId( pt ) ].hasSwapped == true and ONE_SWAP_ONLY then
                call SimError( p, &quot;The player you wish to swap with has already swapped once, and can&#039;t swap again !&quot; )
                
                return false
            endif
            
            if SWAP_TIME_LIMIT then
                call ReleaseTimer( SwapData[ GetPlayerId( p ) ].resetTimer )
                call ReleaseTimer( SwapData[ GetPlayerId( pt ) ].resetTimer )
            endif
            
            set SwapData[ GetPlayerId( p ) ].targetPlayer = pt
            set SwapData[ GetPlayerId( p ) ].targetUnit = SwapData[ GetPlayerId( p ) ].swapUnit
            
            // Start switch ! <img src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" class="smilie smilie--sprite smilie--sprite8" alt=":D" title="Big Grin    :D" loading="lazy" data-shortname=":D" />            
            
            if SwapData[ GetPlayerId( pt ) ].targetPlayer == p and SwapData[ GetPlayerId( pt ) ].targetUnit == SwapData[ GetPlayerId( p ) ].swapUnit then
                set temp = SwapData[ GetPlayerId( p ) ].swapUnit
                
                if RETAIN_PLAYER_COLORS then
                    call SetUnitOwner( SwapData[ GetPlayerId( pt ) ].swapUnit, p, false )
                else
                    call SetUnitOwner( SwapData[ GetPlayerId( pt ) ].swapUnit, p, true )
                endif
                
                set SwapData[ GetPlayerId( p ) ].swapUnit = SwapData[ GetPlayerId( pt ) ].swapUnit
                
                
                if RETAIN_PLAYER_COLORS then
                    call SetUnitOwner( temp, pt, false )
                else
                    call SetUnitOwner( temp, pt, true )
                endif
                
                set SwapData[ GetPlayerId( pt ) ].swapUnit = temp
                
                if USE_PLAYERS_COLOR_ON_NAME then
                
                    static if USE_PLAYERS_COLOR_ON_NAMELIBRARY_PlayerColors then
                        call DisplayTextToPlayer( pt, 0.0, 0.0, &quot;You have accepted &quot; + GetPlayerNameColored( pt ) + &quot;&#039;s swap request !&quot; )
                        call DisplayTextToPlayer( pt, 0.0, 0.0, GetPlayerNameColored( p ) + &quot;has accepted you request to swap heroes !&quot; )
                    endif
                    
                else
                    call DisplayTextToPlayer( pt, 0.0, 0.0, &quot;You have accepted &quot; + GetPlayerName( pt ) + &quot;&#039;s swap request !&quot; )
                    call DisplayTextToPlayer( pt, 0.0, 0.0, GetPlayerName( p ) + &quot;has accepted you request to swap heroes !&quot; )
                endif
                        
                
                if SWITCH_POSITIONS then
                    call SetUnitX( SwapData[ GetPlayerId( pt ) ].swapUnit, GetUnitX( SwapData[ GetPlayerId( p ) ].swapUnit ) )
                    call SetUnitX( SwapData[ GetPlayerId( p ) ].swapUnit, GetUnitX( SwapData[ GetPlayerId( pt ) ].swapUnit ) )
                    call SetUnitY( SwapData[ GetPlayerId( pt ) ].swapUnit, GetUnitY( SwapData[ GetPlayerId( p ) ].swapUnit ) )
                    call SetUnitY( SwapData[ GetPlayerId( p ) ].swapUnit, GetUnitY( SwapData[ GetPlayerId( pt ) ].swapUnit ) )
                endif
                
                if REVIVE_IF_DEAD then
                
                    if not UnitAlive( SwapData[ GetPlayerId( pt ) ].swapUnit ) then
                        call ReviveHero( SwapData[ GetPlayerId( pt ) ].swapUnit, GetUnitX( SwapData[ GetPlayerId( pt ) ].swapUnit ), GetUnitY( SwapData[ GetPlayerId( pt ) ].swapUnit ), true )
                    endif
                    
                    if not UnitAlive( SwapData[ GetPlayerId( p ) ].swapUnit ) then
                        call ReviveHero( SwapData[ GetPlayerId( p ) ].swapUnit, GetUnitX( SwapData[ GetPlayerId( p ) ].swapUnit ), GetUnitY( SwapData[ GetPlayerId( p ) ].swapUnit ), true )
                    endif
                    
                endif
                
                set SwapData[ GetPlayerId( pt ) ].hasSwapped = true
                set SwapData[ GetPlayerId( pt ) ].hasSwapped = true
                
            endif
            
            set p = null
            set pt = null
            
        elseif SWAP_TIME_LIMIT then
            set SwapData[ GetPlayerId( p ) ].resetTimer = NewTimer()
            
            call SetTimerData( SwapData[ GetPlayerId( p ) ].resetTimer, SwapData[ GetPlayerId( p ) ] )
            call TimerStart( SwapData[ GetPlayerId( p ) ].resetTimer, TIME_LIMIT, false, function SwapData.ResetSwapData )
            
            if USE_PLAYERS_COLOR_ON_NAME then
            
                static if USE_PLAYERS_COLOR_ON_NAMELIBRARY_PlayerColors then
                    call DisplayTextToPlayer( pt, 0.0, 0.0, &quot;You have sent a request to &quot; + GetPlayerNameColored( pt ) + &quot;, to swap heroes !&quot; )
                    call DisplayTextToPlayer( pt, 0.0, 0.0, GetPlayerNameColored( p ) + &quot;has sent you a swap request ! Will you accept ?&quot; )
                endif
                
            else
                call DisplayTextToPlayer( pt, 0.0, 0.0, &quot;You have sent a request to &quot; + GetPlayerName( pt ) + &quot;, to swap heroes !&quot; )
                call DisplayTextToPlayer( pt, 0.0, 0.0, GetPlayerName( p ) + &quot;has sent you a swap request ! Will you accept ?&quot; )
            endif
        endif
        
        set s = null
        
        return false
    endfunction
    
    private function PickInitHeroes takes nothing returns boolean
        local unit u = GetFilterUnit()
        local player p = GetOwningPlayer( u )
        
        if tempInt == 0 and IsUnitType( u, UNIT_TYPE_HERO ) and not IsUnitType( u, UNIT_TYPE_STRUCTURE ) and UnitAlive( u ) and SwapData[ GetPlayerId( p ) ].swapUnit == null then
            set SwapData[ GetPlayerId( p ) ].swapUnit = u
            set tempInt = 1
        endif
        
        set u = null
        set p = null
        
        return false
    endfunction

    private function OnInitHeroes takes nothing returns nothing
        local integer i = 0
        local player p
        
        loop
        
            if SWAP_NEUTRALS then
                exitwhen i &gt;= 16
            else
                exitwhen i &gt;= 12
            endif
            
            set tempInt = 0
            set p = Player( i )
            
            if SwapData[ GetPlayerId( p ) ].swapUnit != null and GetPlayerController( p ) == MAP_CONTROL_USER and GetPlayerController( p ) == PLAYER_SLOT_STATE_PLAYING then                    
                call GroupEnumUnitsOfPlayer( ENUM, p, Filter( function PickInitHeroes ) )
            endif
            
            set i = i + 1
        endloop
    
        set p = null
    endfunction

    private function Init takes nothing returns nothing
        local trigger t = CreateTrigger()
        local integer i = 0
        local player p = null
        
        loop
        
            set p = Player( i )
        
            if SWAP_NEUTRALS then
                exitwhen i &gt;= 16
                
                if i &gt;= 12 and ( GetPlayerController( p ) == MAP_CONTROL_COMPUTER or GetPlayerController( p ) == MAP_CONTROL_CREEP ) then
                    set SwapData[ GetPlayerId( p ) ].hasSwapped = false
                    set SwapData[ GetPlayerId( p ) ].swapPlayer = p
                endif
                    
            else
                exitwhen i &gt;= 12
            endif
            
            if GetPlayerController( p ) == MAP_CONTROL_USER and GetPlayerSlotState( p ) == PLAYER_SLOT_STATE_PLAYING then
                call TriggerRegisterPlayerChatEvent( t, p, SWAP_COMMAND, false )
                
                set SwapData[ GetPlayerId( p ) ].hasSwapped = false
                set SwapData[ GetPlayerId( p ) ].swapPlayer = p
            endif
            
            set i = i + 1
        endloop
        
        call TriggerAddCondition( t, Condition( function SwapActions ) )
        
        if HEROES_ON_INIT then
            call OnInitHeroes()
        endif
        
        set p = null
        set t = null
    endfunction
    
endlibrary


What do you think ? :eek:
 

tooltiperror

Super Moderator
Reaction score
231
I'll test it if you want, just tell me what server.
 

Komaqtion

You can change this now in User CP.
Reaction score
469
Actually, I can't host XD Sorry...

I'm using the "Northrend" server ;)
But I can't host (My router won't let me :(), so if you wouldn't mind, just add the code to a new map, and place two heroes for different players on the map, and we'll see what happens :D (Might wanna check the constants, if you wanna change anything ;))
 

Komaqtion

You can change this now in User CP.
Reaction score
469
Nice ! :D

So, is there a need for this ?
And, maybe there are some more functions you would like to be implemented ? :eek:
 

Laiev

Hey Listen!!
Reaction score
188
Nice ! :D

So, is there a need for this ?
And, maybe there are some more functions you would like to be implemented ? :eek:

why don't submit this as resource?

If i'm not wrong, we got no swap system approved :thup:

also, i got a little question.. has a way to do this (using your system) to change string to dialog box?
 

Crazy_Dead

New Member
Reaction score
24
Nice ! :D

So, is there a need for this ?
And, maybe there are some more functions you would like to be implemented ? :eek:

An unswap. Like if you maybe dont want the hero, and dont like the hero, you should be able to swap back in 10 seconds. "1 Charge" :D
 

Komaqtion

You can change this now in User CP.
Reaction score
469
Sure :D
I can add those ;)

And why I haven't submitted this is basically, I want to submit a complete resource, and I didn't even know if this worked before XD
And I also thought that I might want to add more features to it also, before submitting ;)

But I'll probably do it soon ;)
 

tooltiperror

Super Moderator
Reaction score
231
It'd also be nice if you made TimerUtils optional and used your own timers.
 

tooltiperror

Super Moderator
Reaction score
231
Nope, I still wouldn't use it because it requires vJASS. Although, if I ever do make an AoS, I may [LJASS]//! import[/LJASS] it.
 

Executor

I see you
Reaction score
57
  1. JASS:
    if SubString( s, 0, 6 ) == SWAP_COMMAND then


    =>

    JASS:
    if SubString( s, 0, SWAP_COMMAND_LENGTH ) == SWAP_COMMAND then


  2. And as all your configurables are constants, why don't you use static ifs instead of normal ones?
  3. Are that many arrays needed for a system which will (probably) only be used in the first 3 minutes?
 

Rommel

New Member
Reaction score
13
Omg, it is me who asked for a system like this. I tested it at Garena, all works. I hope you will submit it so many more people can use it. Good job and keep it up :thup:

Ah, a small question, how do you think about a Hero Switch System? If this wil be approved? :D
 

Komaqtion

You can change this now in User CP.
Reaction score
469
Ok, here's a VERY updated version, with many tweaks and added features ! :D
The only problem I'm having is that it's getting quite big, to it's hard to keep track of what is what XD

But anyways, please, is there anyone who can do a VERY extensive test of this one ? :S
I know it's alot to ask for, but I would GREATLY appreciate it ! ;)

Here's the code ! :D

JASS:
library SwapHeroes initializer Init requires SimError, optional TimerUtils, optional PlayerColors

    globals
        private constant boolean HEROES_ON_INIT = true      // Change this to true, if each player has a &#039;single&#039; hero at Map Init !
        
        private constant boolean SWAP_NEUTRALS = false      // If you want the players to be able to swap heroes with the &#039;neutral&#039; players (They don&#039;t have to write &quot;-swap ##&quot; back <img src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" class="smilie smilie--sprite smilie--sprite7" alt=":p" title="Stick Out Tongue    :p" loading="lazy" data-shortname=":p" />)
        
        private constant boolean SWAP_ALLIES_ONLY = true    // If you only want the players to be able to swap with their allies !
        
        private constant boolean SWITCH_POSITIONS = true    // If you want the swapped heroes to also swap positions <img src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" class="smilie smilie--sprite smilie--sprite8" alt=":D" title="Big Grin    :D" loading="lazy" data-shortname=":D" />
        
        private constant boolean REVIVE_IF_DEAD = true      // If you swap with a player, and it&#039;s currently dead, then if this is true it&#039;ll revive the unit also <img src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" class="smilie smilie--sprite smilie--sprite8" alt=":D" title="Big Grin    :D" loading="lazy" data-shortname=":D" />
        private constant boolean ELSE_DONT_SWAP = false
        
        private constant boolean USE_GUI_PLAYER_IDS = false
        
        private constant boolean USE_PLAYERS_COLOR_ON_NAME = true
        
        private constant boolean RETAIN_PLAYER_COLORS = false
        
        private constant boolean ONE_SWAP_ONLY = false
        
        private constant boolean SWAP_TIME_LIMIT = true
        private constant real TIME_LIMIT = 30.
        
        private constant string SWAP_COMMAND = &quot;-swap &quot;
        
        private constant string CANCEL_SWAP_CMD = &quot;-swapcancel&quot;
        
        private constant boolean ENABLE_RESWAP = true
        private constant string RESWAP_COMMAND = &quot;-reswap&quot;
        private constant boolean RESWAP_TIME_LIMIT = true
        private constant real RESWAP_TIME = 10.
        private constant boolean NEED_BOTHS_CONSENT = true
        private constant boolean RESWAP_ONCE_ONLY = true
        
            private hashtable TimerHash
    endglobals
    
    native UnitAlive takes unit id returns boolean

    globals
        private group ENUM = CreateGroup()
        
        private integer tempInt = 0
    endglobals

    private struct SwapData extends array
        boolean hasSwapped
        
        unit swapUnit
        unit targetUnit
        unit reswapUnit
        
        player swapPlayer
        player targetPlayer
        player reswapPlayer
        
        timer resetTimer
        timer reswapTimer
        
        static method ResetSwapData takes nothing returns nothing
            local thistype this
            
            static if LIBRARY_TimerUtils then
                set this = GetTimerData( GetExpiredTimer() )
            else
                set this = LoadInteger( TimerHash, GetHandleId( GetExpiredTimer() ), 1 )
            endif
            
            set this.targetUnit = null
            set this.targetPlayer = null
            
            static if LIBRARY_TimerUtils then
                call ReleaseTimer( GetExpiredTimer() )
            else
                call PauseTimer( GetExpiredTimer() )
                call DestroyTimer( GetExpiredTimer() )
                
                set this.resetTimer = null
            endif
            
        endmethod
        
        static method StopReswap takes nothing returns nothing
            local thistype this
            local player pt
            
            static if LIBRARY_TimerUtils then
                set this = GetTimerData( GetExpiredTimer() )
            else
                set this = LoadInteger( TimerHash, GetHandleId( GetExpiredTimer() ), 2 )
            endif
            
            set pt = this.reswapPlayer
            
            set this.reswapPlayer = null
            set this.reswapUnit = null
            set SwapData[ GetPlayerId( pt ) ].reswapPlayer = null
            set SwapData[ GetPlayerId( pt ) ].reswapUnit = null
            
            static if LIBRARY_TimerUtils then
                call ReleaseTimer( GetExpiredTimer() )
                call ReleaseTimer( SwapData[ GetPlayerId( pt ) ].reswapTimer )
            else
                call PauseTimer( GetExpiredTimer() )
                call DestroyTimer( GetExpiredTimer() )
                
                set this.reswapTimer = null
                
                call PauseTimer( SwapData[ GetPlayerId( pt ) ].reswapTimer )
                call DestroyTimer( SwapData[ GetPlayerId( pt ) ].reswapTimer )
                
                set SwapData[ GetPlayerId( pt ) ].reswapTimer = null
            endif
            
        endmethod
        
    endstruct
        
    private function SwapActions takes nothing returns boolean
        local player p
        local player pt
        local string s = GetEventPlayerChatString()
        local boolean conds
        local unit temp = null
        
        if SubString( s, 0, StringLength( SWAP_COMMAND ) ) == SWAP_COMMAND then
            set p = GetTriggerPlayer()
            
            if USE_GUI_PLAYER_IDS then
                set pt = Player( S2I( SubString( s, StringLength( SWAP_COMMAND ), StringLength( s ) ) ) - 1 )
            else
                set pt = Player( S2I( SubString( s, StringLength( SWAP_COMMAND ), StringLength( s ) ) ) )
            endif
            
            if SWAP_NEUTRALS then
                set conds = GetPlayerId( pt ) &gt;= 16 or GetPlayerId( pt ) &lt; 0 or pt == null or SwapData[ GetPlayerId( pt ) ].swapPlayer != null or pt == p or ( SWAP_ALLIES_ONLY and IsPlayerEnemy( p, pt ) )
            else
                set conds = GetPlayerId( pt ) &gt;= 12 or GetPlayerId( pt ) &lt; 0 or pt == null or SwapData[ GetPlayerId( pt ) ].swapPlayer != null or pt == p or ( SWAP_ALLIES_ONLY and IsPlayerEnemy( p, pt ) )
            endif
            
            // Make sure you type a valid player
            
            if conds then
                call SimError( p, &quot;You need to input a valid player-id !&quot; )
                
                return false
            endif
            
            // And also make sure you yourself have a valid hero to swap before starting <img src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" class="smilie smilie--sprite smilie--sprite2" alt=";)" title="Wink    ;)" loading="lazy" data-shortname=";)" />
            
            if SwapData[ GetPlayerId( p ) ].swapUnit == null then
                call SimError( p, &quot;You need to have a swap hero eligible yourself, before you can use the -swap command !&quot; )
                
                return false
            endif
            
            if SwapData[ GetPlayerId( p ) ].hasSwapped == true and ONE_SWAP_ONLY then
                call SimError( p, &quot;You have already swapped once, and can&#039;t swap again...&quot; )
                
                return false
            endif
            
            if SwapData[ GetPlayerId( pt ) ].hasSwapped == true and ONE_SWAP_ONLY then
                call SimError( p, &quot;The player you wish to swap with has already swapped once, and can&#039;t swap again !&quot; )
                
                return false
            endif
            
            /*if SwapData[ GetPlayerId( pt ) ].targetPlayer != p and ONE_SWAP_ONLY then
                call SimError( p, &quot;The player you wish to swap with has already swapped once, and can&#039;t swap again !&quot; )
                
                return false
            endif*/
            
            if ELSE_DONT_SWAP then
            
                if not UnitAlive( SwapData[ GetPlayerId( p ) ].swapUnit ) then
                    call SimError( p, &quot;Your swap-unit needs to be alive to be allowed to swap !&quot; )
                    
                    return false
                endif
                
                if not UnitAlive( SwapData[ GetPlayerId( pt ) ].swapUnit ) then
                    call SimError( p, &quot;Your swap-player has a dead swap-unit, and you cannot swap then !&quot; )
                    
                    return false
                endif
                
            endif
            
            if SWAP_TIME_LIMIT then
                
                static if LIBRARY_TimerUtils then
                    call ReleaseTimer( SwapData[ GetPlayerId( p ) ].resetTimer )
                    call ReleaseTimer( SwapData[ GetPlayerId( pt ) ].resetTimer )
                else
                    call PauseTimer( SwapData[ GetPlayerId( p ) ].resetTimer )
                    call DestroyTimer( SwapData[ GetPlayerId( p ) ].resetTimer )
                    
                    set SwapData[ GetPlayerId( p ) ].resetTimer = null
                    
                    call PauseTimer( SwapData[ GetPlayerId( pt ) ].resetTimer )
                    call DestroyTimer( SwapData[ GetPlayerId( pt ) ].resetTimer )
                    
                    set SwapData[ GetPlayerId( pt ) ].resetTimer = null
                endif
                
            endif
            
            set SwapData[ GetPlayerId( p ) ].targetPlayer = pt
            set SwapData[ GetPlayerId( p ) ].targetUnit = SwapData[ GetPlayerId( p ) ].swapUnit
            
            // Start switch ! <img src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" class="smilie smilie--sprite smilie--sprite8" alt=":D" title="Big Grin    :D" loading="lazy" data-shortname=":D" />            
            
            if SwapData[ GetPlayerId( pt ) ].targetPlayer == p and SwapData[ GetPlayerId( pt ) ].targetUnit == SwapData[ GetPlayerId( p ) ].swapUnit then
                set temp = SwapData[ GetPlayerId( p ) ].swapUnit
                
                if RETAIN_PLAYER_COLORS then
                    call SetUnitOwner( SwapData[ GetPlayerId( pt ) ].swapUnit, p, false )
                else
                    call SetUnitOwner( SwapData[ GetPlayerId( pt ) ].swapUnit, p, true )
                endif
                
                set SwapData[ GetPlayerId( p ) ].swapUnit = SwapData[ GetPlayerId( pt ) ].swapUnit
                
                
                if RETAIN_PLAYER_COLORS then
                    call SetUnitOwner( temp, pt, false )
                else
                    call SetUnitOwner( temp, pt, true )
                endif
                
                set SwapData[ GetPlayerId( pt ) ].swapUnit = temp
                
                if USE_PLAYERS_COLOR_ON_NAME then
                
                    static if LIBRARY_PlayerColors then
                        call DisplayTextToPlayer( p, 0.0, 0.0, &quot;You have accepted &quot; + GetPlayerNameColored( pt ) + &quot;&#039;s swap request !&quot; )
                        call DisplayTextToPlayer( pt, 0.0, 0.0, GetPlayerNameColored( p ) + &quot; has accepted you request to swap heroes !&quot; )
                    endif
                    
                else
                    call DisplayTextToPlayer( p, 0.0, 0.0, &quot;You have accepted &quot; + GetPlayerName( pt ) + &quot;&#039;s swap request !&quot; )
                    call DisplayTextToPlayer( pt, 0.0, 0.0, GetPlayerName( p ) + &quot; has accepted you request to swap heroes !&quot; )
                endif
                        
                
                if SWITCH_POSITIONS then
                    call SetUnitX( SwapData[ GetPlayerId( pt ) ].swapUnit, GetUnitX( SwapData[ GetPlayerId( p ) ].swapUnit ) )
                    call SetUnitX( SwapData[ GetPlayerId( p ) ].swapUnit, GetUnitX( SwapData[ GetPlayerId( pt ) ].swapUnit ) )
                    call SetUnitY( SwapData[ GetPlayerId( pt ) ].swapUnit, GetUnitY( SwapData[ GetPlayerId( p ) ].swapUnit ) )
                    call SetUnitY( SwapData[ GetPlayerId( p ) ].swapUnit, GetUnitY( SwapData[ GetPlayerId( pt ) ].swapUnit ) )
                endif
                
                if REVIVE_IF_DEAD then
                
                    if not UnitAlive( SwapData[ GetPlayerId( pt ) ].swapUnit ) then
                        call ReviveHero( SwapData[ GetPlayerId( pt ) ].swapUnit, GetUnitX( SwapData[ GetPlayerId( pt ) ].swapUnit ), GetUnitY( SwapData[ GetPlayerId( pt ) ].swapUnit ), true )
                    endif
                    
                    if not UnitAlive( SwapData[ GetPlayerId( p ) ].swapUnit ) then
                        call ReviveHero( SwapData[ GetPlayerId( p ) ].swapUnit, GetUnitX( SwapData[ GetPlayerId( p ) ].swapUnit ), GetUnitY( SwapData[ GetPlayerId( p ) ].swapUnit ), true )
                    endif
                    
                endif
                
                set SwapData[ GetPlayerId( p ) ].hasSwapped = true
                set SwapData[ GetPlayerId( pt ) ].hasSwapped = true
                
                static if LIBRARY_TimerUtils then
                    set SwapData[ GetPlayerId( p ) ].reswapTimer = NewTimer()
                    set SwapData[ GetPlayerId( pt ) ].reswapTimer = NewTimer()
                    
                    call SetTimerData( SwapData[ GetPlayerId( p ) ].reswapTimer, SwapData[ GetPlayerId( p ) ] )
                    call SetTimerData( SwapData[ GetPlayerId( pt ) ].reswapTimer, SwapData[ GetPlayerId( pt ) ] )
                else
                    set SwapData[ GetPlayerId( p ) ].reswapTimer = CreateTimer()
                    set SwapData[ GetPlayerId( pt ) ].reswapTimer = CreateTimer()
                    
                    call SaveInteger( TimerHash, GetHandleId( SwapData[ GetPlayerId( p ) ].reswapTimer ), 2, SwapData[ GetPlayerId( p ) ] )
                    call SaveInteger( TimerHash, GetHandleId( SwapData[ GetPlayerId( pt ) ].reswapTimer ), 2, SwapData[ GetPlayerId( pt ) ] )
                endif
                
                set SwapData[ GetPlayerId( p ) ].reswapUnit = SwapData[ GetPlayerId( pt ) ].swapUnit
                set SwapData[ GetPlayerId( pt ) ].reswapUnit = SwapData[ GetPlayerId( pt ) ].swapUnit
                set SwapData[ GetPlayerId( p ) ].reswapPlayer = pt
                set SwapData[ GetPlayerId( pt ) ].reswapPlayer = p
                
                static if ONE_SWAP_ONLY then
                    set SwapData[ GetPlayerId( p ) ].swapUnit = null
                    set SwapData[ GetPlayerId( pt ) ].swapUnit = null
                endif
                
                call TimerStart( SwapData[ GetPlayerId( p ) ].reswapTimer, RESWAP_TIME, false, function SwapData.StopReswap )
                call TimerStart( SwapData[ GetPlayerId( pt ) ].reswapTimer, RESWAP_TIME, false, function SwapData.StopReswap )
            else
        
                if SWAP_TIME_LIMIT then
            
                    static if LIBRARY_TimerUtils then
                        set SwapData[ GetPlayerId( p ) ].resetTimer = NewTimer()
                        
                        call SetTimerData( SwapData[ GetPlayerId( p ) ].resetTimer, SwapData[ GetPlayerId( p ) ] )
                    else
                        set SwapData[ GetPlayerId( p ) ].resetTimer = CreateTimer()
                        
                        call SaveInteger( TimerHash, GetHandleId( SwapData[ GetPlayerId( p ) ].resetTimer ), 1, SwapData[ GetPlayerId( p ) ] )
                    endif
                    
                    call TimerStart( SwapData[ GetPlayerId( p ) ].resetTimer, TIME_LIMIT, false, function SwapData.ResetSwapData )
                
                endif
                
                if USE_PLAYERS_COLOR_ON_NAME then
                
                    static if LIBRARY_PlayerColors then
                        call DisplayTextToPlayer( p, 0.0, 0.0, &quot;You have sent a request to &quot; + GetPlayerNameColored( pt ) + &quot;, to swap heroes !&quot; )
                        call DisplayTextToPlayer( pt, 0.0, 0.0, GetPlayerNameColored( p ) + &quot; has sent you a swap request ! Will you accept ?&quot; )
                    endif
                    
                else
                    call DisplayTextToPlayer( p, 0.0, 0.0, &quot;You have sent a request to &quot; + GetPlayerName( pt ) + &quot;, to swap heroes !&quot; )
                    call DisplayTextToPlayer( pt, 0.0, 0.0, GetPlayerName( p ) + &quot; has sent you a swap request ! Will you accept ?&quot; )
                endif
                
            endif
            
        endif
        
        set s = null
        set p = null
        set pt = null
        set temp = null
        
        return false
    endfunction
    
    private function Reswap takes nothing returns boolean
        local player p = GetTriggerPlayer()
        local player pt
        local unit temp = null
        
        if SwapData[ GetPlayerId( p ) ].reswapPlayer != null and SwapData[ GetPlayerId( p ) ].reswapUnit != null then
            set pt = SwapData[ GetPlayerId( p ) ].reswapPlayer
            
            if not ( UnitAlive( SwapData[ GetPlayerId( p ) ].swapUnit ) and REVIVE_IF_DEAD ) and ELSE_DONT_SWAP then
                call SimError( p, &quot;Your reswap-hero needs to be alive !&quot; )
                
                return false
            endif
            
            if not ( UnitAlive( SwapData[ GetPlayerId( pt ) ].swapUnit ) and REVIVE_IF_DEAD ) and ELSE_DONT_SWAP then
                call SimError( p, &quot;Your reswap-player&#039;s swap-unit needs to be alive !&quot; )
                
                return false
            endif
            
            if NEED_BOTHS_CONSENT then
                set SwapData[ GetPlayerId( p ) ].targetPlayer = pt
                set SwapData[ GetPlayerId( p ) ].targetUnit = SwapData[ GetPlayerId( pt ) ].swapUnit
                
                if SwapData[ GetPlayerId( pt ) ].targetPlayer == p and SwapData[ GetPlayerId( pt ) ].targetUnit == SwapData[ GetPlayerId( p ) ].swapUnit then
                    set temp = SwapData[ GetPlayerId( p ) ].swapUnit
                    
                    if RETAIN_PLAYER_COLORS then
                        call SetUnitOwner( SwapData[ GetPlayerId( pt ) ].swapUnit, p, false )
                    else
                        call SetUnitOwner( SwapData[ GetPlayerId( pt ) ].swapUnit, p, true )
                    endif
                    
                    set SwapData[ GetPlayerId( p ) ].swapUnit = SwapData[ GetPlayerId( pt ) ].swapUnit
                    
                    
                    if RETAIN_PLAYER_COLORS then
                        call SetUnitOwner( temp, pt, false )
                    else
                        call SetUnitOwner( temp, pt, true )
                    endif
                    
                    set SwapData[ GetPlayerId( pt ) ].swapUnit = temp
                    
                    if USE_PLAYERS_COLOR_ON_NAME then
                    
                        static if LIBRARY_PlayerColors then
                            call DisplayTextToPlayer( p, 0.0, 0.0, &quot;You have accepted &quot; + GetPlayerNameColored( pt ) + &quot;&#039;s swap request !&quot; )
                            call DisplayTextToPlayer( pt, 0.0, 0.0, GetPlayerNameColored( p ) + &quot; has accepted you request to swap heroes !&quot; )
                        endif
                        
                    else
                        call DisplayTextToPlayer( p, 0.0, 0.0, &quot;You have accepted &quot; + GetPlayerName( pt ) + &quot;&#039;s swap request !&quot; )
                        call DisplayTextToPlayer( pt, 0.0, 0.0, GetPlayerName( p ) + &quot; has accepted you request to swap heroes !&quot; )
                    endif
                            
                    
                    if SWITCH_POSITIONS then
                        call SetUnitX( SwapData[ GetPlayerId( pt ) ].swapUnit, GetUnitX( SwapData[ GetPlayerId( p ) ].swapUnit ) )
                        call SetUnitX( SwapData[ GetPlayerId( p ) ].swapUnit, GetUnitX( SwapData[ GetPlayerId( pt ) ].swapUnit ) )
                        call SetUnitY( SwapData[ GetPlayerId( pt ) ].swapUnit, GetUnitY( SwapData[ GetPlayerId( p ) ].swapUnit ) )
                        call SetUnitY( SwapData[ GetPlayerId( p ) ].swapUnit, GetUnitY( SwapData[ GetPlayerId( pt ) ].swapUnit ) )
                    endif
                    
                    if REVIVE_IF_DEAD then
                    
                        if not UnitAlive( SwapData[ GetPlayerId( pt ) ].swapUnit ) then
                            call ReviveHero( SwapData[ GetPlayerId( pt ) ].swapUnit, GetUnitX( SwapData[ GetPlayerId( pt ) ].swapUnit ), GetUnitY( SwapData[ GetPlayerId( pt ) ].swapUnit ), true )
                        endif
                        
                        if not UnitAlive( SwapData[ GetPlayerId( p ) ].swapUnit ) then
                            call ReviveHero( SwapData[ GetPlayerId( p ) ].swapUnit, GetUnitX( SwapData[ GetPlayerId( p ) ].swapUnit ), GetUnitY( SwapData[ GetPlayerId( p ) ].swapUnit ), true )
                        endif
                        
                    endif
                    
                    set SwapData[ GetPlayerId( p ) ].hasSwapped = true
                    set SwapData[ GetPlayerId( pt ) ].hasSwapped = true
                    
                    static if LIBRARY_TimerUtils then
                        set SwapData[ GetPlayerId( p ) ].reswapTimer = NewTimer()
                        set SwapData[ GetPlayerId( pt ) ].reswapTimer = NewTimer()
                        
                        call SetTimerData( SwapData[ GetPlayerId( p ) ].reswapTimer, SwapData[ GetPlayerId( p ) ] )
                        call SetTimerData( SwapData[ GetPlayerId( pt ) ].reswapTimer, SwapData[ GetPlayerId( pt ) ] )
                    else
                        set SwapData[ GetPlayerId( p ) ].reswapTimer = CreateTimer()
                        set SwapData[ GetPlayerId( pt ) ].reswapTimer = CreateTimer()
                        
                        call SaveInteger( TimerHash, GetHandleId( SwapData[ GetPlayerId( p ) ].reswapTimer ), 2, SwapData[ GetPlayerId( p ) ] )
                        call SaveInteger( TimerHash, GetHandleId( SwapData[ GetPlayerId( pt ) ].reswapTimer ), 2, SwapData[ GetPlayerId( pt ) ] )
                    endif
                    
                    set SwapData[ GetPlayerId( p ) ].reswapUnit = SwapData[ GetPlayerId( pt ) ].swapUnit
                    set SwapData[ GetPlayerId( pt ) ].reswapUnit = SwapData[ GetPlayerId( pt ) ].swapUnit
                    set SwapData[ GetPlayerId( p ) ].reswapPlayer = pt
                    set SwapData[ GetPlayerId( pt ) ].reswapPlayer = p
                    set SwapData[ GetPlayerId( p ) ].swapUnit = null
                    set SwapData[ GetPlayerId( pt ) ].swapUnit = null
                    
                    call TimerStart( SwapData[ GetPlayerId( p ) ].reswapTimer, RESWAP_TIME, false, function SwapData.StopReswap )
                    call TimerStart( SwapData[ GetPlayerId( pt ) ].reswapTimer, RESWAP_TIME, false, function SwapData.StopReswap )
                else
            
                    if SWAP_TIME_LIMIT then
                
                        static if LIBRARY_TimerUtils then
                            set SwapData[ GetPlayerId( p ) ].resetTimer = NewTimer()
                            
                            call SetTimerData( SwapData[ GetPlayerId( p ) ].resetTimer, SwapData[ GetPlayerId( p ) ] )
                        else
                            set SwapData[ GetPlayerId( p ) ].resetTimer = CreateTimer()
                            
                            call SaveInteger( TimerHash, GetHandleId( SwapData[ GetPlayerId( p ) ].resetTimer ), 1, SwapData[ GetPlayerId( p ) ] )
                        endif
                        
                        call TimerStart( SwapData[ GetPlayerId( p ) ].resetTimer, TIME_LIMIT, false, function SwapData.ResetSwapData )
                    
                    endif
                    
                    if USE_PLAYERS_COLOR_ON_NAME then
                    
                        static if LIBRARY_PlayerColors then
                            call DisplayTextToPlayer( p, 0.0, 0.0, &quot;You have sent a request to &quot; + GetPlayerNameColored( pt ) + &quot;, to swap heroes !&quot; )
                            call DisplayTextToPlayer( pt, 0.0, 0.0, GetPlayerNameColored( p ) + &quot; has sent you a swap request ! Will you accept ?&quot; )
                        endif
                        
                    else
                        call DisplayTextToPlayer( p, 0.0, 0.0, &quot;You have sent a request to &quot; + GetPlayerName( pt ) + &quot;, to swap heroes !&quot; )
                        call DisplayTextToPlayer( pt, 0.0, 0.0, GetPlayerName( p ) + &quot; has sent you a swap request ! Will you accept ?&quot; )
                    endif
                    
                endif
                
            else
                set temp = SwapData[ GetPlayerId( p ) ].swapUnit
                
                if RETAIN_PLAYER_COLORS then
                    call SetUnitOwner( SwapData[ GetPlayerId( pt ) ].swapUnit, p, false )
                else
                    call SetUnitOwner( SwapData[ GetPlayerId( pt ) ].swapUnit, p, true )
                endif
                
                set SwapData[ GetPlayerId( p ) ].swapUnit = SwapData[ GetPlayerId( pt ) ].swapUnit
                
                
                if RETAIN_PLAYER_COLORS then
                    call SetUnitOwner( temp, pt, false )
                else
                    call SetUnitOwner( temp, pt, true )
                endif
                
                set SwapData[ GetPlayerId( pt ) ].swapUnit = temp
                
                if USE_PLAYERS_COLOR_ON_NAME then
                
                    static if LIBRARY_PlayerColors then
                        call DisplayTextToPlayer( p, 0.0, 0.0, &quot;You have now reswapped your hero from &quot; + GetPlayerNameColored( pt ) + &quot; and given him your hero !&quot; )
                        call DisplayTextToPlayer( pt, 0.0, 0.0, GetPlayerNameColored( p ) + &quot; has reswapped his hero from you, and you&#039;ve gotten yours back too !&quot; )
                    endif
                    
                else
                    call DisplayTextToPlayer( p, 0.0, 0.0, &quot;You have accepted &quot; + GetPlayerName( pt ) + &quot;&#039;s swap request !&quot; )
                    call DisplayTextToPlayer( pt, 0.0, 0.0, GetPlayerName( p ) + &quot; has accepted you request to swap heroes !&quot; )
                endif
                        
                
                if SWITCH_POSITIONS then
                    call SetUnitX( SwapData[ GetPlayerId( pt ) ].swapUnit, GetUnitX( SwapData[ GetPlayerId( p ) ].swapUnit ) )
                    call SetUnitX( SwapData[ GetPlayerId( p ) ].swapUnit, GetUnitX( SwapData[ GetPlayerId( pt ) ].swapUnit ) )
                    call SetUnitY( SwapData[ GetPlayerId( pt ) ].swapUnit, GetUnitY( SwapData[ GetPlayerId( p ) ].swapUnit ) )
                    call SetUnitY( SwapData[ GetPlayerId( p ) ].swapUnit, GetUnitY( SwapData[ GetPlayerId( pt ) ].swapUnit ) )
                endif
                
                if REVIVE_IF_DEAD then
                
                    if not UnitAlive( SwapData[ GetPlayerId( pt ) ].swapUnit ) then
                        call ReviveHero( SwapData[ GetPlayerId( pt ) ].swapUnit, GetUnitX( SwapData[ GetPlayerId( pt ) ].swapUnit ), GetUnitY( SwapData[ GetPlayerId( pt ) ].swapUnit ), true )
                    endif
                    
                    if not UnitAlive( SwapData[ GetPlayerId( p ) ].swapUnit ) then
                        call ReviveHero( SwapData[ GetPlayerId( p ) ].swapUnit, GetUnitX( SwapData[ GetPlayerId( p ) ].swapUnit ), GetUnitY( SwapData[ GetPlayerId( p ) ].swapUnit ), true )
                    endif
                    
                endif
                
                set SwapData[ GetPlayerId( p ) ].hasSwapped = true
                set SwapData[ GetPlayerId( pt ) ].hasSwapped = true
                
                static if LIBRARY_TimerUtils then
                    set SwapData[ GetPlayerId( p ) ].reswapTimer = NewTimer()
                    set SwapData[ GetPlayerId( pt ) ].reswapTimer = NewTimer()
                    
                    call SetTimerData( SwapData[ GetPlayerId( p ) ].reswapTimer, SwapData[ GetPlayerId( p ) ] )
                    call SetTimerData( SwapData[ GetPlayerId( pt ) ].reswapTimer, SwapData[ GetPlayerId( pt ) ] )
                else
                    set SwapData[ GetPlayerId( p ) ].reswapTimer = CreateTimer()
                    set SwapData[ GetPlayerId( pt ) ].reswapTimer = CreateTimer()
                    
                    call SaveInteger( TimerHash, GetHandleId( SwapData[ GetPlayerId( p ) ].reswapTimer ), 2, SwapData[ GetPlayerId( p ) ] )
                    call SaveInteger( TimerHash, GetHandleId( SwapData[ GetPlayerId( pt ) ].reswapTimer ), 2, SwapData[ GetPlayerId( pt ) ] )
                endif
                
                static if not RESWAP_ONCE_ONLY then
                    set SwapData[ GetPlayerId( p ) ].reswapUnit = SwapData[ GetPlayerId( pt ) ].swapUnit
                    set SwapData[ GetPlayerId( pt ) ].reswapUnit = SwapData[ GetPlayerId( pt ) ].swapUnit
                    set SwapData[ GetPlayerId( p ) ].reswapPlayer = pt
                    set SwapData[ GetPlayerId( pt ) ].reswapPlayer = p
                endif
                
                set SwapData[ GetPlayerId( p ) ].targetUnit = null
                set SwapData[ GetPlayerId( pt ) ].targetUnit = null
            endif
                
        endif
        
        return false
    endfunction
    
    private function PickInitHeroes takes nothing returns boolean
        local unit u = GetFilterUnit()
        local player p = GetOwningPlayer( u )
        
        if tempInt == 0 and IsUnitType( u, UNIT_TYPE_HERO ) and not IsUnitType( u, UNIT_TYPE_STRUCTURE ) and UnitAlive( u ) and SwapData[ GetPlayerId( p ) ].swapUnit == null then
            set SwapData[ GetPlayerId( p ) ].swapUnit = u
            set tempInt = 1
        endif
        
        set u = null
        set p = null
        
        return false
    endfunction

    private function OnInitHeroes takes nothing returns nothing
        local integer i = 0
        local player p
        
        loop
        
            if SWAP_NEUTRALS then
                exitwhen i &gt;= 16
            else
                exitwhen i &gt;= 12
            endif
            
            set tempInt = 0
            set p = Player( i )
            
            if SwapData[ GetPlayerId( p ) ].swapUnit != null and GetPlayerController( p ) == MAP_CONTROL_USER and GetPlayerController( p ) == PLAYER_SLOT_STATE_PLAYING then                    
                call GroupEnumUnitsOfPlayer( ENUM, p, Filter( function PickInitHeroes ) )
            endif
            
            set i = i + 1
        endloop
    
        set p = null
    endfunction
    
    private function CancelSwap takes nothing returns boolean
        local player p = GetTriggerPlayer()
        local player pt = SwapData[ GetPlayerId( p ) ].targetPlayer
        
        if TimerGetRemaining( SwapData[ GetPlayerId( p ) ].resetTimer ) &gt; 0 then
            
            if USE_PLAYERS_COLOR_ON_NAME then
            
                static if LIBRARY_PlayerColors then
                    call DisplayTextToPlayer( p, 0.0, 0.0, &quot;You have cancelled the request to swap heroes with &quot; + GetPlayerNameColored( pt ) + &quot; !&quot; )
                    call DisplayTextToPlayer( pt, 0.0, 0.0, GetPlayerNameColored( p ) + &quot; has cancelled his request to swap heroes with you !&quot; )
                endif
                
            else
                call DisplayTextToPlayer( pt, 0.0, 0.0, &quot;You have cancelled the request to swap heroes with &quot; + GetPlayerName( pt ) + &quot; !&quot; )
                call DisplayTextToPlayer( pt, 0.0, 0.0, GetPlayerName( p ) + &quot; has cancelled his request to swap heroes with you !&quot; )
            endif
            
            set SwapData[ GetPlayerId( p ) ].targetPlayer = null
            set SwapData[ GetPlayerId( p ) ].targetUnit = null
            
            if SWAP_TIME_LIMIT then
            
                static if LIBRARY_TimerUtils then
                    call ReleaseTimer( SwapData[ GetPlayerId( p ) ].resetTimer )
                else
                    call PauseTimer( SwapData[ GetPlayerId( p ) ].resetTimer )
                    call DestroyTimer( SwapData[ GetPlayerId( p ) ].resetTimer )
                    
                    set SwapData[ GetPlayerId( p ) ].resetTimer = null
                endif
                
            endif
    
        endif
    
        return false
    endfunction

    private function Init takes nothing returns nothing
        local trigger t = CreateTrigger()
        local integer i = 0
        local player p = null
        
        loop
        
            set p = Player( i )
        
            if SWAP_NEUTRALS then
                exitwhen i &gt;= 16
                
                if i &gt;= 12 and ( GetPlayerController( p ) == MAP_CONTROL_COMPUTER or GetPlayerController( p ) == MAP_CONTROL_CREEP ) then
                    set SwapData[ GetPlayerId( p ) ].hasSwapped = false
                    set SwapData[ GetPlayerId( p ) ].swapPlayer = p
                endif
                    
            else
                exitwhen i &gt;= 12
            endif
            
            if GetPlayerController( p ) == MAP_CONTROL_USER and GetPlayerSlotState( p ) == PLAYER_SLOT_STATE_PLAYING then
                call TriggerRegisterPlayerChatEvent( t, p, SWAP_COMMAND, false )
                
                set SwapData[ GetPlayerId( p ) ].hasSwapped = false
                set SwapData[ GetPlayerId( p ) ].swapPlayer = p
            endif
            
            set i = i + 1
        endloop
        
        call TriggerAddCondition( t, Condition( function SwapActions ) )
        
        set t = CreateTrigger()
        set i = 0
        
        loop
            exitwhen i &gt;= 12
            
            set p = Player( i )
            
            if GetPlayerController( p ) == MAP_CONTROL_USER and GetPlayerSlotState( p ) == PLAYER_SLOT_STATE_PLAYING then
                call TriggerRegisterPlayerChatEvent( t, p, CANCEL_SWAP_CMD, false )
            endif
            
            set i = i + 1
        endloop
        
        call TriggerAddCondition( t, Condition( function CancelSwap ) )
        
        if ENABLE_RESWAP then
            set t = CreateTrigger()
            set i = 0
            
            loop
                exitwhen i &gt;= 12
                
                set p = Player( i )
                
                if GetPlayerController( p ) == MAP_CONTROL_USER and GetPlayerSlotState( p ) == PLAYER_SLOT_STATE_PLAYING then
                    call TriggerRegisterPlayerChatEvent( t, p, RESWAP_COMMAND, false )
                endif
                
                set i = i + 1
            endloop
            
            call TriggerAddCondition( t, Condition( function Reswap ) )
        endif
        
        if HEROES_ON_INIT then
            call OnInitHeroes()
        endif
        
        static if not LIBRARY_TimerUtils then
            set TimerHash = InitHashtable()
        endif
        
        set p = null
        set t = null
    endfunction
    
endlibrary
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Members online

      No members online now.

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top