| 02-20-2009, 03:04 PM | #1 |
Healing+Event
HealingEvent is for healing units nicer(only triggered), because it improves the Syntax and makes a simple one lined heal, which triggers a selfmade 'Event' called Healing-Event. It triggers only on triggered healing not in Spellcasts! Documentation inside :D Healing Event:library HealingEvent initializer init uses Table //********************************************************************************* //** //** --HEALING EVENT-- //** ~~by Seshiro //** ~v1.5(1.24b++) //** //** The healing event is a script used to simulate real healing events, as they //** would exist. //** It works similar to the DamageTarget Event, but it doesn't use //** healing-types but that could come if wanted :D //** //** The event works only with triggered-'healing' made with this script, //** because it's only for making more comfortable code! //** //** The functions: //** function GetHealingUnit takes nothing returns unit //** ~returns the Healer of the heal(whichunit) //** //** function GetHealedUnit takes nothing returns unit //** ~returns the target of the heal(target) //** //** function GetHealedLife takes nothing returns real //** ~returns the amount of the healed life(amount) //** //** function TriggerRegisterHealingEvent takes trigger t returns nothing //** ~registers a trigger to the 'healing-event' //** //** function RemoveHealingEvent takes trigger t returns nothing //** ~unregisters a trigger from the event //** //** function HealTarget takes unit whichunit, unit target, real amount returns boolean //** ~Heals the unit target by the amount of amount //** ~returns wether the heal was succesfull or not //** ~whichunit is the 'healing'-unit //** //** //** //********************************************************************************* globals private unit Healer private unit Healed private real Amount = 0 endglobals function GetHealingUnit takes nothing returns unit return Healer // Returns the Healing unit // Not possible to use GetTriggerUnit! endfunction function GetHealedUnit takes nothing returns unit return Healed // returns the Healed unit endfunction function GetHealedLife takes nothing returns real return Amount // Returns the Amonut of the healed life endfunction // This is the module which is used to simulate the healing events! // REMEMBER: The event works only with the function Healunit, not with spells, which are healing! // <!---DON'T CHANGE BELOW---!> globals private trigger array Trigs private integer N = 0 //private integer array table private HandleTable table private HandleTable Stat endglobals function TriggerRegisterHealingEvent takes trigger t returns boolean if ( (N >8190) or (Stat[t] == 1) ) then return false endif set N = N + 1 set Trigs[N] = t set Stat[t] = 1 set table[t] = N return true endfunction function RemoveHealingEvent takes trigger t returns boolean local integer i = N local integer p = table[t] local integer stat = Stat[t] if t == null then debug call BJDebugMsg(SCOPE_PREFIX+" Error: Tried to realease a null trigger") return false elseif stat == 0 then debug call BJDebugMsg(SCOPE_PREFIX+" Error: Trigger was not registered") return false elseif stat == 2 then debug call BJDebugMsg(SCOPE_PREFIX+" Error: Tried to unresgister a trigger multilpy") return false endif set Stat[t] = 2 set Trigs[p] = Trigs[N] set table[Trigs[p]] = p set N = N - 1 return true endfunction function HealTarget takes unit whichunit, unit target, real amount returns boolean local integer i = N local trigger t // This is the Healfunction if GetWidgetLife(target) > .405 and GetWidgetLife(whichunit) > .405 and (amount > 0) then call SetWidgetLife(target,GetWidgetLife(target)+amount) //~'Heals' the unit set Healer = whichunit set Healed = target set Amount = amount loop exitwhen i <= 0 set t = Trigs[i]//locals are faster than globals :) if ( (t != null) and (IsTriggerEnabled(t)) and (Stat[t] == 1) and (TriggerEvaluate(t)) ) then call TriggerExecute(t) endif set i = i - 1 endloop return true endif return false endfunction private function init takes nothing returns nothing set table = HandleTable.create() set Stat = HandleTable.create() endfunction endlibrary Here are two example spells, i dont want to create a testmap sorry :D Example spell for Healunit JASS:scope CalmingKiss initializer init globals private constant integer SpellID = 'A019' private constant string FX = "Abilities\\Spells\\Human\\DivineShield\\DivineShieldTarget.mdl" endglobals private function Calc takes unit u returns real return 20 + I2R(GetUnitAbilityLevel(u,SpellID)) * 10 endfunction private function Acts takes nothing returns nothing local unit c = GetTriggerUnit() local unit t = GetSpellAbilityUnit() call HealTarget(c,t,Calc(c)) call TimedEffect(AddSpecialEffectTarget(FX,c,"chest"),1.5) set c = null set t = null endfunction private function Conds takes nothing returns boolean call UnitRemoveAbility(GetSpellTargetUnit(),'Bmlt') return GetSpellAbilityId() == SpellID endfunction private function init takes nothing returns nothing local trigger t = CreateTrigger() call TriggerRegisterHandler(t,"SpellEffect") call TriggerAddAction(t,function Acts) call TriggerAddCondition(t,Condition(function Conds)) endfunction endscope Example spell for Healing Event JASS:scope GlisteningLights initializer init globals private constant real Range = 230. private constant integer SpellID = 'A01C' private constant real Div = 3. private constant string FX = "Abilities\\Spells\\Human\\HolyBolt\\HolyBoltSpecialArt.mdl" endglobals private function CalcD takes integer i, real r returns real return (I2R(i) * r)/2 + 25. endfunction private function FG takes nothing returns nothing call TimedEffect(AddSpecialEffectTarget(FX,GetEnumUnit(),"origin"),.5) call DamageUnitSimple(TempUnit,GetEnumUnit(),TempReal) endfunction private function Acts takes nothing returns nothing local unit c = GetHealingUnit() local unit t = GetHealedUnit() local real d = GetHealedLife()/Div local integer l = GetUnitAbilityLevel(c,SpellID) local group g = NewGroup() set TempPlayer = t:Owner set TempUnit = t set TempReal = CalcD(l,d) call GroupEnumUnitsInRange(g,t:UX,t:UY,Range,Condition(function EnemyFilter)) call ForGroup(g,function FG) call ReleaseGroup(g) set g = null set c = null set t = null endfunction private function Conds takes nothing returns boolean return GetUnitAbilityLevel(GetHealingUnit(),SpellID) > 0 endfunction private function init takes nothing returns nothing local trigger t = CreateTrigger() call TriggerRegisterHealingEvent(t) call TriggerAddCondition(t,Condition(function Conds)) call TriggerAddAction(t,function Acts) endfunction endscope In the preview Screen you can see my Paladin using Calming Kiss, which triggered Glistening Lights :) Needed is the Jasshelper found in the JNGP and it uses Table. Please Give Credits to Seshiro If there are things to improve, or to change, tell me, I will accept many forms of ctitcism! Greez |
| 02-20-2009, 05:58 PM | #2 |
Seems a bit silly, since healing is usually done on your own (via a couple lines of code) and wouldn't need to be detected (and any other time it could be detected by spell cast). However if you can explain a use that isn't already covered by basic methods of healing and spell detection, please do so. |
| 02-21-2009, 03:08 PM | #3 |
The problem is, that in many cases you don't know the healed value vià OE Healingspell, when you use this system, you can make triggered healing like 20*lvl+30+GetHeroInt(u)*5 as this wouldn't be possible with OE spells or you could make a HoT. You can create a texttag system for shownig healed values thats really cool, Im using it in my current map :D Or you could create spells which are firing on heal, like a hex, which makes the unit unhealable vià SetWidgetLife(GetHealedUnit(),GetWidgetLife(GetHealedUnit())-GetHealedAmount()) That couldn't be done as easy with OE spells! Greez |
| 02-21-2009, 03:42 PM | #4 |
I suppose that's true, but I could do all of that without a system; just making a small function called "HealUnit" that applies instant life w/ an effect. Then it can be a triggered spell, and if I want texttags I would make them directly in the spell's code. It's true this has more functionality than OE spells, but I'm not so sure this needs its own system. But I'll leave that decision to a code-god. |
| 02-24-2009, 03:42 PM | #5 |
please check if the trigger are enabled before checking conditions and call them. I would btw suggest to use Tables for the unregistered stuff. I think the current solution will break if you unregister a trigger you never registered. I think this is pretty cool. We are able to make "critical healing" ^^ |
| 02-25-2009, 05:12 AM | #6 |
I think this can be useful and interesting, so I think it can be approved, pending you fix some things and nobody else has major issues with this system. I'd like to see you change the name of the library to "HealingEvents" or something of that sort; "Healing" is a bit bland/could easily cause conflicts.
Aside from that, it actually looks pretty good. |
| 02-25-2009, 10:08 AM | #7 |
UPDATE: V1.3 I'm now not using table, but an array :) Greez |
| 02-26-2009, 10:03 PM | #8 |
So, Here is a version using table, plz tell me if this is better or not as good as the arrayed one: Table Version:library HealingEvent initializer init uses Table //********************************************************************************* //** //** --HEALING EVENT-- //** ~~by Seshiro //** ~v1.3 //** //** The healing event is a script used to simulate real healing events, as they //** would exist. //** It works similar to the DamageTarget Event, but it doesn't use //** healing-types but that could come if wanted :D //** //** The event works only with triggered-'healing' made with this script, //** because it's only for making more comfortable code! //** //** The functions: //** function GetHealingUnit takes nothing returns unit //** ~returns the Healer of the heal(whichunit) //** //** function GetHealedUnit takes nothing returns unit //** ~returns the target of the heal(target) //** //** function GetHealedLife takes nothing returns real //** ~returns the amount of the healed life(amount) //** //** function TriggerRegisterHealingEvent takes trigger t returns nothing //** ~registers a trigger to the 'healing-event' //** //** function RemoveHealingEvent takes trigger t returns nothing //** ~unregisters a trigger from the event //** //** function HealTarget takes unit whichunit, unit target, real amount returns boolean //** ~Heals the unit target by the amount of amount //** ~returns wether the heal was succesfull or not //** ~whichunit is the 'healing'-unit //** //** private function ExecuteEvent takes nothing returns nothing //** ~runs all triggers regsitered to the event //** //** //********************************************************************************* globals private unit Healer private unit Healed private real Amount = 0 endglobals function GetHealingUnit takes nothing returns unit return Healer // Returns the Healing unit // Not possible to use GetTriggerUnit! endfunction function GetHealedUnit takes nothing returns unit return Healed // returns the Healed unit endfunction function GetHealedLife takes nothing returns real return Amount // Returns the Amonut of the healed life endfunction // This is the module which is used to simulate the healing events! // REMEMBER: The event works only with the function Healunit, not with spells, which are healing! // <!---DON'T CHANGE BELOW---!> globals private trigger array Trigs private integer N = 0 //private integer array table private HandleTable table private HandleTable Stat endglobals private function H2I takes handle h returns integer return h return 0 endfunction function TriggerRegisterHealingEvent takes trigger t returns boolean if ( (N >8190) or (Stat[t] == 1) ) then return false endif set N = N + 1 set Trigs[N] = t set Stat[t] = 1 set table[t] = N return true endfunction function RemoveHealingEvent takes trigger t returns boolean local integer i = N local integer p = table[t] local integer stat = Stat[t] if t == null then debug call BJDebugMsg(SCOPE_PREFIX+" Error: Tried to realease a null trigger") return false elseif stat == 0 then debug call BJDebugMsg(SCOPE_PREFIX+" Error: Trigger was not registered") return false elseif stat == 2 then debug call BJDebugMsg(SCOPE_PREFIX+" Error: Tried to unresgister a trigger multilpy") return false endif set Stat[t] = 2 set Trigs[p] = Trigs[N] set table[Trigs[p]] = p set N = N - 1 return true endfunction function HealTarget takes unit whichunit, unit target, real amount returns boolean local integer i = N local trigger t // This is the Healfunction if GetWidgetLife(target) > .405 and GetWidgetLife(whichunit) > .405 and (amount > 0) then call SetWidgetLife(target,GetWidgetLife(target)+amount) //~'Heals' the unit set Healer = whichunit set Healed = target set Amount = amount loop exitwhen i <= 0 set t = Trigs[i]//locals are faster than globals :) if ( (t != null) and (IsTriggerEnabled(t)) and (Stat[t] == 1) and (TriggerEvaluate(t)) ) then call TriggerExecute(t) endif set i = i - 1 endloop return true endif return false endfunction private function init takes nothing returns nothing set table = HandleTable.create() set Stat = HandleTable.create() endfunction endlibrary Usage is the same, but this one is more saftey, because of the high trigger handle Ids. Greez |
| 02-26-2009, 11:37 PM | #9 |
I much prefer the table version, personally. Also, this is bunk: //locals are faster than globals :) Many different tests have been show that one is better than the other while an equal number of other tests have shown the reverse. Anyway, it doesn't really matter here; there's no way the difference could be noticed at all. That being said, the way you have it is fine. Everything seems in order here, so update your first post with the new version and I'll approve this! It'd be cool if you could get an image to use as the thread image, too, but that's not necessary. |
| 02-27-2009, 10:52 AM | #10 |
Just Released V 1.4: Greez |
| 02-27-2009, 12:13 PM | #11 |
A question: can we heal by setting a negative damage with UnitDamageTarget? If it's possible... a damage detection can do this in a more simple way and manage more properly the events. |
| 02-27-2009, 12:27 PM | #12 |
I dont think so, but test it! Greez |
| 02-27-2009, 12:50 PM | #13 |
> A question: can we heal by setting a negative damage with UnitDamageTarget? I just tested it and negative damage heals the unit. Though, I don't know if it is detected by damage detection systems... Give me 10 minutes and I'll see. EDIT: No, negative damage cannot be detected. |
| 03-01-2009, 08:09 AM | #14 |
In that case, this system has a purpose and I shall approve it. :D |
| 03-01-2009, 10:28 AM | #15 | |
Quote:
Wait ... It's just because damage detections filter the damages under or equal to 0. They can easily be edited to manage negative damages. |
