Home   Help Search Login Register  

Author Topic: NearestObject?  (Read 2073 times)

0 Members and 2 Guests are viewing this topic.

Offline Lone~Wolf

  • Mission Tools & Mods
  • Members
  • *
  • Vladimir Dmitri Mikhail Andreevich Stamenov
NearestObject?
« on: 25 May 2010, 00:36:12 »
Okay, once again I've managed to blow up some core concept of OFP by accident...  ::)

I was working on a script to make intelligent landmines similar to THobson's but without triggers.

I had the landmine 'underground' whereby the player buried a landmine. Then I deletevehicle'd the mine and took note of the position. After that I did a looping nearestObject script to that position.

But here's my problem:

There are no objects remaining as far as I can see that make up the mine, yet when I do nearestObject, It cannot find me unless I'm less then a few centimetres away!

What the fucking hell is going on here!? It's driving me mad!  :weeping:

Here's the Script:

Code: [Select]
; By
;    Lone-Wolf
_p = _this select 0
_a = _this select 1
? (_a == _p) : exit
_p switchmove "CombatToPutDown"
~1
_p removemagazine "Mine"
if not("Mine" in magazines _p) then {goto"GO"}
_p removeMagazine "Mine"
_p addMagazine "Mine"
#GO
_px = (getPos _p select 0)
_py = (getPos _p select 1)
_pd = (getdir _p)
_mine = "Mine" createvehicle [0,0,0]
_mine setdir (getdir _p)
_c = 0
#LOOPPOS
~0.1
_minePos = [_px + 0.75 * sin(_pd),_py + 0.75 * cos(_pd),(0-(_c/80))]
_mine setPos _minepos
_c = _c + 1
? _c < 20 : goto "LOOPPOS"
deletevehicle _mine
_minePos = [_px + 0.75 * sin(_pd),_py + 0.75 * cos(_pd),0.1]
_side = (side _p)
#LOOP
_trig = nearestObject _minePos
? _trig == objnull : goto "LOOP"
? (getpos _trig select 2) > 1 : goto "LOOP"
_vel = (((velocity _trig select 0)^2)+((velocity _trig select 1)^2)+((velocity _trig select 2)^2))^0.5
? _vel == 0 : goto "LOOP"
_mine = "Logic" camcreate _minePos
_dist = _trig distance _mine
deletevehicle _mine
_r = 1; _g = 0
? (side _trig) == _side : _r = 0; _g = 1
_T1 = [0.5,0.5,0.5,0.5]
_T2 = [_r,_g,0,(1/_dist)]
_T3 = [_r,_g,0,((1/_dist)*0.75)]
_T4 = [_r,_g,0,((1/_dist)*0.5)]
_T5 = [_r,_g,0,((1/_dist)*0.25)]
_T6 = [0,0,0,0]
_T7 = [0,0,0]
drop ["cl_fire", "", "Billboard", 1, 0.01, _minepos, [0,0,0], 0, 0.1, 0.1, 0, [0.5,0.4,0.3,0.2,0.1], [_T2, _T3, _T4, _T5, _T6], _T7, 0, 0, "", "", ""]
? ((side _trig) != _side) && _dist < (random 10) : goto "DETONATE"
~0.1
goto "LOOP"
#DETONATE
_c = 0
#L
~0.1
drop ["cl_fire", "", "Billboard", 1, 0.01, _minepos, [0,0,0], 0.5, 0, 0, 0, [10,10,10,10,10], [_T2, _T3, _T4, _T5, _T6], _T7, 0, 0, "", "", ""]
_c = _c + 1
? _c < 3 : goto "L"
~0.1
_bomb = "Shell125" createvehicle _minepos
_bomb setpos _minepos
exit

Anyone?  :confused:
Snarling creature, lurking in the background, still writing in .sqs

Offline RKurtzDmitriyev

  • Former Staff
  • ****
Re: NearestObject?
« Reply #1 on: 25 May 2010, 18:31:41 »
Hi there Lone Wolf.

Quote
There are no objects remaining as far as I can see that make up the mine, yet when I do nearestObject, It cannot find me unless I'm less then a few centimetres away!

Strange. It would be most helpful to know what value nearestObject is returning when it's not returning you. What happens when you use the format command to feed the return of the command into text?

Code: [Select]
hint format ["%1",nearestObject _minepos]
Also, can you elaborate on "unless I'm less then a few centimetres away?" Do you mean that as literally several hundredths of an OFP meter, or as hyperbole? ;)

As I was skimming through your script, one thing happened to catch my eye:

Code: [Select]
? _trig == objnull : goto "LOOP"
You don't seem to realize that objNull is never equal to anything, including itself, so telling to the engine to evaluate _trig == objnull is rather pointless (it will be false no matter what). Try the isNull command instead.

That may or may not be part of the problem. I'll play around and see if I can come up with anything else. :)

EDIT: Another possibility is that the nearestObject command may be picking up the player's footprints. Once again, it would be most helpful to know what your nearestObject command is returning. If it's returning "NOID stopa_l" or "NOID stopa_p" then it's picking up the footprints. (Verified by experiment and noticing that "stopa" is Czech for footprint).

Yet another possibility is that nearestObject is returning some other invisible object. I was playing around on Desert Island earlier and thought that the command must be severely limited in its scanning range, because it would return some "empty" object rather than me unless I was only about 3m away, similar to what you described. But just now I got it to work at up to 50m. There must have been some invisible object throwing the command off.
« Last Edit: 25 May 2010, 19:17:26 by RKurtzDmitriyev »
The OFP Editing Center wishes to remind you that the faithful COMREF will never threaten to stab you and, in fact, cannot speak.
However, in the event that it does speak, you are encouraged to heed its advice. ;)

Offline Lone~Wolf

  • Mission Tools & Mods
  • Members
  • *
  • Vladimir Dmitri Mikhail Andreevich Stamenov
Re: NearestObject?
« Reply #2 on: 25 May 2010, 21:28:34 »
Hmm, interesting.

Would there be a way of defining the nearestObject such that it only picked up humans?

I'm a bit rusty with classes, but would it be possible to do something like specify:
 _obj = nearestObject (class man)
 or something?

Because that it seems would solve our problems.

Otherwise, I can't see a solution except to run nearestObject with the parameter limiting type to every different soldier in the game.  :confused:

Code: [Select]
; Par Example

_array = ["SoldierEB","SoldierWB","SoldierWSaboteur","etc."]
_c = 0
#LOOP
_c = _c + 1
call format ["_object%1 = nearestObject [_mine,_array select %1]",_c]
goto "LOOP"

P.S. It wasn't hyperbole!  :confused:
Snarling creature, lurking in the background, still writing in .sqs

Offline RKurtzDmitriyev

  • Former Staff
  • ****
Re: NearestObject?
« Reply #3 on: 26 May 2010, 00:15:52 »
Would there be a way of defining the nearestObject such that it only picked up humans?

I'm a bit rusty with classes, but would it be possible to do something like specify:
 _obj = nearestObject (class man)
 or something?

Because that it seems would solve our problems.

I don't think so, I'm afraid. :( But those functions that Raptorsaurus posted might come in handy. "ObjsOfTypeInRange.sqf" looks promising. It will return an array of objects of given type (which can be more generic types such as "Man") within a certain range (which can be the range needed to trigger your mine). If there's more than 0 units of necessary type, you can have the script continue. Then, just pick the closest unit in that array (using a loop, forEach, or while...do of some kind), and you have your target.
The OFP Editing Center wishes to remind you that the faithful COMREF will never threaten to stab you and, in fact, cannot speak.
However, in the event that it does speak, you are encouraged to heed its advice. ;)

Offline haroon1992

  • Members
  • *
  • My life is hopeless...
Re: NearestObject?
« Reply #4 on: 26 May 2010, 10:58:14 »

What i found on wiki
[
If class types are used in the filter, then in Arma any object derived from the type is found as well. In OFP, only objects with exactly the type given are found.
]

So, the following two lines may not work,but at least give them a try.

nobj=nearestObject [Player,"MAN"]

pos=getpos player nearestObject "MAN"

the return value is ObjNull if there is no objects within range.
The range is 50 meters.

Why not just create a trigger?
But from the wiki,
Only in OFP Elite you can use the  CreateTrigger command.


The nearestobject command is not a good command to use since it renders units around 50m from the object.
and that distance is too large for a mine.
But there is a way to reduce the distance.

The following snippet will make the unit blow up only if he's within 10m from mine
Quote
#LOOP
~0.1
_trig=nearestObject _minepos;

;check object
? isNull _trig : goto "LOOP"

;check life
? not (alive _trig) : goto "LOOP"

;check speed
? speed _trig < 1 : goto "LOOP"

;check height
? (getpos _trig select 2) > 1 : goto "LOOP"

#CHECK

_chk=nearestObject _minepos;
;check if there's another unit nearer than _trig

? (_chk distance _minepos < _trig distance _minepos ) : _trig=_chk
;if other one (_chk) is nearer to _minepos than currentone (_trig)
;then set otherone(_chk) as the currentone(_trig)

? _trig distance _minepos < 10 : goto "BLOWUP"
;goto BLOWUP is _trig is < 10 from _minepos

~0.2

;keep looping until someone is near 10m distance to mine
goto "CHECK"

#BLOWUP
your desired explosion effects here


NOTE : The snippet is not tested so get a backup of your file before experimenting with it.
Regards,
Haroon1992
Very busy with life, business, and other stuff. Away from OFP for months. Not sure if I could get back onto it. :(

Offline Lone~Wolf

  • Mission Tools & Mods
  • Members
  • *
  • Vladimir Dmitri Mikhail Andreevich Stamenov
Re: NearestObject?
« Reply #5 on: 26 May 2010, 13:14:18 »
Hi Haroon,

I will try the class type thing later today,

As for the Triggers, THobson used them in his mission Abandoned Armies but there he had created a set of triggers in the editor before shifting them around in his mine scripts. I am denying myself that luxury considering that I want this to be an iceberg script. (Sorry I use that term a lot to mean a script that requires you to do nothing other then simply execute it, it does the rest. So that means no placing special things in the editor or typing extensive perameters.)

Thanks for the script but I have no need of it. I have three years of OFP behind my belt and I'm quite competent enough to know how to do a simple thing like find the distance. If you had taken the time to look through my script above, you would have noticed that that function is already present.  :dry:

Thanks though,
        Lone-Wolf  ;)
Snarling creature, lurking in the background, still writing in .sqs