Raised This Month: $ Target: $400
 0% 

Count Player Leaves


  
 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
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
 



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 21:13.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode