//(Don't copy last 2 lines)
//If your wanted spell needs the Handle Variables functions, select the contents of this
// trigger starting with the //************** and finishing with the last enfunction, and copy that
// TO YOUR MAP's CUSTOM SCRIPT SECTION, (it is at the top of the trigger list in the trigger editor) ,
// it MAY WON'T WORK if you just copy this trigger to your map
//
//*********************************************************************************************
//*
//* Handle Variables
//*
//*********************************************************************************************
//=============================================================================================
// Return Bug Exploiters
//=============================================================================================
function HandleVars_GetInt takes handle h returns integer
return h
return 0
endfunction
//=============================================================================================
function LocalVars takes nothing returns gamecache
return InitGameCache("jasslocalvars.w3v")
endfunction
function SetHandleHandle takes handle subject, string name, handle value returns nothing
if value==null then
call FlushStoredInteger(LocalVars(),I2S(HandleVars_GetInt(subject)),name)
else
call StoreInteger(LocalVars(), I2S(HandleVars_GetInt(subject)), name, HandleVars_GetInt(value) )
endif
endfunction
function SetHandleInt takes handle subject, string name, integer value returns nothing
if value==0 then
call FlushStoredInteger(LocalVars(),I2S(HandleVars_GetInt(subject)),name)
else
call StoreInteger(LocalVars(), I2S(HandleVars_GetInt(subject)), name, value)
endif
endfunction
function SetHandleReal takes handle subject, string name, real value returns nothing
if value==0 then
call FlushStoredReal(LocalVars(), I2S(HandleVars_GetInt(subject)), name)
else
call StoreReal(LocalVars(), I2S(HandleVars_GetInt(subject)), name, value)
endif
endfunction
function GetHandleHandle takes handle subject, string name returns handle
return GetStoredInteger(LocalVars(), I2S(HandleVars_GetInt(subject)), name)
return null
endfunction
function GetHandleInt takes handle subject, string name returns integer
return GetStoredInteger(LocalVars(), I2S(HandleVars_GetInt(subject)), name)
endfunction
function GetHandleReal takes handle subject, string name returns real
return GetStoredReal(LocalVars(), I2S(HandleVars_GetInt(subject)), name)
endfunction
function FlushHandleLocals takes handle subject returns nothing
call FlushStoredMission(LocalVars(), I2S(HandleVars_GetInt(subject)) )
endfunction
Name | Type | is_array | initial_value |
FloatyGeneralText | texttag | Yes | |
FloatyVespinMenge | texttag | Yes | |
Mineral1 | real | No | 1500.00 |
PAY | integer | No | 0 |
RACE | dialog | Yes | |
TERRDIA1 | button | Yes | |
TOSSDIA1 | button | Yes | |
Vespin | unit | Yes | |
VespinInteger | integer | Yes | |
ZERGADIA1 | button | Yes | |
Zergling | group | No |
//***************************************************************************************************
//* *
//* Passive Mana Shield (Unit) *
//* *
//* Requires: *
//* - The Handle Variables Functions (See this map Custom Script Section) *
//* - The Passive Mana Shield Ability *
//* - This Trigger (make sure the Configuration Section is pointing *
//* to the right ability rawcodes) *
//* *
//* Note: The spell's target art can be changed with the object editor *
//* *
//***************************************************************************************************
//===================================================================================================
// Passive Mana Shield Spell Configuration:
//
constant function UnitPermanentManaShield_AbilityId takes nothing returns integer
return 'A001' //// The ability's Rawcode (chages between maps)
endfunction
constant function UnitPermanentManaShield_MaxHP takes integer level returns real
return 0.00+level*0.00 //// Mana shield won't work if the unit has more hitpoints than this,
//// leave 0.00 here if you want manashield to always work
endfunction
constant function UnitPermanentManaShield_BufferMana takes integer level returns real
return 0.00+level*0.00 //// Mana shield won't work if the hero has less mana than this value
endfunction
constant function UnitPermanentManaShield_HPperMana takes integer level returns real
return 0.00+level*1.00 //// How much HP is blocked per mana point
endfunction
//===================================================================================================
function SetLifeDelayed_GetUnit takes timer t returns widget
return GetHandleHandle(t, "u")
endfunction
function SetLifeDelayed_child takes nothing returns nothing
local timer t=GetExpiredTimer()
call SetWidgetLife( SetLifeDelayed_GetUnit(t), GetHandleReal( t, "life"))
call FlushHandleLocals(t)
call DestroyTimer(t)
set t=null
endfunction
function SetLifeDelayed takes widget u, real life returns nothing
local timer t=CreateTimer()
call SetHandleHandle( t, "u", u)
call SetHandleReal( t, "life", life)
call TimerStart( t, 0, false, function SetLifeDelayed_child)
endfunction
function UnitPermanentManaShield_GetActions takes trigger t returns triggeraction
return GetHandleHandle( t, "actions")
endfunction
function Trig_UnitPermanentManaShield_BlockDamage takes nothing returns nothing
local unit u=GetTriggerUnit()
local real a
local integer l=GetUnitAbilityLevel(u, UnitPermanentManaShield_AbilityId() )
if GetTriggerEventId() == EVENT_UNIT_DEATH then
// This is to avoid trigger/event leaks, each unit has a trigger for it, and if a unit dies
// I'll have to wait till it is removed, (a good way to know that a unit no longer exists
// Is checking its Maximum life ), I could just destroy trigger once the unit dies, but
// Spells like ressurection would mess this.
loop
if GetUnitState( u, UNIT_STATE_MAX_LIFE) == 0 then
call TriggerRemoveAction( GetTriggeringTrigger(), UnitPermanentManaShield_GetActions(GetTriggeringTrigger()) )
call DestroyTrigger( GetTriggeringTrigger() )
set u=null
return
endif
call TriggerSleepAction(5)
exitwhen GetWidgetLife(u) > 0
endloop
elseif l <= 0 then
call DestroyTrigger( GetTriggeringTrigger())
else
if UnitPermanentManaShield_MaxHP(l) != 0 then
set a=RMinBJ( UnitPermanentManaShield_MaxHP(l)-( GetWidgetLife(u) - GetEventDamage() ), ( GetUnitState(u,UNIT_STATE_MANA) - UnitPermanentManaShield_BufferMana(l) )* UnitPermanentManaShield_HPperMana(l))
else
set a=RMinBJ( GetEventDamage(),( GetUnitState(u,UNIT_STATE_MANA) - UnitPermanentManaShield_BufferMana(l) )* UnitPermanentManaShield_HPperMana(l) )
endif
if a>0 then
call SetUnitManaBJ( u, GetUnitState(u,UNIT_STATE_MANA) - a/UnitPermanentManaShield_HPperMana(l))
call SetLifeDelayed( u, (GetWidgetLife(u)-GetEventDamage())+a )
if GetUnitState(u,UNIT_STATE_MANA) >= UnitPermanentManaShield_BufferMana(l)+1 then
call DestroyEffect( AddSpellEffectTargetById( UnitPermanentManaShield_AbilityId(), EFFECT_TYPE_TARGET, u, "chest" ) )
endif
endif
endif
set u=null
endfunction
function UnitPermanentManaShield_Start takes unit u returns nothing
local trigger dmg=CreateTrigger()
call TriggerRegisterUnitEvent( dmg, u, EVENT_UNIT_DAMAGED )
call TriggerRegisterUnitEvent( dmg, u, EVENT_UNIT_DEATH )
call SetHandleHandle( dmg, "actions", TriggerAddAction( dmg, function Trig_UnitPermanentManaShield_BlockDamage ) )
set u=null
set dmg=null
endfunction
function Trig_UnitPermanentManaShield_Actions takes nothing returns nothing
if GetUnitAbilityLevel( GetTriggerUnit(), UnitPermanentManaShield_AbilityId() ) > 0 then
call UnitPermanentManaShield_Start(GetTriggerUnit() )
endif
endfunction
//===================================================================================================
function UnitPermanentManaShield_Filter takes nothing returns boolean
if GetUnitAbilityLevel( GetFilterUnit() , UnitPermanentManaShield_AbilityId() ) >0 then
call UnitPermanentManaShield_Start( GetFilterUnit() )
endif
return false
endfunction
function Trig_UnitPermanentManaShield_InitEnum takes nothing returns nothing
local group g=CreateGroup()
local unit picked=null
local boolexpr b=Condition( function UnitPermanentManaShield_Filter )
call GroupEnumUnitsInRect(g, GetPlayableMapRect(), b )
call DestroyGroup(g)
call DestroyBoolExpr(b)
set g=null
set b=null
set picked=null
endfunction
function InitTrig_UnitPermanent_Mana_Shield takes nothing returns nothing
set gg_trg_UnitPermanent_Mana_Shield = CreateTrigger( )
call TriggerAddAction( gg_trg_UnitPermanent_Mana_Shield, function Trig_UnitPermanentManaShield_InitEnum )
call TriggerExecute(gg_trg_UnitPermanent_Mana_Shield)
call DestroyTrigger( gg_trg_UnitPermanent_Mana_Shield )
set gg_trg_UnitPermanent_Mana_Shield = CreateTrigger( )
call TriggerRegisterEnterRectSimple( gg_trg_UnitPermanent_Mana_Shield, GetPlayableMapRect() )
call TriggerAddAction( gg_trg_UnitPermanent_Mana_Shield, function Trig_UnitPermanentManaShield_Actions )
endfunction