01.11.2012, 16:08
I know it's possible and I've seen it discussed, but I've never seen a straight answer. It has something to do with OnPlayerUpdate, but I'm not sure. Can someone help me?
Check if they are in the same position. If they are not moving for 3-10 minutes, they might be pausing or afk.
|
new iPlayerPaused[MAX_PLAYERS];
OnPlayerConnect(playerid) {
iPlayerPaused[playerid] = 0;
}
OnPlayerUpdate(playerid) {
iPlayerPaused[playerid] = 0;
}
forward PausedCheck(); public PausedCheck() { // Set timer each second
for(new i = 0; i < MAX_PLAYERS; i++) {
iPlayerPaused[i] += 1;
if(iPlayerPaused[i] > 2) {
// Players most likely Paused.
}
}
}
#include <a_samp>
#include <YSI\y_timers>
new ppaused[MAX_PLAYERS];
ptask setafk[145000](playerid)
{
ppaused[playerid] = 1;
defer afktest(playerid);
}
timer afktest[20000](playerid)
{
if(ppaused[playerid] == 1)
{
SendClientMessage(playerid, 0xFFFF00D4, "WARNING: You have not pressed any key for 20 seconds!");
SendClientMessage(playerid, 0xFFFF00D4, "You have 2 minutes to press any key or you will be kicked for AFK!");
defer afktest2(playerid);
}
}
timer afktest2[120000](playerid)
{
new string[196], pname[MAX_PLAYER_NAME];
if (ppaused[playerid] == 1)
{
GetPlayerName(playerid, pname, sizeof(pname));
SendClientMessage(playerid, 0xFF0037BE, "You have been kicked for being paused for too long!");
SendClientMessage(playerid, 0xFF0037BE, "Come back when you want to play!");
format (string, sizeof(string), "{FF0000}%s {FF7D7D}Has Been Automatically Kicked, {FF0000}Reason: {FF7D7D}AFK.", pname);
SendClientMessageToAll(0xFF0037BE,string);
ppaused[playerid] = 0;
Kick(playerid);
}
}
public OnPlayerConnect(playerid)
{
ppaused[playerid] = 0;
return 1;
}
public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
{
ppaused[playerid] = 0;
return 1;
}
I have to say, I've only just come up with that and as you say - accurate detection can be hard, the simplest solution is often the best.
Edit: Just be careful with players already viewing a dialog. |