Jump to content
Sign in to follow this  
igneous01

adjusting AI Sniper behaviour with Virtual sniper

Recommended Posts

Ok, so I am having a bit of an issue here getting my ai sniper (who is well hidden watching a position) fire at a specific unit if they are detected.

What i want the trigger to do is to check if my sniper or spotter was detected, then execute twirlys virtual sniper script to fire and kill the person that was detected.

Problem is, if i send my spotter to an open area where the ai will detect him, the enemy sniper keeps firing and killing me instead of him. I cant seem to figure out how to get the ai sniper to fire at who he sees.

here is what i have in the trigger

name of trigger: Vsnipetrig

Blufor Present

repeatedly

condition:

(vsniper knowsabout sniper) > 0.05 || (vsniper knowsabout spotter) > 0.05 && alive vsniper

on act:

UnitsTriggered = list Vsnipetrig; vsniper action ["UseWeapon", vsniper, vsniper, 0]; hint "activated"; nul5vsi = [unitsTriggered Select 0,vsniper] execVM "vsniper.sqf";

I thought list would list all units that activated the trigger? Since I as the sniper was hidden and not detected, i didnt activate the trigger. I suspect list preestablishes the array order, so that no matter who activated it, the first element in the array will always be the same person.

Is there a solution to getting this to work? Ive been trying to think up a solution to scripting this behaviour, but Im not sure how to approach this (the amount of time to wait between shots, priority of targets, and alot of other factors)

also another problem ran into is the speed in which the trigger needs to fire. I have it set at 0 right now so that he will immediatly fire when the trigger becomes activated, and since its set to repeatedly, the script will be firing off like a machine gun. But yet when i set the timeout to 30 seconds, even after I killed vsniper, the trigger still activated and i was shot and killed by his ghost! I thought timeout will wait and cancel the activation if the allotted time isnt fulfilled?

any kind of solutions you could think of, ive spent days trying to make a work around on this with no success. I want my enemy sniper to be somewhat intelligent, it would make this mission alot more funner and challenging trying to kill him.

---------- Post added at 03:02 ---------- Previous post was at 01:23 ----------

Ok, so i tried to experiment with the ai snipers behavior using an FSM. Unfortunately this time FSM fails :S

Since there isnt a reliable way of suspending an fsm to a random amount of time (to keep the sniper from firing an automatic machine gun) it wont work. I shall look into scripting it the old fashioned way for now.

If anyone has any solutions, please im desperate!

Share this post


Link to post
Share on other sites

Not quite sure what you're after but I made this little demo here and here the sniper will shoot at any OPFOR that walk into the trigger.... and take them out one by one.

Basically create a trigger with vsniper_targets = thislist in the On Activation.

Trigger set to REPEATEDLY / OPFOR PRESENT or whatever.

Put this in your init.sqf

nul = [] execVM "[b]vsnipercontrol.sqf[/b]";

vsnipercontrol.sqf waits for targets from the trigger list and then tries to kill them one by one.

vsnipercontrol.sqf:-

private ["_target"];

waituntil {count vsniper_targets >=1};

_target  = vsniper_targets select 0;

//keep firing till the guy is dead.
while {alive _target} do {
nul = [_target,vsniper,1.75,1,"B_127x107_Ball",1200] execVM "vsniper.sqf";
sleep 5 + random 5;		//how often the sniper fires.
};
sleep 5 + random 5;		//wait some time before we run the script again
nul = [] execVM "vsnipercontrol.sqf";

Share this post


Link to post
Share on other sites
Not quite sure what you're after but I made this little demo here and here the sniper will shoot at any OPFOR that walk into the trigger.... and take them out one by one.

Basically create a trigger with vsniper_targets = thislist in the On Activation.

Trigger set to REPEATEDLY / OPFOR PRESENT or whatever.

Put this in your init.sqf

nul = [] execVM "[b]vsnipercontrol.sqf[/b]";

vsnipercontrol.sqf waits for targets from the trigger list and then tries to kill them one by one.

vsnipercontrol.sqf:-

private ["_target"];

waituntil {count vsniper_targets >=1};

_target  = vsniper_targets select 0;

//keep firing till the guy is dead.
while {alive _target} do {
nul = [_target,vsniper,1.75,1,"B_127x107_Ball",1200] execVM "vsniper.sqf";
sleep 5 + random 5;		//how often the sniper fires.
};
sleep 5 + random 5;		//wait some time before we run the script again
nul = [] execVM "vsnipercontrol.sqf";

Thanks twirly, thats exactly what i was trying to go for, except in my little script it would only sleep for 15 seconds but never add the random to it?

Here is what i was using:

private ["_sniper", "_Vsniperhandle", "_sniperheight", "_Fsniperheight", "_Fspotterheight"];
_sniper = _this select 0;
_sniperheight = getposasl _sniper select 2;
hint "scriptrunning";

while {alive _sniper} do {
   // Check if sniper has detected an enemy unit
   if (_sniper knowsabout sniper > 0.05) then {
       hint "Sniper Spotted"; 
       _Fsniperheight = getposasl sniper select 2;
       if (unitPos sniper == "DOWN") then {
           player sidechat "sniper is prone";
           _sniper action ["UseWeapon", _sniper, _sniper, 0]; 
           _Vsniperhandle = [sniper, _sniper, 0.3, 1, "B_127x107_Ball", 1000] execVM "vsniper.sqf";
       } else {
           _sniper action ["UseWeapon", _sniper, _sniper, 0]; 
           _Vsniperhandle = [sniper, _sniper, 1.6, 1, "B_127x107_Ball", 1000] execVM "vsniper.sqf";
       };
   };
   if (_sniper knowsabout spotter > 0.05) then {
       hint "Spotter Spotted"; 
       if (unitPos spotter == "DOWN") then {
           player sidechat "spotter is prone";
           _sniper action ["UseWeapon", _sniper, _sniper, 0]; 
           _Vsniperhandle = [sniper, _sniper, 0.3, 1, "B_127x107_Ball", 1000] execVM "vsniper.sqf";
       } else {
           _sniper action ["UseWeapon", _sniper, _sniper, 0]; 
           _Vsniperhandle = [sniper, _sniper, 1.6, 1, "B_127x107_Ball", 1000] execVM "vsniper.sqf";
   };
   sleep (random 30);
};

i noticed a problem where if i i laid down prone and the vsniper was at a higher elevation, he would keep trying to aim for the chest and never kill me, i was hoping unitpos would detect the stance of a unit, but looks like it only detects if it was setunitpos'd

ill try yours and see if it works better

---------- Post added at 16:00 ---------- Previous post was at 14:02 ----------

so i did some tests with it, he still misses alot :S

he fired atleast 20 times on a walking fireteam i set up, when they were walking he couldnt hit them at all (even at 1200m/s bullet speed from 400m), then once they stopped he killed one of them. the rest went prone, and he wasted 10 shots trying to kill them prone (they all overshot or went under) until finally he managed to kill them prone.

Kind of sucks because then players will just decide to go prone and he will miss most of the time.

ill try adjusting the muzzle height to see if that might effect better aiming, as right now depending on which hiding spot he is at (there are 4 of them) the elevation offset and the person going prone leads to always missing the shot :S

Share this post


Link to post
Share on other sites

Glad it sort of works for you.

The original thread just wanted a non-moving person dead! ...so it was created for that in about an hour. ;)

Some elevation tables will need to made for different rounds... just like a real sniper. Windage doesn't come into it... so just elevation. Can also check if the target is standing or prone and probably adjusst for that ewasily enough.

Programming lead into it to hit moving targets will be a challenge.... but I could try when I have some time to spend on it.

Share this post


Link to post
Share on other sites
Glad it sort of works for you.

The original thread just wanted a non-moving person dead! ...so it was created for that in about an hour. ;)

Some elevation tables will need to made for different rounds... just like a real sniper. Windage doesn't come into it... so just elevation. Can also check if the target is standing or prone and probably adjusst for that ewasily enough.

Programming lead into it to hit moving targets will be a challenge.... but I could try when I have some time to spend on it.

that would be great if you could manage to work it out, ive been trying to use unitpos to check if a unit is in prone, but it doesnt work, as it just gives back auto.

there must be some way to defining it - maybe a height check would work on terrain?

since this mission is evolving around ace - wind plays an important factor (but not so much so if the round goes at 1200m/s. I had to do it the dirty way by grouping invisible unarmed spotters that would watch certain positions and reveal targets so that the sniper would shoot and kill them from 500m away if they were out in the open. It works if there standing or crouch (albeit sometimes, even when not moving) but if they go prone then the round will always be 1 metre behind them.

i guess ill just have to leave my sniper ai as is for now, and focus on the rest of the mission.

Edited by Igneous01

Share this post


Link to post
Share on other sites

There's another little demo here for you.

There doesn't seem to be way to get a units stance without first setting it.... which is a real bummer. I found this thread and used that boundingbox method.

I added this line to the script:-

if (((boundingBox _target select 1) select 2) < 1) then {_aimhgt = _aimhgt - [b]1.4[/b]};

The number in bold is how much to subtract from the aim height in order to hit the dude when he's prone. Fiddle with it and see what you can achieve.

Share this post


Link to post
Share on other sites

awesome, i will check this out! thanks twirly!

btw interesting method using bounding box, i was thinking it would need to be getposatl select 2 to get it to work

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
Sign in to follow this  

×