Home   Help Search Login Register  

Author Topic: Finding Nearest Enemy Unit.  (Read 5068 times)

0 Members and 1 Guest are viewing this topic.

SheepOnMintSauce

  • Guest
Finding Nearest Enemy Unit.
« on: 23 Aug 2003, 08:19:31 »
I'm trying to find how to display the nearest enemy unit to a player. After checking out the command reference I spotted :

Quote
nearestObject pos
Operand types:
    pos: Array
Type of returned value:
    Object

Description:
    Nearest building of given type to given position or object. pos may be [x,y,z, "type"] or [object, "type"].

Example:
    nearestObject [player, "StreetLamp"]


Could I use that to find the nearest enemy unit to the player? If so, how would I go about doing that? I was thinking of trying :

Code: [Select]
nearestObject [player1, "east"]
Or something similar along those lines, without trying to get too complicated so it all goes over my head. Lol.  ;D

Help?  :-\

Knut Erik

  • Guest
Re:Finding Nearest Enemy Unit.
« Reply #1 on: 23 Aug 2003, 08:26:27 »
Try:

nearestObject [player1, "soldierEB"]

I think this will detect the nearest russian soldier that is in the "Soldier" class. To make the script detect everyone on the east side, you'll have to play arround with the TypeOf command, and that is far to complicaded to me  :P

SheepOnMintSauce

  • Guest
Re:Finding Nearest Enemy Unit.
« Reply #2 on: 23 Aug 2003, 08:31:29 »
Lol, that's great. I basically want to detect any russian unit which isn't in a vehicle, but actually on foot. I think I'll have a look at the TypeOf command though. Thanks.  ;D

LAPD

  • Guest
Re:Finding Nearest Enemy Unit.
« Reply #3 on: 23 Aug 2003, 14:00:08 »
What Knut Erik meant was that it will detect only east soldiers. It won't detect east medics, east RPG soldier, east AA soldier and so on ... so it won't detect every east soldier on foot. :-\

Just wanted to make it clear. :)

I don't know about the TypeOf command and how to use it.

SheepOnMintSauce

  • Guest
Re:Finding Nearest Enemy Unit.
« Reply #4 on: 23 Aug 2003, 14:04:10 »
Yeah, I gathered that. But, that still helped me a lot anyway. Thanks, for making it clear though.  :)
How do you find out the names of the other types of unit, apart from 'soldierEB'?

Knut Erik

  • Guest
Re:Finding Nearest Enemy Unit.
« Reply #5 on: 23 Aug 2003, 14:27:42 »
Here ya go !!

SoldierEB                       - Soldier
SoldierEG                      - Dunno
SoldierEMedic                - Medic
SoldierECrew                -Tank Crew
SoldierEPilot                  -Pilot
SoldierEMG                    -Machinegunner
SoldierELAW                  -Law Soldier
SoldierEAT                     -At soldier
SoldierEAA                     -At soldier
SoldierEMiner                 -Enginer
OfficerE                          -Officer
OfficerENight                  -Officer nightEq
SoldierESniper                -Sniper
SoldierESaboteurPipe     -SpetzNatz

SheepOnMintSauce

  • Guest
Re:Finding Nearest Enemy Unit.
« Reply #6 on: 23 Aug 2003, 14:29:34 »
Ah thanks, noted!  ;D

GrimMonkey

  • Guest
Re:Finding Nearest Enemy Unit.
« Reply #7 on: 23 Aug 2003, 16:35:16 »
SoldierEG is probably a grenediar. It sure would seem like it.

Knut Erik

  • Guest
Re:Finding Nearest Enemy Unit.
« Reply #8 on: 23 Aug 2003, 16:37:44 »
Ah. I should have tought of that. :P

*Hangs arround in shame*

SheepOnMintSauce

  • Guest
Re:Finding Nearest Enemy Unit.
« Reply #9 on: 23 Aug 2003, 17:43:15 »
Code: [Select]
_target = nearestobject [_sniper, "soldierEB"]
It doesn't seem to work either way. I get a error message '_target = nearestobject [_sniper, "soldierEB"]'|#| : Error 0 elements provided, 3 expected.

Today, isn't my lucky day.  :-\ Any explaination anyone?

Knut Erik

  • Guest
Re:Finding Nearest Enemy Unit.
« Reply #10 on: 23 Aug 2003, 19:17:06 »
How do you call your script ?

SheepOnMintSauce

  • Guest
Re:Finding Nearest Enemy Unit.
« Reply #11 on: 24 Aug 2003, 01:41:18 »
Well, trying to keep it simple :

  • I start a script called 'spotter.sqs' from a trigger set off by radio alpha.
  • In 'spotter.sqs' it makes an action called actionstart which display an action 'Start spotting' which runs 'start.sqs'.
  • The 'start.sqs' does the following code :
Code: [Select]
_sniper removeaction actionstart
[] exec "spot.sqs"
  • Finally '_target = nearestobject [_sniper, "soldierEB"]' lies in the 'spot.sqs'


The script looks like this :

Code: [Select]
?madeaction == "yes" : goto "spot"
actionstop = _sniper addaction ["Stop Spotting", "stop.sqs"]
madeaction = "yes"
#spot
_spotter move [getpos _sniper this select 0, getpos _sniper this select 1 + 10]
? not (unitready _spotter) : goto "spot"
_spotter setUnitPos "Down"
_spotter setdir [getdir _sniper]
_spotter selectweapon "binocular"
;now to get down to business
_soldier = ["OfficerE", "SoldierEPilot", "SoldierECrew", "SoldierEAT", "SoldierEAA", "SoldierEMG", "SoldierELAW", "SoldierEG", "SoldierEMedic", "SoldierESniper", "SoldierESaboteurPipe", "SoldierEB"]
_target = nearestobject [_sniper, "SoldierEB"]
_targetdist = _spotter distance _target
_targetdist = _targetdist + _targetdist*(((random 20)/100)-.1)
_spotter dowatch _target


deaddog

  • Guest
Re:Finding Nearest Enemy Unit.
« Reply #12 on: 24 Aug 2003, 04:49:33 »
Code: [Select]
_spotter move [getpos _sniper this select 0, getpos _sniper this select 1 + 10]
? not (unitready _spotter) : goto "spot"

Remove the word "this" (getpos _sniper select 0, etc)
Also, you shouldn't continously use the move command.  It only needs one.

Use:

@unitready _spotter

or

_spotter move [getpos _sniper select 0, (getpos _sniper select 1) + 10]  ***note the parenthesis
#wait
~2
?!unitready _spotter:goto "wait"


also,

Code: [Select]
_spotter setdir [getdir _sniper]
change the [ ] to ().

And, finally  :),  I don't think the nearestobject function is going to work. It has a finite range of 50 meters.  It will return 1e+010 if that object is greater than that.  I know because I just tried it and I also ran into that in another script.

Man, am i just a wealth of bad news or what  ;D

SheepOnMintSauce

  • Guest
Re:Finding Nearest Enemy Unit.
« Reply #13 on: 24 Aug 2003, 05:45:52 »
Not, really. I found it very helpful, and I'll take all of your advice on-board.  ;D Thanks.

SheepOnMintSauce

  • Guest
Re:Finding Nearest Enemy Unit.
« Reply #14 on: 24 Aug 2003, 08:49:20 »
Does the nearestobject command actually return the value of the nearest unit, or is it strictly for objects like streetlights or buildings?

I'm only asking because, I noticed the nearestbuilding command on the command reference too.

Quote
nearestBuilding obj

Operand types:
obj: Object
Type of returned value:
Object
Description:
Nearest building to given object.

Example:
neareastBuilding player

So that would obviously return the nearest building to an object (the unit.)

But :

Quote
nearestObject pos

Operand types:
pos: Array
Type of returned value:
Object
Description:
Nearest building of given type to given position or object. pos may be [x,y,z, "type"] or [object, "type"].

Example:
nearestObject [player, "StreetLamp"]

Does this mean it will only return the nearest building to an object (the unit), or position?  If so, is there anyway to find the nearest unit to a unit?

I just don't seem to be having any luck trying to detect russian units using the nearestObject command.  :-\