Jump to content
Sign in to follow this  
Kydoimos

Script to Check for Idle Player

Recommended Posts

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

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

Ah, nice! Fantastic! Does that go in the Init. file?

Share this post


Link to post
Share on other sites
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

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

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

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

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
Sign in to follow this  

×