Jump to content

Photo
- - - - -

Ai suppression script help


  • Please log in to reply
157 replies to this topic
Thread Starter
-Coulum-
-Coulum-

    Sergeant Major

  • Members
  • 1765 posts

#1

Posted 08 February 2012 - 23:38

From 20120209 - 20120618 Outdated
Spoiler

From 20120618Updated

There are three versions of the script available:

Basic (stance modifier)
Spoiler


-Units react to bullets passing within 10m
-Affects all units, in vehicles or not
-Units react identically to any kind of bullet fired from more than 25m away
-Units react to identically bullets from any side
-1-5 bullets -->kneel/crouch
->5 bullets --> drop/crawl
-Units regain previous stance after 10 seconds without nearby bullets

Light (stance modifier)
Spoiler


-Units react to bullets passing within 10m
-Only units not in vehicles are affected
-Bullets fired from less than 25m away are ignored
-Bullets from small calibre pistols and SMG are ignored
-Units react differently according to the side of the shooter
-1-5 bullets --> kneel/crouch
->5 bullets --> drop/crawl only if enemy shooter fired bullets
-Units regain previous stance after 10 seconds without nearby bullets

Full (stance and skill modifier)
Spoiler



-Units react to bullets passing within 10m
-Only units not in vehicles are affected
-Bullets fired from less than 25m away are ignored
-Bullets from small calibre pistols and SMG are ignored
-Units react differently according to the side of the shooter
-Friendly shooter: >0 bullets --> kneel/crouch
-Enemy shooter: 1-5 bullets --> kneel/crouch, >5 bullets -->drop/crawl
-Friendly shooter: no skill reduction
-Enemy shooter: skills reduced according to number of bullets
-Units regain previous stance after 10 seconds without nearby bullets
-Units gradually regain skills after 5 or so seconds without bullets

Each script only needs to be initialized once per mission. CBA is required.

Oh and I almost forgot to mention:

tpw is the one responsible for the magority of the script. Credit should really go to him. He's done an excellent job, and I believe he plans to release this as a mod soon.

Edited by -Coulum-, 23 June 2012 - 04:13.


Variable
Variable

    Warrant Officer

  • Members
  • 2967 posts
  • LocationIsrael

#2

Posted 09 February 2012 - 00:08

Wow man if you manage to make such add-on it can literally change the game for the better. Right now no infantry tactics that incorporate suppression can work since the AI simply don't react to it, and I don't know much tactics that don't include any form of suppressing.
I wish I could help myself but all I can do is ask around and let you know if I come up with anything.
Good luck!

kremator
kremator

    Major

  • Members
  • 7519 posts

#3

Posted 09 February 2012 - 12:37

Does sound promising as the current suppression effects don't REALLY work! Can the eventhandler be applied to the bullet (or would that be too CPU intensive)?

Thread Starter
-Coulum-
-Coulum-

    Sergeant Major

  • Members
  • 1765 posts

#4

Posted 09 February 2012 - 16:57

Don't get your hopes up too much. Even if I can get this to work it would be very simplistic and like kremator said, very system intensive.

Now how exactly would I go about creating an event handler? I believe this is what the first script above has done but it seems to only apply when rounds pass near the player. How can I make an event handler that tracks when rounds pass the ai as well.

Jedra
Jedra

    Warrant Officer

  • Members
  • 2048 posts

#5

Posted 09 February 2012 - 19:51

Hi,

You should be able to set the AI aimingaccuracy, aimingspeed and aimingshake very low for a period of time, which will make him a terrible shot. See this page in the Wiki.

I am also making an addon which will affect such things on the fly. You can see how changing the values of these arrays affects the AI's ability to shoot straight in a video I posted at the end of my thread here
Jedra's Addons
Arma 2 : Enhanced Skills Slider
Take On Helicopters : Take On Taxi | Jedra's Time Trials | Weapon Indicators | No Radar

Thread Starter
-Coulum-
-Coulum-

    Sergeant Major

  • Members
  • 1765 posts

#6

Posted 09 February 2012 - 21:36

Thanks Jedra. I was going to set the accuracy of the ai down by using setunitability, but it turns out it doesn't work anymore.I used
setskill ["aimingAccuracy",0.1];
setskill ["aimingShake",0.1];
in a quick editor test and it makes the ai a lot less accurate. It does require a bit of time at the start of the mission before the new skills kick in.
I also used
setunitpos "DOWN";
to make the ai go prone and that works fine and dandy too. Now does anybody have any ideas on how to make the ai skills and posture return to normal after a certain amount of time?
And of course I still can't figure out how to use an eventhandler to track when a round comes close to an ai so if anyone has any tips on how to use eventhandlers your advice would be much appreciated. Thanks.

Jedra
Jedra

    Warrant Officer

  • Members
  • 2048 posts

#7

Posted 09 February 2012 - 22:34

You could have something like;


// Save current skill
_saveAccuracy = _unit skill "aimingAccuracy";
_saveShake = _unit skill "aimingshake";

// make AI stupid
_unit setskill ["aimingAccuracy",0.1];
_unit setskill ["aimingShake",0.1];


// put him in position
setunitpos "DOWN";

sleep 30  // Sleep for 30 seconds (roughly speaking)

// Restore AI
_unit setskill ["aimingAccuracy",_saveAccuracy];
_unit setskill ["aimingShake",_saveShake];

// Stand him up again
setunitpos "UP";  // Or whatever


Eventhandler would look something like this...

_EHFiredIdx1 = badguy1 addEventHandler ["firednear", {STARTTIME = time; badguy1 removeeventhandler ["firednear",0];}];

This runs the stuff in the braces if someone fired within 60 meters of badguy1. I just use it to set a flag, but you could run a .sqf in there.

Firednear passes in an array to the handler;

[unit, firer, distance, weapon, muzzle, mode, ammo]

You can use distance to decide when supression is appropriate. See this page on the Wiki. I guess your challenge here is that the unit firing could be some distance away, yet you can still be surpressed as the rounds themselves are close. There is probably a more appropriate EH for this - I will see if I can find one tomorrow, but you may has well have a scooch round yourself at the wiki.

Edited by Jedra, 09 February 2012 - 22:45.

Jedra's Addons
Arma 2 : Enhanced Skills Slider
Take On Helicopters : Take On Taxi | Jedra's Time Trials | Weapon Indicators | No Radar

Thread Starter
-Coulum-
-Coulum-

    Sergeant Major

  • Members
  • 1765 posts

#8

Posted 10 February 2012 - 02:57

Thanks Jedra.

I was able to get the "effects" working thanks to your help. I didn't know that you could create a variable like that and then sub it in later for a number. probably common knowledge for most scripters, but that just proves how very little I know about this stuff.

As for the event handler. I couldn't get the one you described to work when I tried to exec a script from it but I didn't have much time to play around with it and try to figure out what I have done wrong so when I do get time I will give it some more research.

Your right that the "firednear" isn't exactly ideal for this type of thing because it is limited to detecting shooters within 69 m of the unit according to the wiki. Also the distance returned by the handler would be from the shooter to the target rather than from the round to the shooter, which is more relevant when dealing with suppression. Problem is there isn't many other event handlers suitable. After reading through the wiki list, the fired event handler it probably the best bet

I could use it to detect who shot and what ammo he shot,
Then I could use "nearestobject" to detect the ammo of that type nearest the shooter to find the round,
then actively measure the distance between the round and the target,
and apply effects if the distance becomes small enough.

I don't know if this kind of thing would work, or if it even makes sense. one problem I can foresee is that the script wouldn't know which unit is the target. Anyways I will try working on it soon when I have more time.

Your help is much appreciated Jedra, thanks.

Edited by -Coulum-, 10 February 2012 - 03:09.


Jedra
Jedra

    Warrant Officer

  • Members
  • 2048 posts

#9

Posted 10 February 2012 - 07:52

Thanks Jedra.

I could use it to detect who shot and what ammo he shot,
Then I could use "nearestobject" to detect the ammo of that type nearest the shooter to find the round,
then actively measure the distance between the round and the target,
and apply effects if the distance becomes small enough.

I don't know if this kind of thing would work, or if it even makes sense. one problem I can foresee is that the script wouldn't know which unit is the target. Anyways I will try working on it soon when I have more time.

Your help is much appreciated Jedra, thanks.


This is probably your best bet to play around with. If you use firednear and add the event handler to the AI you could probably get a good approximation of supression if you are also checking for nearest object. I guess it doesn't matter who fired as in reality you could also be supressed by rounds from your own side - a bullet's a bullet at the end of the day and still hurts whoever fired it!!

I might have a play later on. I have a mod of my own to write, a mission to finish, the crap hit the fan with work as well this week, oh and there's the kids to look after - but hey you've got me interested now and it's a cool project! Anyway, I'll have a proper think about it later once I have got the kids to school!
Jedra's Addons
Arma 2 : Enhanced Skills Slider
Take On Helicopters : Take On Taxi | Jedra's Time Trials | Weapon Indicators | No Radar

Variable
Variable

    Warrant Officer

  • Members
  • 2967 posts
  • LocationIsrael

#10

Posted 10 February 2012 - 09:22

Isn't this solution of using the "Fired" EH will suppress the AI even when nearby AI fire on the enemy?

Suppression must occur when bullets IMPACT in close proximity to the AI. Can't that be checked somehow?

2nd Ranger
2nd Ranger

    Sergeant Major

  • Members
  • 1509 posts

#11

Posted 10 February 2012 - 10:05

That already happens. The idea is that rounds passing in close proximity to an AI should also make them suppressed, which doesn't currently happen.

That can be checked with:

(((position _unit) nearestObject "BulletBase") distance _unit) < 5

The easiest way to check this would probably be in a simple FSM, but obviously that would mean running one for every unit, and I don't know how system intensive that would be. AI's behaviour is already governed by FSMs anyway.

empty all your clips at their locations

Vote!
http://feedback.arma...ew.php?id=24134 - Hunter MRAPs sometimes won't move to waypoints
http://feedback.arma...iew.php?id=9341 - Random placement of units and waypoints does not work near buildings
http://feedback.arma...ew.php?id=17665 - Backpacks can't be placed accurately in editor


kremator
kremator

    Major

  • Members
  • 7519 posts

#12

Posted 10 February 2012 - 11:16

Impact proximity maybe a good way forward. A more responsive AI to sonic cracks would be a dream! As I normally play with 200-400 AI I'm thinking about how this would work with huge numbers. Anything you do come up with - gimme a shout and I can test it for you with these HUGE numbers :)

Keep up the good work.

Variable
Variable

    Warrant Officer

  • Members
  • 2967 posts
  • LocationIsrael

#13

Posted 10 February 2012 - 14:47

That already happens.

I believe that it's not, which is the motivation behind this initiative.

The idea is that rounds passing in close proximity to an AI should also make them suppressed, which doesn't currently happen.

That would be great but suppression as reaction to bullet impact in close proximity to the AI is more important.

Edited by Variable, 10 February 2012 - 14:51.


2nd Ranger
2nd Ranger

    Sergeant Major

  • Members
  • 1509 posts

#14

Posted 10 February 2012 - 16:37

It does happen. Go in the editor and put down any player unit, this setCaptive true. Then a BLUFOR rifleman, this setunitpos "up". Place an OPFOR AI 100 metres or so in front of him with this init: removeAllWeapons this; this disableai "move"; this setunitpos "up"; this allowDamage false. When you enter the mission, the armed AI will obviously start firing at the unarmed one. Stand directly behind the armed guy and shoot a few rounds within 2m of his feet. You will notice that his rate of fire decreases dramatically, his aim becomes erratic and you can hear his heavy breathing.

That would be great but suppression as reaction to bullet impact in close proximity to the AI is more important.


Depends on the proximity. If you try what I suggested above you will see that the AI is already suppressed by nearby impacts. The only problem is that the impact area is a bit too small, about 2 meters - because if you are able to hit within that distance of an AI, then more than likely you should be able to hit him too. Another problem with this impact suppression is that it does not work on gunners of static weapons, who should be a major priority for suppression.

So, if the impact area was increased to about 3-4 meters, that would be great. However, if the AI was affected by passing rounds, I think that would be equally useful. You might know the AI's approximate position behind cover, but for whatever reason be unable to hit near enough to suppress him. But if the AI was simulated to detect sonic cracks, you would be able to suppress him just as well.

Edited by 2nd Ranger, 10 February 2012 - 16:41.

empty all your clips at their locations

Vote!
http://feedback.arma...ew.php?id=24134 - Hunter MRAPs sometimes won't move to waypoints
http://feedback.arma...iew.php?id=9341 - Random placement of units and waypoints does not work near buildings
http://feedback.arma...ew.php?id=17665 - Backpacks can't be placed accurately in editor


Thread Starter
-Coulum-
-Coulum-

    Sergeant Major

  • Members
  • 1765 posts

#15

Posted 10 February 2012 - 17:24

Ai do react to nearby impacts but it is often not in the smartest way. They do not react to passing by rounds however and this is what my goal to implement is.

Thanks for all the ideas guys. I should have enough time to try some of them out when I get home tonight. Also keep in mind that I am learning this as I go.

@2nd ranger
You mentioned using fsm to track nearby rounds. Do you have any further info on how to use fsm. It may be system intensive but right now my goal is simply to get this working.

Variable
Variable

    Warrant Officer

  • Members
  • 2967 posts
  • LocationIsrael

#16

Posted 10 February 2012 - 21:14

2nd ranger, thanks for the information, I didn't know that.
Well then, I agree that increasing the range radius of the impact effect and add passing bullets effect is the priority.

Thread Starter
-Coulum-
-Coulum-

    Sergeant Major

  • Members
  • 1765 posts

#17

Posted 11 February 2012 - 00:27

Okay guys, this is what I got so far.
I placed one opfor unit down named "ai"
I placed 1 blufor player down.
I created the following eventhandler that is started in the "init.sqf"
_fired = player addEventHandler ["fired", {_this execVM "suppression.sqf"}];


This means when I (the player) fires suppression.sqf (below) is run

_ammo = _this select 4;

_round = nearestobject [player,_ammo];
while {(speed _round) > 0.1} do {
_dist = _round distance ai;
if (_dist < 10) then {
hint "ai is suppressed";
ai setunitpos "down";
_saveAccuracy = ai skill "aimingAccuracy";
_saveShake = ai skill "aimingshake";
ai setskill ["aimingAccuracy",0.01];
ai setskill ["aimingShake",0.01];
sleep 5;
ai setskill ["aimingAccuracy",_saveaccuracy];
ai setskill ["aimingShake",_saveshake];
ai setunitpos "auto";
};
};


This tracks the shot I have fired and determines if it has come close (10 "units") to the opfor named "ai". if so, it causes "ai" to go prone and have decreased accuracy for 5 seconds before he goes back to his normal stance and accuracy. All this works relatviely smoothly...
Now my newbie scripting questions are:

1. How do I make it so the fired eventhandler is not only created for "player", but also for every unit on the map (Besides manually naming all the ai and typing an eventhandler out for each of these names.)

2. Right now the script only tracks whether the round comes close to "ai". How do I make it so that the distances from the round to all units on the map is measured? (without naming ai1, ai2, ai3...etc. and having corresponding "_dist = _round distance ai;","_dist1 = _round distance ai1;","_dist2 = _round distance ai2;"... etc.)

If my questions aren't clear please let me now and I will try to explain what I mean better. Thanks for your help.

P.S.
from the little "test" I created above, things are looking quite promising in terms of gameplay improvements. If you keep up suppressive fire on "ai" he will go prone and you will sustain very little accurate fire from him. don't keep up the fire and he will start laying down accurate shots and suppressing/hitting you. If this stuff isn't ridiculously system intensive (which it very well may be) I think it will provide alot more depth to firefights.

Xeno
Xeno

    ACE Team Leader

  • Members
  • 1814 posts

#18

Posted 11 February 2012 - 01:28

https://dev-heaven.net/issues/27840

Xeno
[SIZE=1][/SIZE]

Jedra
Jedra

    Warrant Officer

  • Members
  • 2048 posts

#19

Posted 11 February 2012 - 01:32

To add the eventhandler to all the units, there are several methods;

1. If they are all placed in the editor, the in the init line for each unit, you add;

0 = this addeventhandler ["fired" , {_this execVM "supression.sqf"}];

2. If you are adding them in script then simply add the eventhandler to the unit after you create it.

3. Both of the above if you have some in the editor and some you create in script.

4. You could add it in a loop;


[FONT=Courier New][COLOR=#007700]{[/COLOR][/FONT] 
[FONT=Courier New][COLOR=#0000bb]    _fired [/COLOR][COLOR=#007700]= [/COLOR][COLOR=#0000bb]_x addEventHandler [/COLOR][COLOR=#007700][[/COLOR][COLOR=#dd0000]"fired"[/COLOR][COLOR=#007700], {[/COLOR][COLOR=#0000bb]_this execVM [/COLOR][COLOR=#dd0000]"suppression.sqf"[/COLOR][COLOR=#007700]}];

} foreach allunits;

[/COLOR][/FONT]


---------- Post added at 01:32 ---------- Previous post was at 01:28 ----------

https://dev-heaven.net/issues/27840

Xeno


Well, that would save some work. But I would crack on Coulum as it's good to learn this stuff.
Jedra's Addons
Arma 2 : Enhanced Skills Slider
Take On Helicopters : Take On Taxi | Jedra's Time Trials | Weapon Indicators | No Radar

Xeno
Xeno

    ACE Team Leader

  • Members
  • 1814 posts

#20

Posted 11 February 2012 - 01:37

execVM a script everytime a unit fires is not an option.
Just think about heavy firefights with SAW and MG firing. That will start hundreds of scripts in worst case with all the problems it brings.
The execVM itself already removes the most important advantage that code executed in an eventhandler brings, running in the same frame.

Btw, the fired EH does return the projectile itself too since 1.54 or 1.55, no need for a nearestobject check.

Suppresion eventhandler is the only performant way to handle it.

Xeno

Edited by Xeno, 11 February 2012 - 01:44.

[SIZE=1][/SIZE]