Healing Spell+Heal Message every second

TheCrystal

New Member
Reaction score
36
For some reason my spell "Holy" is not working. It loops once, stops, and I don't know why it is doing this. It's a simple JASS trigger with two GUI ones initializing it.

Note: I'm still learning JASS, so I basically use GUI whenever it's the simpler of things instead of finishing up basic JASS training (Events, figuring out things like this)

Trigger:
  • PaladinHoly
    • Events
      • Unit - A unit Starts the effect of an ability
    • Conditions
      • (Ability being cast) Equal to (==) Holy
    • Actions
      • Unit Group - Add (Target unit of ability being cast) to PaladinHolyGroup
      • Set TempReal = (((Real((Level of (Ability being cast) for (Triggering unit)))) / (30.00 / (Real((Level of (Ability being cast) for (Triggering unit)))))) x (Real(ZZZWisdom[(Player number of (Owner of (Triggering unit)))])))
      • Game - Display to (All players) the text: AddedToGroup
        • Multiple FunctionsIf (All Conditions are True) then do (Then Actions) else do (Else Actions)
          • If - Conditions
            • TempReal Less than (<) 1.00
          • Then - Actions
            • Set TempReal = 1.00
            • Game - Display to (All players) the text: LessThen1
          • Else - Actions
      • Set TempUnit = (Target unit of ability being cast)
      • Custom script: set IndexReal2[GetUnitUserData(udg_TempUnit)] = udg_TempReal


Trigger:
  • PaladinHolyPeriod05
    • Events
      • Time - AbilityTimers[0] expires
    • Conditions
    • Actions
      • Custom script: call PaladinHolyTimer()


JASS:
function InitTrig_PaladinHolyTimer takes nothing returns nothing
endfunction
function PaladinHolyTimer takes nothing returns nothing
    local real p = 0
    local real p2 = 0
    local integer i = 0
    local group g = udg_PaladinHolyGroup
    local unit u = null
    loop
        set u = FirstOfGroup(g)
        exitwhen u == null
            if UnitHasBuffBJ(u,'B002')==false then
                call GroupRemoveUnit(udg_PaladinHolyGroup,u)
                call DisplayTextToPlayer(Player(0), 0, 0, "NoBuff")
            endif
        call DisplayTextToPlayer(Player(0), 0, 0, "Looped")
        set i = GetUnitUserData(u)
        set udg_TempReal = IndexReal2<i>
        call SetUnitLifeBJ(u, (GetUnitState(u,UNIT_STATE_LIFE))+udg_TempReal)
        set HolyTimerTime<i>=HolyTimerTime<i>+.05
            if HolyTimerTime<i> &gt;= 1 then
                set HolyTimerTime[1] = 0
                call GoldText(R2I(udg_TempReal)*20,u)
            endif
        call GroupRemoveUnit(g,u)

    endloop
endfunction
</i></i></i></i>


JASS:
function GoldText takes integer I, unit whichunit returns nothing
    local real p = GetUnitX(whichunit)
    local real p2 = GetUnitY(whichunit)
    local texttag T = CreateTextTag()
    set UnitID = GetUnitTypeId(whichunit)
        if IsUnitDeadBJ(whichunit) == false and UnitID !=DummyUnit1 and UnitID != DummyUnit2 and UnitID != DummyUnit3 then
            call SetTextTagPermanent(T, false )
            call SetTextTagPos(T, p, p2, 10)
            call SetTextTagFadepoint(T, 2)
            call SetTextTagLifespan(T, 3)
            call SetTextTagTextBJ(T, &quot;|c00CCCC00&quot; + I2S(I), 8)
            call SetTextTagVelocityBJ( T, 64, GetRandomReal(200.00, 245.00) )
        else
            call DestroyTextTag(T)
        endif //Nothings Wrong, but haven&#039;t tested this specifically
endfunction

It's the correct buff, "NoBuff" never appears, "Looped" appears once, both messages appear in the GUI. The buff stays on the unit.
AbilityTimers[0] is set on Map Init, lots of clutter in that wont so wont post.

If I change local group g = udg_PaladinHolyGroup
to
local group g = null
call GroupAddGroup(udg_PaladinHolyGroup,g)
Looped doesn't appear

If I change
call SetUnitLifeBJ(u,(GetUnitState(u,UNIT_STATE_LIFE))+udg_TempReal)
to
call SetUnitLifeBJ(u,(GetUnitState(u,UNIT_STATE_LIFE))+100)
it Adds 100 HP once (Loop only appears once), but not when I use GroupAddGroup

If I add a message OUTSIDE the loop it shows it every .05 seconds, like I want it to.

I dunno what's wrong with it, but I hope it isn't one of those obvious kind of things.

Edit: Whole point of ability is to heal a target X amount every .05 second then show the message of how much it healed after 1 second. Sorry for forgetting.
 

kingkingyyk3

Visitor (Welcome to the Jungle, Baby!)
Reaction score
216
Bare in mind, Jass is different with GUI.
Tell us what are you trying to do, so we can help you.
 

LearningCode

New Member
Reaction score
24
Use T32x, it's a timer system some where on the forums =x

JASS:
scope Heal initializer HealInit

   globals
      private constant integer SpellID = &#039;A000&#039; //This is the rawcode of your Healing spell
   endglobals
   
   private struct H
      unit SpellTarget
      real TargetX
      real TargetY
      real HealAmount
      real TargetHP
      texttag Tag
      integer ticks


      private method periodic takes nothing returns nothing
         local H h = this
         
         if h.ticks &lt; 20 then
            set h.TargetHP = h.TargetHP + h.HealAmount
            call SetUnitState(h.SpellTarget, UNIT_STATE_LIFE, h.TargetHP) //Something like that.. =x
            set h.ticks = h.ticks + 1
         else
            set h.TargetX = GetUnitX(h.SpellTarget)
            set h.TargetY = GetUnitY(h.SpellTarget)
            //Create TextTag
            call h.stopPeriodic()
            call h.destroy()
         endif
      endmethod
      
      implement T32x

      static method HealAct takes nothing returns nothing
         local H h = H.allocate()
         local unit u = GetTriggerUnit()
         local integer i = GetUnitAbilityLevel(SpellID)
         set h.SpellTarget = GetSpellUnitTarget() //Not sure, I am not at home now, I don&#039;t know the proper native
         set h.TargetHP = GetUnitState(h.SpellTarget, UNIT_STATE_LIFE)
         set h.HealAmount = //Your formula for healing

         
         call h.startPeriodic() //This is using the timer system, but set the options to .05, the T32 timer system uses .03125, I think, alternatively, you can use a timer variable.. But I&#039;m not at home, at a cousin&#039;s house =x
      endmethod

      method onDestroy takes nothing returns nothing
         set .SpellTarget = null
         set .Tag = null
         //Clearing leaks, no need for groups.
      endmethod
   endstruct

   private function HealCond takes nothing returns boolean
      return GetSpellAbilityId() == SpellID
   endfunction

   private function HealInit takes nothing returns nothing
      local trigger t = CreateTrigger()
      local integer i = 0
     
      loop
      exitwhen i == 11 //Assuming that you have a max of 12 players..
         call TriggerRegisterPlayerUnitEvent(t, Player(i), EVENT_PLAYER_UNIT_SPELL_EFFECT, null)
      set i = i+1
      endloop

      call TriggerAddCondition( t, Condition(function HealCond))
      call TriggerAddAction( t, function H.HealAct)
   endfunction

endscope


Err..
Yea, at a cousin's house now, I think it may or may not work.
 

kingkingyyk3

Visitor (Welcome to the Jungle, Baby!)
Reaction score
216
He is still learning Jass, but not vJass. Your code is too difficult for him to understand. We should teach him how to get hang of it 1 by 1 .

JASS:
      local integer i = 0
     
      loop
      exitwhen i == 11 //Assuming that you have a max of 12 players..
         call TriggerRegisterPlayerUnitEvent(t, Player(i), EVENT_PLAYER_UNIT_SPELL_EFFECT, null)
      set i = i+1
      endloop

Instead of keep writing long code, why not to use BJ? It is better to read. The speed is really negligible.
It you want it becomes more efficient, use spell systems. They can help you to fire needed triggers instead of firing all spell triggers(evaluating conditions).

JASS:
local H h = H.allocate()

Hmm, always use "Data" as struct name, since it is neater. "caster"/"cs" for spell's caster, "targ"/"target" for targeted unit.
You will find it is easier to edit when you want to edit it later.
I used "a", "b", "c", "d", and ... as variables' name, when I was still a Jass newbie. I found it is hard to edit ><. So, experience is good. The more the effort you pay on coding, the more the experience you will get. ^_^

The usage of capital letter is important too.
constant globals should be all CAPITAL_LETTER.
globals should be Normal.
locals should be all small case.
struct methods/members should be camelCase.
 

TheCrystal

New Member
Reaction score
36
Well, I use BJ Jass sometimes, often times they seem really silly, like one of them calls a different BJ then calls ANOTHER before going back to the original JASS one. Though I do like to have my things more efficient then, well, 'quicker' to make.
My whole problem with JASS over the period of time I've been messing with it is certain things, like "private STUFF" or structs, even after reading all the tutorials it still is difficult to understand. Often times I learn better by reading other people's code then modifying it for my use.

What do you mean, Spell Systems? You mean creating a function that creates an effect of some sort and then calling them in a series? Right now I try and recycle my past code, like the "GoldText" was derived from "HealingText", just without the adding HP in the HealingText itself, but HealingText is still used from all my other healing things.
The specifics of the period in the variable name remain unknown to me.
 

cryowraith

New Member
Reaction score
7
So I'm not sure what you are trying to do. Periodic healing + text or one time heal + text?

JASS:
loop
        set u = FirstOfGroup(g)
        exitwhen u == null
            if UnitHasBuffBJ(u,&#039;B002&#039;)==false then
                call GroupRemoveUnit(udg_PaladinHolyGroup,u)
                call DisplayTextToPlayer(Player(0), 0, 0, &quot;NoBuff&quot;)
            endif
        call DisplayTextToPlayer(Player(0), 0, 0, &quot;Looped&quot;)
        set i = GetUnitUserData(u)
        set udg_TempReal = IndexReal2<i>
        call SetUnitLifeBJ(u, (GetUnitState(u,UNIT_STATE_LIFE))+udg_TempReal)
        set HolyTimerTime<i>=HolyTimerTime<i>+.05
            if HolyTimerTime<i> &gt;= 1 then
                set HolyTimerTime[1] = 0
                call GoldText(R2I(udg_TempReal)*20,u)
            endif
        call GroupRemoveUnit(g,u)

    endloop</i></i></i></i>


You said it only looped once? It loops only once because there are only 1 unit in g or udg_PaladinHolyGroup. Since you remove the unit from the group in the 1st run, then you'll get an empty group which will exit the loop.

And I assume HolyTimerTime is a global that you declared in another function? You should remember adding a udg_ if it is defined in the variable editor.
 

TheCrystal

New Member
Reaction score
36
It loops once TOTAL once I cast a target for "Holy". As in, there's one unit in the PaladinHolyGroup, then none, until the spell is used once more.
I want the spell to be used on a target, healed for the udg_TempReal amount, then after 20 runs (AKA 1 second) for the unit to have Gold Text appear above them telling how much was healed over the 1 second.
The only time (that this should occur) is when the unit no longer has the buff that the unit stops getting healed.

HolyTimerTime is in my JASSInitialization trigger, and the indexing system works properly.
 

cryowraith

New Member
Reaction score
7
Most probably because you removed the unit during the loop.

JASS:
call GroupRemoveUnit(g,u)


Perhaps put that line inside here.

JASS:
if HolyTimerTime<i> &gt;= 1 then
                set HolyTimerTime[1] = 0
                call GoldText(R2I(udg_TempReal)*20,u)
            endif</i>
 

TheCrystal

New Member
Reaction score
36
Err, I mean I want the unit to be healed by udg_TempReal amount but not all at once in that, loop. After the whole function has been called 20 times (1 second in time total) it THEN displays the text. What you're purposing is healing the unit 20 times then displaying the text before removing it from the group, which is unwanted, since this would happen "instantly".
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Members online

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top