Home   Help Search Login Register  

Author Topic: Nearestobject query  (Read 802 times)

0 Members and 1 Guest are viewing this topic.

aazell

  • Guest
Nearestobject query
« on: 29 Oct 2003, 17:12:44 »
Hi all

I'm using the nearestobject command to allow a gang of civilians to roam the countryside hunting down soldiers and killing them. Should be a fun map but I'm having a bit of a problem with setting the nearestobject command to recognise a west soldier.
Here's the idea in rough code:
------------------------------------------------
_client = this select 0
#hunt
~0.5
_clientpos = getpos _client
_target = nearestobject [_client,"wsoldier"]
_targetpos = getpos _target
_client move _targetpos
#move
~0.5
_targetdis = _client distance _target
?!(alive _target):goto "hunt"
?(_targetdis <20):goto "kill"
goto "move"
#kill
~0.5
_client dofire _target
?!(alive _target):goto "hunt"
goto "kill"

--------------------------------------
It's probably not completely correct above but you get the idea.

so in the line:
_target = nearestobject [_client,"wsoldier"]

I understand that you should place the object class that you wish to search for. Is that right?

"wsoldier" is apparently a valid object yet when I check to see the value returned it only tells me that it couldn't find anything. Even though I have 5 of the bastards in my map.

They do find "civilian2" though and "civilian".

Any Ideas would be really good.

Oh and also is there a way to make the nearestobject command search through an array of object classes rather than just one?

Thanks

aaz

Komuna

  • Guest
Re:Nearestobject query
« Reply #1 on: 29 Oct 2003, 17:17:03 »
The class name of a regular west soldier is "SoldierWB"

Notice that you must use a specific string for each unit type in OFP, as nearestObject doesn't recognise main classes.

aazell

  • Guest
Re:Nearestobject query
« Reply #2 on: 29 Oct 2003, 17:34:50 »
Do you know if nearestobject can search for multiple objects?

If not any suggestions on how this may be acheived?

Komuna

  • Guest
Re:Nearestobject query
« Reply #3 on: 29 Oct 2003, 17:43:10 »
nearestObject just searches for one unit at the time, besides, the closest one.

Therefore, if you want to search multiple classes and mutiple objects you'll have to make a function which monitors every class types in several random positions, within a certain area, of course!

There are a few functions at the Editors Depot that might help you.

aazell

  • Guest
Re:Nearestobject query
« Reply #4 on: 29 Oct 2003, 18:04:15 »
hmmm thanks

Prehaps I'll just make an MP mission with only 1 class of west soldier for player units.
I'll definatly look into your suggestion though It's not really what I had in mind.

aaz

Offline LCD

  • Former Staff
  • ****
    • Everon Cartel
Re:Nearestobject query
« Reply #5 on: 30 Oct 2003, 15:03:07 »
also nearestobject command works only in da 50M around da unit  :o  :-X

so it wont help on somin biger

but if u want 2 make civies hunt west soldiers w/o ny russians dere (or even w/ few) dere may b som workarounds

try groupin da civies 2 russian leader nd put in his init "deletevehicle this"

LCD OUT
« Last Edit: 30 Oct 2003, 15:12:48 by LCD »
"guess being the community has downsides .." - cheetah
Help Perfecting Da Next Best Thing - O-Team Beta

Komuna

  • Guest
Re:Nearestobject query
« Reply #6 on: 30 Oct 2003, 15:06:00 »
also nearestobject command works only in da 15 M around da unit  :o  :-X

Wrong. It works in a radius of 50m around the positon. I've tested it.

Offline LCD

  • Former Staff
  • ****
    • Everon Cartel
Re:Nearestobject query
« Reply #7 on: 30 Oct 2003, 15:13:29 »
wat did i say wrong ::)

even tho i didnt work w/ da nearestobject ever - i do pick som info around ;D ;)

:cheers:

LCD OUT
"guess being the community has downsides .." - cheetah
Help Perfecting Da Next Best Thing - O-Team Beta

Offline General Barron

  • Former Staff
  • ****
  • Semper Fi!
Re:Nearestobject query
« Reply #8 on: 31 Oct 2003, 07:49:08 »
Quote
Do you know if nearestobject can search for multiple objects?

I wrote a function to do just that:

http://www.ofpec.com/editors/funcref.php?filter_func=43

But if you are trying to find the nearest unit (not object), then you should use a trigger instead of the nearestobject command. Use this function that I wrote here:

Code: [Select]
/*This script returns an array of all units within a specified distance
of another unit that are in the passed array. The result is sorted
in acsending order of distance to the center unit. Will never return the
unit originally passed to the function.

[unit, range, [unit array]] call findUnits
*/

private ["_unit", "_range", "_list", "_found","_ok"];

_unit = _this select 0;
_range = _this select 1;
_list = _this select 2;
_found = [];

{if (_x distance _unit <= _range && _x != _unit) then {_found = _found + [_x]}} foreach _list;

_ok = [ _found, "_element distance _value", _unit] call SortBubble;

_found

The "unit array" can be the list of a trigger, so you can just plop down a trigger covering every west unit and you'll be in business.

Sorry if you don't understand everything that I'm talking about. Its late and I'm tired, but I'll explain better in another post (later) if you want.
HANDSIGNALS COMMAND SYSTEM-- A realistic squad-control modification for OFP
kexp.org-- The best radio station in the world, right here at home! Listen to John Richards!

Komuna

  • Guest
Re:Nearestobject query
« Reply #9 on: 31 Oct 2003, 14:35:56 »
wat did i say wrong ::)

even tho i didnt work w/ da nearestobject ever - i do pick som info around ;D ;)

:cheers:

LCD OUT

Ahhhh! You naughty boy! ;D You've changed your post! 50m, indeed.

aazell

  • Guest
Re:Nearestobject query
« Reply #10 on: 31 Oct 2003, 14:52:47 »
Hmm interesting.
I understand what the code is doing. What I really want my civ's to do is search out the nearest west human unit (i.e. not vehicle) and go for him. So I only need to return one object rather than an array of objects.

Each civ must run the script locally. I don't want to set up a global target. Each civ must select their own target and go for it.

Had a few probs getting the civ's to target and shoot at their prey so I'm changing the idea slightly. The civs all have plague. If they get within 2 meters of you and remain there for more than 4 seconds then you've had it.