Raised This Month: $ Target: $400
 0% 

when client connects and client disconnects


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Diegorkable
Veteran Member
Join Date: Jun 2011
Old 09-26-2011 , 08:48   when client connects and client disconnects
Reply With Quote #1

Hey guys I have 2 huge questions that arent answered yet, that really confuse me and make me have a hard time when scripting in these forward publics (client_connect and client_disconnect), so i hope you'll give me the right answer so i'll finally be calm about it.

Question no. 1:

in client_connect, if I do get_playersnum(), will it count the player that has just connected?

Question no. 2:

in client_disconnect, if I do get_playersnum(), will it count the player that has just disconnected?
Diegorkable is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 09-26-2011 , 08:51   Re: when client connects and client disconnects
Reply With Quote #2

You can figure this out yourself, don't be lazy.
__________________
Bugsy is offline
Diegorkable
Veteran Member
Join Date: Jun 2011
Old 09-26-2011 , 09:01   Re: when client connects and client disconnects
Reply With Quote #3

I did it few times, but wierd things happen!!!! I'll tell you what i tried.:

in client_connect i did get_playersnum and if it has 10 players set a pass and do a client print.

in client_disconnect i did get_playersnum and if it has 10 players (before the client has left, meaning there are 9 now) remove the pass.

And this is what happened:

the 10th has logged in a pass was SET.
the 10th has logged out the pass was REMVOED.
the 8th has logged out a pass was set....

wierd random shit happen and i dont know why is this..

ill post the public here:

PHP Code:
// cvar "cvar_playersleft" equals to 10, yeah im sure.

public CheckEmpty(id// Called on client_disconnect
{
    if (
get_maxplayers() == get_pcvar_num(cvar_playersleft))
        return 
PLUGIN_HANDLED
        
        
    
if (get_playersnum() == get_pcvar_num(cvar_playersleft))
    {
        
set_cvar_string("sv_password""")
        
client_print(0print_chat"%s Server password has been REMOVED."PREFIX)
        
set_task(5.0"CheckNow")
    }
    
    return 
PLUGIN_CONTINUE
}

public 
CheckFull(id// Called on client_Connect
{
    if (
get_maxplayers() == get_pcvar_num(cvar_playersleft))
        return 
PLUGIN_HANDLED
        
    
if (get_playersnum()+== get_pcvar_num(cvar_playersleft))
    {
        new 
rnd random_num(999999)
        new 
pass[10]
        
        
num_to_str(rndpass9)
        
        
set_cvar_string("sv_password"pass)
        
client_print(0print_chat"%s Server is now password PROTECTED"PREFIX)
    }
    
    return 
PLUGIN_HANDLED

and dont tell me why you did get_playersnum()+1, cuz i tried it in many many variations, with +1 and without ina ll sequences and havent found the correct code. help pls!
Diegorkable is offline
jim_yang
Veteran Member
Join Date: Aug 2006
Old 09-26-2011 , 09:05   Re: when client connects and client disconnects
Reply With Quote #4

Code:
void C_ClientDisconnect(edict_t *pEntity)
{
	CPlayer *pPlayer = GET_PLAYER_POINTER(pEntity);
	if (pPlayer->initialized)
		executeForwards(FF_ClientDisconnect, static_cast<cell>(pPlayer->index));

	if (pPlayer->ingame)
	{
		--g_players_num;
	}
	pPlayer->Disconnect();

	RETURN_META(MRES_IGNORED);
}

void C_ClientPutInServer_Post(edict_t *pEntity)
{
	CPlayer *pPlayer = GET_PLAYER_POINTER(pEntity);
	if (!pPlayer->IsBot())
	{
		pPlayer->PutInServer();
		++g_players_num;
		executeForwards(FF_ClientPutInServer, static_cast<cell>(pPlayer->index));
	}
	
	RETURN_META(MRES_IGNORED);
}
++playersnum is in putinserver, so in client_connect, it doesn't count
--playersnum is after client_disconnect forward, so it count
__________________
Project : CSDM all in one - 99%
<team balancer#no round end#entity remover#quake sounds#fake full#maps management menu#players punishment menu#no team flash#colored flashbang#grenade trails#HE effect#spawn protection#weapon arena#weapon upgrade#auto join#no weapon drop#one name>
jim_yang is offline
Hunter-Digital
Veteran Member
Join Date: Aug 2006
Location: In the Game [ro]
Old 09-26-2011 , 09:23   Re: when client connects and client disconnects
Reply With Quote #5

Quote:
Originally Posted by jim_yang View Post
++playersnum is in putinserver, so in client_connect, it doesn't count
Well, get_playersnum() has a optional argument that enables it to count connecting players aswell.

Still, @Diegorkable, you should test with a simple print plugin on a private/empty server... something like:
Code:
public client_connect(id)
{
    server_print("[debug] client_connect() :: get_playersnum() = %d | get_playersnum(1) = %d", get_playersnum(), get_playersnum(1))
}

public client_putinserver(id)
{
    server_print("[debug] client_putinserver() :: get_playersnum() = %d | get_playersnum(1) = %d", get_playersnum(), get_playersnum(1))
}

public client_disconnect(id)
{
    server_print("[debug] client_disconnect() :: get_playersnum() = %d | get_playersnum(1) = %d", get_playersnum(), get_playersnum(1))
}
After that you just join and disconnect, then check the console, then you can clearly see if the function includes the connecting player if it says 1 or 0.

EDIT: just out of curiosity I tested it myself, it seems it does count players as intended, get_playersnum() gets players in putinserver and disconnect, and with flag 1 it gets in all 3 forwards.
__________________

Last edited by Hunter-Digital; 09-26-2011 at 09:27.
Hunter-Digital is offline
Diegorkable
Veteran Member
Join Date: Jun 2011
Old 09-26-2011 , 09:30   Re: when client connects and client disconnects
Reply With Quote #6

Look at my code, didnt I do it right then...?
Diegorkable is offline
Diegorkable
Veteran Member
Join Date: Jun 2011
Old 09-26-2011 , 09:38   Re: when client connects and client disconnects
Reply With Quote #7

I have a question. I realise that yeah on connect it doesnt count and on disconnect it does. but I have 1 question. Sometime it fucks up when player is connect (it sees that he has connected then it sets a pass), and if he cancels the connection in the middle he just leaves and the password isnt being removed. How can I fix it? Therefore I think that if a player is in the middle of connecting (just passed client_connect), so if he cancels the loading client_disconnect isnt called? Cuz its not disable the password.

OR Maybe since he wasnt counted in get_playersnum() he wont be counted at disconnect either (if he terminated the connection to the server)
Diegorkable is offline
Hunter-Digital
Veteran Member
Join Date: Aug 2006
Location: In the Game [ro]
Old 09-26-2011 , 09:40   Re: when client connects and client disconnects
Reply With Quote #8

Yes, disconnect is not called if player cancels while in loading.
You could just set password in putinserver :-??
__________________
Hunter-Digital is offline
Diegorkable
Veteran Member
Join Date: Jun 2011
Old 09-26-2011 , 10:03   Re: when client connects and client disconnects
Reply With Quote #9

Yes, but then a situation that 2 players are connecting when there are 9 players. it'll set a pass when there are 11 players only :s
Diegorkable is offline
Diegorkable
Veteran Member
Join Date: Jun 2011
Old 09-26-2011 , 10:49   Re: when client connects and client disconnects
Reply With Quote #10

Well, I did that on client_putinserver it sets the password if playernum is 10, and then check if there are any other users connecting and kicking them out with the reason "Server is FULL!"
Diegorkable 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 19:34.


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