• 🏆 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] Destroy trees

Status
Not open for further replies.
Level 16
Joined
May 1, 2008
Messages
1,605
Moin moin =)

First of all: YES I used the search function and I found everything but not that what I want, so I make a new Thread - hope it's ok!

As the title say: I want destroy trees. In GUI it's very easy but I don't get in jass (vJass). I asked jasshelper but it show me mass bj's and so on, so I thought this can't be the way.

I have 2 globals:
JASS:
        private constant boolean    DESTROY_TREE       = true 
        private constant real       DESTROY_TREE_RANGE = 30.

And now I need something like:
JASS:
if DESTROY_TREE then
   pick every trees in DESTROY_TREE_RANGE and do:
     Kill Tree

Can someone help me with this plz, because again jasshelper shows something I don't understand and so many bj's ...

Greetings - Thanks - Peace
Dr. Boom
 
Level 16
Joined
May 1, 2008
Messages
1,605
Moin moin =)

Yes in GUI it would be "EnumDestructablesInCircleBJ". Now this is a bj and Jasshelper show how to fix it but this mess up for me ...

JASS:
function EnumDestructablesInCircleBJ takes real radius, location loc, code actionFunc returns nothing
    local rect r

    if (radius >= 0) then
        set bj_enumDestructableCenter = loc
        set bj_enumDestructableRadius = radius
        set r = GetRectFromCircleBJ(loc, radius)
        call EnumDestructablesInRect(r, filterEnumDestructablesInCircleBJ, actionFunc)
        call RemoveRect(r)
    endif
endfunction

In addition to fix getRectFromCircleBJ I have to use:
JASS:
function GetRectFromCircleBJ takes location center, real radius returns rect
    local real centerX = GetLocationX(center)
    local real centerY = GetLocationY(center)
    return Rect(centerX - radius, centerY - radius, centerX + radius, centerY + radius)
endfunction

So I thought maybe there's a easier way to do this, because jasshelpers help isn't the best I figured out and I thought it isn't like "just use
JASS:
EnumDestructablesInRect
". .. you know
 
Level 6
Joined
Nov 3, 2008
Messages
117
Here it goes:
JASS:
library AnyLib initializer Init

globals
    private constant boolean    DESTROY_TREE       = true 
    private constant real       DESTROY_TREE_RANGE = 30.
    private constant integer    HARVEST_ORDER      = 852018 // OrderId for the Peasants Harvest
    
    private unit TREE_CHECKER                               // The Unit to check whether a destructable is a tree
    private rect ENUM_RECT   
endglobals

private function IsDestructableTree takes destructable d returns boolean
    local boolean b
    if GetWidgetLife(d)>0.405 then
        call ShowUnit(TREE_CHECKER,true)
        set b = IssueTargetOrderById(TREE_CHECKER,HARVEST_ORDER,d)
        call ShowUnit(TREE_CHECKER,false)
        return b
    endif
    return false
endfunction

private function TreeFilter takes nothing returns boolean
    if IsDestructableTree(GetFilterDestructable()) then
        call KillDestructable(GetFilterDestructable())
    endif
    return false
endfunction

function DestroyTrees takes real x, real y returns nothing
    if DESTROY_TREE then
        call MoveRectTo(ENUM_RECT, x , y )
        // x: The x-coordinate of the point where you want the trees be killed arround
        // y: The y-coordinate of the point where you want the trees be killed arround
        call EnumDestructablesInRect(ENUM_RECT,Condition(function TreeFilter),null)
    endif
endfunction


private function Init takes nothing returns nothing
    set TREE_CHECKER = CreateUnit(Player(15),'hpea',0.,0.,0.)
    set ENUM_RECT = Rect(-DESTROY_TREE_RANGE,-DESTROY_TREE_RANGE,DESTROY_TREE_RANGE,DESTROY_TREE_RANGE)
    
    call ShowUnit(TREE_CHECKER,false)
endfunction 
    
endlibrary

I hope it helps you!
 
Status
Not open for further replies.
Top