Jump to content
Sign in to follow this  
ShinShin

Need help getting script to run 'per player

Recommended Posts

Okay, hello!

I've looked around for the past couple hours now while working on my mission too... and well, i'm quite stumped on this trick i'm wanting to pull for this script. So if anyone could help, awesome! any and all help will be greatly appreciated.

anyways, here ya go...

Question #1: "How do I run the script for each individual player"

Questions #2: "How do I set a cool off timer for the script before it can run again for the individual player"

to sum it up: ⇊ ⇊

Basically what I'm saying is I want this script to do something along the lines of making/giving each individual player the ability to blow his own cover if he fires his weapon without a silencer. But I don't want it to be broadcast on the server, I only want it to broadcast per player/client. and for it to be possible multiple times hence for the cool off timer??

Script:

(Ran From within a "startUpInit.sqf" like [] execVM "checkWeapon.sqf")

checkWeapon.sqf | Status: Working (10/28/2013 - 8:15 AM)

replace anything in red with your own.

if (!isDedicated) then { // run on clients
waitUntil {!isNull player}; // waituntil player variable is valid to use
_playerUnits = [[color="#FF0000"]variableName[/color], [color="#FF0000"]variableName[/color]];
{_x addEventHandler["fired", {_this call TAG_fnc_suppressorCheck}];} Foreach _playerUnits; // add the EH only once, these are retained after death
TAG_fnc_suppressorCheck = {   //store the code into a global variable only one time
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 { // don't need to check whether or not a shot was fired, as we already know one was fired because the fired EH went off, check if it's silenced though
	hint "[color="#FF0000"]the shot was suppressed!![/color]";
	} else {
	hint "[color="#FF0000"]Shot not Suppressed[/color]";
	};

sleep 60;
}; 
};

Edited by ShinShin
Update the code

Share this post


Link to post
Share on other sites

if (!isDedicated) then { // run on clients
waitUntil {!isNull player}; // waituntil player variable is valid to use
player addEventHandler["fired", {if (_this call TAG_fnc_suppressorCheck) then {hint "Shot Suppressed"}}]; // add the EH only once, these are retained after death

TAG_fnc_suppressorCheck = {   //store the code into a global variable only one time. No nasty loop needed.  
    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 { // don't need to check whether or not a shot was fired, as we already know one was fired because the fired EH went off, check if it's silenced though
        hint "the shot was suppressed!!";        
    } else {            
        hint "Shot not Suppressed"; // run more code here to blow his cover

    };          

  }; 

};

You don't need a loop to keep storing the code into the global variable. I changed it to how it should be. Unless i'm majorly missing something here. At any rate, give that a try and let me know.

Edited by Iceman77

Share this post


Link to post
Share on other sites

Alright, it runs fine the first go around. But I'm in the single player editor doing all of this so I don't know how that'd affect anything. But any who... I'm testing it out with a unit as player and shooting once and I get the hint. But when I switch my player to another editor placed unit which is just playable and shoot, I get nothing?? (That's how I'm testing if the script will work, if multiple players are the case). Ohh!! and so far it's only firing **ONCE**.

Edited by ShinShin
forgot to mention...

Share this post


Link to post
Share on other sites

hmm. It's fired for me every time I fire the gun. In any case, it works for me and it would work on a dedicated server with multiple people (whom aren't team switching around I suppose). Team switching can be wonky at times. Though i've never really went to far into it and never use it.

For testing i would run the (dedicated) arma3server.exe and use it for MP testing. If you plan to make the mission for use on a dedicated server. Your testing will be more accurate there.

Edited by Iceman77

Share this post


Link to post
Share on other sites

Nevermind you're correct, it fires repeateadly upon shooting. I was relying on the hint, but I just retested that aspect and changed hint to hintC so everytime it fires the dialogue comes up (just to make sure it's firing.) thanks on that part man :D lol

Share this post


Link to post
Share on other sites
Nevermind you're correct, it fires repeateadly upon shooting. I was relying on the hint, but I just retested that aspect and changed hint to hintC so everytime it fires the dialogue comes up (just to make sure it's firing.) thanks on that part man :D lol

No worries. You are right though. The EH was never added to said unit. Only for player controlled units who start or JIP the mission.

Edited by Iceman77

Share this post


Link to post
Share on other sites

Yeah, which blows. but any who... could there be a work around to that?? Like maybe giving the playable units in editor a variable name, eg "TOM" and executing the script for each and every named unit/player? this way, if playing with any AI or actual people, the event handler is executed for that unit if it fires it's weapon.

Share this post


Link to post
Share on other sites

Okay, so getting to the unit variables...

_playerUnits = [tom, bob, steve, rick];

So i've tried this (and maybe I was doing it totally wrong or missing something) but calling on the units via an array never worked out.

Share this post


Link to post
Share on other sites
_playerUnits = [tom, bob, steve, rick];
{_x addEventHandler["fired", {if (_this call TAG_fnc_suppressorCheck) then {hint "Shot Suppressed"}}];} forEach [color=#ff0000]_playerUnits[/color];

Share this post


Link to post
Share on other sites

Alright, let me replace the line in the script with what you've given me and I'll get right back to you on the out come...

---------- Post added at 08:14 AM ---------- Previous post was at 08:03 AM ----------

_playerUnits = [tom, bob, steve, rick];
{_x addEventHandler["fired", {if (_this call TAG_fnc_suppressorCheck) then {hint "Shot Suppressed"}}];} forEach [color=#ff0000]_playerUnits[/color];

Awesome man, it worked... now with it setup this way, do you know if this would be MP compatible or would I have to take that on a run for myself.

S.N. I'll update the main post for any others who'd wish to use the script and reference the page.

Share this post


Link to post
Share on other sites

Btw, it can be like this too. Without the if check.

_units = [unit1,unit2];
{_x addEventHandler["fired", {[color=#ff0000]_this call TAG_fnc_suppressorCheck[/color]}];} Foreach _units; // add the EH only once, these are retained after death

Also, you'd need to take that on the run yourself, and post here any problems. or unless someone with more knowledge would reply very soon, then you'd be all set 100%.

You could apply the EH to the players group(s) when the player starts or joins the mission.

Edited by Iceman77
suggestion

Share this post


Link to post
Share on other sites
Btw, it can be like this too. Without the if check.

_units = [unit1,unit2];
{_x addEventHandler["fired", {[color=#ff0000]_this call TAG_fnc_suppressorCheck[/color]}];} Foreach _units; // add the EH only once, these are retained after death

Also, you'd need to take that on the run yourself, and post here any problems. or unless someone with more knowledge would reply very soon, then you'd be all set 100%.

You could apply the EH to the players group(s) when the player starts or joins the mission.

Anything to shorten the length of the script it self +1 to that man.

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  

×