Name | Type | is_array | initial_value |
//TESH.scrollpos=-1
//TESH.alwaysfold=0
/*
For Basic attacks I needed a little trick. So I made up this trigger.
Thistrigger notices all incoming damage that is NOT caused by the system, for example basic attacks.
ATTENTION! Damage from untriggered spells will also be noticed.
Just in case:
This trigger usually doesn't need to get changed. It only captures the basic attack for the
functions "OnUnitDeath" and "OnUnitDmg" as well as for the Indicator.
*/
function Trig_Damagedetection_Actions takes nothing returns nothing
if(GetEventDamage() >= 1.) then
call OnUnitDmg(GetEventDamageSource(), GetTriggerUnit(), GetEventDamage(), DMG_Physical)
if(GetWidgetLife(GetTriggerUnit()) < GetEventDamage()) then
call OnUnitDeath(GetEventDamageSource(), GetTriggerUnit())
endif
endif
endfunction
function Trig_Damagedetection_AddUnit takes nothing returns nothing
call TriggerRegisterUnitEvent(gg_trg_System_Damagedetection, GetEnumUnit() , EVENT_UNIT_DAMAGED)
endfunction
function Trig_Damagedetection_UnitEnter takes nothing returns nothing
call TriggerRegisterUnitEvent(gg_trg_System_Damagedetection, GetTriggerUnit() , EVENT_UNIT_DAMAGED)
endfunction
function InitTrig_System_Damagedetection takes nothing returns nothing
local trigger t
local group g = CreateGroup()
set gg_trg_System_Damagedetection = CreateTrigger()
call TriggerAddAction(gg_trg_System_Damagedetection, function Trig_Damagedetection_Actions)
set t = CreateTrigger()
call TriggerRegisterEnterRectSimple(t, GetWorldBounds())
call TriggerAddAction(t, function Trig_Damagedetection_UnitEnter)
call GroupEnumUnitsInRect(g, GetWorldBounds(), null)
call ForGroup(g, function Trig_Damagedetection_AddUnit)
call DestroyGroup(g)
endfunction
//TESH.scrollpos=-1
//TESH.alwaysfold=0
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
//TESH.scrollpos=-1
//TESH.alwaysfold=0
function Trig_Trigger_TestSpellMAG_Conditions takes nothing returns boolean
local real amount = GetUnitAbilityLevel(GetTriggerUnit(), 'AHhb') * 200.
if(GetSpellAbilityId() == 'AHhb') then
if(IsPlayerAlly(GetOwningPlayer(GetSpellTargetUnit()), GetOwningPlayer(GetTriggerUnit()))) then
call OnUnitHeal(GetTriggerUnit(), GetSpellTargetUnit(), amount)
call SetWidgetLife(GetSpellTargetUnit(), GetWidgetLife(GetSpellTargetUnit()) + amount)
else
call DamageTarget(GetTriggerUnit(), GetSpellTargetUnit(), amount, DMG_Magic)
endif
endif
return false
endfunction
//===========================================================================
function InitTrig_Trigger_TestSpellMAG takes nothing returns nothing
set gg_trg_Trigger_TestSpellMAG = CreateTrigger( )
call TriggerRegisterPlayerUnitEvent(gg_trg_Trigger_TestSpellMAG, Player(0), EVENT_PLAYER_UNIT_SPELL_EFFECT, null)
call TriggerAddCondition(gg_trg_Trigger_TestSpellMAG, Condition(function Trig_Trigger_TestSpellMAG_Conditions))
endfunction
//TESH.scrollpos=-1
//TESH.alwaysfold=0
function Trig_Trigger_TestSpellPHY_Conditions takes nothing returns boolean
local real amount = GetUnitAbilityLevel(GetTriggerUnit(), 'AHtc') * 40. + 20.
local group g = CreateGroup()
local unit x
if(GetSpellAbilityId() == 'AHtc') then
call GroupEnumUnitsInRange(g, GetUnitX(GetTriggerUnit()), GetUnitY(GetTriggerUnit()), 300., null)
loop
set x = FirstOfGroup(g)
exitwhen x == null
if(IsPlayerEnemy(GetOwningPlayer(x), GetOwningPlayer(GetTriggerUnit()))) then
call DamageTarget(GetTriggerUnit(), x, amount, DMG_Physical)
endif
call GroupRemoveUnit(g, x)
endloop
call DestroyGroup(g)
endif
return false
endfunction
//===========================================================================
function InitTrig_Trigger_TestSpellPHY takes nothing returns nothing
set gg_trg_Trigger_TestSpellPHY = CreateTrigger( )
call TriggerRegisterPlayerUnitEvent(gg_trg_Trigger_TestSpellPHY, Player(0), EVENT_PLAYER_UNIT_SPELL_EFFECT, null)
call TriggerAddCondition(gg_trg_Trigger_TestSpellPHY, Condition(function Trig_Trigger_TestSpellPHY_Conditions))
endfunction
//TESH.scrollpos=-1
//TESH.alwaysfold=0
function Trig_Trigger_TestSpellTRU_Conditions takes nothing returns boolean
local real amount = GetUnitAbilityLevel(GetTriggerUnit(), 'AOws') * 25.
local group g = CreateGroup()
local unit x
if(GetSpellAbilityId() == 'AOws') then
call GroupEnumUnitsInRange(g, GetUnitX(GetTriggerUnit()), GetUnitY(GetTriggerUnit()), 300., null)
loop
set x = FirstOfGroup(g)
exitwhen x == null
if(IsPlayerEnemy(GetOwningPlayer(x), GetOwningPlayer(GetTriggerUnit()))) then
call DamageTarget(GetTriggerUnit(), x, amount, DMG_True)
endif
call GroupRemoveUnit(g, x)
endloop
call DestroyGroup(g)
endif
return false
endfunction
//===========================================================================
function InitTrig_Trigger_TestSpellTRU takes nothing returns nothing
set gg_trg_Trigger_TestSpellTRU = CreateTrigger( )
call TriggerRegisterPlayerUnitEvent(gg_trg_Trigger_TestSpellTRU, Player(0), EVENT_PLAYER_UNIT_SPELL_EFFECT, null)
call TriggerAddCondition(gg_trg_Trigger_TestSpellTRU, Condition(function Trig_Trigger_TestSpellTRU_Conditions))
endfunction