• 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] Random Tree Regrowth

Status
Not open for further replies.
Level 5
Joined
Oct 5, 2012
Messages
67
So... I made an aos map, and thought it would be kinda funny if the trees would regrow at a random time spawn each (for example 1 to 8 seconds). Is this possible?
 
Well, using that event would still work, you'd just use it to regrow 1 tree each time, another method would be to array each tree as it dies and set a variable to a random number between 1 and 8 and apply that to them in the array, then using an artificial wait in a loop trigger, reduce the "time left" by 1 and then revive each tree and remove them from the array as they do so.
 
Level 23
Joined
Apr 16, 2012
Messages
4,041
I dont know about the efficiency of this since I never before used Event - destructable dies but ow well...
JASS:
// In case you have JNGP uncomment this:
//  globals
//      hashtable udg_hashrev = InitHashtable()
//  endglobals

function trigger2 takes nothing returns nothing
    local timer t = GetExpiredTimer()
    local destructable dest = LoadDestructableHandle(udg_hashrev, GetHandleId(t), 0)
    call DestructableRestoreLife(dest, 9999, true)
    set dest = null
    call DestroyTimer(t)
    set t = null
endfunction

function trigger1 takes nothing returns boolean
    local timer t = CreateTimer()
    call SaveDestructableHandle(udg_hashrev, GetHandleId(t), 0, GetTriggerDestructable())
    call TimerStart(t, GetRandomReal(4., 8.), false, function trigger2)
    set t = null
    return false
endfunction

//===========================================================================
function InitTrig_randomdest takes nothing returns nothing
    local trigger t = CreateTrigger(  )
    call TriggerRegisterDestDeathInRegionEvent(t, GetWorldBounds() )
    call TriggerAddCondition( t, Condition(function trigger1))
endfunction

It revives a dying destructable after 4 to 8 seconds of its dead, In case you have JNGP uncomment the global variable otherwise create your own with name hashrev.

This can be done in GUI but using wait so its not that good:
  • randomdest
    • Events
      • Destructible - A destructible within (Entire map) dies
    • Conditions
    • Actions
      • Custom script: local destructable dest = GetTriggerDestructable()
      • Wait (Random real number between 1.00 and 8.00) seconds
      • Custom script: call DestructableRestoreLife(dest, 9999, true)
      • -------- the first argument is the destructable, because I use local destructable Im also calling --------
      • -------- the GUI function Revive/Restore Destructable as custom script --------
      • -------- the second argument is with how much health should it revive --------
      • -------- the third argument is if we want a birth animation to show or not --------
      • Custom script: set dest = null
The problem is that this would revive even things like barrels etc, so If you are going to use the GUI one just add to conditions the trees you are using like:
  • (Destructible-type of (Dying destructible)) Equal to Summer Tree Wall
In GUI, GetTriggerDestructable is actually Dying destructable, so dont be confused ;)

Hope this helps you
edit: forgot to clear leak in GUI function :D
 
There's a much better GUI solution which doesn't use a wait and differenciates between things without using specific destructible types:


  • TreeRevival Init
    • Events
      • Map initialization
    • Conditions
    • Actions
      • Set TempPoint = (Center of (Playable map area))
      • Unit - Create 1 Peasant for Neutral Passive at TempPoint facing Default building facing degrees
      • Set TreeDetector = (Last created unit)
      • Unit - Hide TreeDetector
      • Custom script: call RemoveLocation(udg_TempPoint)
  • TreeDeath
    • Events
      • Destructible - A destructible within (Playable map area) dies
    • Conditions
    • Actions
      • Set TempTree = (Dying destructible)
      • Unit - Order TreeDetector to Harvest TempTree
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Current order of TreeDetector) Equal to (Order(harvest))
        • Then - Actions
          • Unit - Order TreeDetector to Stop
          • Set TreeMaxIndex = (TreeMaxIndex + 1)
          • Set DeadTree[TreeMaxIndex] = TempTree
          • Set TreeTimer[TreeMaxIndex] = (Random real number between 1.00 and 8.00)
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • TreeMaxIndex Equal to 1
            • Then - Actions
              • Trigger - Turn on TreeLoop <gen>
            • Else - Actions
        • Else - Actions
      • Destructible - Kill TempTree
  • TreeLoop
    • Events
      • Time - Every 0.03 seconds of game time
    • Conditions
    • Actions
      • For each (Integer TreeCurrentIndex) from 1 to TreeMaxIndex, do (Actions)
        • Loop - Actions
          • Set TreeTimer[TreeCurrentIndex] = (TreeTimer[TreeCurrentIndex] - 0.03)
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • TreeTimer[TreeCurrentIndex] Less than or equal to 0.00
            • Then - Actions
              • Destructible - Resurrect DeadTree[TreeCurrentIndex] with (Max life of (Last created destructible)) life and Show birth animation
              • Set TreeTimer[TreeCurrentIndex] = TreeTimer[TreeMaxIndex]
              • Set DeadTree[TreeCurrentIndex] = DeadTree[TreeMaxIndex]
              • Set TreeMaxIndex = (TreeMaxIndex - 1)
              • Set TreeCurrentIndex = (TreeCurrentIndex - 1)
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • TreeMaxIndex Equal to 0
                • Then - Actions
                  • Trigger - Turn off (This trigger)
                • Else - Actions
            • Else - Actions


Short JASS version is a lot better than this in terms of efficiency, though I just wanted to make sure GUI got the right look there of how it should be done strictly in GUI XD
 
Status
Not open for further replies.
Top