• 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.

[Trigger] Tree resurrection skill

Level 3
Joined
Dec 8, 2023
Messages
13
I need help in debugging some scripts. what i want to find out is if it has some memory leaks (i have no idea what that means) or whatever that will make the game crash after a long run. and other suggestions to make the script cleaner. and other stuff that evaded my noobie eyes that you may have noticed. thanks! ;)


SCRIPT 1
  • Natures Prophet resurrect
    • Events
      • Time - Every 10.00 seconds of game time
    • Conditions
    • Actions
      • Unit Group - Pick every unit in (Units in (Playable map area)) and do (Actions)
        • Loop - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Unit-type of (Picked unit)) Equal to Keeper of the Grove
            • Then - Actions
              • Set NaturesProphetcasterunit = (Picked unit)
              • Destructible - Pick every destructible within 1000.00 of (Position of NaturesProphetcasterunit) and do (Actions)
                • Loop - Actions
                  • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                    • If - Conditions
                      • ((Picked destructible) is dead) Equal to True
                    • Then - Actions
                      • Set NaturesProphettreeresurrectrea = (NaturesProphettreeresurrectrea + 1.00)
                      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                        • If - Conditions
                          • Or - Any (Conditions) are true
                            • Conditions
                              • (Life of NaturesProphetcasterunit) Less than ((Max life of NaturesProphetcasterunit) x 0.50)
                              • (NaturesProphettreeresurrectrea x 50.00) Greater than ((Life of NaturesProphetcasterunit) x 0.50)
                              • (NaturesProphettreeresurrectrea x 50.00) Greater than ((Max life of NaturesProphetcasterunit) x 0.50)
                              • NaturesProphettreeresurrectrea Equal to 0.00
                        • Then - Actions
                          • Set NaturesProphettreeresurrectrea = 0.00
                          • Skip remaining actions
                        • Else - Actions
                          • Unit - Set life of NaturesProphetcasterunit to ((Life of NaturesProphetcasterunit) - (NaturesProphettreeresurrectrea x 20.00))
                          • Destructible - Resurrect (Picked destructible) with (Max life of (Picked destructible)) life and Show birth animation
                          • Hero - Add ((Integer(NaturesProphettreeresurrectrea)) x 10) experience to NaturesProphetcasterunit, Show level-up graphics
                          • Set NaturesProphetsfxinteger = 1
                    • Else - Actions
                      • Do nothing
            • Else - Actions
              • Do nothing
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • NaturesProphetsfxinteger Equal to 1
        • Then - Actions
          • Animation - Play NaturesProphetcasterunit's spell animation
          • Special Effect - Create a special effect attached to the origin of NaturesProphetcasterunit using Abilities\Spells\NightElf\Tranquility\Tranquility.mdl
          • Set NaturesProphetsfx = (Last created special effect)
          • Wait 2.00 seconds
          • Animation - Reset NaturesProphetcasterunit's animation
          • Special Effect - Destroy NaturesProphetsfx
          • Set NaturesProphettreeresurrectrea = 0.00
          • Set NaturesProphetsfxinteger = 0
        • Else - Actions
          • Do nothing
DESCRIPTION
What it does is that for every 10 secs a hero if there are dead trees in 1000 aoe around him will resurrect it that will cost him 20 hp and give him 10 xp. but if the hero doesn't have enough life, it will not work. the math that i used is sloppy and i think does not really work how i intended it to be, but works nonetheless. it is supposed to be that when his life is less than half or if the cost is more than half is current or max life.


SCRIPT 2
  • Natures Prophet regen
    • Events
      • Time - Every 2.00 seconds of game time
    • Conditions
    • Actions
      • Unit Group - Pick every unit in (Units in (Playable map area)) and do (Actions)
        • Loop - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Unit-type of (Picked unit)) Equal to Keeper of the Grove
            • Then - Actions
              • Destructible - Pick every destructible within 1000.00 of (Position of (Picked unit)) and do (Actions)
                • Loop - Actions
                  • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                    • If - Conditions
                      • ((Picked destructible) is alive) Equal to True
                    • Then - Actions
                      • Set NaturesProphettreeregenreal = (NaturesProphettreeregenreal + 1.00)
                    • Else - Actions
                      • Do nothing
              • Unit - Set life of (Picked unit) to ((Life of (Picked unit)) + (NaturesProphettreeregenreal x 0.50))
              • Unit - Set mana of (Picked unit) to ((Mana of (Picked unit)) + (NaturesProphettreeregenreal x 0.25))
              • Special Effect - Create a special effect attached to the origin of (Picked unit) using Objects\Spawnmodels\NightElf\EntBirthTarget\EntBirthTarget.mdl
              • Set NaturesProphettreeregenreal = 0.00
            • Else - Actions
              • Do nothing
DESCRIPTION
what this does is that every two seconds every tree in 1000 aoe around the hero will restore him 0.5 hp and .25 mp.
 
Last edited:
Level 3
Joined
Dec 8, 2023
Messages
13
The text is unreadable. Use the in brackets trigger and /trigger or select text and press the yellow cogwheel to convert to readable gui
Thanks for bringing this up. I'm a noob so i didn't know this function. Anyway, I edited the original prompt. Is there wrong with it? like leaks or whatever i don't know about?
 

Rheiko

Spell Reviewer
Level 27
Joined
Aug 27, 2013
Messages
4,243
what i want to find out is if it has some memory leaks (i have no idea what that means)

To quote from that thread:
If your computer's memory keeps occupied with stuff you already lost access to, it's called memory leak. It slows down the computer for no benefits.
Having tons of leaks may lead to lag-spikes upto a total game freeze.

Let's find the leaks
empty.gif
unitgroup.gif
Unit Group - Pick every unit in (Units in (Playable map area)) and do (Actions)
This one leaks, this function always creates a new group in the background. To prevent this, we can create a group variable and store it there then destroy it like this
  • Set MyGroup = Pick every unit in (Units in (Playable map area))
  • Unit Group - Pick every unit in MyGroup and do (Actions)
    • Loop - Actions
      • -------- do your thing here --------
  • Custom script: call DestroyGroup(udg_MyGroup)
you can also do something like this so you don't have to create a group variable
  • Custom script: set bj_wantDestroyGroup = true
  • Unit Group - Pick every unit in Pick every unit in (Units in (Playable map area)) and do (Actions)
    • Loop - Actions
      • -------- do your thing here --------

  • Destructible - Pick every destructible within 1000.00 of (Position of NaturesProphetcasterunit) and do (Actions)
This one has a location leak. You need to store the location into a variable first and then remove it like this
  • Set TempPoint = (Position of NaturesProphetcasterunit)
  • Destructible - Pick every destructible within 1000.00 of TempPoint and do (Actions)
    • Loop - Actions
      • -------- do your thing here --------
  • Custom script: call RemoveLocation(udg_TempPoint)
The same thing for your second script.

  • Do nothing
does absolutely nothing, so you don't even have to use that. It's useless. Just remove them.

Your second script, It should be something like this
  • Set TempPoint = (Position of (Picked unit))
  • Destructible - Pick every destructible within 1000.00 of TempPoint and do (Actions)
    • Loop - Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • ((Picked destructible) is alive) Equal to True
        • Then - Actions
          • Unit - Set life of (Picked unit) to ((Life of (Picked unit)) + 0.50)
          • Unit - Set mana of (Picked unit) to ((Mana of (Picked unit)) + 0.25)
        • Else - Actions
  • Custom script: call RemoveLocation(udg_TempPoint)
This will heal the hero everytime there is an alive destructible found within 1000 radius.
  • Destructible - Pick every destructible within 1000.00 of TempPoint and do (Actions)
This function right here is a loop, meaning it will repeat the code inside it everytime it finds a destructible.

In your first script, the logic inside the loop also does not seem quite right. It should be something like this.
  • Set TempPoint = (Position of NaturesProphetcasterunit)
  • Destructible - Pick every destructible within 1000.00 of TempPoint and do (Actions)
    • Loop - Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • ((Picked destructible) is dead) Equal to True
        • Then - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • Or - Any (Conditions) are true
                • Conditions
                  • (Life of NaturesProphetcasterunit) Greater than ((Max life of NaturesProphetcasterunit) x 0.50)
                  • ((Life of NaturesProphetcasterunit) * 0.50) Greater than 50.0
                  • ((Max life of NaturesProphetcasterunit) * 0.50) Greater than 50.0
            • Then - Actions
              • Unit - Set life of NaturesProphetcasterunit to ((Life of NaturesProphetcasterunit) - 20.00)
              • Destructible - Resurrect (Picked destructible) with (Max life of (Picked destructible)) life and Show birth animation
              • Hero - Add ((Integer(NaturesProphettreeresurrectrea)) x 10) experience to NaturesProphetcasterunit, Show level-up graphics
            • Else - Actions
        • Else - Actions
  • Custom script: call RemoveLocation(udg_TempPoint)
I assume the cost is 50 for every tree? I'm not sure I get the right logic for the if part in first script. Could his max life get lower than the cost?

Also you could use a boolean variable to play animation and create special effect in place of integer (integer should be fine as well though), Remove wait, they're inaccurate and can cause some problems later if handled incorrectly. Most special effects will still play their animation before they're removed from the game when you destroy them.
  • Custom script: set bj_wantDestroyGroup = true
  • Unit Group - Pick every unit in Pick every unit in (Units in (Playable map area)) and do (Actions)
    • Loop - Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Unit-type of (Picked unit)) Equal to Keeper of the Grove
        • Then - Actions
          • Set TreeIsFound = false
          • Set NaturesProphetcasterunit = (Picked unit)
          • Set TempPoint = (Position of NaturesProphetcasterunit)
          • Destructible - Pick every destructible within 1000.00 of TempPoint and do (Actions)
            • Loop - Actions
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • ((Picked destructible) is dead) Equal to True
                • Then - Actions
                  • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                    • If - Conditions
                      • Or - Any (Conditions) are true
                        • Conditions
                          • (Life of NaturesProphetcasterunit) Greater than ((Max life of NaturesProphetcasterunit) x 0.50)
                          • ((Life of NaturesProphetcasterunit) * 0.50) Greater than 50.0
                          • ((Max life of NaturesProphetcasterunit) * 0.50) Greater than 50.0
                    • Then - Actions
                      • Set TreeIsFound = true
                      • Unit - Set life of NaturesProphetcasterunit to ((Life of NaturesProphetcasterunit) - 20.00)
                      • Destructible - Resurrect (Picked destructible) with (Max life of (Picked destructible)) life and Show birth animation
                      • Hero - Add 10 experience to NaturesProphetcasterunit, Show level-up graphics
                    • Else - Actions
                  • Else - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • TreeIsFound Equal to True
            • Then - Actions
              • Animation - Play NaturesProphetcasterunit's spell animation
              • Animation - Queue NaturesProphetcasterunit's stand animation
              • Animation - Reset NaturesProphetcasterunit's animation
              • Special Effect - Create a special effect attached to the origin of NaturesProphetcasterunit using Abilities\Spells\NightElf\Tranquility\Tranquility.mdl
              • Special Effect - Destroy (Last created special effect)
            • Else - Actions
          • Custom script: call RemoveLocation(udg_TempPoint)
 
Last edited:
Level 3
Joined
Dec 8, 2023
Messages
13
T

To quote from that thread:


Let's find the leaks

This one leaks, this function always creates a new group in the background. To prevent this, we can create a group variable and store it there then destroy it like this
  • Set MyGroup = Pick every unit in (Units in (Playable map area))
  • Unit Group - Pick every unit in MyGroup and do (Actions)
    • Loop - Actions
      • -------- do your thing here --------
  • Custom script: call DestroyGroup(udg_MyGroup)
you can also do something like this so you don't have to create a group variable
  • Custom script: set bj_wantDestroyGroup = true
  • Unit Group - Pick every unit in Pick every unit in (Units in (Playable map area)) and do (Actions)
    • Loop - Actions
      • -------- do your thing here --------


This one has a location leak. You need to store the location into a variable first and then remove it like this
  • Set TempPoint = (Position of NaturesProphetcasterunit)
  • Destructible - Pick every destructible within 1000.00 of TempPoint and do (Actions)
    • Loop - Actions
      • -------- do your thing here --------
  • Custom script: call RemoveLocation(udg_TempPoint)
The same thing for your second script.

  • Do nothing
does absolutely nothing, so you don't even have to use that. It's useless. Just remove them.

Your second script, It should be something like this
  • Set TempPoint = (Position of (Picked unit))
  • Destructible - Pick every destructible within 1000.00 of TempPoint and do (Actions)
    • Loop - Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • ((Picked destructible) is alive) Equal to True
        • Then - Actions
          • Unit - Set life of (Picked unit) to ((Life of (Picked unit)) + 0.50)
          • Unit - Set mana of (Picked unit) to ((Mana of (Picked unit)) + 0.25)
        • Else - Actions
  • Custom script: call RemoveLocation(udg_TempPoint)
This will heal the hero everytime there is an alive destructible found within 1000 radius.
  • Destructible - Pick every destructible within 1000.00 of TempPoint and do (Actions)
This function right here is a loop, meaning it will repeat the code inside it everytime it finds a destructible.

In your first script, the logic inside the loop also does not seem quite right. It should be something like this.
  • Set TempPoint = (Position of NaturesProphetcasterunit)
  • Destructible - Pick every destructible within 1000.00 of TempPoint and do (Actions)
    • Loop - Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • ((Picked destructible) is dead) Equal to True
        • Then - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • Or - Any (Conditions) are true
                • Conditions
                  • (Life of NaturesProphetcasterunit) Greater than ((Max life of NaturesProphetcasterunit) x 0.50)
                  • ((Life of NaturesProphetcasterunit) * 0.50) Greater than 50.0
                  • ((Max life of NaturesProphetcasterunit) * 0.50) Greater than 50.0
            • Then - Actions
              • Unit - Set life of NaturesProphetcasterunit to ((Life of NaturesProphetcasterunit) - 20.00)
              • Destructible - Resurrect (Picked destructible) with (Max life of (Picked destructible)) life and Show birth animation
              • Hero - Add ((Integer(NaturesProphettreeresurrectrea)) x 10) experience to NaturesProphetcasterunit, Show level-up graphics
            • Else - Actions
        • Else - Actions
  • Custom script: call RemoveLocation(udg_TempPoint)
I assume the cost is 50 for every tree? I'm not sure I get the right logic for the if part in first script. Could his max life get lower than the cost?

Also you could use a boolean variable to play animation and create special effect in place of integer (integer should be fine as well though), Remove wait, they're inaccurate and can cause some problems later if handled incorrectly. Most special effects will still play their animation before they're removed from the game when you destroy them.
  • Custom script: set bj_wantDestroyGroup = true
  • Unit Group - Pick every unit in Pick every unit in (Units in (Playable map area)) and do (Actions)
    • Loop - Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Unit-type of (Picked unit)) Equal to Keeper of the Grove
        • Then - Actions
          • Set TreeIsFound = false
          • Set NaturesProphetcasterunit = (Picked unit)
          • Set TempPoint = (Position of NaturesProphetcasterunit)
          • Destructible - Pick every destructible within 1000.00 of TempPoint and do (Actions)
            • Loop - Actions
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • ((Picked destructible) is dead) Equal to True
                • Then - Actions
                  • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                    • If - Conditions
                      • Or - Any (Conditions) are true
                        • Conditions
                          • (Life of NaturesProphetcasterunit) Greater than ((Max life of NaturesProphetcasterunit) x 0.50)
                          • ((Life of NaturesProphetcasterunit) * 0.50) Greater than 50.0
                          • ((Max life of NaturesProphetcasterunit) * 0.50) Greater than 50.0
                    • Then - Actions
                      • Set TreeIsFound = true
                      • Unit - Set life of NaturesProphetcasterunit to ((Life of NaturesProphetcasterunit) - 20.00)
                      • Destructible - Resurrect (Picked destructible) with (Max life of (Picked destructible)) life and Show birth animation
                      • Hero - Add 10 experience to NaturesProphetcasterunit, Show level-up graphics
                    • Else - Actions
                  • Else - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • TreeIsFound Equal to True
            • Then - Actions
              • Animation - Play NaturesProphetcasterunit's spell animation
              • Animation - Queue NaturesProphetcasterunit's stand animation
              • Animation - Reset NaturesProphetcasterunit's animation
              • Special Effect - Create a special effect attached to the origin of NaturesProphetcasterunit using Abilities\Spells\NightElf\Tranquility\Tranquility.mdl
              • Special Effect - Destroy (Last created special effect)
            • Else - Actions
          • Custom script: call RemoveLocation(udg_TempPoint)
Thanks for entertaining my query. I am going to study this. Have a nice day. Ps. i should probably just study JASS but i'm so lazy and i have other things to prioritize but i'm also lazy.
 

Rheiko

Spell Reviewer
Level 27
Joined
Aug 27, 2013
Messages
4,243
You're welcome and honestly, yes you should :)
But if you're lazy like me, I guess GUI is a good start.

It still needs some custom scripts (which is JASS btw) here and there, but it should be much simpler to understand, in my opinion.
You will eventually come to understand JASS as you learn more scripts.

If you have a programming background, I would recommend learning JASS right away.
Lua is even better if you are on version 1.31.1 and beyond.
 
Top