- Reaction score
- 333
Ok, here we go. Sorry about the double post, but the thread would look stagnant if I simply edited my last one.
The only known [to me] limitations of this system:
1. There is no buff placed to indicate that the unit is stunned.
2. The stun effect appears additional to the normal stun effect (ie, if you stun a unit with a storm bolt and this system, the graphic appears twice).
3. This stun will screw up paused units.
4. The stun can not be removed manually.
5. Only 8192 units can be stunned at the same time.
I have tested it, and it seems to work fine otherwise. Post if there are bugs.
To use:
1. Place code in map header or empty trigger.
2. Call with "Custom Script: Stun_SetStun(udg_your_unit, udg_your_duration)"
Here is the code:
The only known [to me] limitations of this system:
1. There is no buff placed to indicate that the unit is stunned.
2. The stun effect appears additional to the normal stun effect (ie, if you stun a unit with a storm bolt and this system, the graphic appears twice).
3. This stun will screw up paused units.
4. The stun can not be removed manually.
5. Only 8192 units can be stunned at the same time.
I have tested it, and it seems to work fine otherwise. Post if there are bugs.
To use:
1. Place code in map header or empty trigger.
2. Call with "Custom Script: Stun_SetStun(udg_your_unit, udg_your_duration)"
Here is the code:
JASS:
library Stun initializer DeclareCache
globals
private gamecache gc
endglobals
private function H2I takes handle h returns integer
return h
return 0
endfunction
private function DeclareCache takes nothing returns nothing
set gc = InitGameCache("cstun.w3v")
endfunction
private struct Data
effect fx = null
integer i = 0
unit u = null
method onDestroy takes nothing returns nothing
call DestroyEffect(this.fx)
call PauseUnit(this.u, false)
call FlushStoredInteger(gc, I2S(H2I(this.u)), SCOPE_PRIVATE+"Data")
endmethod
endstruct
private constant function StunFX takes nothing returns string
//You won't need/want to change this.
return "Abilities\\Spells\\Human\\Thunderclap\\ThunderclapTarget.mdl"
endfunction
private constant function StunFXAttach takes nothing returns string
//You won't need/want to change this.
return "overhead"
endfunction
private function StunTimerExpire takes nothing returns nothing
local timer t = GetExpiredTimer()
local Data dat = GetStoredInteger(gc, I2S(H2I(t)), SCOPE_PRIVATE+"Data")
set dat.i = dat.i-1
if (dat.i <= 0) then
call dat.destroy()
endif
call FlushStoredInteger(gc, I2S(H2I(t)), SCOPE_PRIVATE+"Data")
call DestroyTimer(t)
set t = null
endfunction
public function SetStun takes unit u, real d returns nothing
local Data dat = GetStoredInteger(gc, I2S(H2I(u)), SCOPE_PRIVATE+"Data")
local timer t = CreateTimer()
if (dat>0) then
set dat.i = dat.i+1
else
set dat = Data.create()
set dat.i = 1
set dat.fx = AddSpecialEffectTarget(StunFX(), u, StunFXAttach())
set dat.u = u
call StoreInteger(gc, I2S(H2I(u)), SCOPE_PRIVATE+"Data", dat)
call PauseUnit(u, true)
endif
call TimerStart(t, d, false, function StunTimerExpire)
call StoreInteger(gc, I2S(H2I(t)), SCOPE_PRIVATE+"Data", dat)
set t = null
endfunction
endlibrary