Player position check
#2

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!"


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(playeridpedPosition[BREADTH], pedPosition[HEIGHT], pedPosition[DEPTH]);
  if(
IsPlayerInRangeOfPoint(playeridPLAYER_IDLE_MOVE_RANGEplayerIdlePositions[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(stroka20"AFK: %d sec"idleTime);
      
SetPlayerChatBubble(playeridstroka, -1PLAYER_IDLE_LABEL_RANGE1100);
    }
  }
  else {
    if(
GetPVarInt(playerid"AFK") > 0)
      return 
SetPVarInt(playerid"AFK"0);
    
    
GetPlayerPos(playeridplayerIdlePositions[playerid][BREADTH], playerIdlePositions[playerid][HEIGHT], playerIdlePositions[playerid][DEPTH]);
  }
  return 
1;

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.
Reply


Messages In This Thread
Player position check - by ,TomY' - 05.08.2018, 18:32
Re: Player position check - by DBZdabIt3Bro7 - 05.08.2018, 18:49
Re: Player position check - by NeXTGoD - 05.08.2018, 18:59
Re: Player position check - by DBZdabIt3Bro7 - 05.08.2018, 19:02
Re: Player position check - by NeXTGoD - 05.08.2018, 19:05
Re: Player position check - by DBZdabIt3Bro7 - 05.08.2018, 19:07
Re: Player position check - by NeXTGoD - 05.08.2018, 19:16
Re: Player position check - by ,TomY' - 05.08.2018, 20:25
Re: Player position check - by DBZdabIt3Bro7 - 05.08.2018, 20:41
Re: Player position check - by ,TomY' - 06.08.2018, 08:14

Forum Jump:


Users browsing this thread: 1 Guest(s)