Home   Help Search Login Register  

Author Topic: please help; units in water  (Read 599 times)

0 Members and 2 Guests are viewing this topic.

Grendel

  • Guest
please help; units in water
« on: 16 May 2005, 21:33:02 »
I have tried searching the forum and FAQ, and can't seem to find any way to find out if a unit is in the water or not.  I have a patrol spawn script thing, and would like it to keep units from spawning in the water without adding a million triggers.  Is there already a way to check this?

If not, I think I could use a camera created at the same point (I think they float) as the patrol spawn, and check to see if the unit's z position is lower than the camera, and then run the random setpos script again untill they are on dry land (with a setDammage 0 of course).

Ideas? already done?

Offline bedges

  • Administrator
  • *****
    • OFPEC The Editing Center
Re:please help; units in water
« Reply #1 on: 16 May 2005, 22:01:41 »
i recall seeing a thread related to finding the waterline, but can't find it either. the gist of it was along the lines you've suggested, using the floating camera method. i think that's probably your best bet.

Grendel

  • Guest
Re:please help; units in water
« Reply #2 on: 16 May 2005, 22:22:06 »
cool, thanks bedges.

Offline Wadmann

  • OFPEC Patron
  • ****
  • I'm the next evolutionary step after a llama!
Re:please help; units in water
« Reply #3 on: 16 May 2005, 23:07:59 »
Good to see your name on the boards again Grendel. Your AA script was nice, although it seemed to fire through buildings! ;D

snYpir made a function to check if a unit is over water and is available here.

Wadmann
Check out my Camouflage Collection! New items added 31 July 2005.

Grendel

  • Guest
Re:please help; units in water
« Reply #4 on: 17 May 2005, 01:13:41 »
OUTSTANDING thanks Wadmann! thanks for remembering that little AA script (and me) BTW.

-Grendel

Grendel

  • Guest
Re:please help; units in water
« Reply #5 on: 19 May 2005, 20:09:58 »
OK then,

I had originally solved this topic, but when I tested it with my MOD, the OverWater.sqf only seemed to work about 25% of the time.

I have since found a much more reliable method of ensuring units do not spawn in the water (among other uses; it could easily be configured to ensure boats DO spawn only in the water, I'm even using it to add water splashes to scripted arty without all the addon/config.cpp tomfoolery)

The answer was right under my nose the whole time.  The getheightASL.sqf will reliably get an objects height above sea level in meters.  Due to some idiosyncrosies of water in OFP, the height ASL for water can be 0 (duh), -1# something or other, or (maybe due to tide/waves) as much as 7m ASL (usually but not always around shorelines).  

SOooooo after some trial and error I came up with this snippet in conjunctin with a patrol spawn script that spawns patrols around a randomly placed invisible"H"...

Note: you must have the getheightASL.sqf properly set up first of course...

Code: [Select]
;find spawn center (gamelogic)
_pos=getpos spawncentergamelogic
_xpos=_pos select 0
_ypos=_pos select 1

;Check to see if it is around sea level by moving an invis"h" to random spawn location first
#checkwater
~.01
_randomx=_xpos+random(100)-50
_randomy=_ypos+random(100)-50

patrolspawn setpos [_randomx,_randomy]

_heightASL=[patrolspawn] call getheightASL
?!(_heightASL>7): goto "checkwater"

;If spawn is above 7m ASL then spawn patrol around the invis"h"
"_x setpos [_randomx+random(10)-5,_randomy+random(10)-5]" foreach units enemypatrolgroup

I have tried to make this alot easier to follow than my usual cryptic shorthand code with no comments...so hopefully this makes sense.

This will run a loop to find another random spot that is over 7m ASL.  It works pretty much all the time (so far at least), and creates a "buffer" around pretty much any coastline.

I will leave this unsolved in case anyone has any questions/comments or finds anything wrong with the code (going off of memory here)...Then maybe it should go to the FAQ (?).

-Grendel