|
|
|
|
| JASS Resources Find JASS code snippets and functions here or write your own and post it on the Submissions sub-forum. |
 |
|
09-13-2011, 05:03 PM
|
#1 (permalink)
|
|
JESUS MAN
Resource Moderator
Join Date: Dec 2008
Posts: 5,700
|
[System] Heal
This system efficiently handles healing units instantly and over time.
Jass:
/************************************************************
*
* Heal
* v4.0.0.3
* By Magtheridon96
*
* - Heals units instantly or over time.
* - Can also allow Damage over time with negative heal amount.
* - Comes with heal events:
*
* - Heal.ANY
* - Fires on any healing event.
* - This would be used for systems like:
* - Accurate Unit Regeneration Logs
* - Accurate Damage Logs
* - Heal Block/Spell Effect Block
*
* - Heal.INSTANT
* - Fires on instant heal events.
* - This would be used for systems like:
* - Texttag Displays
*
* - Heal.TIMED
* - Fires 32x a second during a timed heal.
* - This was only added for a sense of
* completeness. It may be useful.
*
* - Requires:
*
* - UnitEvent by Nestharus
* - hiveworkshop.com/forums/jass-resources-412/extension-unit-event-172365/
* - UnitIndexer by Nestharus
* - hiveworkshop.com/forums/jass-resources-412/system-unit-indexer-172090/
* - Event by Nestharus
* - hiveworkshop.com/forums/jass-resources-412/snippet-event-186555/
* - CTL by Nestharus
* - hiveworkshop.com/forums/jass-resources-412/snippet-constant-timer-loop-32-a-201381/
*
* - API:
* ----
*
* - struct Heal extends array
* - readonly static Event ANY
* - readonly static Event TIMED
* - readonly static Event INSTANT
* - Heal events
*
* - static boolean enabled
* - Used to enable/disable the system
*
* - static method healUnit takes unit source, unit target, real amount returns nothing
* - static method healUnitOverTime takes unit source, unit target, real amount, real duration returns nothing
* - Heal a unit instantly or over time
*
* - function RegisterInstantHealEvent takes code c returns nothing
* - function RegisterTimedHealEvent takes code c returns nothing
* - function RegisterAnyHealEvent takes code c returns nothing
* - These functions register specific heal events that fire differently.
*
* - function GetHealingUnit takes nothing returns unit
* - function GetHealingUnitId takes nothing returns integer
* - These functions are used to get the healing unit or its id.
*
* - function GetHealedUnit takes nothing returns unit
* - function GetHealedUnitId takes nothing returns integer
* - These functions are used to get the healed unit or its id.
*
* - function GetHealedAmount takes nothing returns real
* - function GetEffectiveHealedAmount takes nothing returns real
* - function GetOriginalLife takes nothing returns real
* - These functions are used to get:
* - Amount of HP intended to be healed.
* - Amount of HP actually healed.
* - Original HP before healing.
*
* - function HealUnit takes unit source, unit target, real amount returns nothing
* - function HealUnitOverTime takes unit source, unit target, real amount, real duration returns nothing
* - These are the wrappers used for healing units.
*
************************************************************/
library Heal requires UnitIndexer, UnitEvent, Event, CTL
private module Init
private static method onInit takes nothing returns nothing
set INSTANT = CreateEvent()
set TIMED = CreateEvent()
set ANY = CreateEvent()
endmethod
endmodule
struct Heal extends array
readonly static Event INSTANT
readonly static Event TIMED
readonly static Event ANY
static boolean enabled = true
static UnitIndex sourceId = 0
static UnitIndex targetId = 0
static real amount = 0.0
static real original = 0.0
static real effective = 0.0
private static unit array source
private static unit array target
private static real array regen
private static real array duration
private static method lock takes nothing returns nothing
if sourceId != 0 then
call sourceId.lock()
endif
if targetId != 0 then
call targetId.lock()
endif
endmethod
private static method unlock takes nothing returns nothing
if sourceId != 0 then
call sourceId.unlock()
endif
if targetId != 0 then
call targetId.unlock()
endif
endmethod
implement CTL
local real r
local integer u
implement CTLExpire
set r = GetWidgetLife(target[this])
set u = GetUnitUserData(target[this])
if not IsUnitDead(u) and duration[this] <= 0. then
set duration[this] = duration[this] - 0.03125
call SetWidgetLife(target[this], r + regen[this])
if enabled then
set sourceId = GetUnitUserData(source[this])
set targetId = u
set amount = regen[this]
set original = r
set effective = GetWidgetLife(target[this]) - r
call lock()
call TIMED.fire()
call ANY.fire()
call unlock()
endif
else
set source[this] = null
set target[this] = null
call this.destroy()
endif
implement CTLNull
implement CTLEnd
static method healUnit takes unit source, unit target, real howMuch returns nothing
local real r = GetWidgetLife(target)
local integer u = GetUnitUserData(target)
if not IsUnitDead(u) then
call SetWidgetLife(target, r + howMuch)
if enabled then
set sourceId = GetUnitUserData(source)
set targetId = u
set amount = howMuch
set original = r
set effective = GetWidgetLife(target) - r
call lock()
call INSTANT.fire()
call ANY.fire()
call unlock()
endif
endif
endmethod
static method healUnitOverTime takes unit src, unit trgt, real howMuch, real dur returns nothing
local thistype this = create()
set source[this] = src
set target[this] = trgt
set regen[this] = 0.03125 * howMuch / dur
set duration[this] = dur
endmethod
implement Init
endstruct
function RegisterInstantHealEvent takes code c returns nothing
call Heal.INSTANT.register(Filter(c))
return
endfunction
function RegisterTimedHealEvent takes code c returns nothing
call Heal.TIMED.register(Filter(c))
return
endfunction
function RegisterAnyHealEvent takes code c returns nothing
call Heal.ANY.register(Filter(c))
return
endfunction
function GetHealingUnit takes nothing returns unit
return GetUnitById(Heal.sourceId)
endfunction
function GetHealingUnitId takes nothing returns integer
return Heal.sourceId
endfunction
function GetHealedUnit takes nothing returns unit
return GetUnitById(Heal.targetId)
endfunction
function GetHealedUnitId takes nothing returns integer
return Heal.targetId
endfunction
function GetHealedAmount takes nothing returns real
return Heal.amount
endfunction
function GetEffectiveHealedAmount takes nothing returns real
return Heal.effective
endfunction
function GetOriginalLife takes nothing returns real
return Heal.original
endfunction
function HealUnit takes unit source, unit target, real amount returns nothing
call Heal.healUnit(source,target,amount)
endfunction
function HealUnitOverTime takes unit source, unit target, real amount, real duration returns nothing
call Heal.healUnitOverTime(source,target,amount,duration)
endfunction
endlibrary
Demo Code
Jass:
struct Tester extends array
private static unit fighters1
private static unit fighters2
private static unit regen
private static method instant takes nothing returns nothing
call HealUnit(null, fighters1, 150)
call DisplayTimedTextToPlayer(GetLocalPlayer(), 0, 0, 60, "Healed unit for 150 HP")
endmethod
private static method onInit takes nothing returns nothing
set fighters1 = CreateUnit(Player(0), 'Hpal', 128, 0, 180)
set fighters2 = CreateUnit(Player(1), 'Hpal', -128, 0, 0)
call TimerStart(CreateTimer(), 10, true, function thistype.instant)
set regen = CreateUnit(Player(0), 'Hpal', 0, 1024, 270)
call CreateUnit(Player(1), 'Hpal', 0, 1024, 270)
call SetWidgetLife(regen, GetUnitState(regen, UNIT_STATE_MAX_LIFE) / 2)
// This will regenerate 500000 HP over 50000 seconds meaning 10 HP/sec
call HealUnitOverTime(null, regen, 500000, 50000)
call PauseUnit(regen, true)
endmethod
endstruct
Feel free to comment..
Last edited by Magtheridon96; 02-19-2012 at 09:12 PM.
Reason: Updated, yet again
|
|
|
09-14-2011, 01:09 AM
|
#2 (permalink)
|
|
User
Join Date: Jul 2007
Posts: 4,911
|
Look into the timer loop lib I wrote. Because you are dealing with indexed units, you'd be best looping over those indexes. T32 doesn't allow it, but the CTL or w/e it is does.
|
|
|
09-14-2011, 02:09 AM
|
#3 (permalink)
|
|
JESUS MAN
Resource Moderator
Join Date: Dec 2008
Posts: 5,700
|
Why not? :P
I just read your CTL library.. I liked it :)
In fact, it made me realize how redundant a destroy method is >:P
|
|
|
09-14-2011, 02:56 AM
|
#4 (permalink)
|
|
User
Join Date: Nov 2007
Posts: 1,055
|
Jass:
if r>=0.405 then
call SetWidgetLife(.target,r+.amount)
set Heal.sourceId = GetUnitUserData(.source)
set Heal.targetId = GetUnitUserData(.target)
set Heal.amount = .amount
set Heal.original = r
set Heal.effective = GetWidgetLife(.target)-r
call Heal.onHeal.fire()
else
call .stopPeriodic()
call .destroy()
return
endif
set .counter = .counter + T32_PERIOD
if .counter>=.duration then
call .stopPeriodic()
call .destroy()
endif
->
Jass:
if r>=0.405 and .counter < .duration then
set .counter = .counter + T32_PERIOD
call SetWidgetLife(.target,r+.amount)
set Heal.sourceId = GetUnitUserData(.source)
set Heal.targetId = GetUnitUserData(.target)
set Heal.amount = .amount
set Heal.original = r
set Heal.effective = GetWidgetLife(.target)-r
call Heal.onHeal.fire()
else
call .stopPeriodic()
call .destroy()
endif
You should probably add a function to test the effectiveness of the healing seeing that you already have a effective member.
You should write better documentation.
Does the system support healing inside a healing event?
I suggest that healing also consider the ethereal heal bonus. You could also make it easier for the user to specify healing modifiers, which would be similar to damage modifiers.
|
|
|
09-14-2011, 03:26 AM
|
#5 (permalink)
|
|
JESUS MAN
Resource Moderator
Join Date: Dec 2008
Posts: 5,700
|
Quote:
|
Does the system support healing inside a healing event?
|
Got it.
static boolean enabled = true
:P I'll add that in.
Quote:
|
You should write better documentation
|
Yeah, I'll probably just list the API :P
Quote:
|
I suggest that healing also consider the ethereal heal bonus. You could also make it easier for the user to specify healing modifiers, which would be similar to damage modifiers
|
Nah ;p
Quote:
|
You should probably add a function to test the effectiveness of the healing seeing that you already have a effective member.
|
Oh sorry about that :P
I added those members and modified the code inside the post ^)^
edit
Updated.
Last edited by Magtheridon96; 09-14-2011 at 04:40 AM.
|
|
|
09-14-2011, 06:54 AM
|
#6 (permalink)
|
|
User
Join Date: Jun 2004
Posts: 166
|
So, I have questions:
First of all, you really need better documentation. If you want people to use a system, you better tell them how to use it. It's easy for you to understand because you made it, but you put it here for other people to use. It makes little sense if notes for using the system are poor, but you put it here for other people to use.
Heal.onTimedHeal
has an incomplete note. "Fires 32x a second with overtime heals (I would use this for *BLANK*)". Nothing? Okay, then why is it there? >_>
What is the difference between
GetHealAmount
and
GetEffectiveHealAmount
? I didn't find any random value in any healing factor. Healing values don't register as damage anyway, since you're using GetWidgetLife.
Also, are you using this for something of your own? I'm gonna be evil here: What's the point in this system when it's easy to replicate what you have with a library with very simple function calls? I don't see the point.
|
|
|
09-14-2011, 09:06 AM
|
#7 (permalink)
|
|
User
Join Date: Mar 2008
Posts: 111
|
GetHealAmount = the healing that you inputed and GetEffectiveHealAmount is the actual healing done.
Ex.
Unit has 150/180 hp
You heal him for 100
then GetHealAmount returns 100
and GetEffectiveHealAmount returns 30 (180-150)
|
|
|
09-14-2011, 07:00 PM
|
#8 (permalink)
|
|
JESUS MAN
Resource Moderator
Join Date: Dec 2008
Posts: 5,700
|
Quote:
|
First of all, you really need better documentation. If you want people to use a system, you better tell them how to use it. It's easy for you to understand because you made it, but you put it here for other people to use. It makes little sense if notes for using the system are poor, but you put it here for other people to use.
|
The API has been listed and I put a small description for the functions in the API.
Quote:
|
Heal.onTimedHeal has an incomplete note. "Fires 32x a second with overtime heals (I would use this for *BLANK*)". Nothing? Okay, then why is it there? >_>
|
In case you wanted to reverse the effects of some healing, you'd want the event to fire everytime the unit is given bonus life.
I'm using the event Heal.ANY for my Is Unit Regenerating snippet so that I can filter out any given HP and get real regeneration.
Quote:
|
What is the difference between GetHealAmount and GetEffectiveHealAmount ? I didn't find any random value in any healing factor. Healing values don't register as damage anyway, since you're using GetWidgetLife.
|
dudeim explained it above this comment :P
Quote:
|
What's the point in this system when it's easy to replicate what you have with a library with very simple function calls? I don't see the point.
|
There are 2 major systems involving "Healing"
One is found at wc3c.net, but it's absolutely terrible.
The other is at TheHelper, it's decent, but it needs a bit of work.
|
|
|
09-14-2011, 10:27 PM
|
#9 (permalink)
|
|
MORE CONTESTS PLS
Join Date: Nov 2008
Posts: 3,554
|
Doesn't keyword suck terriably? And why nulling struct members? Because of the CTL lib? (No I haven't read it thru as I haven't used the UnitIndexer until now (nonlua ftw))
__________________
Nobody dies a virgin, life fucks us all. - Master Arena is alive! v4.0 in construction. - Dr Super Good for president! - Sorry derps but I do not do requests unless they prove themselves worthy of my time.
My Resources! - Help me out with my project! - How To Import vJASS spells tutorial! - Practice makes perf... improves you.
Quote:
Originally Posted by Marc Mamales
Hey guys, please fix my spells, cz i dont know how to make it GUI.
|
|
|
|
09-14-2011, 10:34 PM
|
#10 (permalink)
|
|
JESUS MAN
Resource Moderator
Join Date: Dec 2008
Posts: 5,700
|
All keyword does is move the a piece of the script to a certain position ;p
CTL isn't too complicated :D
|
|
|
09-14-2011, 10:48 PM
|
#11 (permalink)
|
|
MORE CONTESTS PLS
Join Date: Nov 2008
Posts: 3,554
|
Oh I see. When I released my dummy lib people complained about the keyword thingie although the readability would be silly without it. I still wonder why as I cannot find that thread as it got rejected (due to no update and purge). Yeah seems pretty simple with the modules implemention but still I don't need the index looping :P
__________________
Nobody dies a virgin, life fucks us all. - Master Arena is alive! v4.0 in construction. - Dr Super Good for president! - Sorry derps but I do not do requests unless they prove themselves worthy of my time.
My Resources! - Help me out with my project! - How To Import vJASS spells tutorial! - Practice makes perf... improves you.
Quote:
Originally Posted by Marc Mamales
Hey guys, please fix my spells, cz i dont know how to make it GUI.
|
|
|
|
09-15-2011, 08:06 AM
|
#12 (permalink)
|
|
Keep it simple
Spells, Help Zones & JASS Moderator
Join Date: Sep 2009
Posts: 5,581
|
If only keywords ran before textmacros, which would obviously make sense,
then we wouldn't even need modules except for initializers.
__________________
How to post your triggers on the Hive Workshop.
JPAG - Bettering the cause of readable source code.
|
|
|
09-15-2011, 10:37 AM
|
#13 (permalink)
|
|
JESUS MAN
Resource Moderator
Join Date: Dec 2008
Posts: 5,700
|
modules are IMBA actually :P
I just love the keyword
implement
^_^
|
|
|
09-15-2011, 10:48 AM
|
#14 (permalink)
|
|
Keep it simple
Spells, Help Zones & JASS Moderator
Join Date: Sep 2009
Posts: 5,581
|
I was greatly disappointed when Zinc removed that keyword in favor of repeating the word "module".
__________________
How to post your triggers on the Hive Workshop.
JPAG - Bettering the cause of readable source code.
|
|
|
09-15-2011, 03:38 PM
|
#15 (permalink)
|
|
MORE CONTESTS PLS
Join Date: Nov 2008
Posts: 3,554
|
ZINC failed instantly with ->...
__________________
Nobody dies a virgin, life fucks us all. - Master Arena is alive! v4.0 in construction. - Dr Super Good for president! - Sorry derps but I do not do requests unless they prove themselves worthy of my time.
My Resources! - Help me out with my project! - How To Import vJASS spells tutorial! - Practice makes perf... improves you.
Quote:
Originally Posted by Marc Mamales
Hey guys, please fix my spells, cz i dont know how to make it GUI.
|
|
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|
|
|
|
|
|
|
|
All times are GMT. The time now is 08:21 AM.
|