library Damagesystem
/*
Damagesystem v1.0 by Crixx
This system provides possibilities to add your own damagetypes. For example your spell can ignore
armor or can be reduced through resistence.
Beforehand:
Remember to disable the exp-gain for every hero on the map as well as the "gives gold" - flag from
neutral monsters. If you don't do this, heros will gain extra exp and you will get more gold for
a kill with basic attacks.
Also this system is only working with triggered spells. You just need to add the "DamageTarget"
line in your code.
Changeable Features:
-every Constant - variable can be edited(gold- and exp-gain as well as the damagetypes)
-you can change the effects if a unit gets damage(standard is a little blood)
or gets healed(standard is the effect from vapiric aura)
-you can edit what is happening when a unit gets damaged, healed or when a unit dies
Pros and Cons:
Pros:
-great variety of damagetypes for example fireattack or siege and such
-the function "OnUnitDeath" offers space for code, so no extra trigger is needed for "A Unit Dies"
-the function "OnUnitDamage" offer space for code, so you can realize things like fire buff, which
burn the enemy hit
-you can easily adjust gold- and exp-gain
-no leaks
Cons:
-only works with triggered spells
-with a big army the numbers are a bit annoying during battle
So, I hope it's useful for you and if you find some more Cons or Pros or a leak, a bug, whatever,
contact me.
E-mail: [email protected]
Hiveworkshop: Crixx
*/
globals
// Feel free to add some
constant integer DMG_Physical = 0
constant integer DMG_Magic = 1
constant integer DMG_True = 2
// Change this to your needs
constant integer CONSTANT_UNIT_Gold = 7 // Base Gold that a unit gives
constant integer CONSTANT_UNIT_Gold_Variance = 3 // Base Gold +- this is the gold you acquire
constant integer CONSTANT_UNIT_EXP_Per_LvL = 5 // EXP per Unitlevel
constant integer CONSTANT_HERO_Gold = 50 // Same as for normal units just for heros
constant integer CONSTANT_HERO_Gold_Variance = 10 // -"-
constant integer CONSTANT_HERO_EXP_Per_LvL = 25 // -"-
endglobals
// Feel free to add code to "OnUnitDmg" and "OnUnitDeath"
function OnUnitDmg takes unit source, unit target, real damage, integer dmgtype returns nothing
local real x
local real y
local texttag t = CreateTextTag()
// Just a little Blood-Effect
if(IsUnitType(GetTriggerUnit(), UNIT_TYPE_STRUCTURE) == false) then
call DestroyEffect( AddSpecialEffectTarget("Objects\\Spawnmodels\\Critters\\Albatross\\CritterBloodAlbatross.mdl", target, "origin") )
endif
// The Damageindicator which shows the damage you did
// First the Coords
set x = GetUnitX(target) + GetRandomReal(-25.00, 25.00)
set y = GetUnitY(target) + GetRandomReal(-25.00, 25.00)
// Now setting up the texttag
call SetTextTagText(t, I2S(R2I(damage)), .0161)
call SetTextTagPos(t, x, y, 0.)
call SetTextTagFadepoint(t, .35)
call SetTextTagLifespan(t, 2.35)
call SetTextTagVelocity(t, .05546875 * Cos(90. * bj_DEGTORAD), .05546875 * Sin(90. * bj_DEGTORAD))
call SetTextTagVisibility(t, false)
// Only showing to the involved players so you don't have 100 numbers on screen
if(GetLocalPlayer() == GetOwningPlayer(source)) then
call SetTextTagVisibility(t, true)
endif
if(GetLocalPlayer() == GetOwningPlayer(target)) then
call SetTextTagVisibility(t, true)
endif
call SetTextTagPermanent(t, false)
// Some eye-candy showing diffrent colors for the diffrent damage-types
if(dmgtype == DMG_Physical) then
call SetTextTagColor(t, 255, 0, 0, 0)
elseif(dmgtype == DMG_Magic) then
call SetTextTagColor(t, 175, 0, 175, 0)
else
call SetTextTagColor(t, 255, 255, 255, 0)
endif
// Your Code
endfunction
function OnUnitHeal takes unit source, unit target, real amount returns nothing
local real x
local real y
local texttag t = CreateTextTag()
// Just a little Heal-Effect
if(IsUnitType(GetTriggerUnit(), UNIT_TYPE_STRUCTURE) == false) then
call DestroyEffect( AddSpecialEffectTarget("Abilities\\Spells\\Undead\\VampiricAura\\VampiricAuraTarget.mdl", target, "origin") )
endif
// The Healindicator which shows the amount you healed
// First the Coords
set x = GetUnitX(target) + GetRandomReal(-25.00, 25.00)
set y = GetUnitY(target) + GetRandomReal(-25.00, 25.00)
// Setting up the texttag... again
call SetTextTagText(t, I2S(R2I(amount)), .0161)
call SetTextTagPos(t, x, y, 0.)
call SetTextTagFadepoint(t, .35)
call SetTextTagLifespan(t, 2.35)
call SetTextTagVelocity(t, .05546875 * Cos(90. * bj_DEGTORAD), .05546875 * Sin(90. * bj_DEGTORAD))
call SetTextTagVisibility(t, false)
// Only showing to the involved players so you don't have 100 numbers on screen
if(GetLocalPlayer() == GetOwningPlayer(source)) then
call SetTextTagVisibility(t, true)
endif
if(GetLocalPlayer() == GetOwningPlayer(target)) then
call SetTextTagVisibility(t, true)
endif
call SetTextTagPermanent(t, false)
call SetTextTagColor(t, 0, 255, 0, 0)
// Your Code
endfunction
function OnUnitDeath takes unit killer, unit dying returns nothing
local real x = GetUnitX(dying) + GetRandomReal(-25.00, 25.00)
local real y = GetUnitY(dying) + GetRandomReal(-25.00, 25.00)
local integer gold
local integer exp
local texttag t = CreateTextTag()
// Set the gold- and exp-values dependent on the type
if(IsUnitType(dying, UNIT_TYPE_HERO)) then
set gold = GetHeroLevel(dying) * CONSTANT_HERO_Gold + GetRandomInt(-1 * CONSTANT_HERO_Gold_Variance, CONSTANT_HERO_Gold_Variance)
set exp = GetHeroLevel(dying) * CONSTANT_HERO_EXP_Per_LvL
else
set gold = GetUnitLevel(dying) * CONSTANT_UNIT_Gold + GetRandomInt(-1 * CONSTANT_UNIT_Gold_Variance, CONSTANT_UNIT_Gold_Variance)
set exp = GetUnitLevel(dying) * CONSTANT_UNIT_EXP_Per_LvL
endif
// Setting up the texttag.... the 3rd time now :)
call SetTextTagText(t, "+" + I2S(gold) + "G", .023)
call SetTextTagPos(t, x, y, 0.)
call SetTextTagFadepoint(t, .35)
call SetTextTagLifespan(t, 2.35)
call SetTextTagVelocity(t, .05546875 * Cos(90. * bj_DEGTORAD), .05546875 * Sin(90. * bj_DEGTORAD))
call SetTextTagVisibility(t, false)
call SetTextTagColor(t, 255, 204, 0, 0)
call SetTextTagPermanent(t, false)
if(GetLocalPlayer() == GetOwningPlayer(killer)) then
call SetTextTagVisibility(t, true)
endif
// Give EXP and gold to the killer
call AddHeroXP(killer, exp, true)
call SetPlayerState(GetOwningPlayer(killer), PLAYER_STATE_RESOURCE_GOLD, GetPlayerState(GetOwningPlayer(killer), PLAYER_STATE_RESOURCE_GOLD) + gold)
// Your Code
endfunction
// "GetArmor" should remain like this until you change the armor-system of the game
private function GetArmor takes unit u returns real
local real life = GetWidgetLife(u)
local real red
call SetWidgetLife(u, 20.)
call UnitDamageTarget(u, u, 10., true, false, ATTACK_TYPE_NORMAL, DAMAGE_TYPE_NORMAL, null)
set red = (GetWidgetLife(u) - 10.) / 10.
call SetWidgetLife(u, life)
if(red > 1.) then
return 1.
else
return red
endif
endfunction
private function GetResistence takes unit u returns real
// Change this to your needs
return ((GetUnitLevel(u) - 1) * (15.08 - Pow(1.2, GetUnitLevel(u)))) / 100
endfunction
// Change "DamageTarget" in case you added some DMG_*** - types
function DamageTarget takes unit source,unit target,real damage,integer dmgtype returns real
local integer p = GetPlayerId(GetOwningPlayer(source))
local real life = GetWidgetLife(target)
local real red = 0.
local real realdmg = 0.
local integer i = 0
// Dead ones cannot get damage or deal damage
if(life < .405 or GetWidgetLife(source) < .405) then
return 0.
endif
// Decide whether armor or resistence is needed to be calculated
if(dmgtype == DMG_Physical) then
set red = GetArmor(target)
set realdmg = damage * (1 - red)
elseif(dmgtype == DMG_Magic) then
set red = GetResistence(target)
set realdmg = damage * (1 - red)
else
set realdmg = damage
endif
// less than 1 dmg is nothing
if(realdmg < 1.) then
return 0.
endif
// Decide whether it kills the target or not
if(life <= realdmg) then
call KillUnit(target)
call OnUnitDmg(source, target, realdmg, dmgtype)
call OnUnitDeath(source, target)
else
call SetWidgetLife(target, life - realdmg)
call OnUnitDmg(source, target, realdmg, dmgtype)
// Wake up sleeping creeps
if(UnitIsSleeping(target)) then
call UnitWakeUp(target)
call IssueTargetOrder(target, "attack", source)
endif
endif
return realdmg
endfunction
endlibrary