OFPEC Forum

Editors Depot - Mission Editing and Scripting => ArmA - Editing/Scripting Resources Beta Testing & Submission => Topic started by: Rommel92 on 17 Apr 2008, 05:12:59

Title: ROMM_IA (ACCEPTED)
Post by: Rommel92 on 17 Apr 2008, 05:12:59
Rommels Improved AI
Version 110 by Rommel

This new version of Rommels fMorale/Suppressive Fire Reactive Ai, or the new name: ROMM_IA (Rommel Improved AI). Despite the name changes, has had great improvement. With increased AI reactions, effective suppressive fire, designed for multiplayer and a huge increase in their apparent IQ.  :P
Its initial aim was just to make AI's drop to the deck, but over the last few weeks my scripting knowledge has increased and so has this script. It has reached what i wanted to become, and I will only be working on bugs if any are found.

NO GLOBAL VARIABLES + SQF Optimized.

Preview Mission Included which as Surdus' Priest's nearExp resource included (love it.),otherwise feel free to edit, keep base credits if possible please, else its open source and go insane.  :)

HowTo: Implement

A simple init line execution is suffice to include this into your missions.
nul = [group this] execVM "ROMM_IA.sqf";

However for multiple groups use:
SQF: {[_x]execVM "ROMM_IA.sqf"; sleep 0.25} forEach [group1,group2,group3];
SQS: {[_x]execVM "ROMM_IA.sqf"; ~0.25} forEach [group1,group2,group3]

HowTo: DAC v2

Code: [Select]
_Events_Unit_S =
[
["[_group] call compile preProcessFile "ROMM_IA.sqf""],
[],
[],
[],
[],
[]
];

This will launch the script afterBuildUp in the Dynamic Ai Creator (v2), this area can be found in DAC config folder (config_events.sqf)


Please report and bugs found.


VERSION 112.2

http://pb.6thsense.eu/pb/89 (112 Debug Version)

Below is test mission with non-debug version:
Get ROMM IA 112 (http://www.ofpec.com/ed_depot/index.php?action=details&id=555&game=ArmA&type=sc&cat=ai)
Title: Re: AI Suppressive Fire Reactive (Ready To Submit?)
Post by: Imutep on 17 Apr 2008, 22:22:30
Hi Rommel92 ...i've tested your script, but my ArmA hang up  ???
Title: Re: AI Suppressive Fire Reactive (READY)
Post by: Rommel92 on 19 Apr 2008, 04:46:07
I've tested it with ArmA version 1.08 upwards. I highly doubt it to be a compatibility error with mods... however, were you running any, how does it go with standard ArmA if so... when did it crash (if thats what you mean via "hang up").

Any chance of this being submitted? Otherwise... any feedback...  :dunno:
Title: Re: AI Suppressive Fire Reactive (READY)
Post by: Mandoble on 19 Apr 2008, 10:11:21
At mission start I get an scalar message, a bit later:
Error in expression <_nInt + (count _nArr);

If ((_nInt > _c + _d select 0) || (_mInt > 24)) then
{
>
  Error position: <+ _d select 0) || (_mInt > 24)) then
{
>
  Error Generic error in expression

I get the message XXX start supression, but no effect at all.

plain 1.08.
Title: Re: AI Suppressive Fire Reactive (READY)
Post by: Rommel92 on 19 Apr 2008, 15:54:11
The SCALAR bool 0xf message at start is an ArmA bug, seems group names aren't given until 1 second after game start (BIS ones, like EAST 1-1-A), was mainly for debugging on a delayed start.

The error stated is unusual, but it explains the lack of effect of the script, will fix and have re-uploaded as 1.01b for recognition. Sorry for the error, I simply didn't check enough.  :confused:

EDIT: Fixed, missing ().

Title: Re: AI Suppressive Fire Reactive (READY)
Post by: Mandoble on 19 Apr 2008, 16:52:32
//===========================================================================//
// "suppr.sqf"
// Version: n01 [17, 04, 2008]
// Author(s): Rommel [rommelvonrichtofen_at_bigpond.com]
// Execution: [group] execVM "suppr.sqf"
//===========================================================================//

While it gets 2 arguments, being the second an array. Please, document the script header with all the needed argument and a detailed explanation of the meaning.

Testing again now.
Title: Re: AI Suppressive Fire Reactive (READY)
Post by: Rommel92 on 20 Apr 2008, 01:47:45
Added a readme explaining the optional integers in the array for the suppression effects, and an extended execution code inside the header.
 ;)
Title: Re: AI Suppressive Fire Reactive (READY)
Post by: Mandoble on 21 Apr 2008, 20:28:44
Ok, now please, use your tag (I assume you have one) for these two scripts (rom_whatever.sqf)  ;)
Title: Re: ROMM_IA
Post by: Rommel92 on 06 Jun 2008, 03:32:20
Updated. Finished. Renamed.

And damn it kicks ass  :D.
Enjoy! Check first first for finished product. Please report and bugs you may find.
Title: Re: ROMM_IA
Post by: johnnyboy on 09 Jun 2008, 01:20:36
Rommel,

This is an impressive script.  I love a few guys laying down covering fire, while other guys ordered to cover.  I also learned a new trick from you about having a gamelogic perform the UseWeapon action (without this trick, the units would perform the gear animation...). 

Your use of targeting with UseWeapon command appears to eliminate the need for invisible target addons.  That is very cool.

Here's a few issues I'd like to report to you.

1. After all the opfor is dead, soldiers sometimes decide to continue suppressing in directions nowhere near the dead enemy.  Like 90 or 150 degrees different direction. I think this occurs if the foe was killed while moving.  When targeting, the suppressor is pointing his weapon at the AI's best guess of where the target unit is (based on knowsabout).  If the target was moving, knowsabout logic makes the suppressor guess a position based on last known speed and heading of the unit.  To illustrate this, I placed a line of empty vehicles (with some gaps between) as cover in front of the opfor.  I then gave them waypoints to move from one end of the line to the other, then cycle.  The shooter tracked them pretty well until they were dead, but then they started shooting way off mark.

2. UseWeapon on snipers will fire a sniper rifle bullet from the pistol (ARMA bug I guess).  This breaks immersion when player sees it.  I tried adding some code that if typeOf unit was sniper, then remove the pistol, and add it back after done suppressing.  This worked better, but sometimes the sniper would go into pistol animation (with no pistol), and rifle would shoot from shoulder, which is even worse.  So that's no good.  So I opted for not allowing sniper class units to suppress.  That would eliminate this silly ARMA bug.

Again, thanks for the great script.
Title: Re: ROMM_IA
Post by: Rommel92 on 09 Jun 2008, 03:40:25
Thanks for the reports, I've noticed myself the random shooting, however it seems that even though theres a alive check, a knowsabout and an ammo check, they keep shooting regardless. I'll continue looking into it.

The sniper bug sounds interesting, I'll make sure to dis-allow them to suppress. (When do snipers supress anyway aye?)
Title: Re: ROMM_IA
Post by: johnnyboy on 09 Jun 2008, 08:49:08
Hi Rommel.

I noticed 2 more UseWeapon firing bugs:

a) AT soldiers will fire bullets out of their rocket tubes.
b) Grenadiers often point their weapon at a severe up angle (like they were going to shoot a grenade), and then UseWeapon fires a bullet at that funny angle.  Looks dumb.

Also, I may have solved the random shooting problem, and the AT soldier problem.  Attached is a sample mission I was tinkering with (based from your sample mission).  In it are 3 IA scripts:

- ROMMIA.sqf  - your original script, unchanged
- ROMMIA3.sqf - modified to cure random shooting using Mando Angles
- ROMMIA2.sqf - modified to cure random shooting using Mando Angles plus a new game logic that shooters target as a proxy for the foe.  This version also has code in it for excluding snipers, and removing/restoring all rockets from AT soldiers (which cures them of shooting bullets from their rocket tubes).

I tested the 3 different versions by modifying the init lines of the 3 west groups to call whichever script I wanted to test.  In order to trigger the suppression scripts, you need to run to one of the cover objects and fire your MG at each of the 3 groups.  Then hide.  Then switch to the West officers to observe how the suppressors are shooting.

In the modified scripts I put in comments to clearly bracket the changes I made to make it easy for you to identify the new code.  If you decide to use any of this code, feel free to rip out my comments.

I used Mando Angles to prevent the shooter from shooting unless he is pointing at original target +/- 30 degrees.  So when he is tracking a phantom target too far away from original target, he will not shoot.

In the ROMMIA2 version, I also added a gamelogic for the shooter to target, rather than target the foe unit himself.  I discovered that as time elapses, the knowsabout is less fresh, and the shooter will be more likely to target away from the foe location (especially if the foe was moving).  The game logic is setposed to the foe's location, and it is deleted and recreated inside the main suppress loop.  By recreating it, the knowsabout is fresh again, and the shooter re-targets close to the foe position.

I don't know if there is any performance consideration with deleting and recreating a gamelogic with every loop iteration...but it has worked fine in these limited tests.

Anyway, I had fun doing this, and I hope you find it useful.  I know I plan to use this on the sequel to my mission Last Tango in Bagango.  :D

Adios,

Johnnyboy.

Edit1:  The same type of fix used for AT soldiers, also works for grenadiers, to prevent them from shooting up in the air.  You simply remove and save their grenades at the top of the suppress function:

Code: [Select]
// Remove rifle grenades from shooter, so we don't see problem where soldier
// points weapon in air and useweapon makes him fire bullets up (which looks stupid)
if ((magazines _x) find "1Rnd_HE_GP25" > -1) then
{
   _grenMag = "1Rnd_HE_GP25";
   _grenCount = count(magazines _x - (magazines _x - [_grenMag]));
   for "_y" from 1 to _grenCount do {_x removemagazine _grenMag};
   player sidechat format ["removing %1 grenade mags",_grenCount];
};
if ((magazines _x) find "1Rnd_HE_M203" > -1) then
{
   _grenMag = "1Rnd_HE_M203";
   _grenCount = count(magazines _x - (magazines _x - [_grenMag]));
   for "_y" from 1 to _grenCount do {_x removemagazine _grenMag};
   player sidechat format ["removing %1 grenade mags",_grenCount];
};

And then add the grenades back before exiting suppress function:

Code: [Select]
for "_y" from 1 to _grenCount do {_x addmagazine _grenMag};
Edit2:  In a copy of your script where I only use the suppress code, I had a problem where once suppressing units "needed ammo", they would go off course to get ammo, but the UseWeapon was still making them fire, so they fired in the wrong direction.  So I placed some ammo boxes near the 3 suppressing teams into your demo mission, and the modified demo mission I made, and I removed all but 1 magazine from some of the suppressors.  These missions passed the test (both your original, and the modified one).  When they went for ammo, they did not fire in the wrong direction.  So that's good!  In my smaller test suppress version that I copied from your code I must be missing something that allowed the problem to occur...

Title: Re: ROMM_IA
Post by: Rommel92 on 14 Jun 2008, 20:29:07
VERSION 112 RELEASED. Check first post for updated download link.

 :)
Title: Re: ROMM_IA
Post by: Terox on 22 Jun 2008, 15:49:24
Just a couple of points, to help avoid others making the same mistake I did

Thanks goes to killswitch for finding the solution !

Am implementing this into a mod that our community is developing.
In the readme it states
Quote
"Execution: nul = [group this] call compile preProcessFile "ROMM_IA.sqf";
(see the commented out section at the top of the readme)

and lower down it states
Quote
However for multiple groups use:
{[_x]call compile preProcessFile "ROMM_IA.sqf"} forEach [group1,group2,group3];

This only allows the code to run on the first group that initiated the code.
You can verify this by having the following line  at the start of the supression script

player sidechat format ["Group initiating: %1",_this];

If you have 5 groups, you will only see 1 instance of the sidechat message whereas you should see 5 all with different group names.

What ideally should occur, is that the precompile should be done only once and prior to any groups calling the code
Each group simply needs then to call the code....

for example...
Quote
ESP_fAIsuppression    = compile preProcessFile "esp_sys\server\ROMM_IA.sqf";
and then for each group that you want to run the supression script use....

{if((isServer)&&(local leader _x))then{[_x] spawn ESP_fAIsuppression; sleep 0.25}} forEach _groups;



If you wanted to automate the entire system without having to enter code into each groups init field in the mission editor, you could do this by having server side create a trigger, list all the units in the trigger and from that filter an array of groups

something like
Code: [Select]
if!(IsServer)exitwith{};
ESP_fAIsuppression = compile preProcessFile "esp_sys\server\ROMM_IA.sqf";
ESP_MainTrig           = createTrigger ["EmptyDetector",getArray(configFile >> "CfgWorlds" >> worldName >> "centerPosition")];
ESP_MainTrig setTriggerType "NONE";
ESP_MainTrig setTriggerArea [30000,30000,0,true];
ESP_MainTrig setTriggerActivation ["ANY","PRESENT",False];
sleep 0.5;

_groups = [];
{if !(group _x in _groups)then{_groups = _groups + [group _x]}} foreach (list ESP_Maintrig);
{if((isServer)&&(local leader _x))then{[_x] spawn ESP_fAIsuppression; sleep 0.25}} forEach _groups;
{if(local leader _x)then{[_x] spawn ESP_fAIsuppression; sleep 0.25}} forEach _groups;


Thanks for the effort Rommel, keep up the good work


Title: Re: ROMM_IA (ACCEPTED)
Post by: Mr.Peanut on 02 Jul 2008, 14:08:35
Quote
However for multiple groups use:
{[_x]call compile preProcessFile "ROMM_IA.sqf"} forEach [group1,group2,group3];
Tx, do you know why doesn't this work? I figure it must be related to ArmA caching the compiled function, but I don't really understand.
Title: Re: ROMM_IA (ACCEPTED)
Post by: Rommel92 on 02 Jul 2008, 17:51:12
{[_x]call compile preProcessFile "ROMM_IA.sqf"} forEach [group1,group2,group3];

When a function is "called" it will wait for the function to finish before moving on to the next one. The script ends when the group is killed, so once group1 is dead, group2 would launch the script, and so on and so forth.

 :)
Title: Re: ROMM_IA (ACCEPTED)
Post by: Shadow.D. ^BOB^ on 02 Aug 2008, 01:28:07
Hey guys just a quick note.  I have tried to implement this into DACv2 but with no luck.

I have added the code you posted rommel, exactly the same (copy n paste).  But when DAC starts to initialise on mission run, its gives an error about a missing ].

Any ideas?

Cheers
Title: Re: ROMM_IA (ACCEPTED)
Post by: Rommel92 on 02 Aug 2008, 05:54:36
 Hey Shadow Bob, I haven't tested it in a while, and have been really  busy etc, however try these sets of possible working code:
Code: [Select]
_Events_Unit_S =
[
[[_group] call compile preProcessFile "ROMM_IA.sqf"],
[],
[],
[],
[],
[]
];

Code: [Select]
_Events_Unit_S =
[
["[_group] call compile preProcessFile ''ROMM_IA.sqf''"],
[],
[],
[],
[],
[]
];

Code: [Select]
_Events_Unit_S =
[
["[_group] execVM ''ROMM_IA.sqf''"],
[],
[],
[],
[],
[]
];


Code: [Select]
_Events_Unit_S =
[
[[_group] execVM "ROMM_IA.sqf"],
[],
[],
[],
[],
[]
];
Title: Re: ROMM_IA (ACCEPTED)
Post by: Shadow.D. ^BOB^ on 06 Sep 2008, 06:23:02
Hey Romm, sorry i havent replied sooner, but ive been working overseas and have only just taken his project up again.  I tried the suggestions you posted and the 1st option seems to be the only one workin without an error.  The problem is when i call the scrip as an event, any units in the DAC zone stop responding to the waypoints created, and just stay static.  I don't suppose you have any idea on the subject do you?  Or has anyone else been able to get the 2 systems working together?

Thankyou for any help in advance.
Title: Re: ROMM_IA (ACCEPTED)
Post by: Rommel92 on 14 Sep 2008, 07:15:20
Code: [Select]
_Events_Unit_S = [
["[_group] execVM ""ROMM_IA.sqf"""],
[],
[],
[],
[],
[]
];

Is what I'm using in my latest mission, and I'll possibly be updating the ROMM_IA.sqf script soon aswell.
Sorry for the dud solutions  :whistle:.
Title: Re: ROMM_IA (ACCEPTED)
Post by: Shadow.D. ^BOB^ on 07 Oct 2008, 01:10:09
Dud solution or not lol, seems to have worked cheers dude.  Looking forward to an updated version if u get round to it.
Title: Re: ROMM_IA (ACCEPTED)
Post by: Binary on 01 Dec 2008, 10:31:13
Will this also increase AI effectiveness over distance?

With vanilla AI it seems that (especially in multiplayer) they are completely useless at +250 meters.
Title: Re: ROMM_IA (ACCEPTED)
Post by: Manzilla on 02 Dec 2008, 00:45:25
Try Six Pack 2 and FFN together. I'm not sure if this does much for distance.