Raised This Month: $37 Target: $400
 9% 

Removing pass get_playersnum()


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
deprale
Member
Join Date: Oct 2018
Location: Leeds
Old 01-13-2019 , 10:10   Removing pass get_playersnum()
Reply With Quote #1

PHP Code:
//AMXX 1.8.2
#define TAG "PASS"
new emptypass;

public 
plugin_init()
{
    
//pass check
    
emptypass get_cvar_pointer"sv_password" );
}

public 
client_disconnect(id)
{
set_task(5.0"aremovepass"___"a"1);
}

public 
aremovepass()
{
    new 
curpass[32];
    
get_pcvar_string(emptypasscurpass31);
    if((
get_playersnum() == 0) && (strlen(curpass)<1)) 
    {
        
set_cvar_string("sv_password","");
        
ColorChat(0RED"%s Password has been removed."TAG);
    }

My objective: Setting cvar sv_password to "" when the last player has disconnected from a password protected server!

I tried learning from some old sources, but I failed miserably each time, I tried also with get_players() and getting players from CT/T/SPECTATOR/UNASSIGNED, created a variable summing all the 4 teams up. The same result, the password does NOT get removed.


Any tips are appreciated, thanks!

UMM(EDIT): I also tried using client_remove
__________________
Hey there, I'm eager to learn more and more about amxmodx and coding in general.

If you need any small help I can provide I'll gladly help you!

Last edited by deprale; 01-13-2019 at 10:15. Reason: Some formatting and some useful info!
deprale is online now
HamletEagle
AMX Mod X Plugin Approver
Join Date: Sep 2013
Location: Romania
Old 01-13-2019 , 10:17   Re: Removing pass get_playersnum()
Reply With Quote #2

What is the point of strlen(curpass) < 1?
__________________
HamletEagle is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 01-13-2019 , 10:24   Re: Removing pass get_playersnum()
Reply With Quote #3

PHP Code:
#include <amxmodx>

#define TAG "PASS"

new emptypass;

public 
plugin_init()
{
    
emptypass get_cvar_pointer"sv_password" );
}

public 
client_disconnectid )
{
    
//if you need a task to execute one time then you do not need any flags.
    //set_task(5.0, "aremovepass", _, _, _, "a", 1);
    
set_task5.0 "aremovepass" );
}

public 
aremovepass()
{
    new 
curpass32 ];
    
get_pcvar_stringemptypass curpass charsmaxcurpass ) );
    
    
//If you want to set the password from something to nothing, then you need to check if the len is currently > 0, not less than 1.
    //An alternative way, avoiding a native call, is to just check if the first character is null.
    //if((get_playersnum() == 0) && (strlen(curpass)<1)) 
    
    //If
    // No players currently connnected
    // AND
    // current password is not ""
    
if ( ( get_playersnum() == ) && ( curpass] != EOS ) )
    {
        
set_cvar_string("sv_password","");
        
ColorChat(0RED"%s Password has been removed."TAG);
    }

__________________

Last edited by Bugsy; 01-13-2019 at 10:26.
Bugsy is offline
deprale
Member
Join Date: Oct 2018
Location: Leeds
Old 01-13-2019 , 10:28   Re: Removing pass get_playersnum()
Reply With Quote #4

Quote:
Originally Posted by HamletEagle View Post
What is the point of strlen(curpass) < 1?
To check if there is a password > execute code.
Otherwise just save memory, I guess?
__________________
Hey there, I'm eager to learn more and more about amxmodx and coding in general.

If you need any small help I can provide I'll gladly help you!
deprale is online now
deprale
Member
Join Date: Oct 2018
Location: Leeds
Old 01-13-2019 , 10:31   Re: Removing pass get_playersnum()
Reply With Quote #5

Quote:
Originally Posted by Bugsy View Post
PHP Code:
#include <amxmodx>

#define TAG "PASS"

new emptypass;

public 
plugin_init()
{
    
emptypass get_cvar_pointer"sv_password" );
}

public 
client_disconnectid )
{
    
//if you need a task to execute one time then you do not need any flags.
    //set_task(5.0, "aremovepass", _, _, _, "a", 1);
    
set_task5.0 "aremovepass" );
}

public 
aremovepass()
{
    new 
curpass32 ];
    
get_pcvar_stringemptypass curpass charsmaxcurpass ) );
    
    
//If you want to set the password from something to nothing, then you need to check if the len is currently > 0, not less than 1.
    //An alternative way, avoiding a native call, is to just check if the first character is null.
    //if((get_playersnum() == 0) && (strlen(curpass)<1)) 
    
    //If
    // No players currently connnected
    // AND
    // current password is not ""
    
if ( ( get_playersnum() == ) && ( curpass] != EOS ) )
    {
        
set_cvar_string("sv_password","");
        
ColorChat(0RED"%s Password has been removed."TAG);
    }

Thank you very much, I'm gonna test it right now, I love how you commented everything.
I suppose EOS means End Of String? If so, it makes sense because if current pass DOES NOT EQUAL to nothing then it goes forwards, thanks, just learned something new!

P.S: Sorry for double-posting, won't happen again, I thought I was editing the reply above! Woops

EDIT:
Doesn't work Compiles just fine, after I type disconnect in console after setting up a password it just won't set it to nothing!

EDIT2: FIXED. Everything was fine before. Thanks everyone!
__________________
Hey there, I'm eager to learn more and more about amxmodx and coding in general.

If you need any small help I can provide I'll gladly help you!

Last edited by deprale; 01-13-2019 at 10:44.
deprale is online now
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 01-13-2019 , 10:52   Re: Removing pass get_playersnum()
Reply With Quote #6

Yeah, your original code was pretty much good, except for the len check.

if((get_playersnum() == 0) && (strlen(curpass)<1))
__________________
Bugsy is offline
deprale
Member
Join Date: Oct 2018
Location: Leeds
Old 01-13-2019 , 11:26   Re: Removing pass get_playersnum()
Reply With Quote #7

Thanks again Bugsy, you've been of great help!
__________________
Hey there, I'm eager to learn more and more about amxmodx and coding in general.

If you need any small help I can provide I'll gladly help you!
deprale is online now
HamletEagle
AMX Mod X Plugin Approver
Join Date: Sep 2013
Location: Romania
Old 01-13-2019 , 11:38   Re: Removing pass get_playersnum()
Reply With Quote #8

Quote:
Originally Posted by deprale View Post
To check if there is a password > execute code.
Otherwise just save memory, I guess?
No. You are checking if the password is empty(strlen < 1 means the string has 0 characters) => no password. The check should be reversed, meaning strlen >= 1 or simply check if first char is not EOS, as suggested before.

This:
PHP Code:
set_cvar_string("sv_password",""); 
Should be
PHP Code:
set_pcvar_string(emptypass""); 
You already got the cvar pointer, so no reason to use the slow set_cvar_* natives.

PHP Code:
 ColorChat(0RED"%s Password has been removed."TAG); 
Isn't this totally useless? It will be displayed when the server is empty - no one can see the message.
__________________

Last edited by HamletEagle; 01-13-2019 at 11:39.
HamletEagle is offline
deprale
Member
Join Date: Oct 2018
Location: Leeds
Old 01-13-2019 , 12:44   Re: Removing pass get_playersnum()
Reply With Quote #9

Quote:
Originally Posted by HamletEagle View Post
No. You are checking if the password is empty(strlen < 1 means the string has 0 characters) => no password. The check should be reversed, meaning strlen >= 1 or simply check if first char is not EOS, as suggested before.

This:
PHP Code:
set_cvar_string("sv_password",""); 
Should be
PHP Code:
set_pcvar_string(emptypass""); 
You already got the cvar pointer, so no reason to use the slow set_cvar_* natives.

PHP Code:
 ColorChat(0RED"%s Password has been removed."TAG); 
Isn't this totally useless? It will be displayed when the server is empty - no one can see the message.
1. Wow, thanks, I've put emptypass instead of sv_password
2. Yeah, I removed the ColorChat line as well, it was just for debugging purposes, edited it into being a console (and log) message.

Thanks, HamletEagle!
__________________
Hey there, I'm eager to learn more and more about amxmodx and coding in general.

If you need any small help I can provide I'll gladly help you!
deprale is online now
Reply


Thread Tools
Display Modes

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:29.


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