- Joined
- Oct 12, 2008
- Messages
- 1,570
Hello people,,
I have seen people whining about: 'Damage detection, but you cant remove any events so it might bug after some time'
So i thought, why not make a trigger for every unit then? And destroy that trigger when the unit leaves?
This is the code i made, i would like you guys to look at it and tell me all stupid mistakes i made and if it would be usefull, and if it would even work!
Thanks!
I have seen people whining about: 'Damage detection, but you cant remove any events so it might bug after some time'
So i thought, why not make a trigger for every unit then? And destroy that trigger when the unit leaves?
This is the code i made, i would like you guys to look at it and tell me all stupid mistakes i made and if it would be usefull, and if it would even work!
JASS:
library DamageDetection Initializer Init
struct Data
trigger t
static method onDestroy takes nothing returns nothing
set .t = null
static method Enter takes nothing returns nothing
local Data dat = Data.allocate()
local unit u = GetTriggerUnit()
set dat.t = CreateTrigger()
call SetUnitUserData(u, dat)
call TriggerRegisterUnitEvent(dat.t, u, EVENT_UNIT_DAMAGED)
call TriggerAddAction(dat.t , Damage())
set u = null
endmethod
static method Leave takes nothing returns nothing
local unit u = GetTriggerUnit()
local Data dat = GetUnitUserData(u)
call DestroyTrigger(dat.t)
call dat.destroy()
set u = null
endmethod
private function Damage takes nothing returns nothing
local unit u = GetTriggerUnit()
local player p = GetOwningPlayer(u)
DisplayTextToPlayer(p, GetUnitName(u) + " has taken Damage")
set u = null
set p = null
private function Init takes nothing returns nothing
local trigger t1 = CreateTrigger()
local trigger t2 = CreateTrigger()
local region rr = CreateRegion()
local integer index = 0
call RegionAddRect(rr, bj_mapInitialPlayableArea)
loop
call TriggerRegisterEnterRegion(t1, rr, null)
call TriggerRegisterLeaveRegion(t2, rr, null)
set index = index + 1
exitwhen index == bj_MAX_PLAYER_SLOTS
endloop
call TriggerAddAction(t1, function Data.Enter)
call TriggerAddAction(t2, function Data.Leave)
set t1 = null
set t2 = null
set rr = null
endfunction
endstruct
endlibrary
Thanks!