new Float:AFK_X[MAX_PLAYERS], Float:AFK_Y[MAX_PLAYERS], Float:AFK_Z[MAX_PLAYERS]; forward UpdatePlayer(playerid); public UpdatePlayer(playerid) { new Float:x[MAX_PLAYERS], Float:y[MAX_PLAYERS], Float:z[MAX_PLAYERS]; GetPlayerPos(playerid, x[playerid], y[playerid], z[playerid]); if(x[playerid] == AFK_X[playerid] || y[playerid] == AFK_Y[playerid] || z[playerid] == AFK_Z[playerid]) { SetPVarInt(playerid, "AFK", GetPVarInt(playerid, "AFK")+1); if(GetPVarInt(playerid, "AFK") > 30) { new stroka[20]; format(stroka, 20, "AFK: %d sec", GetPVarInt(playerid, "AFK")); SetPlayerChatBubble(playerid, stroka, -1, 20.0, 1100); } } if(x[playerid] != AFK_X[playerid] || y[playerid] != AFK_Y[playerid] || z[playerid] != AFK_Z[playerid]) { if(GetPVarInt(playerid, "AFK") > 0) return SetPVarInt(playerid, "AFK", 0); GetPlayerPos(playerid, AFK_X[playerid], AFK_Y[playerid], AFK_Z[playerid]); } return 1; }
#define PLAYER_IDLE_MOVE_RANGE (3.0)
#define PLAYER_IDLE_LABEL_RANGE (20.0)
#define MAX_PLAYER_IDLE (30)
enum COORDINATION {
Float:BREADTH,
Float:HEIGHT,
Float:DEPTH
}
new playerIdlePositions[MAX_PLAYERS+1][COORDINATION];
forward public OnPlayerIdleCheck(playerid);
public OnPlayerIdleCheck(playerid) {
new pedPosition[COORDINATION];
GetPlayerPos(playerid, pedPosition[BREADTH], pedPosition[HEIGHT], pedPosition[DEPTH]);
if(IsPlayerInRangeOfPoint(playerid, PLAYER_IDLE_MOVE_RANGE, playerIdlePositions[playerid][BREADTH], playerIdlePositions[playerid][HEIGHT], playerIdlePositions[playerid][DEPTH])) {
new idleTime = GetPVarInt(playerid, "AFK")+1;
SetPVarInt(playerid, "AFK", idleTime);
if(idleTime > MAX_PLAYER_IDLE) {
new stroka[9+11+1]; // 9 = AFK: sec, 11 = integer, 1 = \0
format(stroka, 20, "AFK: %d sec", idleTime);
SetPlayerChatBubble(playerid, stroka, -1, PLAYER_IDLE_LABEL_RANGE, 1100);
}
}
else {
if(GetPVarInt(playerid, "AFK") > 0)
return SetPVarInt(playerid, "AFK", 0);
GetPlayerPos(playerid, playerIdlePositions[playerid][BREADTH], playerIdlePositions[playerid][HEIGHT], playerIdlePositions[playerid][DEPTH]);
}
return 1;
}
new Float:AfkPos[MAX_PLAYERS][3]; new Float:GPos[3]; SetTimer("CheckAFK",5000,true); function CheckAFK() { GetPlayerPos(i, GPos[0],GPos[1],GPos[2]); if(AfkPos[i][0] == GPos[0] && AfkPos[i][1] == GPos[1] && AfkPos[i][2] == GPos[2]) AFKTime[i] += 5; else { if(AFKTime[i] == 30) //Player is not moving for 30 seconds.. also don't forget to add 'return 1;' in the end GetPlayerPos(i, AfkPos[i][0], AfkPos[i][1], AfkPos[i][2]); } return 1; }
Код:
new Float:AfkPos[MAX_PLAYERS][3]; new Float:GPos[4]; SetTimer("CheckAFK",5000,true); function CheckAFK() { GetPlayerPos(i, GPos[0],GPos[1],GPos[2]); if(AfkPos[i][0] == GPos[0] && AfkPos[i][1] == GPos[1] && AfkPos[i][2] == GPos[2]) AFKTime[i] += 5; else { if(AFKTime[i] == 30) //Player is not moving for 30 seconds.. also don't forget to add 'return 1;' in the end GetPlayerPos(i, AfkPos[i][0], AfkPos[i][1], AfkPos[i][2]); } return 1; } |
Also there is a way to detect if a player pressed ESC or minimized his game |
Do not use this code. Not only will this not work since this is a clear copy and paste, but also, this is very unoptimized and... just terrible in general.
There is not. There is however a possibility to detect when the server has stopped receiving packets from the client, but the client is still connected, might be what you refer to. |
Well this code untested but there is a way and by using OnPlayerUpdate ( :
|
new playerIdlePositions[MAX_PLAYERS+1][COORDINATION];
Hey man, it works great, but I have one question.
Код:
new playerIdlePositions[MAX_PLAYERS+1][COORDINATION]; |
public OnPlayerConnect(playerid) {
playerIdlePositions[playerid] = playerIdlePositions[MAX_PLAYERS];
// also valid:
playerIdlePositions[playerid] = EOS;
return 1;
}
playerIdlePositions[playerid] = playerIdlePositions[MAX_PLAYERS];
playerIdlePositions[playerid] = EOS;
new pedPosition[COORDINATION]; GetPlayerPos(playerid, pedPosition[BREADTH], pedPosition[HEIGHT], pedPosition[DEPTH]);