05.08.2018, 18:49
Your code is... terribly formatted and it hurts my eyes to read it... you should consider taking more use of macro definitions, enumerators and generally naming your variables to a position where it's understandable to say
"oh, I wonder what this variable holds for data... 'playerIdlePositions' - oh! it must be holding the positions of the players positions where they've been marked to be idling!"
To add on to this 'feature' overall: I wouldn't be too safe to use this kind of method to detect if a player is idling for thirty seconds. When I'm playing on for say a role play server, I usually don't move around for up to 15 minutes because I might just like to spectate scenarios and so on. I'm not sure what kind of game mode you're running, but it's just a friendly tip! Good luck.
"oh, I wonder what this variable holds for data... 'playerIdlePositions' - oh! it must be holding the positions of the players positions where they've been marked to be idling!"
PHP код:
#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;
}
