Kydoimos 915 Posted February 12, 2014 Is there a way to check to see if a player has not pressed a key in, say, a minute? Like an idle script? Share this post Link to post Share on other sites
tpw 2315 Posted February 12, 2014 This works for me: // Initialise time_to_idle = time + 60; // Add keypress eventhandler (findDisplay 46) displayAddEventHandler ["keyDown", "_this call fnc_key"]; // Detect keypress fnc_key = { time_to_idle = time + 60; }; // Stuff to execute if idle fnc_idle = { time_to_idle = time + 60; hint "Idle!"; }; // Scan for idleness! while {true} do { if (time > time_to_idle) then { 0 = [] spawn fnc_idle; }; sleep 5; }; Share this post Link to post Share on other sites
Kydoimos 915 Posted February 12, 2014 Ah, nice! Fantastic! Does that go in the Init. file? Share this post Link to post Share on other sites
tpw 2315 Posted February 12, 2014 Ah, nice! Fantastic! Does that go in the Init. file? It can go anywhere you'd like, but init.sqf is as good a place as any. Share this post Link to post Share on other sites
KC Grimes 79 Posted February 12, 2014 Just note that if you put it in the init.sqf you will have to put it at the bottom because of the while loop. I suggest just execVMing another .sqf with it in it, for practical purposes. Share this post Link to post Share on other sites
IndeedPete 1038 Posted February 12, 2014 Or [] spawn {} it from init. Share this post Link to post Share on other sites
Kydoimos 915 Posted February 12, 2014 Wow - great stuff guys, thanks! Share this post Link to post Share on other sites
zapat 56 Posted February 12, 2014 And you probably want to wait until display is ready: // Add keypress eventhandler waitUntil {!isNull (findDisplay 46)}; (findDisplay 46) displayAddEventHandler ["keyDown", "_this call fnc_key"]; (Adding an eventhandler to a null display will not start your script. And running the code from init has a high probability of finishing before main display is ready.) This will only work in a spawned block, but as I read it, you are already doing that. Share this post Link to post Share on other sites
chessmaster42 11 Posted February 13, 2014 This is what I have built for tracking idle players: https://github.com/chessmaster42/mcc_sandbox/blob/master/mcc_sandbox.altis/idle_info/idle_info.sqf You initialize the system just by calling 'call II_Global_Load;' and then it will stay persistent and load for all clients and the server and any new clients that connect. It's still a WIP but the core is functional. Share this post Link to post Share on other sites