How to make unit avoid snow?

staind25

TH.net Regular
Reaction score
7
I have a custom unit based off of a Footman that I want to avoid specific tiles. The reason being, I have a path drawn for it, and when I order it to "attack-move", I want it to follow that path. It would really cut down on the triggering (Map is large and the unit's going across the map).

Is this possible? If so, how do I go about doing this?

My idea was to somehow use the object editor, and a little triggering if necessary. I was thinking of checking "Editor - Has Tileset Specific Data", but from there, I'm not sure how to specify that I want snow to be unwalkable for that unit.

Thank you :)
 

Sui-cookie

You can change this now in User CP.
Reaction score
49
wellll you could always edit tile path ability for snow to be un-walkable, but then no units except flying could go on them... and idk if footmen are the only units in your map?

nvm, i didnt read:
I'm not sure how to specify that I want snow to be unwalkable for that unit.

umm. idk , ill see if i can figure something out o_O
 

xPass

All aboard the xPass Express!
Reaction score
26
What about using regions to move, though it WILL flood the WE with triggers :D (Or do you not want a lot of triggers?)
 

HydraRancher

Truth begins in lies
Reaction score
197
What about using regions to move, though it WILL flood the WE with triggers :D (Or do you not want a lot of triggers?)

You can use 2 triggers to make it walk along a path.

I don't think it's possible to create a path that is unpathable for 1 unit type. You'll have to use triggers & regions.
 

KaerfNomekop

Swim, fishies. Swim through the veil of steel.
Reaction score
613
My idea was to somehow use the object editor, and a little triggering if necessary. I was thinking of checking "Editor - Has Tileset Specific Data", but from there, I'm not sure how to specify that I want snow to be unwalkable for that unit.

No, tileset specific data means that it only appears on the list of neutral units for a certain tileset. You could make a periodic trigger to check if the terrain under the footman is snow, and if so move it back a small range.
 

staind25

TH.net Regular
Reaction score
7
Thanks for the responses...sorry it took me awhile to get back.

@HydraRancher, which 2 triggers are you referring to? If I could order a unit to walk along a specified path with only 2 triggers across the whole map I'd be very happy.

@Sui-cookie, yeah, I'm trying to make it so that it only affects this unit, not the whole game :)

@xPass, using a ton of triggers is the most likely option but also my last resort. It would take a LOT of triggers and a ton of regions too. The map is already very large and has tons of regions/triggers...I'd be concerned with lag after all of that.

@KaerfNomekop, ahh, thanks for the clarification. I was actually thinking about a solution such as that. I was thinking maybe something like:

Every x seconds...
set TempPoint = point 100 range in front of unit
if terrain at TempPoint = snow, then make that square unwalkable
wait (some small interval)
make that square walkable again

I'm HOPING that this would make it so that the unit would have to seek an alternate path, assuming the game would figure out that it's unwalkable a short time in advance. Not sure if this is possible but was thinking about it. Think I'll give it a shot, seeing as there's apparently no easy way to do it, haha.

Thank you all, again. Much appreciated.
 

Hatebreeder

So many apples
Reaction score
381
JASS:
function IsTerrainSnow takes unit u, real a  returns real
     local real UnitX = GetUnitX(u)
     local real UnitY = GetUnitY(u)
     local real X
     local real Y
     local integer Addition = 0

     loop
      set X = UnitX + DISTANCE * Cos((a*bj_RADTODEG)+addition)
      set Y = UnitY + DISTANCE * Sin((a*bj_RADTODEG)+addition)
         exitwhen IsTerrainType(X,Y) != 'SNOW' or Addition >= 360
      set Addition = Addition + 1
    endloop

    set a = ((a*bj_RADTODEGG) + Addition) * bj_DEGTORAD
    return a
endfunction


JASS:
function Move takes nothing returns nothing
   local unit Ordered = GetEnumUnit()
   local real Angle = IsTerrainSnow(Ordered,GetUnitFacing(Ordered))
   local real X = GetUnitX(Ordered) + DISTANCE * Cos(Angle)
   local real Y = GetUnitY(Ordered) + DISTANCE * Sin(Angle)

   call IssuePointOrder(Ordered,"attack",X,Y)
   set Ordered = null
endfunction


JASS:
function Timer takes nothing returns nothing
    local timer Timer = GetExpiredTimer()
    
    call ForGroup( UNITGROUP, function Move )

    set Timer = null
endfunction


"DISTANCE" is a global real (can also be a function) that defines the range of the path the unit should move.
"UNITGROUP" is a global group that contains all the units you want to move.
Just make a function that adds all units that enter the map of a type and initiate the Timer function during Map init or 0.00 of game time.

PS: I just freehanded this one, so you'd need to correct one or two things. But the structure of it should be right.
 

staind25

TH.net Regular
Reaction score
7
Wow, very nice. I don't know my JASS, but I should be able to understand this...just not be able to write my own. Thank you very much. Going to take a detailed look here in a minute.

Edit: Due to lack of experience, I'm not exactly sure how to integrate this. Do each of those functions go in their own triggers, or do they all go in one? Also, what purpose does the timer serve? Guess I'm not sure why a timer is needed.

For the globals, how do I define DISTANCE? I should be able to handle UNITGROUP but not sure how and what value to give DISTANCE.

Thanks again :)
 

skyblader

You're living only because it's illegal killing.
Reaction score
159
Distance is real value.

hatebreeder said:
"DISTANCE" is a global real (can also be a function) that defines the range of the path the unit should move.

He already said that :p
 

staind25

TH.net Regular
Reaction score
7
I know, but I'm asking what value I should give it. Like...how do I determine the value?
 

Hatebreeder

So many apples
Reaction score
381
I know, but I'm asking what value I should give it. Like...how do I determine the value?

I usually take 20-40 for missiles.

Since units are not that fast usually, try something like 17 =P

EDIT:
JASS:
library WhiteOut initializer Init
// Create a new trigger. Rename it to "WhiteOut" and convert it to Text.
// Replace the Text with this.
// Check the Rawcodes in the object editor using CTRL + D

   globals
      private constant integer TERRAIN = 'SNOW'
      private constant real DISTANCE = 17.00

      private group UNITGROUP = CreateGroup()
   endglobals

private function IsTerrainSnow takes unit u, real a  returns real
     local real UnitX = GetUnitX(u)
     local real UnitY = GetUnitY(u)
     local real X
     local real Y
     local integer Addition = 0

     loop
      set X = UnitX + DISTANCE * Cos((a*bj_RADTODEG)+Addition)
      set Y = UnitY + DISTANCE * Sin((a*bj_RADTODEG)+Addition)
         exitwhen GetTerrainType(X,Y) != TERRAIN or Addition >= 360
      set Addition = Addition + 1
    endloop

    set a = ((a*bj_RADTODEG) + Addition) * bj_DEGTORAD
    return a
endfunction

private function Move takes nothing returns nothing
   local unit Ordered = GetEnumUnit()
   local real Angle = IsTerrainSnow(Ordered,GetUnitFacing(Ordered))
   local real X = GetUnitX(Ordered) + DISTANCE * Cos(Angle)
   local real Y = GetUnitY(Ordered) + DISTANCE * Sin(Angle)

   call IssuePointOrder(Ordered,"attack",X,Y)
   set Ordered = null
endfunction

private function Timer takes nothing returns nothing
    local timer Timer = GetExpiredTimer()
    
    call ForGroup( UNITGROUP, function Move )

    set Timer = null
endfunction

private function Truth takes nothing returns boolean
   return true // Don't bother with this. It's only there to prevent a leak.
endfunction

private function Conditions takes nothing returns boolean
   return true //replace the Conditions with the units you want to effect
endfunction

private function Actions takes nothing returns nothing
   call GroupAddUnit(UNITGROUP,GetEnteringUnit())
endfunction

private function Init takes nothing returns nothing
   local trigger Trig = CreateTrigger()
   local timer Time = CreateTimer()
   local rect r = CreateRegion()   

   call RegionAddRect(r, bj_mapInitialPlayableArea)
   call TriggerRegisterEnterRegion(Trig , r, function Truth)
   call TriggerAddCondition( Trig, Condition( function Conditions))
   call TriggerAddAction( Trig, function Actions)

   call TimerStart(Time,0.03,true,function Timer)

   call RemoveRegion(r)

   set Time = null
   set Trig = null
   set r = null
endfunction
endlibrary


I went ahead and summed it up into a library and gave you import instructions. Now, you just need to replace the values I commented on and the globals.
It's not perfect, but I guess this will do.

I also have corrected the mistakes in my freehanded one, so, this should be fine.
If not, gimme a PM with the error message and I'll fix it.

You need Jass New Gen for this to work.
 

Switch33

New Member
Reaction score
12
Pretty sure UMSWE found in newgen can do this completely for you if you edit the tilesets pathability.
 
General chit-chat
Help Users
  • No one is chatting at the moment.
  • Monovertex Monovertex:
    How are you all? :D
    +1
  • Ghan Ghan:
    Howdy
  • Ghan Ghan:
    Still lurking
    +3
  • The Helper The Helper:
    I am great and it is fantastic to see you my friend!
    +1
  • The Helper The Helper:
    If you are new to the site please check out the Recipe and Food Forum https://www.thehelper.net/forums/recipes-and-food.220/
  • Monovertex Monovertex:
    How come you're so into recipes lately? Never saw this much interest in this topic in the old days of TH.net
  • Monovertex Monovertex:
    Hmm, how do I change my signature?
  • tom_mai78101 tom_mai78101:
    Signatures can be edit in your account profile. As for the old stuffs, I'm thinking it's because Blizzard is now under Microsoft, and because of Microsoft Xbox going the way it is, it's dreadful.
  • The Helper The Helper:
    I am not big on the recipes I am just promoting them - I use the site as a practice place promoting stuff
    +2
  • Monovertex Monovertex:
    @tom_mai78101 I must be blind. If I go on my profile I don't see any area to edit the signature; If I go to account details (settings) I don't see any signature area either.
  • The Helper The Helper:
    You can get there if you click the bell icon (alerts) and choose preferences from the bottom, signature will be in the menu on the left there https://www.thehelper.net/account/preferences
  • The Helper The Helper:
    I think I need to split the Sci/Tech news forum into 2 one for Science and one for Tech but I am hating all the moving of posts I would have to do
  • The Helper The Helper:
    What is up Old Mountain Shadow?
  • The Helper The Helper:
    Happy Thursday!
    +1
  • Varine Varine:
    Crazy how much 3d printing has come in the last few years. Sad that it's not as easily modifiable though
  • Varine Varine:
    I bought an Ender 3 during the pandemic and tinkered with it all the time. Just bought a Sovol, not as easy. I'm trying to make it use a different nozzle because I have a fuck ton of Volcanos, and they use what is basically a modified volcano that is just a smidge longer, and almost every part on this thing needs to be redone to make it work
  • Varine Varine:
    Luckily I have a 3d printer for that, I guess. But it's ridiculous. The regular volcanos are 21mm, these Sovol versions are about 23.5mm
  • Varine Varine:
    So, 2.5mm longer. But the thing that measures the bed is about 1.5mm above the nozzle, so if I swap it with a volcano then I'm 1mm behind it. So cool, new bracket to swap that, but THEN the fan shroud to direct air at the part is ALSO going to be .5mm to low, and so I need to redo that, but by doing that it is a little bit off where it should be blowing and it's throwing it at the heating block instead of the part, and fuck man
  • Varine Varine:
    I didn't realize they designed this entire thing to NOT be modded. I would have just got a fucking Bambu if I knew that, the whole point was I could fuck with this. And no one else makes shit for Sovol so I have to go through them, and they have... interesting pricing models. So I have a new extruder altogether that I'm taking apart and going to just design a whole new one to use my nozzles. Dumb design.
  • Varine Varine:
    Can't just buy a new heatblock, you need to get a whole hotend - so block, heater cartridge, thermistor, heatbreak, and nozzle. And they put this fucking paste in there so I can't take the thermistor or cartridge out with any ease, that's 30 dollars. Or you can get the whole extrudor with the direct driver AND that heatblock for like 50, but you still can't get any of it to come apart
  • Varine Varine:
    Partsbuilt has individual parts I found but they're expensive. I think I can get bits swapped around and make this work with generic shit though

      The Helper Discord

      Members online

      No members online now.

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top