JASS:
//////////////////////////////////////////////////////////////////////////////////////
// GetDamage Function //
// call GetDamage(casting unit, targeted unit, median damage, "magic type") //
// //
// GetHeal Function //
// call GetHeal(casting unit, targeted unit, median heal amount, "magic type") //
// //
// GetDamageText Function //
// call GetDamageText(targeted unit, amount, crit? (t/f), type ("damage"/"heal") //
// //
// GetImmuneText Function //
// call GetImmuneText(targeted unit) //
// //
// GetCritical Function //
// call GetCritical(casting unit) //
//////////////////////////////////////////////////////////////////////////////////////
globals
hashtable Hash_dmg = InitHashtable()
endglobals
function GetImmuneText takes unit target returns nothing
local texttag immunetxt
set immunetxt = CreateTextTag()
call SetTextTagPermanent(immunetxt, false)
call SetTextTagVisibility(immunetxt, true)
call SetTextTagPosUnit(immunetxt, target, 0)
call SetTextTagText(immunetxt, "immune", .023)
call SetTextTagFadepoint(immunetxt, 1)
call SetTextTagLifespan(immunetxt, 1.5)
call SetTextTagVelocity(immunetxt, 0, .05)
call SetTextTagColor(immunetxt, 255, 255, 255, 255)
endfunction
function GetDamageText takes unit target, real dmg, boolean critical, string runtype returns nothing
local texttag dmgtxt
local real txtsize
local string txtcolor
local string txtoutput
set dmgtxt = CreateTextTag()
//changes text color depending on whether it's a damage or heal
if runtype == "damage" then
set txtcolor = "|cffCD0000"
elseif runtype == "heal" then
set txtcolor = "|cff00CD00"
endif
//increases text size and adds and exclamation mark if it's a crit
if critical == false then
set txtsize = .023
set txtoutput = (txtcolor + I2S(R2I(dmg)) + "|r")
else
set txtsize = .03
set txtoutput = (txtcolor + I2S(R2I(dmg)) + "!|r")
endif
//applies the necessary texttag properties
call SetTextTagPermanent(dmgtxt, false)
call SetTextTagVisibility(dmgtxt, true)
call SetTextTagPosUnit(dmgtxt, target, 0)
call SetTextTagText(dmgtxt, txtoutput, txtsize)
call SetTextTagFadepoint(dmgtxt, 1)
call SetTextTagLifespan(dmgtxt, 1.5)
call SetTextTagVelocity(dmgtxt, 0, .05)
call SetTextTagColor(dmgtxt, 255, 255, 255, 255)
endfunction
function GetCritical takes unit caster returns boolean
//function rolls to see if the casting unit gets a crit
local integer random = GetRandomInt(1, 100)
if random <= LoadRealBJ(3, GetHandleIdBJ(caster), Hash_dmg) then
return true
else
return false
endif
endfunction
function GetDamage takes unit caster, unit target, real dmg, string magictype returns nothing
local boolean critical
//Converts the median damage to a -10% to +10% range (i.e. 100 becomes 90-110)
set dmg = GetRandomReal((dmg - (dmg * .1)), (dmg + (dmg * .1)))
//Grabs the casting units black/white magic bonus depending on what the damage type is
if magictype == "Black" then
set dmg = dmg + LoadRealBJ(1, GetHandleIdBJ(caster), Hash_dmg)
elseif magictype == "White" then
set dmg = dmg + LoadRealBJ(2, GetHandleIdBJ(caster), Hash_dmg)
endif
//Rolls to see if a crit occurs (dependant upon casting units magic crit %)
set critical = GetCritical(caster)
if critical == true then
set dmg = dmg * 1.5
endif
//Grabs the targeted units magic defense and calculates that into the total damage (also calls the floating text function)
if dmg > LoadRealBJ(4, GetHandleIdBJ(target), Hash_dmg) then
set dmg = dmg - LoadRealBJ(4, GetHandleIdBJ(target), Hash_dmg)
call GetDamageText(target, dmg, critical, "damage")
else
call GetImmuneText(target)
endif
//Deals the damage
call UnitDamageTarget(caster, target, dmg, false, false, ATTACK_TYPE_NORMAL, DAMAGE_TYPE_NORMAL, WEAPON_TYPE_WHOKNOWS)
endfunction
function GetHeal takes unit caster, unit target, real amount, string magictype returns nothing
local boolean critical
//Converts the median amount to a -10% to +10% range (i.e. 100 becomes 90-110)
set amount = GetRandomReal((amount - (amount * .1)), (amount + (amount * .1)))
//Grabs the casting units black/white magic bonus depending on what the heal type is
if magictype == "Black" then
set amount = amount + LoadRealBJ(1, GetHandleIdBJ(caster), Hash_dmg)
elseif magictype == "White" then
set amount = amount + LoadRealBJ(2, GetHandleIdBJ(caster), Hash_dmg)
endif
//Rolls to see if a crit occurs (dependant upon casting units magic crit %)
set critical = GetCritical(caster)
if critical == true then
set amount = amount * 1.5
endif
//calls the floating text function and then increases the unit's health for whatever the heal amount was
call GetDamageText(target, amount, critical, "heal")
call SetUnitState(target, UNIT_STATE_LIFE, (GetUnitState(target, UNIT_STATE_LIFE) + amount))
endfunction
I'm trying to put the above into a library, but I keep getting a ton of errors when I try to do it. All i'm doing is writing
JASS:
library abilities
JASS:
endlibrary
Also, and this may be my problem as well, do libraries require an initializer? I am accessing one of the functions in this library with a call statement and the rest of the functions are internal and are only used by the called function.