Home   Help Search Login Register  

Author Topic: Check if enemy is a certain distance from player.  (Read 2070 times)

0 Members and 1 Guest are viewing this topic.

Offline The-Architect

  • Former Staff
  • ****
  • Bite my shiny metal...
    • Bob's Un-official Flashpoint Page
Check if enemy is a certain distance from player.
« on: 10 Apr 2008, 01:02:45 »
Ok, How do I delete every single badguy outside of a distance of 1500m from the player?
James Andrew Wilkinson 1977 - 2005 R.I.P.
"If it ain't the friggin' incoming it's the friggin' outgoing. Only difference is who gets the friggin' grease, and that ain't no friggin' difference at all."

Offline Mandoble

  • Former Staff
  • ****
    • Grunt ONE and MandoMissile suite
Re: Check if enemy is a certain distance from player.
« Reply #1 on: 10 Apr 2008, 01:11:14 »
I think vehicles command returns also soldiers so:
Code: [Select]
{
   if ((vehicle _x == _x) && (side _x == badsideguys)) then
   {
      deleteVehicle _x;
   };
} forEach vehicles;

Offline paritybit

  • Members
  • *
Re: Check if enemy is a certain distance from player.
« Reply #2 on: 10 Apr 2008, 01:15:57 »
This is most likely not the best approach, but it is an approach.

You could create a trigger that covers the whole map, get a list of all the units within the area of the trigger (the whole map); then create a trigger that covers a 1500 m radius around the player and get a list of all the units within this area.  Then, subtract the units near the player from the list of units on the map and and delete all the units in the resulting array.

Alternatively, if you're using BAS-f (which I highly recommend at least for single player missions) and have been maintaining the list of EAST units when you create new units (as instructed in the manual), then all you need to do is determine what units are close and subtract them from the total list to have a list of units to delete.
Heroes don't die -- they just respawn.

Offline The-Architect

  • Former Staff
  • ****
  • Bite my shiny metal...
    • Bob's Un-official Flashpoint Page
Re: Check if enemy is a certain distance from player.
« Reply #3 on: 10 Apr 2008, 01:17:05 »
Mandoble where is the distance part of your code?

What about something along the lines of countnits east side, if they are +1500 delete those units.
How would I write that?
James Andrew Wilkinson 1977 - 2005 R.I.P.
"If it ain't the friggin' incoming it's the friggin' outgoing. Only difference is who gets the friggin' grease, and that ain't no friggin' difference at all."

Offline paritybit

  • Members
  • *
Re: Check if enemy is a certain distance from player.
« Reply #4 on: 10 Apr 2008, 01:26:18 »
Try this modification to what Mandoble posted:
Code: [Select]
{
    if ( (vehicle _x == _x) && (side _x == badsideguys) && ( (player distance _x) >= 1500 ) ) then {
        deleteVehicle _x;
    };
} forEach vehicles;

« Last Edit: 10 Apr 2008, 09:51:16 by h- »
Heroes don't die -- they just respawn.

Offline The-Architect

  • Former Staff
  • ****
  • Bite my shiny metal...
    • Bob's Un-official Flashpoint Page
Re: Check if enemy is a certain distance from player.
« Reply #5 on: 10 Apr 2008, 01:41:39 »
getting an error message. missing ]

Can I just paste it into my script as is?
James Andrew Wilkinson 1977 - 2005 R.I.P.
"If it ain't the friggin' incoming it's the friggin' outgoing. Only difference is who gets the friggin' grease, and that ain't no friggin' difference at all."

Offline paritybit

  • Members
  • *
Re: Check if enemy is a certain distance from player.
« Reply #6 on: 10 Apr 2008, 01:54:42 »
Make sure you've changed "badguyside" to a value that actually indicates the bad guy side, such as "east" (without quotation marks I think).

There's no '[' so I'm not sure how it could be missing a ']'; are you sure that you've not an error somewhere else in your script?  Or, it's possible the syntax I've used for distance is not correct.

You could try this variation ...
Code: [Select]
(player distance getpos _x)
Heroes don't die -- they just respawn.

Offline The-Architect

  • Former Staff
  • ****
  • Bite my shiny metal...
    • Bob's Un-official Flashpoint Page
Re: Check if enemy is a certain distance from player.
« Reply #7 on: 10 Apr 2008, 01:58:38 »
Still getting the error. It's a {

Here's my full script.

Code: [Select]
setacctime 1.0

#Start
~5
TitleCut ["\nLt. Aylwyn ~ This is Pagan. We're at the evac point. Charlie is everywhere. Come get us. Over.","plain Down"]
~5
soho6 sidechat "Roger Pagan. Angel 1 is inbound. He'll come up on your push when he's close to the LZ. Soho out."
~10
savegame
~1
evac1 = true
{
    if ( (vehicle _x == _x) && (side _x == east) && ( (player distance _x) >= 1500 ) ) then {
        deleteVehicle _x;
    };
} forEach vehicles

goto "Exit"


#exit
exit
James Andrew Wilkinson 1977 - 2005 R.I.P.
"If it ain't the friggin' incoming it's the friggin' outgoing. Only difference is who gets the friggin' grease, and that ain't no friggin' difference at all."

Offline paritybit

  • Members
  • *
Re: Check if enemy is a certain distance from player.
« Reply #8 on: 10 Apr 2008, 01:59:49 »
You lost me when you posted an SQS script; I'm only familiar with SQF syntax.  Someone else will have to help.
Heroes don't die -- they just respawn.

Offline The-Architect

  • Former Staff
  • ****
  • Bite my shiny metal...
    • Bob's Un-official Flashpoint Page
Re: Check if enemy is a certain distance from player.
« Reply #9 on: 10 Apr 2008, 02:02:08 »
Couldn't I do it by launching a sqf from my sqs?
James Andrew Wilkinson 1977 - 2005 R.I.P.
"If it ain't the friggin' incoming it's the friggin' outgoing. Only difference is who gets the friggin' grease, and that ain't no friggin' difference at all."

Offline schuler

  • Contributing Member
  • **
Re: Check if enemy is a certain distance from player.
« Reply #10 on: 10 Apr 2008, 05:43:36 »
Hi Architect, what about Chris's editor? Helps in the'  { [ (  'kinda thingos! There is a little dif in ofp and arma.
Cheers Schuler. Chris has a new one for ArmA,,,, but you more then likly knew that,
Ps I am not a good scripter by any means  :P
Quote
You lost me when you posted an SQS script; I'm only familiar with SQF syntax
?????
Semper Fi

Offline Rommel92

  • Members
  • *
Re: Check if enemy is a certain distance from player.
« Reply #11 on: 10 Apr 2008, 06:17:48 »
Code: (SQF) [Select]
setacctime 1.0;
sleep 5.0;
TitleCut ["\nLt. Aylwyn ~ This is Pagan. We're at the evac point. Charlie is everywhere. Come get us. Over.","plain Down"];
sleep 5.0;
soho6 sidechat "Roger Pagan. Angel 1 is inbound. He'll come up on your push when he's close to the LZ. Soho out.";
sleep 5.0;
savegame;
sleep 1.0;
evac1 = true;
trigger1 = true;

Code: (SQS) [Select]
setacctime 1.0;
~5
TitleCut ["\nLt. Aylwyn ~ This is Pagan. We're at the evac point. Charlie is everywhere. Come get us. Over.","plain Down"];
~5
soho6 sidechat "Roger Pagan. Angel 1 is inbound. He'll come up on your push when he's close to the LZ. Soho out.";
~5
savegame;
~1
evac1 = true;
TRIGGER1 = true;
exit

Make sure you define trigger1 in the init.sqs/sqf as false.
Then in a trigger "EAST PRESENT":
Code: (Condition "TRIGGER1") [Select]
Activation: {?((vehicle _x == _x) && (side _x == east) && ( (player distance _x) >= 1500 ) ): deleteVehicle _x;} forEach thisList;
« Last Edit: 10 Apr 2008, 06:21:34 by Rommel92 »

Offline Wolfrug

  • Addons Depot
  • Former Staff
  • ****
  • Official OFPEC Old Timer
Re: Check if enemy is a certain distance from player.
« Reply #12 on: 10 Apr 2008, 08:47:56 »
Ah, this whole thread operates under the assumption that the vehicles command also returns units : not so however! It only returns, as the name would suggest, vehicles (unless something has changed in the latest betas).

I would suggest for this to use a trigger that's very very large and covers the whole island/area of operations, activated by OPFOR present (repeatedly if you want, I don't think it makes a difference). Name the trigger (in example "AllEnemy") and then do something like this (in .sqs, I hope):

Code: [Select]
AllEnemy setPos getpos Player
_allenemyList = list AllEnemy
~0.1
{if ((_x distance Player) > 1500) then {deleteVehicle _x}} forEach _allenemyList

That -should- work, so try it out :)

Wolfrug out.
"When 900 years YOU reach, look as good you will not!"