Name | Type | is_array | initial_value |
//TESH.scrollpos=0
//TESH.alwaysfold=0
scope initunits initializer init
private function createunits takes nothing returns nothing
local integer i = 0
local unit dummy = null
loop
exitwhen i == 4
set dummy = CreateUnit(Player(0), 'hfoo', 20.00, 20.00, 0.00)
call DamageReduction.create(dummy, .5, .5)
set i = i + 1
endloop
//Init the Item
call ItemTable.create( 'rde1', .1, .1)
//Add the hero...
call DamageReduction.create(gg_unit_Emns_0000, 0.00, 0.00)
call DamageReduction.create(gg_unit_Emns_0003, 0.00, 0.00)
endfunction
private function init takes nothing returns nothing
call TimerStart(CreateTimer(), 1.00, false, function createunits)
endfunction
endscope
//TESH.scrollpos=48
//TESH.alwaysfold=0
//This is a custom Damage Reduction system that provides easy setting and changing of
//a unit's damage reduction and spell reduction by just using some function calls
//No object data needed to be created in the Object editor
//This system is useful for maps that will be having a custom damage system
//////////////////////////////////////////////////////////////////////////////
//--------------HOW TO USE--------------------------------------------------//
//--------------HOW TO INITIALIZE-------------------------------------------//
//First you need to initialize each unit that will use this system using //
// //
//DamageReduction.create(unit target, real damagered, real spellred) //
// //
//unit target = unit to be initialized //
// //
//real damagered = damage reduction value //
// //
//real spellred = spell reduction value //
// //
//-------------HOW TO GET VALUES--------------------------------------------//
// //
//To get the value of spell or damage reduction just use these 2 functions: //
// //
//DamageReduction.GetDamageReduction(unit u) //
// //
//DamageReduction.GetSpellReduction(unit u) //
// //
//-------------HOW TO MODIFY VALUES IN-GAME---------------------------------//
// //
//To modify values in-game just use these 2 functions: //
// //
//DamageReduction.AddSpellReduction(unit target, real value, boolean add) //
// //
//DamageReduction.AddDamageReduction(unit target, real value, boolean add) //
// //
//unit target is the unit whose reduction value you want to change //
// //
//real value is the value of reduction to be used //
// //
//boolean add if true will add real value to the current reduction //
// //
//while if false will set reduction to real value //
// //
//NOTE: these two functions returns the new reduction values so if you need //
//to use those right away, you can directly use these function rather than //
//using the Add function and then using the Get functions afterwards //
// //
//------------REMOVING INSTANCES--------------------------------------------//
// //
//The system already checks every UPDATE_TIME interval for instances that //
// //
//are already unused due to the unit being dead and destroys that instance //
// //
//automatically. //
// //
//You can destroy an instance directly by using //
//DamageReduction.Clear(unit u) //
//////////////////////////////////////////////////////////////////////////////
library DamageReductionTable
//Version 1.1c
//By: Adiktuz
globals
private constant real UPDATE_TIME = 1.00
//This is the timer interval between the system's check for dead units to remove their instances
private integer array DRI
private integer TOTAL = 0
private timer DRT_TIMER = CreateTimer()
endglobals
struct DamageReduction
real DAMAGE_REDUCTION
real SPELL_REDUCTION
unit u
static thistype data
//Used by the methods in this system to translate the unit parameter
//into its struct instance
static method GetInstance takes unit target returns thistype
local integer i = 0
loop
exitwhen i == TOTAL
set data = DRI[i]
if target == data.u then
set i = TOTAL
else
set i = i + 1
set data = 0
endif
endloop
return data
endmethod
//Methods for Getting and setting reduction data
static method GetDamageReduction takes unit u returns real
return data.GetInstance(u).DAMAGE_REDUCTION
endmethod
static method GetSpellReduction takes unit u returns real
return data.GetInstance(u).SPELL_REDUCTION
endmethod
static method AddSpellReduction takes unit target, real value ,boolean add returns real
set data = DamageReduction.GetInstance(target)
if add then
set data.SPELL_REDUCTION = data.SPELL_REDUCTION + value
else
set data.SPELL_REDUCTION = value
endif
return data.SPELL_REDUCTION
endmethod
static method AddDamageReduction takes unit target, real value ,boolean add returns real
set data = DamageReduction.GetInstance(target)
if add then
set data.DAMAGE_REDUCTION = data.DAMAGE_REDUCTION + value
else
set data.DAMAGE_REDUCTION = value
endif
return data.DAMAGE_REDUCTION
endmethod
//Method for clearing a unit's instance immediately
static method Clear takes unit u returns nothing
local integer i = 0
set data = DamageReduction.GetInstance(u)
loop
exitwhen i == TOTAL
if data == DRI[i] then
set TOTAL = TOTAL - 1
set DRI[i] = DRI[TOTAL]
set i = TOTAL
call data.destroy()
else
set i = i + 1
endif
endloop
endmethod
//This method scans for instanced units that are already dead
//and destroy's their instance
static method update takes nothing returns nothing
local integer i = 0
loop
exitwhen i == TOTAL
set data = DRI[i]
if data.u == null or GetWidgetLife(data.u) < .405 then
set TOTAL = TOTAL - 1
set DRI[i] = DRI[TOTAL]
set i = i - 1
call data.destroy()
endif
set i = i + 1
endloop
if TOTAL == 0 then
call PauseTimer(DRT_TIMER)
endif
endmethod
//This method is used to initialize each unit for the system
static method create takes unit target, real damagered, real spellred returns thistype
set data = DamageReduction.allocate()
set data.DAMAGE_REDUCTION = damagered
set data.SPELL_REDUCTION = spellred
set data.u = target
set DRI[TOTAL] = data
if TOTAL == 0 then
call TimerStart(DRT_TIMER, UPDATE_TIME, true, function DamageReduction.update)
endif
set TOTAL = TOTAL + 1
return data
endmethod
endstruct
endlibrary
//TESH.scrollpos=57
//TESH.alwaysfold=0
////////////////////////////////////////////////////////
//Item Init //
// //
//-A simple library that saves the armor bonus //
// of items, and automatically updates the //
// reduction values of a unit that picks/drops //
// an item. //
//----------------------------------------------------//
// //
//How To initialize items: //
// //
//call ItemTable.create(integer id, real dr, real sr //
// //
//integer id = rawcode of item //
// //
//real dr = damage reduction bonus of that item //
// //
//real sr = spell reduction bonus of that item //
// //
//----------------------------------------------------//
library ItemInit initializer init requires DamageReductionTable
globals
private integer TOTAL = 0
private integer array IT [8190]
endglobals
struct ItemTable
integer ItemId
real idr
real isr
static thistype data
static method GetInstance takes item Item returns thistype
local integer i = 0
local integer target = GetItemTypeId(Item)
loop
exitwhen i > TOTAL
set data = IT[i]
if target == data.ItemId then
set i = TOTAL + 1
else
set i = i + 1
set data = 0
endif
endloop
return data
endmethod
static method GetItemDr takes item Item returns real
return ItemTable.GetInstance(Item).idr
endmethod
static method GetItemSr takes item Item returns real
return ItemTable.GetInstance(Item).isr
endmethod
static method PickItem takes nothing returns nothing
call DamageReduction.AddDamageReduction(GetTriggerUnit(), ItemTable.GetItemDr(GetManipulatedItem()), true)
call DamageReduction.AddSpellReduction(GetTriggerUnit(), ItemTable.GetItemSr(GetManipulatedItem()), true)
endmethod
static method DropItem takes nothing returns nothing
call DamageReduction.AddDamageReduction(GetTriggerUnit(), -ItemTable.GetItemDr(GetManipulatedItem()), true)
call DamageReduction.AddSpellReduction(GetTriggerUnit(), -ItemTable.GetItemSr(GetManipulatedItem()), true)
endmethod
static method create takes integer id, real dr, real sr returns thistype
local thistype dat = .allocate()
set TOTAL = TOTAL + 1
set IT[TOTAL] = dat
set dat.ItemId = id
set dat.idr = dr
set dat.isr = sr
return dat
endmethod
endstruct
private function init takes nothing returns nothing
local integer i = 0
local trigger t = CreateTrigger()
local trigger tt = CreateTrigger()
call TriggerAddAction(t, function ItemTable.PickItem)
call TriggerAddAction(tt, function ItemTable.DropItem)
loop
exitwhen i > 15
call TriggerRegisterPlayerUnitEvent(t, Player(i), EVENT_PLAYER_UNIT_PICKUP_ITEM,null)
call TriggerRegisterPlayerUnitEvent(tt, Player(i), EVENT_PLAYER_UNIT_DROP_ITEM,null)
call TriggerRegisterPlayerUnitEvent(tt, Player(i), EVENT_PLAYER_UNIT_PAWN_ITEM,null)
set i = i + 1
endloop
endfunction
endlibrary
//TESH.scrollpos=0
//TESH.alwaysfold=0
//A simple custom damage system I created as an example on how to use the DamageReductionTable
//This system if fully functional and you can use this in your maps
library DamageSystem requires DamageReductionTable
//By: Adiktuz
globals
private real damage = 0.00
endglobals
function DamageSpell takes unit source, unit target, real amount returns real
set damage = amount*(1- DamageReduction.GetSpellReduction(target))
call UnitDamageTarget(source, target, damage, false, false, ATTACK_TYPE_CHAOS, DAMAGE_TYPE_DIVINE, null)
return damage
endfunction
function DamagePhysical takes unit source, unit target, real amount returns real
set damage = amount*(1- DamageReduction.GetDamageReduction(target))
call UnitDamageTarget(source, target, damage, false, false, ATTACK_TYPE_CHAOS, DAMAGE_TYPE_DIVINE, null)
return damage
endfunction
//This function causes full damage without considering the unit's reduction values
function DamageForce takes unit source, unit target, real amount returns real
set damage = amount
call UnitDamageTarget(source, target, damage, false, false, ATTACK_TYPE_CHAOS, DAMAGE_TYPE_DIVINE, null)
return damage
endfunction
endlibrary