Raised This Month: $ Target: $400
 0% 

Count Player Leaves


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
pepe_thugs
Senior Member
Join Date: Aug 2010
Location: Portugal , Braga
Old 06-17-2014 , 08:46   Count Player Leaves
Reply With Quote #1

I want to count how many times the player leaves server but not count the retry command.
I have this simple code (test code) i saw other codes but i want one simple solution.
Someone can help me ?

PHP Code:
new gDisc[33]

public 
client_disconnect(id)
{
    
set_task(10.0"LeaveSv"id)
}

public 
LeaveSv(id)
{
    if(!
is_user_connected(id))
    {
        
gDisc[id]++
        
SaveLeave(id)
    }

pepe_thugs is offline
YamiKaitou
Has a lovely bunch of coconuts
Join Date: Apr 2006
Location: Texas
Old 06-17-2014 , 09:00   Re: Count Player Leaves
Reply With Quote #2

It is not possible to detect if the user disconnected with the retry command. Also, if they do use retry, there is no guarantee that they will have the same index as they did before
__________________
ProjectYami Laboratories

I do not browse the forums regularly anymore. If you need me for anything (asking questions or anything else), then PM me (be descriptive in your PM, message containing only a link to a thread will be ignored).
YamiKaitou is offline
HamletEagle
AMX Mod X Plugin Approver
Join Date: Sep 2013
Location: Romania
Old 06-17-2014 , 09:17   Re: Count Player Leaves
Reply With Quote #3

I want to count how many times the player leaves server but not count the retry command.

So:

PHP Code:
new gDisc

public client_disconnect(id

        
gDisc++ 
        
SaveLeave(id

Why not simply do this ?

Last edited by HamletEagle; 06-17-2014 at 09:17.
HamletEagle is offline
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
pepe_thugs
Senior Member
Join Date: Aug 2010
Location: Portugal , Braga
Old 06-17-2014 , 16:36   Re: Count Player Leaves
Reply With Quote #5

Quote:
Originally Posted by HamletEagle View Post

Why not simply do this ?
Because i want to count how many times the player disconnect but count when player disconnect more than 10 seconds.

@Nextra Thanks but one more question i can use a global count because i want to run one function to save this in sqlx?
Like this:

PHP Code:

#include <amxmodx>

#define RETRY_TIME 10.0

new Trie:g_last_leaveTrie:g_leave_countg_steamid[33][33];
new 
count[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) {

      
TrieGetCell(g_leave_countg_steamid[client], count[client]);

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

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

   
TrieGetCell(g_leave_countg_steamid[client], count[client]);
   
TrieSetCell(g_leave_countg_steamid[client], count[client]++);


Last edited by pepe_thugs; 06-17-2014 at 16:37.
pepe_thugs is offline
Nextra
Veteran Member
Join Date: Apr 2008
Location: Germany
Old 06-17-2014 , 18:42   Re: Count Player Leaves
Reply With Quote #6

Storing the counts globally based on player index is pointless. As multiple people have told you the indexes are meaningless after a user disconnects. The code you have posted above will break because of this. I repeat: Indexes are not permanent! There is a reason I used the tries to work with steamids instead of player indexes.

If you want a per-user count use my code. Add a global counter if you want, but do it separately from the player counts.

If you want only a global count you can remove everything regarding the g_leave_count trie and just work with the global counter.


/edit: Please try to actually understand what I did with the code. Your changes break it completely and shows that you did not understand it at all.
__________________
In Flames we trust!

Last edited by Nextra; 06-17-2014 at 18:47.
Nextra is offline
^SmileY
Veteran Member
Join Date: Jan 2010
Location: Brazil [<o>]
Old 06-18-2014 , 01:32   Re: Count Player Leaves
Reply With Quote #7

Search in forum, i think the Disconnect reason (With orpheu) can help you

EDIT: https://forums.alliedmods.net/showthread.php?p=1545485

You need to custom this plugin to use a DR_DROPPED to count as quit
__________________
Projects:

- See my Git Hub: https://github.com/SmileYzn
PHP Code:
set_pcvar_num(pCvar, !get_pcvar_num(pCvar)); 

Last edited by ^SmileY; 06-18-2014 at 01:33.
^SmileY is offline
Send a message via MSN to ^SmileY Send a message via Skype™ to ^SmileY
ezio_auditore
Senior Member
Join Date: May 2013
Old 06-18-2014 , 12:52   Re: Count Player Leaves
Reply With Quote #8

Or simply incrementing his leaves in client_disconnect() and save it using nVault with AutdID
__________________
ezio_auditore is offline
Send a message via Skype™ to ezio_auditore
^SmileY
Veteran Member
Join Date: Jan 2010
Location: Brazil [<o>]
Old 06-18-2014 , 16:11   Re: Count Player Leaves
Reply With Quote #9

Quote:
Originally Posted by ezio_auditore View Post
Or simply incrementing his leaves in client_disconnect() and save it using nVault with AutdID
Client disconnect do not return if an player leaves by timeout or dropped or kicked.
__________________
Projects:

- See my Git Hub: https://github.com/SmileYzn
PHP Code:
set_pcvar_num(pCvar, !get_pcvar_num(pCvar)); 
^SmileY is offline
Send a message via MSN to ^SmileY Send a message via Skype™ to ^SmileY
pepe_thugs
Senior Member
Join Date: Aug 2010
Location: Portugal , Braga
Old 06-18-2014 , 20:07   Re: Count Player Leaves
Reply With Quote #10

Problem Solved.
Thanks for all answers.
And special thanks Nextra for the code and sorry my ignorance.
pepe_thugs is offline
Reply



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 17:34.


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