Skip to content

Commit

Permalink
Fix laser cycling too quickly (#712)
Browse files Browse the repository at this point in the history
* Fix laser cycling too quickly

https://www.youtube.com/watch?v=LMWf6TOveJE

* Update addons/common/functions/fnc_canFire.sqf

Co-authored-by: mharis001 <[email protected]>

* nextFireTime after reload

* check magazine too

* Check ammo simulation and fire time for all units

---------

Co-authored-by: mharis001 <[email protected]>
Co-authored-by: mharis001 <[email protected]>
  • Loading branch information
3 people authored Mar 14, 2023
1 parent ad98311 commit e460e94
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
1 change: 1 addition & 0 deletions addons/common/functions/fnc_canFire.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ private _unit = _unit call FUNC(getEffectiveGunner);
alive _unit
&& {!isPlayer _unit}
&& {lifeState _unit in ["HEALTHY", "INJURED"]}
&& {CBA_missionTime >= _unit getVariable [QGVAR(nextFireTime), 0]}
&& {
private _vehicle = vehicle _unit;

Expand Down
12 changes: 11 additions & 1 deletion addons/common/functions/fnc_fireWeapon.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
* Public: No
*/

#define LASER_WEAPON_TIMEOUT 1

params [["_unit", objNull, [objNull]], ["_infiniteAmmo", false, [false]]];

if (!local _unit) exitWith {
Expand Down Expand Up @@ -61,12 +63,20 @@ switch (true) do {
// Vehicle gunner
default {
private _turretPath = _vehicle unitTurret _unit;
weaponState [_vehicle, _turretPath] params ["_weapon", "_muzzle", "_fireMode"];
weaponState [_vehicle, _turretPath] params ["_weapon", "_muzzle", "_fireMode", "_magazine"];

if (_weapon isKindOf ["CarHorn", configFile >> "CfgWeapons"]) exitWith {
_unit forceWeaponFire [_muzzle, _fireMode];
};

// Prevent laser weapons from firing too quickly to allow for reliably switching to the desired state
private _ammo = getText (configFile >> "CfgMagazines" >> _magazine >> "ammo");
private _ammoSimulation = getText (configFile >> "CfgAmmo" >> _ammo >> "simulation");

if (_ammoSimulation == "laserDesignate") then {
_unit setVariable [QGVAR(nextFireTime), CBA_missionTime + LASER_WEAPON_TIMEOUT];
};

if (_infiniteAmmo) then {
_unit setAmmo [_muzzle, 1e6];
};
Expand Down

0 comments on commit e460e94

Please sign in to comment.