- Joined
- Oct 2, 2014
- Messages
- 215
Does anyone know how to make or if there is an ability to change the colour and team of a unit? If you do I would love to know. 
|
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
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)"
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.That is a hell of a lotta code for a timed mind control.![]()
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.
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.