• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

Does this function has an destructible version?

Status
Not open for further replies.
Level 11
Joined
Oct 9, 2015
Messages
721
Can this function have an destructible version of it, using destructible instead of units? I'm not very good with JASS so I don't know

  • Custom script: call GroupEnumUnitsInRangeOfSegmentLoc( udg_TempGroup, udg_Loc1, udg_Loc2, 10.0, null )
 
There exists this native functions:

native EnumDestructablesInRect takes rect r, boolexpr filter, code actionFunc returns nothing

But you can use it also with GUI as said. If you want achieve something in jass/custom script from GUI you can search the respective action in GUI and convert it to custom text. So you will see the output.
 
Level 11
Joined
Oct 9, 2015
Messages
721
GUI is also a good option since the most portion of my map is GUI. however how can this be adapted to fit the rect of Loc1 and Loc2, and how can I put the trees in an group? Sorry Iceman I'm not an JASS scripter, I sometimes can work with them, but can't create them myself
 
Read my previous posts. You can not create a "group" of destructables. At least not the way you are thinking of it.

I didn't read the first custom script close enough, and you forgot it to mention. You use a library which provides this custom function "GroupEnumUnitsInRangeOfSegmentLoc" for you.
So you can not use it directly in GUI, but instead need to rewrite it.

Provide the library you use.
 
Level 11
Joined
Oct 9, 2015
Messages
721
Code:
function GroupEnumUnitsInRangeOfSegment takes group whichgroup, real Ax, real Ay, real Bx, real By, real distance, boolexpr filter returns nothing
    local real dx = Bx-Ax
    local real dy = By-Ay
    local real L = ((dx)*(dx) + (dy)*(dy)) // Get quasi length
    local real r = SquareRoot(dx*dx+dy*dy)/2+distance + 400.0 // replace 400.0 with the max collision size in your map
    local unit u
    call GroupClear(whichgroup)
    call GroupEnumUnitsInRange(udg_LineTempGroup, Ax+(dx/2), Ay+(dy/2), r, filter)
    loop
        set u = FirstOfGroup(udg_LineTempGroup)
        exitwhen u == null
        if L == 0 and IsUnitInRangeXY(u, Ax, Ay, distance) then // seg is actually a point so lets return the point
            call GroupAddUnit(whichgroup, u)
        else
            set r = ((GetUnitX(u)-Ax)*(dx) + (GetUnitY(u)-Ay)*(dy))/(L) // get the ratio
            if r > 1 then // split if/thens so that it exists properly
                if IsUnitInRangeXY(u, Bx, By, distance) then // closests point is past seg, so return end point B
                    call GroupAddUnit(whichgroup, u)
                endif
            elseif r < 0 then
                if IsUnitInRangeXY(u, Ax, Ay, distance) then // same as B, but at A instead
                    call GroupAddUnit(whichgroup, u)
                endif
            elseif IsUnitInRangeXY(u, Ax+r*(dx), Ay+r*(dy), distance) then // In the middle of A and B so use the ratio to find the point
                call GroupAddUnit(whichgroup, u)
            endif
        endif
        call GroupRemoveUnit(udg_LineTempGroup, u)
    endloop
    set u = null    
endfunction
function GroupEnumUnitsInRangeOfSegmentLoc takes group whichgroup, location A, location B, real distance, boolexpr filter returns nothing
    call GroupEnumUnitsInRangeOfSegment(whichgroup, GetLocationX(A), GetLocationY(A), GetLocationX(B), GetLocationY(B), distance, filter)
endfunction
 
Level 11
Joined
Oct 9, 2015
Messages
721
I opened it and walked arround with the footmans but nothing happanned
PS: Will it work with normal world editor or only with JassNewgen? If so I'll ask purgeandfire to make a normal JASS version of it to work with normal world editor
 
Level 11
Joined
Oct 9, 2015
Messages
721
Thanks a lot, IcemanBo it's working, the trees are getting destroyed! I'll send the code to purgeandfire for vJass -> JASS translation. If you could translate it that would be great but I'm requiring too much from you, you already helped me a lot, thanks again!
 
Level 11
Joined
Oct 9, 2015
Messages
721
It's working fine, IcemanBo thanks a lot! I'll try implementing it on my map and if I cross with any trouble I'll be back here to ask for help, again thanks a lot for helping me out!

EDIT: The editor is returning an error when I try to initiate the my map after I just copied the category containing the triggers, I just copied it with the preferences for variables enabled and it can't start.
 
Last edited:
Level 11
Joined
Oct 9, 2015
Messages
721
I've run into a problem, sometimes the tree is killed, but sometimes it doesn't o_O
The part of the trigger I've implemented on mine:
  • LSE How to Use Copy
    • Events
    • Conditions
    • Actions
      • Set LSE_Loc_1 = Loc1
      • Set LSE_Loc_2 = Loc2
      • Set LSE_Width = 10.00
      • Trigger - Run LSE_Trigger_GetDestructables (ignoring conditions)
      • For each (Integer A) from 1 to LSE_Counter, do (Actions)
        • Loop - Actions
          • Destructible - Kill LSE_Destructable[(Integer A)]
      • Custom script: call RemoveLocation(udg_LSE_Loc_1)
      • Custom script: call RemoveLocation(udg_LSE_Loc_2)
 
Level 11
Joined
Oct 9, 2015
Messages
721
The event is "A unit dies" I've tested the Width with higher values such as 100 and had the same effect.
Loc1 and Loc2 are set in the same trigger before those actions, Loc1 menas the position of an unit (player hero) and Loc2 the position of another unit (dying or triggering unit)
 
Level 11
Joined
Oct 9, 2015
Messages
721
Iceman, does this line works with verry small lines? I was using an line of about 100-120 long and it wasn't always working, I changed to a longer line (100 to the back of one unit, 100 to the front of the another. Loc1 and Loc2) and most of the trees were now sucesfully chopped down.
 
Level 11
Joined
Oct 9, 2015
Messages
721
I may have found what's causing the issue, but I don't know how to fix it. Here's what I've found so far:
The triggers system I'm using for this is based on creating an unit at distance from the player hero, then add expiration timer to it, when it dies a trigger will be fired. I firstly was using an invisible dummy, but once I made the unit visible I could see the unit could not be created correctly because of the destructible in the path of the hero, instead it is created somewhere else near. The positions I'm using are: Loc1 = Position of hero. Loc2 = Position of the dummy unit. I think that that I need to bypass that issue of creating the unit on the wrong place, but how ?

PS: If I set the second location to very far in front of the hero, the system works, because the destructible don't cause interference.
 
Use:

call SetUnitX( <yourunitVariable>, <newX>)
call SetUnitY( <yourunitVariable>, <newY>)

GUI variables in JASS/Custom script need usg_ prefix ; so "Unit" will becomes "udg_Unit".

For new x/y you can use:

GetLocationX(<yourLocationVariable>)
GetLocationY(<yourLocationVariable>)

... ^ these functions get the x/y coodinate of a location/point. So take these in combination to move a unit to a location.

So finaly you will need two lines of custom script using the SetUnitX/Y natives, and within them to define which x/y you use the GetLocationX/Y natives.
 
Level 11
Joined
Oct 9, 2015
Messages
721
I understood a little about what you said, but I've come to a conclusion that it's not the unit's position that's causing the problem. I've set Loc1 to position of hero, and Loc2 to position of hero with polar offset (120 towards facing of hero) and it keeps the same way, sometimes some trees are destroyed and some aren't. here's an clear test map:


EDIT: I may have found what was causing the error:
  • For each (Integer A) from 1 to LSE_Counter, do (Actions)
    • Loop - Actions
      • Destructible - Kill LSE_Destructable[(Integer A)]
I replaced this function with:
  • Destructible - Pick every destructible within 120.00 of Loc1 and do (Actions)
    • Loop - Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (LSE_Rect contains (Position of (Picked destructible))) Equal to True
        • Then - Actions
          • Destructible - Kill (Picked destructible)
        • Else - Actions
So the trigger was like that:
  • Test
    • Events
      • Unit - A unit Dies
    • Conditions
      • (Unit-type of (Triggering unit)) Equal to YourUnitType
    • Actions
      • Set Loc1 = (Position of Hero)
      • Set Loc2 = (Position of (Triggering unit))
      • Set LSE_Loc_1 = Loc1
      • Set LSE_Loc_2 = Loc2
      • Set LSE_Width = 10.00
      • Trigger - Run LSE_Trigger_GetDestructables (ignoring conditions)
      • Destructible - Pick every destructible within 120.00 of Loc1 and do (Actions)
        • Loop - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (LSE_Rect contains (Position of (Picked destructible))) Equal to True
            • Then - Actions
              • Destructible - Kill (Picked destructible)
            • Else - Actions
      • Custom script: call RemoveLocation(udg_LSE_Loc_1)
      • Custom script: call RemoveLocation(udg_LSE_Loc_2)
And now the destructibles are getting picked correctly without a single error!
 

Attachments

  • Test_IcemanBo.w3x
    23.9 KB · Views: 21
Last edited:
Level 11
Joined
Oct 9, 2015
Messages
721
Yeah I forgot about changing it properly when I paste it to the demo map. I've set it to a correct location but it ended up the same way as before, I think the problem was really the "For each.." function, because I've changed for the new function and it works like magic! Thanks a lot for your coding, IcemanBo!

PS: It's an system that detects the animation of the swing of the sword, that's why the so low Width, to pick everything by intervals of 10 to 10 distance and when it crashes to a tree, the attack stops. It's like an coded normal attack, but using an ability instead.
 
Status
Not open for further replies.
Top