• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

[JASS] Healing Function (still learning)

Status
Not open for further replies.
Level 19
Joined
Oct 12, 2007
Messages
1,821
Hey readers..

I'm currently still learning stuff with Jass..
I tried to do something that's a bit harder for me, however I got a bit stuck.

I wanted to make a system that allows me to heal a target with a special effect and floating text with just one line of text.
Something like this:
Call HealTarget(GetTriggerUnit(), GetSpellTargetUnit(), amount, true)
the true means if it's crittable or not.

I made something like this, but I don't know how to finish it.. because it's currently missing the unit's and real's that are needed for the function after "takes".
JASS:
function HealUnit takes unit healer, unit target, real amount, boolean critcheck returns nothing

    if udg_HeroCritChance[GetPlayerId(GetOwningPlayer(healer))] <= GetRandomInt(1, 100) and critcheck == true then
    ////(The line here checked if the spell is a crit AND if the spell is able to crit)
        call SetUnitLifeBJ(target, (GetUnitStateSwap(UNIT_STATE_LIFE, target)+amount*2))
        call CreateTextTagUnitBJ(I2S(R2I(amount*2.00)), t, 0, 9.50, 0.00, 100.00, 0.00, 0)
        call SetTextTagPermanentBJ( GetLastCreatedTextTag(), false)
        call SetTextTagLifespanBJ(GetLastCreatedTextTag(), 1.10)
        call SetTextTagFadepointBJ(GetLastCreatedTextTag(), 0.65)
        call AddSpecialEffectLocBJ(GetUnitLoc(target), "Abilities\\Spells\\Human\\Heal\\HealTarget.mdl" )
        call DestroyEffectBJ( GetLastCreatedEffectBJ())
    else
        call SetUnitLifeBJ(target, (GetUnitStateSwap(UNIT_STATE_LIFE, target)+amount))
        call CreateTextTagUnitBJ(I2S(R2I(amount)), amount, 0, 8.50, 0.00, 75.00, 0.00, 0)
        call SetTextTagPermanentBJ( GetLastCreatedTextTag(), false)
        call SetTextTagVelocityBJ(GetLastCreatedTextTag(), 64, 55)
        call SetTextTagLifespanBJ(GetLastCreatedTextTag(), 1.10)
        call SetTextTagFadepointBJ(GetLastCreatedTextTag(), 0.65)
        call AddSpecialEffectLocBJ(GetUnitLoc(target), "Abilities\\Spells\\Human\\Heal\\HealTarget.mdl" )
        call DestroyEffectBJ( GetLastCreatedEffectBJ())
    endif
endfunction

This is probably horrible jass, and i know this might be 50% of the trigger.. But I'm kinda stuck on what to do now. I don't know which things I have to add, however I know there are some things missing.

Could anyone give me some hints or examples?

thanks.
 
Level 19
Joined
Oct 12, 2007
Messages
1,821
Nobody knows what to do next?

I have to declare the variables "healer, target, amount and critcheck" but I don't know how.
a simple thing like this here wont work ofc, but what will work then?

JASS:
local unit healer
local unit target
local real amount
local boolean critcheck
 
Level 11
Joined
Apr 6, 2008
Messages
760
I'm not at a comp with WE but i just give some comments.

first of u use alots of BJ's and Swapped, dont do that (converted GUI to get the functions?). one thing u can do too find the natives is if u have JNGP is too Ctrl+Klick on the function and u will see a native (purple text)

eg.

SetUnitLifeBJ

will show something like

JASS:
function SetUnitLifeBJ takes unit whichUnit, real newValue returns nothing
    call SetUnitState(whichUnit, UNIT_STATE_LIFE, RMaxBJ(0,newValue))
endfunction

so what im trying to say is that it's better to use SetUnitState then SetUnitLifeBJ
 
Last edited:
Level 11
Joined
Apr 6, 2008
Messages
760
here are after some clean up

JASS:
function HealUnit takes unit healer, unit target, real amount, boolean critcheck returns nothing
    local texttag Text = CreateTextTag()
    local real x = GetUnitX(target) //X/Y cords are way faster then locations
    local real y = GetUnitY(target)
    
    if udg_HeroCritChance[GetPlayerId(GetOwningPlayer(healer))] <= GetRandomInt(1, 100) and critcheck  then
    ////(The line here checked if the spell is a crit AND if the spell is able to crit)
        set amount = amount * 2
    endif

    call SetWidgetLife(target,GetWidgetLife(target)+amount)
    call SetTextTagText(Text,R2S(amount),10)
    call SetTextTagColor(Text,0,255,0,0)
    call SetTextTagPos(Text,x,y,10)
    call SetTextTagPermanent(Text,false)
    call SetTextTagLifespan(Text,1.1)
    call SetTextTagFadepoint(Text,0.65)
    call SetTextTagVisibility(Text,true)
    call DestroyEffect(AddSpecialEffect("Abilities\\Spells\\Human\\Heal\\HealTarget.mdl",x,y))
    
    set Text = null
    set healer = null
    
endfunction
 
Last edited:
Level 19
Joined
Oct 12, 2007
Messages
1,821
here are after some clean up
Thanks alot!
Learned a few things from your Jass.

NEVER use GetLastCreatedTExtTag again, save it in local variables o_O
Yeah I always knew this was leaking, but I never fixed it. Think it was some kind of lazyness.
But guess I have to make a local texttag xxx = CreateTextTag()
like Ciebron did.
Will remember this.

one thing u can do too find the natives is if u have JNGP is too Ctrl+Klick on the function and u will see a native (purple text)
Don't really know what you mean by Ctrl+Click on the function, but I try to ctrl click on some things and see if I get something:D

For some reason it isn't working.

I get the error when saving:

Undeclared function HealUnit

This is what I did in a healing spell:

JASS:
function RoL_Conditions takes nothing returns boolean
    return (GetSpellAbilityId() == 'A025')
endfunction

function RoL_Actions takes nothing returns nothing

local unit u = GetTriggerUnit()
local unit t = GetSpellTargetUnit()
local real int = I2R(GetHeroInt(u, true))*0.80
local real hb = 0.50 * I2R(udg_PlayerHealbonus[GetPlayerId(GetOwningPlayer(u))])
local real amount = int + hb

    
call HealUnit(u, t, amount, true)

    
set t = null
set u = null
endfunction


function InitTrig_Rune_of_Life takes nothing returns nothing
    local trigger trg = CreateTrigger()
    call TriggerRegisterAnyUnitEventBJ(trg, EVENT_PLAYER_UNIT_SPELL_EFFECT)
    call TriggerAddCondition(trg, Condition(function RoL_Conditions))
    call TriggerAddAction(trg, function RoL_Actions)
    set trg = null
endfunction

And this is how the system looks like now:

JASS:
function HealUnit takes unit healer, unit target, real amount, boolean critcheck returns nothing
local texttag Text = CreateTextTag()    
local real x = GetUnitX(target)     
local real y = GetUnitY(target)
local integer color = 255 / 4 * 3

if udg_PlayerHealingCrit[GetPlayerId(GetOwningPlayer(healer))] <= GetRandomInt(1, 100) and critcheck  then
    set amount = amount * 2
    set color = 255
endif    
call SetWidgetLife(target,GetWidgetLife(target)+amount)    
call SetTextTagText(Text,R2S(amount),10)    
call SetTextTagColor(Text,0,color,0,0)    
call SetTextTagPos(Text,x,y,10)    
call SetTextTagPermanent(Text,false)    
call SetTextTagLifespan(Text,1.1)    
call SetTextTagFadepoint(Text,0.65)    
call SetTextTagVisibility(Text,true)    
call DestroyEffect(AddSpecialEffect("Abilities\\Spells\\Human\\Heal\\HealTarget.mdl",x,y))    
set Text = null    
set healer = null
endfunction
 
Last edited by a moderator:
Level 7
Joined
Jul 20, 2008
Messages
377
You probably placed HealUnit after the RoL actions. Therefore, RoL doesn't know HealUnit exists... yet.
 
Level 19
Joined
Oct 12, 2007
Messages
1,821
You probably placed HealUnit after the RoL actions. Therefore, RoL doesn't know HealUnit exists... yet.

Well the HealUnit trigger is .. well an other trigger.
It's 1 trigger that should become activated when I use call HealUnit(blabla). However I think this aint happening atm, it should be a .. uhm how do I call it.. a global trigger that get's activated multiple times.

I use a DoT system RolePlaynGamer made for me like this, and ofc the DamageDetect System from Rising_Dust
CallDamageTargetEx(.....), and (dot) CallDamageUnitOverTime(....)
 
Level 19
Joined
Oct 12, 2007
Messages
1,821
maybe put your HealUnit function in the map-specific custom script area?

Should be possible withoud because I have 3 systems like that already, however they weren't made by me.

1. Damage Detection System by Rising_Dusk
JASS:
DamageTargetUnitEx(damager, target, dmg, dmgtype, ignore armor?)

2. Damage over Time by RolePlaynGamer
JASS:
UnitDamageOverTime(damager, target, total damage, duration)

3. Heal over Time copied from Damage over Time
JASS:
UnitHealOverTime(healer, target, total amount, duration)

I wanted to add a 4th one to Heal someone like this example below.
Like this I don't have to create the floating texts with every single spell but can just use this command for it.
JASS:
local unit u = GetTriggerUnit()
local unit t = GetSpellTargetUnit()
local real amount = I2R(GetHeroInt(u, true))*3.00

call HealUnit(u, t, amount, true)
///true means the spell is able to crit///
 
Level 11
Joined
Apr 6, 2008
Messages
760
JASS:
local integer color = 255 / 4 * 3

this is kinda stupid if u ask me

JASS:
local integer color = 191

better to do that if u ask me

and yeah as ghostwolf said. library it or put it in the map header (if u dont have JNGP)
 
Last edited:
Level 19
Joined
Oct 12, 2007
Messages
1,821
So now it should become like this if I am right:

JASS:
library HealSystem
function HealUnit takes unit healer, unit target, real amount, boolean critcheck returns nothing
local texttag Text = CreateTextTag()
local real x = GetUnitX(target)
local real y = GetUnitY(target)
local integer color = 191

if udg_PlayerHealingCrit[GetPlayerId(GetOwningPlayer(healer))] <= GetRandomInt(1, 100) and critcheck  then
    set amount = amount * 2
    set color = 255
endif
call SetWidgetLife(target,GetWidgetLife(target)+amount)
call SetTextTagText(Text,R2S(amount),10)
call SetTextTagColor(Text,0,color,0,0)
call SetTextTagPos(Text,x,y,10)
call SetTextTagPermanent(Text,false)
call SetTextTagLifespan(Text,1.1)
call SetTextTagFadepoint(Text,0.65)
call SetTextTagVisibility(Text,true)
call DestroyEffect(AddSpecialEffect("Abilities\\Spells\\Human\\Heal\\HealTarget.mdl",x,y))
set Text = null
set healer = null
endfunction
endlibrary

Not at home atm, but I try this out. Seems like a small edit but I have the feeling this will work.:grin:
 
Status
Not open for further replies.
Top