• 🏆 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!
  • 🏆 Hive's 6th HD Modeling Contest: Mechanical is now open! Design and model a mechanical creature, mechanized animal, a futuristic robotic being, or anything else your imagination can tinker with! 📅 Submissions close on June 30, 2024. Don't miss this opportunity to let your creativity shine! Enter now and show us your mechanical masterpiece! 🔗 Click here to enter!

[JASS] Detecting if a unit is on water

Status
Not open for further replies.
Level 2
Joined
Aug 15, 2007
Messages
11
Hello all,

I'm trying to detect whether or not an Amphibious unit is on water. I've scoured the forums, and came up with this:

JASS:
function IsPointWater takes real x, real y returns nothing
  if ( not IsTerrainPathable(x,y,PATHING_TYPE_FLOATABILITY) == true ) then
    set udg_NAGAONWATER = true
  else
    set udg_NAGAONWATER = false
  endif
endfunction


Just to emphasize - I have hardly any idea what I'm doing here, as JASS is completely alien to me. I understand that this function will take an x and an y of a spot on the map and determine whether or not that spot is indeed water, but I'm getting all sorts of errors -- the "Expected a name" one being the most prominent one.

What I want is to have this function check if a specified unit is currently floating on water, and return a boolean so I can use the GUI to do whatever it is I want to do. JASS purists will undoubtably disagree with that last part, but I'd prefer to stick to things I understand -- it's just that I haven't been able to find an efficient way of doing this in the GUI, so I have no choice. :confused:

Can anyone help me out? Thanks in advance.

Edit: I suppose I should clarify that I want to call this function using "Custom Script".

Edit 2: If at all possible, it would be even better if it would only return true when said unit is floating over deep water.
 
Level 3
Joined
Aug 19, 2005
Messages
47
I was doing exactly the same ability for my map. Wait for momnt, I will paste it here.

EDIT: Here you go. It check the terrain height, not the pathability. You just have to insert debugmsg here to get the value of sea level and the replace my value with yours (I guess it is not the same for every map). It should be able to detect even the depth of the sea. I'm using this to add speed bonusand invisibility while in water.
JASS:
function Trig_Naga_Tidelord_Tiderunner_Actions takes nothing returns nothing
    local group g = CreateGroup()
    local location l
    local unit u
    set g=GetUnitsOfTypeIdAll('e003') // get all Tidelord units You may replace it with ability check
    loop
        set u=FirstOfGroup(g)
        exitwhen u==null
        set l = GetUnitLoc(u) // get height of terrain
        if GetLocationZ(l)<=51.200 then // if it is lower than the se level...
            call UnitAddAbility(u,'A00P') // add invisibility
            call UnitAddAbility(u,'A00Q') // add speed
        else // otherwise...
            call UnitRemoveAbility(u,'A00P') // remove them
            call UnitRemoveAbility(u,'A00Q')        
        endif
        call RemoveLocation(l)
        call GroupRemoveUnit(g,u)
    endloop
    call DestroyGroup(g)
    set g=null
    set u=null
    set l=null    
endfunction

//===========================================================================
function InitTrig_Naga_Tidelord_Tiderunner takes nothing returns nothing
    set gg_trg_Naga_Tidelord_Tiderunner = CreateTrigger(  )
    call TriggerRegisterTimerEventPeriodic( gg_trg_Naga_Tidelord_Tiderunner, 0.50 ) // run every 0.50 secs
    call TriggerAddAction( gg_trg_Naga_Tidelord_Tiderunner, function Trig_Naga_Tidelord_Tiderunner_Actions )
endfunction
 
Level 2
Joined
Aug 15, 2007
Messages
11
I get "Expected a variable name" and two "Expected a name" for:

JASS:
set gg_trg_Naga_Tidelord_Tiderunner = CreateTrigger( )
call TriggerRegisterTimerEventPeriodic( gg_trg_Naga_Tidelord_Tiderunner, 0.50 ) // run every 0.50 secs
call TriggerAddAction( gg_trg_Naga_Tidelord_Tiderunner, function Trig_Naga_Tidelord_Tiderunner_Actions )


these three lines, respectively. What am I to do?
 
Level 3
Joined
Aug 19, 2005
Messages
47
It is complete copied trigger, you will have to adjust this to your needs. The best way will be to create completely new trigger in GUI with event "Time - Periodic event" and timeout 0.5 secs. Then take the body of the function and copy it to your actions.

PS: It works perfectly in my map :) (see the signature)
 
Level 2
Joined
Aug 15, 2007
Messages
11
Okay, I got the script to work just fine... With regular units. For one reason or another, this

JASS:
set g=GetUnitsOfTypeIdAll('e003') // get all Tidelord units You may replace it with ability check


line doesn't detect my customized hero, which has the id 'U001'. No matter what I do, it won't take it. What should I do?
 
Level 3
Joined
Aug 19, 2005
Messages
47
It should just create a group from all units of one type, it has nothing to do with heroes or regular units. Check everything - if you are really checking the righthero...I don't know, it should work.

Or you ma try to put this after the exitwhen line:

PingMinimap(GetUnitX(u),GetUnitY(u),0.5)

It should ping the minimap with the unit being processed.
 
Level 2
Joined
Aug 15, 2007
Messages
11
Thanks, that Minimap Ping did the trick. :grin:

I've been reading through a lot of JASS material on four sites or so... I'm daunted, really. All those leaks, triggers not being good if they're not MUI or whatnot... If this keeps up, I'll spend more time triggering'n making a fun scenario. :eekani:
 
Level 2
Joined
Aug 15, 2007
Messages
11
I know that JASS is more powerful, and ultimately easier than the GUI once you get the hang of it; looking at the various examples, and knowing a little of how to read pseudo-code is enough to make that fairly obvious. It's not exactly what I meant, though. What I meant was that this is really starting to look like raw "programming", which isn't really what I usually associate with scenario design. I've got a seven-year backgound designing for AoK:TC, and that's a whole different ballpark... Probably because the editor is less advanced.

I got drawn into the WE because of the "The Founing of Durotar" bonus campaign -- it really struck me only then that the range and power of this editor is exactly what I need to realise some of my ideas. I've been looking at those scenario files, and I suppose I can, for the moment, settle for what's good enough. It's not like the GUI is completely helpless, though the memory leaks are a reason for mild concern; I've seen what that can do to a thriving project.

Oh well... *Opens JASS manuals*
 
Level 40
Joined
Dec 14, 2005
Messages
10,532
By the way, I suggest not using CommanderZ's solution -- you can have terrain lower than the water level which isn't water.

JASS:
function IsPointWater takes real x, real y returns boolean
    return not IsTerrainPathable(x,y,PATHING_TYPE_FLOATABILITY)
endfunction

Should work fine (it has whenever I've used it); the your original one should've made use of return to be alot cleaner, btw.

Oh, and by the way, the IsTerrainPathable function returns the opposite result of what it should, thus the not
 
Level 2
Joined
Aug 15, 2007
Messages
11
Yeah, but how do I call that? It needs a variable to pass on. And what's the name of the boolean that is returned?

Edit: Do I have to pass on a region, a point, the location of a unit?
 
Status
Not open for further replies.
Top