| 12-20-2007, 03:01 PM | #1 |
This is a script I copied and edited from Emjlr3's Map, It's supposed to revive destructables, There is no problem with the script, the problem is I don't know why it works, I can't understand how it works, can someone explain this to me please . Thank you! JASS:scope TreeRevive globals private constant boolexpr DUMMY_BOOLEXPR = null endglobals function RegrowTrees_Actions takes nothing returns nothing local destructable d = GetDyingDestructable() call TriggerSleepAction(GetRandomReal(5.00, 20.00)) call DestructableRestoreLife( d, GetDestructableMaxLife(d), true ) call SetDestructableAnimation(d, "birth") set d = null endfunction function Trees_Setup takes nothing returns nothing local trigger trig = CreateTrigger() call TriggerAddAction(trig, function RegrowTrees_Actions ) call TriggerRegisterDeathEvent( trig, GetEnumDestructable() ) set trig = null endfunction //=========================================================================== public function InitTrig takes nothing returns nothing call EnumDestructablesInRect( GetWorldBounds(), DUMMY_BOOLEXPR, function Trees_Setup ) endfunction endscope Question 2: When you create a destructable via script, you can put multiple destructables on a single location. Is there a way to check if a point can't be used to put a destructable? JASS:call CreateDestructable(d, 0,0,0.00,1.00,0) call CreateDestructable(d, 0,0,0.00,1.00,0)// This will create another destructable on the same // location as the first one, is there a way for me to make it not check if there's already a // destructable there and tell the script not to continue executing? |
| 12-20-2007, 03:29 PM | #2 |
For the second issue you're having, you can check if the terrain is pathable. I think the function is something like IsPathable() or something of that nature...I have no idea, I don't have WE up and running though, just search for a function with pathable in it that returns boolean. |
| 12-20-2007, 03:40 PM | #3 |
1) See the comments in correct order JASS:scope TreeRevive globals private constant boolexpr DUMMY_BOOLEXPR = null endglobals function RegrowTrees_Actions takes nothing returns nothing local destructable d = GetDyingDestructable() // 5) you need to save the dying tree into the variable, because the GetDyingDestructable() would be cleared by the sleepaction in point 6. Please note, that the dead tree is still a tree, but it has 0 HP call TriggerSleepAction(GetRandomReal(5.00, 20.00)) // 6) waint 5-20 seconds before reviving the tree call DestructableRestoreLife( d, GetDestructableMaxLife(d), true ) // 7) This function causes the tree to become alive again and play the "birth" animation call SetDestructableAnimation(d, "birth") // 8) this command is useless imo, the birth animation is afaik treated by the dunction in point 7 set d = null endfunction function Trees_Setup takes nothing returns nothing local trigger trig = CreateTrigger() // 2) you create a dummy trigger call TriggerAddAction(trig, function RegrowTrees_Actions ) // 4) you tell it to run the function RegrowTrees_Actions everytime the event in point 3 is triggered call TriggerRegisterDeathEvent( trig, GetEnumDestructable() ) // 3) you tell it to run EVERY time the tree being enumerated (see point 1) dies set trig = null endfunction //=========================================================================== public function InitTrig takes nothing returns nothing call EnumDestructablesInRect( GetWorldBounds(), DUMMY_BOOLEXPR, function Trees_Setup ) // 1) You pick ALL destructibles in the map and run the function Trees_Setup on each of them endfunction endscope 2) You can use the function CreateDestructibleLoc, which should attempt to create the destructible on the closest pathable location. and then check if the location is the same as you wanted it to be. You can remove it then if the location is shifted. The CreateDestructible may crash if the terrain wasn't pathable. |
| 12-20-2007, 03:55 PM | #4 |
Thanks CommanderZ for explaining, now I know why the hell it didn't need a global var LOL. Now I have another question, how come step 1 fires if the event triggering the action is in step 3? Also about step 8, it's not worthless, try removing it and you would see the complete birth animation of trees having 60.00 seconds animation time. It only works for animations no longer than 3 seconds, Well at least that was what I encountered. + REP EDIT: I can't rep there's an error, I don't know why? Nonetheless I will still try to add some rep for you for helping me, thanks a lot! |
| 12-20-2007, 04:17 PM | #5 |
The 1) is in the InitTrig function, which is alway ran on the map init without requiring any event. I you extracted the map .j file from the w3x, you would see that all valid InitTrig functions are being called in the map script header. Ad animation - it is strange. I'm using similiar system I made on my own. I don't have the call SetDestructableAnimation(d, "birth") there, but the animation is played correctly. Maybe it is caused by the fact I'm using the timer and not sleepaction. |
| 12-20-2007, 04:30 PM | #6 |
I'll try using timers and see what happens. |
| 12-20-2007, 05:01 PM | #7 |
I'm using this JASS:function ReviveTree takes nothing returns nothing local destructable tree=GetDyingDestructable() call TriggerSleepAction(30.) call DestructableRestoreLife( tree, GetDestructableMaxLife(tree), true ) set tree=null endfunction function Trig_Init_Tree_Revival takes nothing returns nothing local trigger t set t=CreateTrigger() call TriggerRegisterDeathEvent( t, GetEnumDestructable() ) call TriggerAddAction(t,function ReviveTree) set t=null endfunction function Init_Tree_Revive takes nothing returns nothing call EnumDestructablesInRectAll( GetPlayableMapRect(), function Trig_Init_Tree_Revival ) endfunction The Init_Tree_Revive must be called manually on map init. |
| 12-20-2007, 05:07 PM | #8 |
Using timers, I got the animation to work, You were right CommanderZ, Thanks for the help and the information. EDIT: I used your code and it works flawlessly, I think something's wrong with mine, can I ask permission to use your code, I'll add it to a system I'm building, it's a must have since I'm making a Region-based Tree Creation system, this would be an optional part. I'll give credits to you and if there's more I need to credit regarding this script then please tell me. Great Help you gave CommanderZ, I salute you! EDIT_2: I know why its acting like that! It's because I called TriggerAddAction before the TriggerRegister. |
| 12-20-2007, 05:41 PM | #9 |
No problem, it is 15 lines of code :D |
| 12-20-2007, 07:22 PM | #10 | |
Quote:
You mean IsTerrainPathable? The one function that ignores destructables? |
| 12-21-2007, 05:18 PM | #11 |
If it ignores destructables then it won't work on destructables? |
| 12-21-2007, 06:20 PM | #12 |
Btw this code have an side effect, it will revive doors as well, i think thats why you need the global boolexpr to filter out the doors and other doodads that you don't need to revive. |
| 12-22-2007, 05:07 AM | #13 |
Yes it revives anything that is a destructable including cages, boxes, etc. Thanks for pointing it out. |
| 12-22-2007, 08:57 AM | #14 | |
Quote:
Yes, I know about that (I just forget to point it out). It is written to be as simple as possible in my map where I don't have any non-tree destructibles. If you have some, just use EnumDestructablesInRect instead of EnumDestructablesInRectAll and set up a filter with some rawcode checks. |
| 12-22-2007, 09:04 AM | #15 |
I used an array to acomplish the task. lol Thanks for the info guys. |
