Moderator
M
Moderator
19th Oct 2011
Bribe: Thanks for making the changes - good system.
Bribe: Thanks for making the changes - good system.
(1 ratings)
Tree Revival SystemVersion: 1.2.3.2
Requirements:
- standard World Editor
Note: that this system is GUI-friendly.
Created due to limitation (max 64 destuctibles registered) brought by function TriggerRegisterDestDeathInRegionEvent(trig, r). Take a look:
When map initialization starts, bj_MAX_DEST_IN_REGION_EVENTS is automaticaly set to 64:JASS:function RegisterDestDeathInRegionEnum takes nothing returns nothing set bj_destInRegionDiesCount = bj_destInRegionDiesCount + 1 if (bj_destInRegionDiesCount <= bj_MAX_DEST_IN_REGION_EVENTS) then call TriggerRegisterDeathEvent(bj_destInRegionDiesTrig, GetEnumDestructable()) endif endfunction function TriggerRegisterDestDeathInRegionEvent takes trigger trig, rect r returns event set bj_destInRegionDiesTrig = trig set bj_destInRegionDiesCount = 0 call EnumDestructablesInRect(r, null, function RegisterDestDeathInRegionEnum) return trig endfunction
And thats the true reason why such issue occurs.JASS:constant integer bj_MAX_DEST_IN_REGION_EVENTS = 64
Idea is to enumerate through all destructibles on map and register death event of picked one (ofcourse at first we check if it's actually a tree).
Configurables:
- Recurrection time
- Show/hide birth animation
How to import:
- Copy and paste 'Tree Revival' category into your map
- 'TR Variable Creator' can be deleted as soon as you import system - it's here only for automatic variable creation
Additionaly:
- Features vanilla Jass IsDestructableTree version by PitzerMike.
So, whenever you want to check if given desctructible is actually a tree write down:
call TR_IsDestructableTree(somedest)
or for GUI-users:
Make sure to add 'udg_' prefix if you are using GUI globals.
- Custom script: call TR_IsDestructibleTree(<destructible here>)
- You can disable/enable tree reviving via global TRisEnabled.
Anytime you want tree not to be resurrected just use:
By defaul system has 'TRisEnabled' set to 'True', so trees are being revived anytime they die.
- Set TRisEnabled = False
- Destructable - Kill <tree here>
- Set TRisEnabled = True
Credits:
- PitzerMike for IsDestructableTree.
Special thanks to:
- Bribe for 'uloc' dummy idea
- baassee for timers recycling idea
Note: Units which step on position of tree which is currently being resurrected may get stuck between trees in that area.- Version 1.2.0.0 - system released
- Version 1.2.1.0 - added constant function for dummy, harvest ability and harvest order rawdatas
- Version 1.2.2.0 - replaced order of 'if' parameters in TRgetTimer function to improve script's speed
- Version 1.2.3.0 - added option TRisEnabled, you can now shut down the system anytime you want to
- Version 1.2.3.1 - function names has been changes, as Bribe suggested. Variable Creator added.
- Version 1.2.3.2 - Fixed debug tag usage for TR_recycleTimer so code compiles with new WE versions when debug mode is turned off.
System Code:JASS://************************************************************************************************ //* ____ ___ ___ * //* /_ _| _ \/ __/ Tree Revival System * //* | || /\__ \ by Bannar * //* |_||_|\_\___/ v1.2.3.2 * //* * //************************************************************************************************ //********************************************************* //* Globals required //********************************************************* //* udg_TRtrig Trigger for handling the revive actions //* udg_TRhash Hashtable for timer issues //* udg_TRindexD Stores revival instances //* udg_TRindexN Parameter for timers manipulation //* udg_TRtimers Timer array variable for recycle issues //* udg_TRdummyh Dummy harvester for IsDestructibleTree function //* udg_TRisEnabled Boolean parameter for enabling/disabling the system //********************************************************* //* Important //********************************************************* // Note: Units which step on position of tree which is currently // being resurrected may get stuck between trees in that area //********************************************************* //* Constant configurable functions //********************************************************* //* Rawdata of undead locust unit type constant function TR_dummyhId takes nothing returns integer return 'uloc' endfunction //* Rawdata of dummy ghoul harvest ability constant function TR_harvestId takes nothing returns integer return 'Ahrl' endfunction //* Harvest order ID constant function TR_orderId takes nothing returns integer return 852018 endfunction //* Delay before tree gets resurrected constant function TR_ReviveDelay takes nothing returns real return 5. endfunction //* Tells if birth animation should be shown while resurrecting a tree constant function TR_ShowAnimation takes nothing returns boolean return true endfunction //********************************************************* //* System itself //********************************************************* function TR_recycleTimer takes timer t returns nothing debug if t == null then debug call BJDebugMsg("Attempt to release a null timer") debug else call PauseTimer(t) set udg_TRtimers[udg_TRindexN] = t set udg_TRindexN = udg_TRindexN + 1 debug endif endfunction function TR_getTimer takes nothing returns timer if 0 == udg_TRindexN then return CreateTimer() endif set udg_TRindexN = udg_TRindexN - 1 return udg_TRtimers[udg_TRindexN] endfunction function TR_Callback takes nothing returns nothing local destructable d = LoadDestructableHandle(udg_TRhash, 0, GetHandleId(GetExpiredTimer())) call DestructableRestoreLife(d, GetDestructableMaxLife(d), TR_ShowAnimation()) call TR_recycleTimer(GetExpiredTimer()) set udg_TRindexD = udg_TRindexD - 1 if udg_TRindexD == 0 then call FlushChildHashtable(udg_TRhash, 0) endif set d = null endfunction function TR_CallRevive takes nothing returns boolean local timer t if udg_TRisEnabled then set t = TR_getTimer() set udg_TRindexD = udg_TRindexD + 1 call SaveDestructableHandle(udg_TRhash, 0, GetHandleId(t), GetTriggerDestructable()) call TimerStart(t, TR_ReviveDelay(), false, function TR_Callback) set t = null endif return false endfunction function TR_IsDestructableTree takes destructable dest returns boolean return IssueTargetOrderById(udg_TRdummyh, TR_orderId(), dest) endfunction function TR_AddTree takes nothing returns nothing if TR_IsDestructableTree(GetEnumDestructable()) then call TriggerRegisterDeathEvent(udg_TRtrig, GetEnumDestructable()) endif endfunction //*************************************************************************** function InitTrig_TreeRevival takes nothing returns nothing set udg_TRtrig = CreateTrigger() set udg_TRhash = InitHashtable() //* By default enabled set udg_TRisEnabled = true //* Actions required for IsDestructibleTree function set udg_TRdummyh = CreateUnit(Player(15), TR_dummyhId(), 0., 0., 0.) call ShowUnit(udg_TRdummyh, false) call UnitAddAbility(udg_TRdummyh, TR_harvestId()) call UnitRemoveAbility(udg_TRdummyh, 'Amov') //* Revival setup call EnumDestructablesInRect(bj_mapInitialPlayableArea, null, function TR_AddTree) call TriggerAddCondition(udg_TRtrig, Condition(function TR_CallRevive)) endfunction
if udg_TRindexD == 0 then
if 0 == udg_TRindexD then
function InitTrig_TreeRevive takes nothing returns nothing
set udg_TreeReviveTrig = CreateTrigger()
set udg_TRhash = InitHashtable()
//* Actions required for IsDestructibleTree function
set udg_dummyh = CreateUnit(Player(15), 'uloc', 0., 0., 0.)
call ShowUnit(udg_dummyh, false)
call UnitAddAbility(udg_dummyh, 'Ahrl')
call UnitRemoveAbility(udg_dummyh, 'Amov')
//* Revival setup
call EnumDestructablesInRect(bj_mapInitialPlayableArea, null, function CallAddTree)
call TriggerAddCondition(udg_TreeReviveTrig, Condition(function CallTreeRevive))
endfunction
function TRrecycleTimer takes timer t returns nothing
debug if t == null then
debug call BJDebugMsg("Attempt to release a null timer")
else
call PauseTimer(t)
set udg_TRtimers[udg_TRindexN] = t
set udg_TRindexN = udg_TRindexN + 1
endif
endfunction
function TRrecycleTimer takes timer t returns nothing
debug if t == null then
debug call BJDebugMsg("Attempt to release a null timer")
debug else
call PauseTimer(t)
set udg_TRtimers[udg_TRindexN] = t
set udg_TRindexN = udg_TRindexN + 1
debug endif
endfunction
function TRrecycleTimer takes timer t returns nothing
debug if t == null then
debug call BJDebugMsg("Attempt to release a null timer")
else
call PauseTimer(t)
set udg_TRtimers[udg_TRindexN] = t
set udg_TRindexN = udg_TRindexN + 1
endif
endfunction
function TRrecycleTimer takes timer t returns nothing
debug if t == null then
debug call BJDebugMsg("Attempt to release a null timer")
debug else
call PauseTimer(t)
set udg_TRtimers[udg_TRindexN] = t
set udg_TRindexN = udg_TRindexN + 1
debug endif
endfunction
I just tried and my system register totaly of 0 trees if I use boolexpr trick
function CallAddTree takes nothing returns nothing
if IsDestructableTree(GetEnumDestructable()) then
call TriggerRegisterDeathEvent(udg_TreeReviveTrig, GetEnumDestructable())
endif
endfunction
function CallAddTree takes nothing returns nothing
if IssueTargetOrderById(udg_dummyh, TRorderId(), GetEnumDestructable()) then
call TriggerRegisterDeathEvent(udg_TreeReviveTrig, GetEnumDestructable())
endif
endfunction
- You can now disable/enable tree reviving via global TRisEnabled.
Anytime you want tree not to be resurrected just use:
By defaul system has 'TRisEnabled' set to 'True', so trees are being revived anytime they die.
- Set TRisEnabled = False
- Destructable - Kill <tree here>
- Set TRisEnabled = True
how about this one?@ xorkatoss: that would revive every destructable not just trees... and also buggy...
Just additional issue about your script (to those mentioned already above): GetDyingDestructible() is slower than GetTriggerDestructible().
@Adiktuz
It gets inlined anyways
Why dont just make it a simple system of GUI periodic event each 5 mins or 8 mins or wharever.
Event:
each 10 mins of the game
Conditions:
Null
Action
IfThenElse:
Pick every destructible in entire map
-Or Multiple conditions
-If Picked destructible (all types of tree)
-If life of picked desructible is equal to 0
--Action:
Resurrect picked destructible and show birth anims
Else: Remove not matching destructibles.. etc
Else you can do a pick destructible group and try saving it on a hashtable by the use of another trigger (with custom script). Anyways its a good system.
Else you should remember that if there is a unit near a dead tree (100 units near) i recommend you to remove the tree or to avoid the resurrection of it.
ive already readed the one above, i just didn't understand anything xD
i really couldn't care less about the GetTriggerDestructible() thingy...
only useful scripts to me are "RemoveLocation" and "call want_DestroyGroup = true" since im a GUIer...
EDIT:
i forgot to tell you, that tree revival system is not mine, it was in this spell...so it wasn't me who actually failed lol
function TRrecycleTimer takes timer t returns nothing
debug if t == null then
debug call BJDebugMsg("Attempt to release a null timer")
else
call PauseTimer(t)
set udg_TRtimers[udg_TRindexN] = t
set udg_TRindexN = udg_TRindexN + 1
endif
endfunction
function TRrecycleTimer takes timer t returns nothing
else
call PauseTimer(t)
set udg_TRtimers[udg_TRindexN] = t
set udg_TRindexN = udg_TRindexN + 1
endif
endfunction
function TRrecycleTimer takes timer t returns nothing
debug if t == null then
debug call BJDebugMsg("Attempt to release a null timer")
debug else
call PauseTimer(t)
set udg_TRtimers[udg_TRindexN] = t
set udg_TRindexN = udg_TRindexN + 1
debug endif
endfunction
IssueImmediateOrderById(udg_dummyh, 851972)
will fix the issue.i don't get it...is your system better than this?
it does pretty much the same thing...
- Tree Setup
- Events
- Map initialization
- Conditions
- Actions
- Destructible - Pick every destructible in (Playable map area) and do (Actions)
- Loop - Actions
- Trigger - Add to TreeRevive Setup <gen> the event (Destructible - (Picked destructible) dies)
- Tree Resurrection
- Events
- Conditions
- Actions
- Wait 6.00 seconds
- Destructible - Resurrect (Dying destructible) with (Max life of (Dying destructible)) life and Show birth animation
Thank you for reporting this.07/Mar/2019
Moved to awaiting updated: The map fails to save on 1.30.4 editor due to bad debug tag usage. It can only be saved with JASSHelper set to debug build mode.
The error is in the TR_recycleTimer function. One has to debug tag the else and endif blocks so they are ignored when not built in debug mode.