Team Change Ability

Status
Not open for further replies.
Level 12
Joined
May 20, 2009
Messages
822
I made a mind control ability a while back where you could control how long the unit was under control and to give it back to the original player after a certain amount of time. I don't know if I have it anymore but it originally only took me like an hour to make and debug, so if you want it let me know.

I don't see much of a reason to use something other the Charm unless you're looking to customize it with effects such as this. (Or of course something else)

EDIT: Found it, it was really simple to change the ownership back. I just indexed the original owner, then in a clock trigger I checked when the unit no longer had the mind control buff and gave it back to the original owner. This also allowed for it to be dispelled, which at the time I thought would be a really useful balancing mechanism to make it not overpowered but still useful. (Considering it was a short cooldown and low-ish mana cost and a normal, 3-level ability)
 
Level 24
Joined
Aug 1, 2013
Messages
4,658
If you want to change the unit's team and/or color completely... you can do what IcemanBo mentioned...
If you want it timed... you can use this:
JASS:
library mindControlSystem
    
    globals
        hashtable       MCS_Hash                        = InitHashtable()
    endglobals
    
    private function MCS_Callback takes nothing returns nothing
        local timer t = GetExpiredTimer()
        local integer timerId = GetHandleId(t)
        local unit whichUnit = LoadUnitHandle(MCS_Hash, timerId, 0)
        local player originalPlayer = LoadPlayerHandle(MCS_Hash, timerId, 1)
        
        call SetUnitOwner(whichUnit, originalPlayer, true)
        
        call FlushChildHashtable(MCS_Hash, timerId)
        call RemoveSavedHandle(MCS_Hash, GetHandleId(whichUnit), 0)
        
        call DestroyTimer(t)
        set t = null
        set whichUnit = null
        set originalPlayer = null
    endfunction
    
    public function RemoveMindControl takes unit whichUnit returns nothing
        local integer unitId = GetHandleId(whichUnit)
        local timer t
        local integer timerId
        
        if HaveSavedHandle(MCS_Hash, unitId, 0) then
            set t = LoadTimerHandle(MCS_Hash, unitId, 0)
            set timerId = GetHandleId(t)
            
            call SetUnitOwner(whichUnit, LoadPlayerHandle(MCS_Hash, timerId, 1), true)
            
            call FlushChildHashtable(MCS_Hash, timerId)
            call RemoveSavedHandle(MCS_Hash, unitId, 0)
            call PauseTimer(t)
            call DestroyTimer(t)
            set t = null
        endif
    endfunction
    
    public function AddMindControl takes unit whichUnit, real duration, player newPlayer, boolean changeColor returns nothing
        local timer t
        local integer timerId
        local integer unitId = GetHandleId(whichUnit)
        local player originalPlayer
        
        if HaveSavedHandle(MCS_Hash, unitId, 0) then
            set t = LoadTimerHandle(MCS_Hash, unitId, 0)
            set timerId = GetHandleId(t)
            set originalPlayer = LoadPlayerHandle(MCS_Hash, timerId, 1)
            
            if newPlayer == originalPlayer then
                call SetUnitOwner(whichUnit, originalPlayer, true)
                call FlushChildHashtable(MCS_Hash, timerId)
                call RemoveSavedHandle(MCS_Hash, unitId, 0)
                call PauseTimer(t)
                call DestroyTimer(t)
            else
                call TimerStart(t, duration, false, function MCS_Callback)
                
                call SetUnitOwner(whichUnit, newPlayer, changeColor)
            endif
        else
            set t = CreateTimer()
            set timerId = GetHandleId(t)
            set originalPlayer = GetOwningPlayer(whichUnit)
            
            call TimerStart(t, duration, false, function MCS_Callback)
            call SaveTimerHandle(MCS_Hash, unitId, 0, t)
            call SaveUnitHandle(MCS_Hash, timerId, 0, whichUnit)
            call SavePlayerHandle(MCS_Hash, timerId, 1, originalPlayer)
            
            call SetUnitOwner(whichUnit, newPlayer, changeColor)
        endif
        
        set originalPlayer = null
        set t = null
    endfunction
    
endlibrary

Just make a custom script "call AddMindControl(udg_MyGlobalUnit, 123.45, true)"
 
Level 12
Joined
May 20, 2009
Messages
822
If you want to change the unit's team and/or color completely... you can do what IcemanBo mentioned...
If you want it timed... you can use this:
JASS:
library mindControlSystem
    
    globals
        hashtable       MCS_Hash                        = InitHashtable()
    endglobals
    
    private function MCS_Callback takes nothing returns nothing
        local timer t = GetExpiredTimer()
        local integer timerId = GetHandleId(t)
        local unit whichUnit = LoadUnitHandle(MCS_Hash, timerId, 0)
        local player originalPlayer = LoadPlayerHandle(MCS_Hash, timerId, 1)
        
        call SetUnitOwner(whichUnit, originalPlayer, true)
        
        call FlushChildHashtable(MCS_Hash, timerId)
        call RemoveSavedHandle(MCS_Hash, GetHandleId(whichUnit), 0)
        
        call DestroyTimer(t)
        set t = null
        set whichUnit = null
        set originalPlayer = null
    endfunction
    
    public function RemoveMindControl takes unit whichUnit returns nothing
        local integer unitId = GetHandleId(whichUnit)
        local timer t
        local integer timerId
        
        if HaveSavedHandle(MCS_Hash, unitId, 0) then
            set t = LoadTimerHandle(MCS_Hash, unitId, 0)
            set timerId = GetHandleId(t)
            
            call SetUnitOwner(whichUnit, LoadPlayerHandle(MCS_Hash, timerId, 1), true)
            
            call FlushChildHashtable(MCS_Hash, timerId)
            call RemoveSavedHandle(MCS_Hash, unitId, 0)
            call PauseTimer(t)
            call DestroyTimer(t)
            set t = null
        endif
    endfunction
    
    public function AddMindControl takes unit whichUnit, real duration, player newPlayer, boolean changeColor returns nothing
        local timer t
        local integer timerId
        local integer unitId = GetHandleId(whichUnit)
        local player originalPlayer
        
        if HaveSavedHandle(MCS_Hash, unitId, 0) then
            set t = LoadTimerHandle(MCS_Hash, unitId, 0)
            set timerId = GetHandleId(t)
            set originalPlayer = LoadPlayerHandle(MCS_Hash, timerId, 1)
            
            if newPlayer == originalPlayer then
                call SetUnitOwner(whichUnit, originalPlayer, true)
                call FlushChildHashtable(MCS_Hash, timerId)
                call RemoveSavedHandle(MCS_Hash, unitId, 0)
                call PauseTimer(t)
                call DestroyTimer(t)
            else
                call TimerStart(t, duration, false, function MCS_Callback)
                
                call SetUnitOwner(whichUnit, newPlayer, changeColor)
            endif
        else
            set t = CreateTimer()
            set timerId = GetHandleId(t)
            set originalPlayer = GetOwningPlayer(whichUnit)
            
            call TimerStart(t, duration, false, function MCS_Callback)
            call SaveTimerHandle(MCS_Hash, unitId, 0, t)
            call SaveUnitHandle(MCS_Hash, timerId, 0, whichUnit)
            call SavePlayerHandle(MCS_Hash, timerId, 1, originalPlayer)
            
            call SetUnitOwner(whichUnit, newPlayer, changeColor)
        endif
        
        set originalPlayer = null
        set t = null
    endfunction
    
endlibrary

Just make a custom script "call AddMindControl(udg_MyGlobalUnit, 123.45, true)"

That is a hell of a lotta code for a timed mind control. o_O

This would be so much more code then just making a short main trigger that checks a timer, or in my trigger checks for a Buff, and when the timer/buff ends it changes the owner back to the original and deindexes everything...

And it'd achieve the same thing.
 
Level 24
Joined
Aug 1, 2013
Messages
4,658
In that case, you want it to be permanent...
You can just use the action which as mentioned by IcemanBo... however, how do you want to choose the player that will get the unit?

That is a hell of a lotta code for a timed mind control. o_O
Except that you forget that if you mind control one of my units and then player 3 will mind control that unit again... it will get complicated.
Also, if you mind control one of my units and I mind control them back... I want the mind control to be removed instead of me having a mind controlled unit.
That system works flawlessly and has a remove action so you can interrupt it as well... and it is not even that big code.
 
Level 12
Joined
May 20, 2009
Messages
822
In that case, you want it to be permanent...
You can just use the action which as mentioned by IcemanBo... however, how do you want to choose the player that will get the unit?


Except that you forget that if you mind control one of my units and then player 3 will mind control that unit again... it will get complicated.
Also, if you mind control one of my units and I mind control them back... I want the mind control to be removed instead of me having a mind controlled unit.
That system works flawlessly and has a remove action so you can interrupt it as well... and it is not even that big code.

I'm pretty sure that by using a buff, neither of those are a problem. It would basically works like RA2 mind control where it cannot be re-mind controlled until the original unit that mind controlled them dies or mind controls something else (Or in this case until the original buff is removed)

But I could be wrong, I never tested it in a scenario where there was more then 1 mind control going on. (Other then for MUI purposes)
 

EdgeOfChaos

E

EdgeOfChaos

There's no need for a system like that to do something as simple as he's saying, that just over-complicates things. Just use Iceman's code.

(edit) Plus, seeing as he's probably a new-ish mapmaker, using that library could be a challenge if he doesn't understand custom scripts.
 

Chaosy

Tutorial Reviewer
Level 40
Joined
Jun 9, 2011
Messages
13,223
There's no need for a system like that to do something as simple as he's saying, that just over-complicates things. Just use Iceman's code.

As Wiet said more than once, IF he just wants the unit controlled for a certain duration Iceman's single line would not be very helpful. And how hard is to write out 2 variables?

udg_u = target unit of ability being cast
udg_p = owner of triggering unit

call AddMindControll(udg_u, udg_p, true)

Brain overload. Wiet even gave him the the copy>paste line to use it. In the end it's a one variable difference in terms of effort.
 
Status
Not open for further replies.
Top