OFPEC Forum

Editors Depot - Mission Editing and Scripting => ArmA - Editing/Scripting General => Topic started by: The-Architect on 10 Apr 2008, 01:02:45

Title: Check if enemy is a certain distance from player.
Post by: The-Architect on 10 Apr 2008, 01:02:45
Ok, How do I delete every single badguy outside of a distance of 1500m from the player?
Title: Re: Check if enemy is a certain distance from player.
Post by: Mandoble 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;
Title: Re: Check if enemy is a certain distance from player.
Post by: paritybit 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.
Title: Re: Check if enemy is a certain distance from player.
Post by: The-Architect 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?
Title: Re: Check if enemy is a certain distance from player.
Post by: paritybit 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;

Title: Re: Check if enemy is a certain distance from player.
Post by: The-Architect on 10 Apr 2008, 01:41:39
getting an error message. missing ]

Can I just paste it into my script as is?
Title: Re: Check if enemy is a certain distance from player.
Post by: paritybit 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)
Title: Re: Check if enemy is a certain distance from player.
Post by: The-Architect 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
Title: Re: Check if enemy is a certain distance from player.
Post by: paritybit 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.
Title: Re: Check if enemy is a certain distance from player.
Post by: The-Architect on 10 Apr 2008, 02:02:08
Couldn't I do it by launching a sqf from my sqs?
Title: Re: Check if enemy is a certain distance from player.
Post by: schuler 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
?????
Title: Re: Check if enemy is a certain distance from player.
Post by: Rommel92 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;
Title: Re: Check if enemy is a certain distance from player.
Post by: Wolfrug 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.