View Single Post
Nextra
Veteran Member
Join Date: Apr 2008
Location: Germany
Old 06-17-2014 , 11:22   Re: Count Player Leaves
Reply With Quote #4

You need to work with SteamIDs here, using a Trie is usually the best option for that. Just using the client entity index is not reliable because they are not constant for any one client. If player a leaves and player b connects afterwards they will have the same index.

PHP Code:
#include <amxmodx>

#define RETRY_TIME 10.0

new Trie:g_last_leaveTrie:g_leave_countg_steamid[33][33];

public 
plugin_init() {
   
g_last_leave TrieCreate();
   
g_leave_count TrieCreate();
}

public 
client_authorized(client) {
   
get_user_authid(clientg_steamid[client], charsmax(g_steamid[]));

   new 
Float:last;
   if (
TrieGetCell(g_last_leaveg_steamid[client], last) && get_gametime() - last <= RETRY_TIME) {
      new 
count;
      
TrieGetCell(g_leave_countg_steamid[client], count);

      
TrieSetCell(g_leave_countg_steamid[client], count 1);
   }
}

public 
client_disconnect(client) {
   
TrieSetCell(g_last_leaveg_steamid[client], get_gametime());

   new 
count;
   
TrieGetCell(g_leave_countg_steamid[client], count);
   
TrieSetCell(g_leave_countg_steamid[client], count 1);

This is a very basic example. On client_disconnect we save the last time the player disconnected and increment the leave count by one. If the player reconnects within RETRY_TIME seconds we decrement the counter by one.
__________________
In Flames we trust!
Nextra is offline