Shark111 0 Posted June 3, 2003 Now it’s time for nearestobject. How do I use this? I want to put in a variable the object of a specific type that is nearest to the player. My scripts did not work, here’s what I used: _near = nearestobject [player, “manâ€] _near = nearestobject [player, man] _near = nearestobject [getpos player, “manâ€] _near = nearestobject [getpos player, man] These all gave ObjNull as value of _near. _near = nearestobject getpos(player) This, instead, gave always and only West Bravo Black: 1, i.e. the player’s unit. What have I to do, if I want _near to be the nearest man, for example, or Scud Launcher, or any other accident?!? Thx ...somewhere a shark hopes to meet ya... Share this post Link to post Share on other sites
RED 0 Posted June 3, 2003 Yes I was having problems with this, I just did something like: <table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE"> _i = 0 #loop _pos = [(getpos player select 0) + sin (getdir player + 180) * _i, (getpos player select 1) + cos (getdir player + 180) * _i,0] _nearest = nearestobject _pos _i = _i + 0.1 ?_nearest == player && _i < 20: goto "loop" That will search out from behind the unit for 20 meters unit it finds something other than the player. RED Share this post Link to post Share on other sites
toadlife 3 Posted June 4, 2003 Unfortunately nearestobject only works with spcific types , not base classes, so... _near = nearestobject [player, “manâ€] ...will never work.:crazy: This of course, REALLY sucks. You would have to do something like this to get it to work: _near = nearestobject [player, “SoldierWBâ€] Share this post Link to post Share on other sites
uiox 0 Posted June 4, 2003 Here it is radar script for land objects <table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE"> ArrayTarget = [] _TempArray = [] #Loop ;player globalchat format[" Nb %1 List %2 ",count ArrayTarget ,ArrayTarget ] ~1 ; Trigger follow the drone Radar setpos getpos objDrone _NbUnits = count list Radar _ArrayRadar = +list Radar updateTargetlist = false ; Remove player and drone from list If (player in _ArrayRadar) then {_ArrayRadar = _ArrayRadar - [player]} If ( objDrone in _ArrayRadar) then {_ArrayRadar = _ArrayRadar - [objDrone ]} If (count _ArrayRadar == 0) then {If (count ArrayTarget !=0 ) then {arrayTarget = [];updateTargetlist = true}; goto "loop"} _i = 0 _TempArray = [] #SearchLand if ( ("Land" countType units ( _ArrayRadar select _i ) !=0 ) && (player countEnemy [ _ArrayRadar select _i] != 0 ) ) then {_TempArray = _TempArray + [_ArrayRadar select _i] } _i = _i +1 If (_i < count _ArrayRadar) then { goto "SearchLand"} ;update the unit list If ( ( count ArrayTarget == 0 ) && ( count _TempArray == 0 ) ) then {goto "loop"} _i = 0 #updateSetNewTarget if ( ! ( (_TempArray select _i ) in (ArrayTarget ) ) ) then {updateTargetlist = true; ArrayTarget = ArrayTarget + [_TempArray select _i] } _i = _i +1 If (_i < count _TempArray ) then {goto "updateSetNewTarget"} If (updateTargetlist ) then {goto "Loop"} _i = 0 #updateOldUnit If ( ! ( ( ArrayTarget select _i) in (_TempArray ) ) ) then {updateTargetlist = true; ArrayTarget = _TempArray; goto "loop" } _i = _i +1 If (_i < count ArrayTarget ) then {goto "updateOldUnit"} Goto "Loop" It uses a trigger "Radar" following an object "objDrone" and updates an array "ArrayTarget" last it sets to true "updateTargetlist" boolean when the list is update... Share this post Link to post Share on other sites
Shark111 0 Posted June 5, 2003 Yes, I tried the script suggested by RED, and it works, but it takes a lot of time to individuate a soldier at about 5mt away from the player’s position. Is there something in the code that could be faster or is NearestObject a command which significantly slows down the execution? My code was this: _i = 0 #search ;starts searching from the player's position, then will ;shift along player’s direction _xc = GetPos Player Select 0 _yc = GetPos Player Select 1 _dir = GetDir Player _pos = [_xc + _i * (Cos _dir), _yc + _i * (Sin _dir), 0] _near = NearestObject _pos _i = _i + 0.1 ~0.1 ;executes some tests to establish wether _nearest is an ;enemy healthy soldier or not. If a test fails, searches ;again from another position ?(_near == Player) : GoTo "search" ?(Side (_near) == Side (Player)) : GoTo "search" ?(!(CanStand _near)) : GoTo "search" ;if there's nothing interesting within 20.1mt. stops the ;script ?(_i > 20) : GoTo "end" ;this should give the debug output TitleText [Format ["Found: %1", _near], "plain down"] [_near] Exec "surrender.sqs" #end Exit Would it be faster if the range from player’s position is incremented by 1mt instead of 0.1 each time? I hope so… …continues ...somewhere a shark hopes to meet ya... Share this post Link to post Share on other sites