• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

[vJASS] [Snippet] DestructableLibII

Level 9
Joined
Jun 21, 2012
Messages
432
Well another share:

JASS:
library DestructableLibII initializer Init
/*********************************************************************************
*
*   DestructableLibII
*   _________________
*   v1.0.1.1
*   Originally made by PitzerMike, update by Thelordmarshall.
*   
*   This is a useful compilation of all custom destructable functions in one 
*   library.
*   
*   API:
*   ____
*       - function IsDestructableDead takes destructable d returns boolean
*       - function IsDestructableTree takes destructable d returns boolean
*       - function KillDestructablesInRange takes real x, real y, real range returns nothing
*       - function ReviveDestructable takes destructable d, boolean birth returns boolean
*
*   Credits: PitzerMike.
**********************************************************************************/

    globals
        private constant integer DUMMY_ID         = 'uloc'  // locust
        private constant integer HARVEST_ID       = 'Ahrl'  // ghouls harvest
        private constant integer HARVEST_ORDER_ID = 0xD0032 // harvest order ID
        private integer i=0
        private unit u=null
    endglobals
    
    function IsDestructableDead takes destructable d returns boolean
        return GetDestructableLife(d)<=.405
    endfunction
    
    function IsDestructableTree takes destructable d returns boolean
        return IssueTargetOrderById(u,HARVEST_ORDER_ID,d)
    endfunction
    
    private function KillTrees takes nothing returns nothing
        local destructable d=GetEnumDestructable()
        if(d!=null and not IsDestructableDead(d) and IsDestructableTree(d))then
            call KillDestructable(d)
            set i=i+1
        endif
        set d=null
    endfunction
    
    function KillDestructablesInRange takes real x, real y, real range returns boolean
        local rect r=Rect(x-range,y-range,x+range,y+range)
        set i=0
        call EnumDestructablesInRect(r,null,function KillTrees)
        call RemoveRect(r)
        set r=null
        return i>0
    endfunction
    
    function ReviveDestructable takes destructable d, boolean birth returns boolean
        if(IsDestructableDead(d))then
            call DestructableRestoreLife(d,GetDestructableMaxLife(d),birth)
            return true
        endif
        return false
    endfunction
    
    private function Init takes nothing returns nothing
        set u=CreateUnit(Player(15),DUMMY_ID,0.,0.,0.)
        call ShowUnit(u,false)
        call UnitAddAbility(u,HARVEST_ID)
        call UnitRemoveAbility(u,'Amov')
    endfunction
endlibrary
 
Last edited:
Level 23
Joined
Apr 16, 2012
Messages
4,041
JASS:
    function IsDestructableTree takes destructable d returns boolean
        return IssueTargetOrderById(u,HARVEST_ORDER_ID,d)
    endfunction

wont this glitch actually?

Lets say I call it once, the unit is ordered to harvest the tree, and so he goes harvest the tree. And then after 30 seconds I try to call it again, he goes harvest another tree, but wont he actually harvest so much from the first tree as to kill it? Or get filled and try to run to some town building to drop the wood off?

KillDestructablesInRange is inaccurate, because range means circle, and you convert the circle into square, meaning that you actually include more than you should. However, I dont think there is any way to fix this in wc3
 
Level 19
Joined
Mar 18, 2012
Messages
1,716
edo494, it won't harvest from the tree because he removed the dummy unit's ability to move.
I'm pretty sure you have to oder stop after harvest. When I uploaded IsDestructableTree, I (probably) tried that out.
Thelordmarshall should test it, just to be sure.

I think we have something similar made by Bannar in the Jass section.
The only function which could be usefull/new is DamageDestructablesInCircle, which is not equal to DamageDestructablesInRange.
 

Kazeon

Hosted Project: EC
Level 33
Joined
Oct 12, 2011
Messages
3,449
JASS:
    function KillDestructablesInRange takes real x, real y, real range returns boolean
        local rect r=Rect(x-range,y-range,x+range,y+range)
        set i=0
        call EnumDestructablesInRect(r,null,function KillTrees)
        call RemoveRect(r)
        set r=null
        return i>0
    endfunction

Should be "KillTreesInRect". And I thought about something better, when the action (code) should become a parameter, so user can determine their own actions, not only to kill. And you can use one rect instead of recreating one on every call. And is it really necessary to return "boolean"?

And I think this is too simple. It doesn't do anything particularly special. Checking IsTree is available in other resource already. While IsDestDead is.. just.. not really something. My point is, those functions can be done by user using native functions easily. There is just no "special trick" to achieve something special. Such simple "wrapper" is not necessary to be made imho
 

Bannar

Code Reviewer
Level 26
Joined
Mar 19, 2008
Messages
3,140
Please, just don't.

Together with Bribe and BPower IDT was evaluated and optimalized to the limit. Their and mine resources can be found on this very forum.

We do not need another ctrl+c/v version of the exact same resource.
Sorry, but thats true - if you want to add something useful to the subject, especially if it's rather small update post a comment and/or suggestion instead.
 
Level 9
Joined
Jun 21, 2012
Messages
432
Please, just don't.

Together with Bribe and BPower IDT was evaluated and optimalized to the limit. Their and mine resources can be found on this very forum.

We do not need another ctrl+c/v version of the exact same resource.
Sorry, but thats true - if you want to add something useful to the subject, especially if it's rather small update post a comment and/or suggestion instead.

Hi Bannar :) ok although it was not my intention at first the copy/paste, i agree with you.:fp: I think can send this resource to GY
 

Bannar

Code Reviewer
Level 26
Joined
Mar 19, 2008
Messages
3,140
That is to say, I appreciate every person that makes an effort and spends his/her time to improve the resources and the overall quality of forum. Without such passionate people, you would meet only dust here.

Sometimes tho, it does not have to be "big" one i.e even simple suggestion/comment can mean a lot. Don't worry man, I have been there too. Took time before I realized that.
 
Top