globals
hashtable Hash_dmg = InitHashtable()
endglobals
struct unitdata
real spellMultiplier
real spellDefense
static method operator [] takes unit u returns thistype
return GetUnitUserData(u)
endmethod
endstruct
... // when a unit enters the map (and the unit's user-data value is 0)
call SetUnitUserData(GetTriggerUnit(), unitdata.create())
set unitdata[GetTriggerUnit()].spellDefense= 0.1 // 10%
set unitdata[GetTriggerUnit()].spellMultiplier = 0.2 // 20%
...
Well its not in a library, I want it to be accessible by all libraries and functions since i'll be referring to it in multiple aspects of the game
EDIT - Units have custom stats in my map (magic: increases damage done by spells, magic defense: decreases damage taken from spells, etc.). So what i'm trying to do is build a function that I can send a casting unit, target unit, and real damage amount to and it will factor in the casting units magic and the targeted units magic defense and any other factors that need to be calculated and then deal the end-amount of damage to the targeted unit.
So i'm creating a hashtable that will allow me to save each units magic/magic defense to their ID. I need to be able to access the data in the hashtable in the damage function i'm trying to make as well as modify the data in the hashtable during the course of certain abilities and as a result of gear and/or items that give magic/magic defense bonuses.
So the hashtable needs to be universal - if that made any sense at all (i hope)?
function CasterDamageTarget takes unit caster, unit target, real damage returns nothing
local real bonusDamage = damage * unitdata[caster].spellMultiplier
local real negDamage = damage * unitdata[target].spellDefense
call UnitDamageTarget(caster, target, damage+bonusDamage-negDamage, false, false, /*
*/ ATTACK_TYPE_SPELL, DAMAGE_TYPE_NORMAL, null)
endfunction
GetUnitUserData / SetUnitUserData
natives.GetHandleId
.GetHandleId
by GetHandleId(null)
(I think the constant is 0x100008 or 0x100000.GetUnitUserData / SetUnitUserData
- I believe however that this is one of the fastest ways of storing integer data to a unit.