HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

Regrowing Trees

02-22-2007, 07:20 PM#1
Omnikron13
Hey.
My brother is trying to make the trees in his map regrow after a while, provided they aren't too close to buildings or units. However his attempt at this lags. I cannot show you what he tried, as it is on his computer, but it was made in GUI, and doesn't work anyway, due to the lag.

Anyway, how would you recommend doing this without it lagging really badly?
02-22-2007, 07:36 PM#2
Chocobo
Collapse JASS:
function Trig_Doodad_Ressurection takes nothing returns nothing
call DestructableRestoreLife(<the tree>,0.00,true)
endfunction

To revive it, and if you need conditions :

Collapse JASS:
function Trig_Doodad_Ressurection takes nothing returns nothing
if //conditions
then
call DestructableRestoreLife(<the tree>,0.00,true)
endif
endfunction
02-22-2007, 07:39 PM#3
Fireeye
Should it be a periodical event or only happen once?
02-22-2007, 07:52 PM#4
Omnikron13
Sorry, forgot to specify, periodically. However, he doesn't want it to look like a load regrow at once, then a wait, then repeat.

The main problem is that it seems to involve enuming through the maps destructables, and there are a -LOT- of those...
02-22-2007, 08:00 PM#5
Fireeye
I think i got a solution, i'll finish it and send it, but my wc3 is bugged so i'm unable to test it.
02-22-2007, 08:05 PM#6
Omnikron13
Thanks. =)

I'll test it when you do, and get back to you.
02-22-2007, 08:25 PM#7
Fireeye
Alright, you'll need 2 triggers.
1. Add all events to the target trigger.
Trigger:
Destructible - Pick every destructible in (Playable map area) and do (Actions)
Collapse Loop - Actions
Collapse If (All Conditions are True) then do (Then Actions) else do (Else Actions)
Collapse If - Conditions
(Destructible-type of (Last created destructible)) Equal to <Your Types>
Collapse Then - Actions
Trigger - Add to <Your Trigger containing the 2nd. Trigger> the event (Destructible - (Picked destructible) dies)
Else - Actions
2. Then use this Trigger, hope it'll work.
Hidden information:
Collapse JASS:
globals
    gamecache udg_gc = null
endglobals

function H2I takes handle h returns integer
    return h
    return 0
endfunction

function I2Des takes integer i returns destructable
    return i
    return null
endfunction

constant function Wait takes nothing returns real
    return 30.00
endfunction

constant function Range takes nothing returns real
    return 300.00
endfunction

function LoopReviveDestructables takes nothing returns nothing
    local timer t = GetExpiredTimer()
    local string s = I2S(H2I(t))
    local destructable d = I2Des(GetStoredInteger(udg_gc,"Revive Des",s))
    local location l = Location(GetDestructableX(d), GetDestructableY(d))
    local group g = GetUnitsInRangeOfLocMatching(Range(),l,null) //You could also add an condition here
    local integer i = CountUnitsInGroup(g)
    if i <= 0 then
        call DestructableRestoreLife(d,GetDestructableMaxLife(d),true)
        call PauseTimer(t)
        call DestroyTimer(t)
        call DestroyGroup(g)
        call RemoveLocation(l)
        set t = null
        set l = null
        set d = null
        set g = null
        return
    endif
    call DestroyGroup(g)
    call RemoveLocation(l)
    set t = null
    set l = null
    set d = null
    set g = null
endfunction

function StartReviveDestructables takes nothing returns nothing
    local destructable d = GetDyingDestructable()
    local timer t = CreateTimer()
    call StoreInteger(udg_gc,"Revive Des",I2S(H2I(t)),H2I(d))
    call TimerStart(t,Wait(),true,function LoopReviveDestructables)
    set d = null
    set t = null
endfunction

How to do:
1. create a game cache variable called gc
2. Make new Trigger call it however you want to
3. copy H2I and I2Des into the Custom Script Code Section (The Map icon in the trigger editor)
4. copy the 2 constant functions and LoopReviveDestructables into your new trigger (have to be above the beginning function)
5. now copy all actions from StartReviveDestructables into your trigger and it should work, at least if i didn't make something wrong, so try it first in a test map.
Description:
The function StartReviveDestructables creates a Timer and stores the destructable as integer into the gamecach, then it call the Loop function which checks if there are any units in range, if there are none it'll revive the destructable, pause and destroy the timer to prevent further runnings.
The 2 constant functions set the Duration between each pick and range is obviously the range in which units will be picked.
02-22-2007, 09:36 PM#8
Omnikron13
I couldn't actually get that to work, no trees seemed to be reviving at all...

If I add those events to a simple trigger to PolledWait() X seconds then revive the dying destructable, that works...
As I'm not very experienced in JASS, I can't say as to why it isn't working, though...
02-23-2007, 11:51 AM#9
Fireeye
I think i know what you've forgotten, you forgot to init the game cache, i attached a working test map so you can check your triggers.
Attached Files
File type: w3xTreeRevive.w3x (20.4 KB)
02-23-2007, 09:27 PM#10
Ammorth
Doesn't a Destructible group have a limit to 64 destructibles?