Skip to content

Instantly share code, notes, and snippets.

@Drofseh
Last active November 15, 2020 04:00
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Drofseh/298d3dfb5245a9d5258772b66db9114a to your computer and use it in GitHub Desktop.
Save Drofseh/298d3dfb5245a9d5258772b66db9114a to your computer and use it in GitHub Desktop.
Rate of fire test script
test_shotTimeArray = [];
test_totalShots = 0;
test_totalShotTime = 0;
test_averageShotTime = 0;
test_averageRPM = 0;
test_previousFireTime = diag_tickTime;
player addEventHandler [
"Fired",
{
params ["_unit", "_weapon", "_muzzle", "_mode", "_ammo", "_magazine", "_projectile", "_gunner"];
test_magCapacity = getNumber (configFile >> "CfgMagazines" >> _magazine >> "count");
test_expectedROF = 60 / (getNumber (configFile >> "CfgWeapons" >> _weapon >> _mode >> "reloadTime"));
if (test_totalShots < test_magCapacity) then {
test_totalShots = test_totalShots + 1;
test_newFireTime = diag_tickTime;
test_timeBetweenShots = test_newFireTime - test_previousFireTime;
test_shotTimeArray pushBack test_timeBetweenShots;
test_previousFireTime = test_newFireTime;
diag_log ("diag_frameNo: " + (str diag_frameNo));
systemChat (str test_timeBetweenShots);
};
if (test_totalShots == test_magCapacity) exitWith {
test_shotTimeArray deleteAt 0;
{
test_totalShotTime = test_totalShotTime + _x;
} forEach test_shotTimeArray;
test_averageShotTime = test_totalShotTime / (count test_shotTimeArray);
test_averageRPM = 60 / test_averageShotTime;
systemChat ("Total Shots: " + (str test_totalShots));
systemChat ("Total Shots Counted: " + (str (test_totalShots - 1)));
systemChat ("Total Time for Counted Shots: " + (str test_totalShotTime));
systemChat ("Average Time Between Counted Shots: " + (str test_averageShotTime));
systemChat ("Average Rate of Fire: " + (str test_averageRPM) + " RPM");
systemChat ("Expected Rate of Fire: " + (str test_expectedROF) + " RPM");
systemChat ("Discrepancy: " + (str ((1 - (test_averageRPM/test_expectedROF))*100)) + " percent");
diag_log (format ["Rate of Fire Test - Weapon: %1, Firemode: %2, Total Shots: %3, Total Shots Counted: %4, Total Time for Counted Shots: %5, Average Time Between Counted Shots: %6, Average Rate of Fire: %7 RPM, Expected Rate of Fire: %8 RPM, Discrepancy: %9 percent.", _weapon, _mode, test_totalShots, (test_totalShots - 1), test_totalShotTime, test_averageShotTime, test_averageRPM, test_expectedROF, ((1 - (test_averageRPM/test_expectedROF))*100)]);
test_shotTimeArray = [];
test_totalShots = 0;
test_totalShotTime = 0;
test_averageShotTime = 0;
test_averageRPM = 0;
};
}
];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment