Jump to content
seth0351

Suppressing Fire Scipt

Recommended Posts

Hey guys I need help on this Supressive fire script, I got it from

. So as it stands there, it works fine and I use it for a few gun emplacements. The problem is the guns shoot too low when aiming up a hill. I want to replace markers and use objects instead so I can change their height and get the desired effect. I've been using the grass cutter larger object in game as invisible targets and they work as targets with [this dotarget T1] in the int of the static mg.

So here is the code that works with the markers:

// Random Fire anything with a name. By Big_Wilk (Chris2). A how to video can be found here: http://www.youtube.com/watch?v=4kDPo0J2Q_8&feature=youtu.be
//nul = [Gun1,"t1","t2","t3","t4","t5","t6",60] execVM "randomfire.sqf"; 
private ["_gunname","_marker1","_marker2","_marker3","_marker4","_marker5","_marker6","_targetname","_changetarget","_fortime","_sleeptime","_gunnername"];
if (!isServer) exitWith {};
_gunname = _this select 0;
_gunnername = gunner _gunname;
_marker1 = _this select 1;
_marker2 = _this select 2;
_marker3 = _this select 3; 
_marker4 = _this select 4;
_marker5 = _this select 5;
_marker6 = _this select 6;
_fortime = 0;
_fortime = _this select 7;

while {_fortime > 0} do { 
if (!alive _gunnername) exitwith {};
_changetarget = floor(random 15);
		switch (_changetarget) do {
		_sleeptime = ceil(random 5);
sleep _sleeptime;
_fortime = _fortime - 1;
       case 0: {_gunname doWatch (getmarkerpos _marker1); _gunname action ["useWeapon",_gunname,gunner _gunname,1]; };
       case 1: {_gunname doWatch (getmarkerpos _marker2); _gunname action ["useWeapon",_gunname,gunner _gunname,1]; };
       case 2: {_gunname doWatch (getmarkerpos _marker3); _gunname action ["useWeapon",_gunname,gunner _gunname,1]; };
       case 3: {_gunname doWatch (getmarkerpos _marker4); _gunname action ["useWeapon",_gunname,gunner _gunname,1]; };
	case 4: {_gunname doWatch (getmarkerpos _marker5); _gunname action ["useWeapon",_gunname,gunner _gunname,1]; };
    case 5: {_gunname doWatch (getmarkerpos _marker6); _gunname action ["useWeapon",_gunname,gunner _gunname,1]; };
	};
};


and here is the code that I want to work with objects:

// Random Fire anything with a name. By Big_Wilk (Chris2). A how to video can be found here: http://www.youtube.com/watch?v=4kDPo0J2Q_8&feature=youtu.be
//nul = [Gun1,"t1","t2","t3","t4","t5","t6",60] execVM "randomfire.sqf"; 
private ["_gunname","_marker1","_marker2","_marker3","_marker4","_marker5","_marker6","_targetname","_changetarget","_fortime","_sleeptime","_gunnername"];
if (!isServer) exitWith {};
_gunname = _this select 0;
_gunnername = gunner _gunname;
_marker1 = _this select 1;
_marker2 = _this select 2;
_marker3 = _this select 3; 
_marker4 = _this select 4;
_marker5 = _this select 5;
_marker6 = _this select 6;
_fortime = 0;
_fortime = _this select 7;

while {_fortime > 0} do { 
if (!alive _gunnername) exitwith {};
_changetarget = floor(random 15);
		switch (_changetarget) do {
		_sleeptime = ceil(random 5);
sleep _sleeptime;
_fortime = _fortime - 1;
       case 0: {_gunname dowatch [_marker1];_gunname dotarget (_marker1); _gunname action ["useWeapon",_gunname,gunner _gunname,1]; };
       case 1: {_gunname dowatch [_marker2];_gunname dotarget (_marker2); _gunname action ["useWeapon",_gunname,gunner _gunname,1]; };
       case 2: {_gunname dowatch [_marker3];_gunname dotarget (_marker3); _gunname action ["useWeapon",_gunname,gunner _gunname,1]; };
       case 3: {_gunname dowatch [_marker4];_gunname dotarget (_marker4); _gunname action ["useWeapon",_gunname,gunner _gunname,1]; };
	case 4: {_gunname dowatch [_marker5];_gunname dotarget (_marker5); _gunname action ["useWeapon",_gunname,gunner _gunname,1]; };
    case 5: {_gunname dowatch [_marker6];_gunname dotarget (_marker6); _gunname action ["useWeapon",_gunname,gunner _gunname,1]; };
	};
};


If you guys could figure out where I'm messing up that would be awsome

Edited by Seth0351

Share this post


Link to post
Share on other sites

Via trigger int: nul = [Gun6,"t1_5","t2_5","t3_5","t4_5","t5_5","t6_5",1200] execVM "randomfire.sqf";

Share this post


Link to post
Share on other sites

When using objects (like the grass cutter) you need to remove the quote marks, so [Gun6,t1_5,t2_2....etc

Share this post


Link to post
Share on other sites

This is a great script that I've gotten to work successfully with a few different turrets, but what I would really like to do is make it work with infantry units. I tried modifying it, but instead of firing, the unit just goes into a reload animation. Is there a kind soul who might be willing to take a look at this and help figure out why it's not working?

*/
myArray = [t1, t2, t3];          
nul = [myUnitName, myArray, 6000] execVM "randomSuppress.sqf"; 
*/

private ["_shooter","_myArray","_fortime","_targetToFireAt"];

if (!isServer) exitWith {};
_shooter = _this select 0;

_myArray = _this select 1;
_fortime = _this select 2; 

while {_fortime > 0} do 
{ 
 _targetToFireAt = _myArray call BIS_fnc_selectRandom; 
 _shooter doWatch (getpos _targetToFireAt); 
 _shooter action ["useWeapon", _shooter, _shooter, 2];
 sleep ceil(random 3); //At 0 the gunner doesn't seem to shoot. Or he shoots only once.
 _fortime = _fortime - 1;
 _shooter setammo [primaryWeapon _shooter, 500];
};

 

Share this post


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

You are necroing a 2015 post!

 

Try doSuppressiveFire

Sorry for the necro, pierre - honest! This is the only bit of suppressive fire I've gotten to work since Achilles was deprecated.

 

I've tested the doSuppressiveFire command, and it does work, but it only lasts for 15 seconds. What I need is for a group to fire for much longer. I tried using a while loop to extend the duration for as long as the unit was alive, but that seemed to fail. I don't suppose there's a way to fix that?:

 

while {alive "group1"} do {
	_test = [group1,group2] call { 
	params ["_group1","_group2"]; 
	{_x doSuppressiveFire selectRandom units _group2} foreach units _group1; 
	};
}

 

Share this post


Link to post
Share on other sites
[] spawn {
   while {units group1 isNotEqualTo [] && units group2 isNotEqualTo []} do {
     {_x doSuppressiveFire selectRandom units group2; _x suppressFor 10} foreach units group1;
     sleep 10;
   };
};

 

  • Like 1

Share this post


Link to post
Share on other sites

First up, huge thanks to this community once again for sharing its expertise. You guys never cease to amaze. @pierremgi wins my hero award this week, as his code pretty much does exactly what I needed it to do. If you have a patreon or other donation point, let me know and I'm contributing. Side note: what's the forum etiquette for a post like mine? Do I necro a post that speaks to my issue or create a new one with same-sounding verbiage? I want to get it right in the future!

 

@Soapbox0331, thank you very much for sharing the link to beno's support by fire script! I haven't gotten it to work right yet, but it looks like it has potential. Right now, my units don't seem to fire with the ferocity of the demo videos, but I'll post in that thread to see if there's a solution.

 

Since pierre's code relies on group variable names, and there doesn't seem to be a way to slap a variable name on a group as Zeus, what do you think is the most efficient way to assign one during play? I read that you should create an empty group and then assign units, but what if the units don't have variable names? Is it better to somehow learn the group's default variable name and use that?

 

If assigning my own, would it be like?:

groupName = grpNull;

Followed by this on the unit?:

[this] join (groupName);

 

  • Like 1

Share this post


Link to post
Share on other sites

First of all, thank you for your congrats.
The etiquette you asked for is a little bit hidden but here. Necroing a topic is not a real problem, if you previously made a search and your question didn't receive an answer, or if you can report something significant.

 

If you assign a unit to grpNull , this unit will stay alone, in a new group in fact, because grpNull is not a workable group for alive units, rather a way to test a null value. For example, dead are belonging to grpNull (after a delay).

 

For Zeus, I'm not skilled with all possibilities. What you can do is running a code when double clicking on a group:
 

In init field of the game master module:

this addEventHandler ["CuratorGroupDoubleClicked", {
  _this spawn {
    params ["_curator", "_group"];
    if (isNil {_group getVariable "treated"}) then {
      _group setVariable ["treated",true,true];
      waitUntil {(leader _group targets [true,200]) isNotEqualTo []};
      private _tgts = units ((leader _group targets [true,200]) #0);
      while {units _group isNotEqualTo [] && _tgts isNotEqualTo []} do {
        {_x doSuppressiveFire selectRandom _tgts; _x suppressFor 10} foreach units _group;
        sleep 10;
      };
    };
  };
}];

When, as Zeus, you double click on a group, you run the code.

Not sure it's a great solution for what you want to do.

 

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

×