- Joined
- Mar 10, 2009
- Messages
- 5,016
JASS:
/*
===UnSelectableUnit v1.3
===by mckill2009
Simple to understand, makes any unit unselectable...
REQUIRES:
- JassNewGenPack by vexorian
API:
function MakeUnitSelectable takes unit u returns nothing
function MakeUnitUnSelectable takes unit u, real duration returns nothing
- put 0 for to the duration for permanent
KNOWN ISSUES:
- Unit can still be attacked, ordered and castable by spells
*/
library UnSelectableUnit
globals
private hashtable ht = InitHashtable()
endglobals
private struct US
unit u
boolean permanent
private static integer index = 0
private static integer array indexAR
private static timer t = CreateTimer()
private static method periodic takes nothing returns nothing
local thistype this
local integer i = 0
local integer id
loop
set i = i+1
set this = indexAR[i]
set id = GetHandleId(.u)
if LoadInteger(ht, id, 1)==2 or IsUnitType(.u, UNIT_TYPE_DEAD) then //reset
call FlushChildHashtable(ht, id)
set .u = null
call .destroy()
set indexAR[i] = indexAR[index]
set indexAR[index] = this
set index = index - 1
set i = i-1
if index==0 then
call PauseTimer(t)
endif
elseif LoadInteger(ht, id, 1)==1 then //permanent
call SelectUnit(.u, false)
else
if LoadReal(ht, id, 2) > 0 and not IsUnitType(.u, UNIT_TYPE_DEAD) then
call SaveReal(ht, id, 2, LoadReal(ht, id, 2)-0.03125)
call SelectUnit(.u, false)
else
call SaveInteger(ht, id, 1, 2)
endif
endif
exitwhen i==index
endloop
endmethod
static method startTimer takes unit u, real d, integer id returns nothing
local thistype this
if LoadBoolean(ht, id, 0) then
if d==0 then
debug call DisplayTimedTextToPlayer(GetOwningPlayer(u), 0, 0, 10, "[UnSelectableUnit][MakeUnitUnSelectable] ERROR: Zero duration is not possible!")
else
call SaveReal(ht, id, 2, LoadReal(ht, id, 2)+d)
endif
else
set this = allocate()
set .u = u
if d==0 then
call SaveInteger(ht, id, 1, 1) //making permanent
endif
call SaveReal(ht, id, 2, d)
call SaveBoolean(ht, id, 0, true)
if index==0 then
call TimerStart(t, 0.03125, true, function thistype.periodic)
endif
set index = index + 1
set indexAR[index] = this
endif
endmethod
endstruct
//API:
function MakeUnitSelectable takes unit u returns nothing
call SaveInteger(ht, GetHandleId(u), 1, 2) //resetting
endfunction
function MakeUnitUnSelectable takes unit u, real duration returns nothing
call US.startTimer(u, duration, GetHandleId(u))
endfunction
endlibrary
DEMO:
-
UnSelectableUnit TIMED
-
Events
- Unit - A unit Starts the effect of an ability
- Conditions
-
Actions
- Custom script: local unit u = GetSpellTargetUnit()
- Custom script: call MakeUnitUnSelectable(u, 50)
- Wait 5.00 seconds
- Custom script: call MakeUnitSelectable(u)
-
Events
-
UnSelectableUnit PERMANENT
-
Events
- Unit - A unit Starts the effect of an ability
- Conditions
-
Actions
- -------- Set the duration to zero to make the unit permanently unselectable until death --------
- -------- or until removes from system via MakeUnitSelectable --------
- Custom script: call MakeUnitUnSelectable(GetSpellTargetUnit(), 0)
-
Events
- Unit can still be attacked, ordered and castable by spells
v1.3
- Bear and Metamorphosis ability requirements are removed due to a nasty bug
- Table requirement removed and replaced by a normal hashtable
- API reduced from 3 to 2
Last edited: