Jump to content
Maddog9933

FIRING RANGE CLEAN UP SCRIPT

Recommended Posts

Hi All,

 

Hoping to get some guidance from you seasoned scripting guys.

 

Disclaimer: I am a self taught scripter, so everything I do is by trial and error, reading forums like these and taking guidance from YouTube tutorials.

 

I have created a Live Fire Range to practice Air-to Ground and Air-to-Air engagements.

 

An instructor uses a Laptop to spawn OPFOR targets into the firing range. I have this set up and it works really well.

 

To "clean" the range, I have the following script:

 

{if ((side (effectiveCommander _x) == east) && (!isPlayer effectiveCommander _x)) then {deleteVehicle _x}} forEach vehicles; 
{if ((side _x == east) && (!isPlayer _x)) then {deleteVehicle _x}} forEach allUnits;

 

Problem is that it only removes remaining or missed units, but that wrecks and abandoned vehicles are left behind.

 

Can anyone please give me guidance on how to improve this script to delete everything that is on the range?

 

Note that it must be limited to the range or to OPFOR,  as I have other assets (i.e aircraft, rearming and refueling trucks for BLUFOR) on the map which must not be deleted.

 

 

 

 

Share this post


Link to post
Share on other sites

@Maddog9933
Create a trigger and size it to fit your range, then execute this: (Just a quick example)

 

{if(_x inArea MyHappyLittleTrigger)then{deleteVehicle _x}}forEach allUnits+allDead;

 


It will delete all units and dead things that are located within the trigger named MyHappyLittleTrigger.

  • Like 3

Share this post


Link to post
Share on other sites

Works perfectly for the wrecks and dead bodies, but abandoned vehicles are still not removed. Any suggestions?

Share this post


Link to post
Share on other sites

{

if(_x inArea MyHappyLittleTrigger)then{

 

//Code for empty vehicles

if(_x isKindOf"Car" || _x isKindOf"Tank" || _x isKindOf"Air")then

if((count(_x emptyPositions"cargo")==0)&&(count ((crew _x)selext{alive _x})==0))then{

deleteVehicle _x}};

 

//Deletes dead stuff

if(!alive _x)then{deleteVehicle _x};

}

}forEach(allUnits+allDead+vehicles)select{side _x==east};

 

 

 

Or... if you want to delete all Opfor stuff, regardless if alive or dead, do this:

 

//Deletes everything in trigger that is side East, dead or alive

{

if(_x inArea MyHappyLittleTrigger)then{deleteVehicle _x}}

forEach(allUnits+allDead+vehicles)select{side _x==east};

  • Like 2

Share this post


Link to post
Share on other sites

{deleteVehicle _x} count ((allUnits+vehicles+allDeadMen) select {_x inArea MyHappyLittleTrigger && side _x != WEST});

 

Note: dead are civilian, as empty vehicles.

 

  • Like 3

Share this post


Link to post
Share on other sites
3 hours ago, pierremgi said:

{deleteVehicle _x} count ((allUnits+vehicles+allDeadMen) select {_x inArea MyHappyLittleTrigger && side _x != WEST});

Question, what is the reason for not using the {ifthen}}count?

 

{if (_x inArea MyHappyLittleTrigger && side _x !=WEST) then {deleteVehicle _x}} count (allUnits+allDead+vehicles);

Share this post


Link to post
Share on other sites
3 hours ago, Robustcolor said:

Question, what is the reason for not using the {ifthen}}count?

 

{if (_x inArea MyHappyLittleTrigger && side _x !=WEST) then {deleteVehicle _x}} count (allUnits+allDead+vehicles);

 

It's faster (especially with plenty of units), because you apply a code on a filtered array. That can be significant on huge array (configs or else).

Depends on array / code / filter.

  • Like 2

Share this post


Link to post
Share on other sites

This codes from the first to the last post help a lot to understand the statements given to trigger and prepare the execution. Already modified them and use the same principles and it works in many cases. Now I have a problem that I can't resolve so please if someone has a solution to this:

There are multiple forces placed in a zone and they are all cached with MCC template script so I can't give it variables because it is lost after the unit is cached - no problem. There are tanks, mechanized vehicles, live forces, and artillery pieces all from one side - blufor. I am trying to fire the trigger only if artillery pieces are destroyed (while the zone is active of course - not while cached) so I try if kindOf "artillery" and every variant of the code with this statement I can think of without result. Is there a way to do this? Thanks in advance guys

 

EDIT: {deleteVehicle _x} count ((isKindOf "artillery") select {_x inArea tg1 && side _x == WEST});   this was my best guess but can't understand why error is showed - error missing )

Share this post


Link to post
Share on other sites

isKindOf needs object and type name parameters as shown in BIKI

Anyway "artillery" is not a workable filter for type of vehicles. editorSubcategory = "EdSubcat_Artillery" should work like this:

 

{deleteVehicleCrew _x; deleteVehicle _x} count (vehicles select {_x inArea tg1 && side _x == WEST && {getText (configOf _x / "editorSubcategory") ==  "EdSubcat_Artillery"} });

That's for deleting BLUFOR artillery in this area.

 

1 hour ago, Nemanjic said:

I am trying to fire the trigger only if artillery pieces are destroyed (while the zone is active of course - not while cached) so I try if kindOf "artillery" and every variant of the code with this statement I can think of without result. Is there a way to do this? Thanks in advance guys

 

EDIT: {deleteVehicle _x} count ((isKindOf "artillery") select {_x inArea tg1 && side _x == WEST});   this was my best guess but can't understand why error is showed - error missing )

 

  Do you need a code for deleting the artilleries or do you need a condition for a trigger firing when there is no more alive BLUFOR artillery? It's not clear.

 

Share this post


Link to post
Share on other sites

For some reason code does not work "error missing ;" . Yea I need a trigger condition so if there are no artillery pieces in the area trigger will fire because there are a lot of other vehicles guarding that artillery convoy so the condition is only if artillery pieces are destroyed. Also it will be good if the condition includes side because it is possible that I enter an area with my artillery (opfor) so the trigger needs to know clearly which artillery pieces to count.

 

Do you need a code for deleting the artilleries or do you need a condition for a trigger firing when there is no more alive BLUFOR artillery? It's not clear.

I need a condition for a trigger, not a code to delete pieces.  Sorry for the confusing writing.

 {deleteVehicle _x} count ((isKindOf "artillery") select {_x inArea tg1 && side _x == WEST}); this was just an example of what I am trying to do in general but instead of {deleteVehicle _x} could be anything else because  count was important so trigger can select only artillery kind vehicles.

Share this post


Link to post
Share on other sites

I found this but can't understand what is a workable filter for artillery.

Share this post


Link to post
Share on other sites

condition of the trigger:

preset : BLUFOR PRESENT   (trigger's area mandatory)

cond: {getText (configOf _x / "editorSubcategory") == "EdSubcat_Artillery"} count thisList == 0

 

That supposes BLUFOR artillery are present at the start of the game, inside this trigger. BLUFOR PRESENT (as preset condition) can return an arry thisList with infantry and vehicles, WEST side.

The simple filter I gave you will return only artilleries. If none (no more), count is 0.

 

If your convoy is moving, attach the trigger (trigname attachTo [vehiclename,[0,0,0]] in init field of this vehicle, for example)

 

Share this post


Link to post
Share on other sites

Vehicles are spawned but cached on mission start but that is not a problem because a moment before the check, the trigger is disabled with tg1 enableSimulation false; and only enabled when a player is inside of the center area and all units are wake up and running (not cached) so that's not a problem. But anyway, I tried this way you told me, placed artillery vehicles in editor, create a trigger with that condition params, and it is fired on mission start no matter what kind of vehicles are inside of area. Look

preplaced and trigger 

Trigger fires if artillery MLRS or any other is inside the trigger also.

 

 {deleteVehicle _x} count ((isKindOf "artillery") select {_x inArea tg1 && side _x == WEST});  I was using this just to test if artillery is filtered or not but in fact I need cond for trigger not code to delete arti (hope I am clear now)

Edited by Nemanjic

Share this post


Link to post
Share on other sites

The condition I gave you, definitively works. Now, I can't guess what you're doing with your scripts and all behaviors of your mods.

Check:

- if crew are spawned at once after creating your tank. You can add a little timeout (1,1,1) or even (5,5,5) to be sure there is no side problem while spawning all the stuff (at start).

- if you don't have some extra script setting: your crew captive, even for short time...

Once again, condition works as intended (tested with edited artillery).

 

Share this post


Link to post
Share on other sites
19 minutes ago, pierremgi said:

The condition I gave you, definitively works

This gives me hope! 

I will screenshot step by step now, please just check where I mistaking. 

omG, you were right! The problem with the filter was that my artillery is alive ORBAT-created pieces, not vanilla ones. I placed Sholef vanilla artillery vehicle and the trigger stays quiet until the vehicle was inside, only activating after the vehicle was destroyed as it should! 

If you have some idea of how to count custom vehicles instead of EdSubcat_Artillery (I suppose this is the key), please point me out. Thank you for your time friend!

I have class names for these vehicles so if they can be filtered by class name it will be great...

Share this post


Link to post
Share on other sites

This is self-crafted code somehow after a whole day of trying:

{ _x in thislist} count (_x isKindOf "eart03") == 0

eart03 is the class name of artillery vehicle so I tried this to put in trigger cond without success. Leastwise, it will make clear what I am trying to do...

 

Finally, I make a progress: "eart03" countType thisList == 0 in Cond do the job only thing I need to do now is to make an array of class names consisting of four because there are four different possibly spawned vehicles and them are: eart03, eart04, eart05 and eart06 so I tried:

["eart03", "eart04", "eart05", "eart06"]  countType thislist == 0

{"eart03", "eart04", "eart05", "eart06"}  countType thislist == 0

"eart03" countType thisList == 0 && "eart04" countType thisList == 0 && "eart05" countType thisList == 0 && "eart06" countType thisList == 0

but every time I got an error. Condition only works if there is one class name like in the first case. I feel this is not the hard part but my knowledge is depleted and is hit the limit about making arrays... Please any help?

 

finally

("eart03" countType thisList == 0) && ("eart04" countType thisList == 0) && ("eart05" countType thisList == 0) && ("eart06" countType thisList == 0)

 

Edited by Nemanjic
solved

Share this post


Link to post
Share on other sites

{ _x in thislist} count (_x isKindOf "eart03") == 0

can't work because (_x isKindOf "eart03") is a boolean, not an array (neither string,config or hashmap).  Always stick to syntax.  return value of isKindOf   parameters for count.

 

Are you sure "eart03" "eart04" .... are class names? Which mod?

 

Share this post


Link to post
Share on other sites
1 hour ago, pierremgi said:

can't work because (_x isKindOf "eart03") is a boolean, not an array (neither string,config or hashmap)

I use this: 

("eart03" countType thisList == 0) && ("eart04" countType thisList == 0) && ("eart05" countType thisList == 0) && ("eart06" countType thisList == 0) for trigger condition

I don't know how but it works fantastic and now triggers only recognize the exact vehicles of the class name. I can send you files for the check. It works so well that I spread code to all other triggers that need to refer to specific types of units.

 

1 hour ago, pierremgi said:

Are you sure "eart03" "eart04" .... are class names? Which mod?

Absolutely sure because I make them using orbat creator with that classes so no mod - it is a custom faction. But vanilla and other mod vehicles also can be manipulated this way I tried it today during hard times making it work.

 

Your way is working just fine of course, but for vanilla vehicles. For some reason, the same vehicle vanilla and orbat-created don't belong to the same kind.

Share this post


Link to post
Share on other sites
3 hours ago, Nemanjic said:

 

Your way is working just fine of course, but for vanilla vehicles. For some reason, the same vehicle vanilla and orbat-created don't belong to the same kind.

 

 

My code is working for any vehicles you can see sorted as artillery in the editor assets (editor right column) (that's the filter I chose) and that works for vanilla, mods and DLCs, as far as vehicles ARE artillery.

On the other hand, I asked you your mod (for vehicles and units) as I wish to understand what vehicles are you using. orbat doesn't modify classes for created vehicles. So, I'd like to test your vehicles mod.

 

Share this post


Link to post
Share on other sites

Understand. Yes of course your code works for mod units also that's what I mean, but not for orbat-created for some reason, at least not for this type I use in mission. And they are: mlrs, bm21, himars and seara. I can tell you exact config classes (original samples used for those vehicles in orbat creator) tommorow I am not at pc right now,but I am pretty sure that seara is vanilla NATO faction, and 70% sure bm21 is cdf ground forces west sided. Hope that what you want to know?  All of them are rewrited class names using orbat and goes like eart03, eart04....to eart09 but original ones are different of course. 

For basic units I use B_Soldier_F as original source, but for specops, pilots, crew, naval crew and divers I using different sources can't think of classes. 

I think that happens orbat IS changing classes, or types or anything of that (you know what I mean) and that's why trigger recognize same vehicles with same conditions differently. (my opinion) 

Share this post


Link to post
Share on other sites

Ah OK, I guess you're using ALIVE Orbat, customizing vehicles. This way, inheritance for editorSubcategory may be lost.

Share this post


Link to post
Share on other sites
3 hours ago, pierremgi said:

Ah OK, I guess you're using ALIVE Orbat, customizing vehicles

Yes. They first need to be created and defined as units like any other so they can be defined as a group or part of a group after that.

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now

×