function H2I takes handle h returns integer
return h
return 0
endfunction function I2U takes integer i returns unit
return i
return null
endfunction
function StoreObject takes handle h, string key, integer val returns nothing
call StoreInteger(udg_cache, I2S(H2I(h)), key, val)
endfunction
function StoreRealH takes handle h, string key, real val returns nothing
call StoreReal(udg_cache, I2S(H2I(h)), key, val)
endfunction
function RestoreObject takes handle h, string key returns integer
return GetStoredInteger(udg_cache, I2S(H2I(h)), key)
endfunction
function RestoreReal takes handle h, string key returns real
return GetStoredReal(udg_cache, I2S(H2I(h)), key)
endfunction
function ReleaseObject takes handle h returns nothing
call FlushStoredMission(udg_cache, I2S(H2I(h)))
endfunction
function CalcExp takes nothing returns nothing
local trigger t=GetTriggeringTrigger()
local unit attacked = I2U(RestoreObject(t,"u1"))
local real HP=RestoreReal(t,"r")
local unit u=I2U(RestoreObject(t,"u2"))
set udg_schot[1] =udg_schot[1]+HP-GetUnitStateSwap(UNIT_STATE_LIFE, attacked)
call ReleaseObject(t)
call DestroyTrigger(t)
set t=null
set attacked=null
set u=null
endfunction
function InitCalc takes nothing returns nothing
local unit attacked = GetAttackedUnitBJ()
local real HP=GetUnitStateSwap(UNIT_STATE_LIFE, attacked)
local unit u=GetAttacker()
local trigger t=CreateTrigger()
call TriggerRegisterUnitLifeEvent( t, attacked, LESS_THAN, HP )
call TriggerAddAction(t, function CalcExp )
call StoreObject(t,"u1",H2I(attacked))
call StoreRealH(t,"r",HP)
call StoreObject(t,"u2",H2I(u))
set attacked=null
set u=null
set t=null
endfunction
function Trig_Expirience_Actions takes nothing returns nothing
endfunction
//===========================================================================
function InitTrig_Expirience takes nothing returns nothing
set gg_trg_Expirience = CreateTrigger( )
call TriggerRegisterPlayerUnitEventSimple( gg_trg_Expirience, Player(PLAYER_NEUTRAL_AGGRESSIVE), EVENT_PLAYER_UNIT_ATTACKED )//Тут ставишь игрока, юнит которого должен быть атакован вместо PLAYER_NEUTRAL_AGGRESSIVE
call TriggerAddAction( gg_trg_Expirience, function InitCalc )
endfunction