Jump to content
Sign in to follow this  
IndeedPete

forceWeaponFire does not work on pistols?

Recommended Posts

Hey there,

getting completely nuts again by trying to get another, totally simple, ambient firing range scene to work. I have a working script for a unit to shoot randomly at some targets, changing stances etc. It works almost perfectly with a rifle (well, the AI can't hit a damn thing but it's just show after all). However, if I try the same script on a unit with a pistol nothing happens. I think I've zeroed in the error - it's most likely the forceWeaponFire command. The wiki says nothing will happen if the fire mode parameter is not available for the weapon in question. Rifles usually have "Single", "Burst" or "FullAuto". But the ACP-C2 .45 only has "This" as fire mode in its config. Tried "Single" and "This" to no avail. Any suggestions? Or might be something wrong with the command?

Thanks in advance!

Share this post


Link to post
Share on other sites

Nope, those old commands are broken since I don't know. At least on static targets (i.e. not real enemies) nothing happens. It's a real pain in the ass to get the AI to shoot at something particular.

Share this post


Link to post
Share on other sites

It does seem broke but then most things are when it comes to controlling the AI.

Can't you use fire or useweapon?

If you want them to fire more than once just script a small loop

this will fire a pistol as long as the riffle has been removed first.

null=[] spawn {while {true} do {targ=[targ1,targ2,targ3] call BIS_fnc_selectRandom; man dotarget targ;sleep 4;man fire (currentWeapon man)}};

It hits the targets but on reload it seems to stop working.

Probably best to give infinite ammo.

Edited by F2k Sel

Share this post


Link to post
Share on other sites

player forceWeaponFire ["hgun_ACPC2_F", "hgun_ACPC2_F"];

If the mode is "This", then it needs to be the classname of the weapon. :)

Share this post


Link to post
Share on other sites

Yes Das Attorney that works, but again only up to the point at which the AI reloads they then won't fire again.

In fact AI seem to stop firing most weapons after reloading even when not using any commands.

Switching to them reveals they only perform the animation as gun is still empty.

If you reload the gun and switch to previous player allowing AI to take over they still don't fire.

Share this post


Link to post
Share on other sites

Not a problem on my PC.

while {true} do {man1 forceWeaponFire ["hgun_P07_F", "hgun_P07_F"]; sleep 1};

Fires until dry, reloads, fires until dry, reloads etc rinse repeat until totally out of ammo.

Share this post


Link to post
Share on other sites

Not here runs empty and that's all she wrote, weird.

I'm not using any mods either.

Maybe time for a re-install in the near future.

I just ran steam verification and one file has failed, I'll try again when it's repaired it.

Oh well that didn't work either.

Edited by F2k Sel

Share this post


Link to post
Share on other sites

Have you tried something like this? I've modified it for you to test, but it's similar to what I use, based on the tracers module:

[] spawn
{
private ["_grp","_gunner","_weapon"];

scopeName "MainScope";

if (!isDedicated) then { player setcaptive true };

_grp = creategroup EAST;
_gunner = _grp createunit ["O_Soldier_AR_F",getpos player,[],0,"none"];
_gunner dowatch [((getpos player) select 0) + 100,(getpos player) select 1,20];
removeheadgear _gunner;
_gunner disableai "target";
_gunner disableai "autotarget";
_gunner setbehaviour "combat";
(group _gunner) setCombatMode "BLUE";

removeallWeapons _gunner;
_gunner addMagazine "30Rnd_65x39_caseless_green_mag_Tracer";
_gunner addMagazine "30Rnd_65x39_caseless_green_mag_Tracer";
_gunner addWeapon "arifle_Katiba_ARCO_pointer_F";

_weapon = weapons _gunner select 0;

sleep 2;

while {true} do
{
	if (count magazinesAmmo _gunner == 0) then { breakTo "MainScope" };
	waitUntil {(_gunner ammo (primaryWeapon _gunner)) > 0};

	while {(_gunner ammo (primaryWeapon _gunner)) > 0} do
	{
		_gunner fire _weapon;

		_delay = 0.05 + random 0.3;

		sleep _delay;
	};
};

deletevehicle _gunner;
};

P.S.: argh, didn't notice before everyone said it was for pistols. Haven't tested this with side arms.

Edited by rakowozz

Share this post


Link to post
Share on other sites

Thanks all, you're brilliant! Das' solution works perfectly! My ambient shooting range script is just an adaption of BI's suppressive fire script from the campaign plus a wrapper around it. It's a but chaotic right now but it does its job:

suppressiveFire.sqf

//Parameters
private ["_unit", "_target", "_roundsPerBurst", "_delayBetweenBursts", "_delayBetweenShots", "_condition"];
_unit 			= [_this, 0, objNull, [objNull]] call BIS_fnc_param;
_target			= [_this, 1, [0,0,0], [[]]] call BIS_fnc_param;
_roundsPerBurst		= [_this, 2, 20, [0]] call BIS_fnc_param;
_delayBetweenBursts	= [_this, 3, 2, [0]] call BIS_fnc_param;
_delayBetweenShots	= [_this, 4, 0.2, [0]] call BIS_fnc_param;
_condition		= [_this, 5, {true}, [{}]] call BIS_fnc_param;

//The magazine type so we can add magazines if needed
private ["_magazines", "_magazine", "_mode"];
_weapon = currentWeapon _unit;
_magazines 	= getArray (configfile >> "CfgWeapons" >> _weapon >> "magazines");
_magazine	= _magazines select 0;
_mode = (getArray(configFile >> "CfgWeapons" >> _weapon >> "modes")) select 0;
if (toUpper(_mode) == "THIS") then {_mode = _weapon};

//The relative direction between unit and target
private "_direction";
_direction = [_unit, _target] call BIS_fnc_dirTo;

//Prepare unit
_unit disableAi "MOVE";
_unit disableAi "ANIM";

//The shots fired
private "_shotsFired";
_shotsFired = 0;

//Main loop
while {(alive _unit) && (_unit call _condition)} do {
//In deed to reload weapon?
if (needReload _unit < 1) then {
	//Add magazines
	if ({ _x == _magazine } count magazines _unit < 2) then {
		_unit addMagazine _magazine;
	};

	//The shots fired
	_shotsFired = _shotsFired + 1;

	if (_shotsFired >= _roundsPerBurst) then {
		//Reset counter
		_shotsFired = 0;

		//Delay between bursts
		sleep _delayBetweenBursts;
	} else {
		//Force unit to fire his weapon
		_unit setDir _direction;
		_unit doWatch _target;
		_unit forceWeaponFire [_weapon, _mode];

		//Delay between each shot
		sleep _delayBetweenShots;
	};
} else {
	sleep 1;
};
};

//Enable AI
_unit enableAi "MOVE";
_unit enableAi "ANIM";

ambientShootingRange.sqf

_unit = [_this, 0, objNull, [objNull]] call BIS_fnc_param;
_targets = [_this, 1, [], [[]]] call BIS_fnc_param;
_condition = [_this, 2, {true}, [{}]] call BIS_fnc_param;

while {(alive _unit) && (call _condition)} do {
_targetSet = _targets call BIS_fnc_selectRandom;
_target = [_targetSet, 0, objNull, [objNull]] call BIS_fnc_param;
_stance = [_targetSet, 1, "UP", [""]] call BIS_fnc_param;
_duration = [_targetSet, 2, 30, [0]] call BIS_fnc_param;
_roundsPerBurst = [_targetSet, 3, 5, [0]] call BIS_fnc_param;
_delayBetweenBursts = [_targetSet, 4, 3, [0]] call BIS_fnc_param;
_delayBetweenShots = [_targetSet, 5, 0.2, [0]] call BIS_fnc_param;

_roundsPerBurst = 1 + floor(random _roundsPerBurst);
_duration = 1 + floor(random _duration);	
_unit doWatch ObjNull;

sleep 2.5;

_unit setUnitPos _stance;
_unit doWatch _target;
_unit doTarget _target;

sleep 5;

_unit setVariable ["IP_Shooting", true];
_hande = [_unit, (getPos _target), _roundsPerBurst, _delayBetweenBursts, _delayBetweenShots, {_this getVariable "IP_Shooting"}] spawn IP_fnc_suppressiveFire;
sleep _duration;
_unit setVariable ["IP_Shooting", false];
waitUntil {scriptDone _hande};	
};

Share this post


Link to post
Share on other sites

Thanks for the heads up about reload working for you Das, I just did full re-install and it's working correctly now.

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  

×