Jump to content
Sign in to follow this  
fildred13

Suppressor Check Script Problems

Recommended Posts

I have the following in my init.sqf in order to add a fired event handler for the player:

player addEventHandler["fired", {if !(this call "fil_scripts\suppressorCheck.sqf") then {hint "Unsuppressed shot detected"}}];

The code successfully detects the fired event, as the following code works just fine:

player addEventHandler["fired", {hint "weapon fired"}];

My problem is that I'm not sure how to call my suppressorCheck.sqf correctly. I am trying to pass the array of information of the "fired" event to suppressorCheck.sqf, and then that will return true if an unsuppressed weapon was fired.

Frankly, I think my only problem is in calling the script from the event handler, but in case people are curious, here is the suppressorCheck.sqf:

private ["_suppressor"];

_weaponFired = _this select 1;
_weaponItems = weaponsItems player;
_suppressor = false;

{
   if ((_weaponFired == _x select 0) && !((_x select 1) == "")) then {
       _suppressor = true;
   };
} forEach _weaponItems;

/*
if (_suppressor) then {
   player sideChat "Yes, I had a silencer";
} else {
   player sideChat "No, I didn't";
};
*/


_suppressor

Share this post


Link to post
Share on other sites

// compile the function
fil_fnc_suppressorCheck = compile preprocessFileLineNumbers "fil_scripts\suppressorCheck.sqf";

// add EH
player addEventHandler["fired", {if !(this call fil_fnc_suppressorCheck) then {hint "Unsuppressed shot detected"}}];

or

// place the code right in the EH
player addEventHandler["fired",{
   _weaponFired = _this select 1;
_weaponItems = weaponsItems player;
_suppressor = false;

{
	if ((_weaponFired == _x select 0) && !((_x select 1) == "")) then {
		_suppressor = true;
	};
} forEach _weaponItems;

if !(_suppressor) then {hint "Unsuppressed shot detected"};
}];

dont

// will recompile on every shot... no need for that
player addEventHandler["fired", {if !(this call compile preprocessFile "fil_scripts\suppressorCheck.sqf") then {hint "Unsuppressed shot detected"}}];

Edited by Fight9

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  

×