Jump to content
Sign in to follow this  
Goro

Problem with globality of KeyPressed

Recommended Posts

Hello, fellas. I've got an uncommon problem. I'm trying to get my flashlight script to work. Everything is great, but players can switch someone's else flashlight on/off. This is the globality problem. I've tried Replacing _this with units' name or units' group, but no success so far. Any guesses?

 
DisableSerialization; waituntil {!(IsNull (findDisplay 46))};   


keyDown = (findDisplay 46) displayAddEventHandler ["KeyDown", "if (_this select 1 == 37) then {p1 execVM 'ON1.sqf'}"]; 
waituntil {!(IsNull (findDisplay 46))};   


keyDown = (findDisplay 46) displayAddEventHandler ["KeyDown", "if (_this select 1 == 38) then {p1 execVM 'OFF1.sqf'}"]; 


 waituntil {!(IsNull (findDisplay 46))};   


keyDown = (findDisplay 46) displayAddEventHandler ["KeyDown", "if (_this select 1 == 24) then {p2 execVM 'ON2.sqf'}"]; 
waituntil {!(IsNull (findDisplay 46))};   


keyDown = (findDisplay 46) displayAddEventHandler ["KeyDown", "if (_this select 1 == 25) then {p2 execVM 'OFF2.sqf'}"]; 
 
 

 

Share this post


Link to post
Share on other sites

You can just use variable 'player' in the scope of a keyDown EH:

keyDown = (findDisplay 46) displayAddEventHandler ["KeyDown", "if (_this select 1 == 37) then {player execVM 'ON1.sqf'}"]; 

And you really only need one waitUntil loop, and the other issue that may be causing your other player to turn the light on/off is that any player coming in would get 4 key down eventhandlers (for each key bind), so you may want to have a name/guid check, i.e.:

if (name player == "John Smith") then
{
    //add keybinds
};

if (name player == "Jane Doe") then
{
    //add keybinds
};
  • Like 1

Share this post


Link to post
Share on other sites
Guest
This topic is now closed to further replies.
Sign in to follow this  

×