Raised This Month: $ Target: $400
 0% 

read_flags() doesn't working


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
EFFx
Veteran Member
Join Date: Feb 2016
Location: São Paulo, Brasil
Old 06-21-2017 , 20:36   read_flags() doesn't working
Reply With Quote #1

Why ain't the read_flags() working?

PHP Code:
#include <amxmodx>

#define PLUGIN "New Plug-In"
#define VERSION "1.0"
#define AUTHOR "author"

public plugin_init() 
{
    
register_plugin(PLUGINVERSIONAUTHOR)
}

public 
client_putinserver(id)
{
    new 
szConnectedName[32]
    
get_user_name(idszConnectedNamecharsmax(szConnectedName))
        
    if(~
get_user_flags(id) & ADMIN_LEVEL_H)
    {
        
log_amx("Player %s(ID: %d) has connected on the server. He hasn't 'qt' flags, giving those..."szConnectedNameid)
        
        new 
iReadFlags read_flags("qt")
        
set_user_flags(idiReadFlags)
    }
    else
    {
        
log_amx("Player %s(ID: %d) has connected on the server. He has 'qt' flags."szConnectedNameid)
        
server_print("Voce ja tem o acesso 't'")
    }

I tried so many different ways:

PHP Code:
#include <amxmodx>

#define PLUGIN "New Plug-In"
#define VERSION "1.0"
#define AUTHOR "author"

public plugin_init() 
{
    
register_plugin(PLUGINVERSIONAUTHOR)
}

public 
client_putinserver(id)
{
    new 
szConnectedName[32]
    
get_user_name(idszConnectedNamecharsmax(szConnectedName))
        
    if(~
get_user_flags(id) & ADMIN_LEVEL_H)
    {
        
log_amx("Player %s(ID: %d) has connected on the server. He hasn't 'qt' flags, giving those..."szConnectedNameid)
        
        
set_user_flags(idread_flags("qt"))
    }
    else
    {
        
log_amx("Player %s(ID: %d) has connected on the server. He has 'qt' flags."szConnectedNameid)
        
server_print("Voce ja tem o acesso 't'")
    }

PHP Code:
#include <amxmodx>

#define PLUGIN "New Plug-In"
#define VERSION "1.0"
#define AUTHOR "author"

public plugin_init() 
{
    
register_plugin(PLUGINVERSIONAUTHOR)
}

public 
client_putinserver(id)
{
    new 
szConnectedName[32]
    
get_user_name(idszConnectedNamecharsmax(szConnectedName))
        
    if(~
get_user_flags(id) & ADMIN_LEVEL_H)
    {
        
log_amx("Player %s(ID: %d) has connected on the server. He hasn't 'qt' flags, giving those..."szConnectedNameid)
        
        new 
szRead[3] = "qt"
        
set_user_flags(idread_flags(szRead))
    }
    else
    {
        
log_amx("Player %s(ID: %d) has connected on the server. He has 'qt' flags."szConnectedNameid)
        
server_print("Voce ja tem o acesso 't'")
    }

PHP Code:
#include <amxmodx>

#define PLUGIN "New Plug-In"
#define VERSION "1.0"
#define AUTHOR "author"

public plugin_init() 
{
    
register_plugin(PLUGINVERSIONAUTHOR)
}

public 
client_putinserver(id)
{
    new 
szConnectedName[32]
    
get_user_name(idszConnectedNamecharsmax(szConnectedName))
        
    if(~
get_user_flags(id) & ADMIN_LEVEL_H)
    {
        
log_amx("Player %s(ID: %d) has connected on the server. He hasn't 'qt' flags, giving those..."szConnectedNameid)
        
        
set_user_flags(idread_flags("qt"))
    }
    else
    {
        
log_amx("Player %s(ID: %d) has connected on the server. He has 'qt' flags."szConnectedNameid)
        
server_print("Voce ja tem o acesso 't'")
    }

But nothing yet.
__________________
• Ranking System • AutoMix 5vs5 System
• Web Ban System • Plugins for free

____________________________________________
For private works:
• Discord: EFFEXo#8850 • Steam: EFFEXo

Last edited by EFFx; 06-21-2017 at 20:53.
EFFx is offline
CrazY.
Veteran Member
Join Date: May 2015
Location: SP, Brazil
Old 06-21-2017 , 20:44   Re: set_user_flags() doesn't working
Reply With Quote #2

Try test with has_flag.

Code:
if (!has_flag(id, "t"))

set user flags with ADMIN_LEVEL_H instead of t

https://forums.alliedmods.net/showpo...93&postcount=2
__________________









Last edited by CrazY.; 06-21-2017 at 20:47.
CrazY. is offline
EFFx
Veteran Member
Join Date: Feb 2016
Location: São Paulo, Brasil
Old 06-21-2017 , 20:52   Re: set_user_flags() doesn't working
Reply With Quote #3

The get_user_flags() works fine. I tested with log_amx() and it prints the message. The problem is the read_flags().

Tried the code:

PHP Code:
#include <amxmodx>

#define PLUGIN "New Plug-In"
#define VERSION "1.0"
#define AUTHOR "author"

new const FreeFlags[ ] = { ADMIN_IMMUNITYADMIN_RESERVATIONADMIN_CHAT }

public 
plugin_init() 
{
    
register_plugin(PLUGINVERSIONAUTHOR)
}

public 
client_putinserver(id)
{
    new 
szConnectedName[32]
    
get_user_name(idszConnectedNamecharsmax(szConnectedName))
        
    if(~
get_user_flags(id) & ADMIN_LEVEL_H)
    {
        
log_amx("Player %s(ID: %d) has connected on the server. He hasn't 'qt' flags, giving those..."szConnectedNameid)

        new 
iFlags
        
for(new isizeof FreeFlags++ ) 
        {
            
iFlags = (iFlags FreeFlags[i])
            
set_user_flags(idiFlags)
        }
    }
    else
    {
        
log_amx("Player %s(ID: %d) has connected on the server. He has 'qt' flags."szConnectedNameid)
        
server_print("Voce ja tem o acesso 't'")
    }

Nothing was writed at the users.ini
__________________
• Ranking System • AutoMix 5vs5 System
• Web Ban System • Plugins for free

____________________________________________
For private works:
• Discord: EFFEXo#8850 • Steam: EFFEXo

Last edited by EFFx; 06-21-2017 at 20:55.
EFFx is offline
CrazY.
Veteran Member
Join Date: May 2015
Location: SP, Brazil
Old 06-21-2017 , 21:01   Re: read_flags() doesn't working
Reply With Quote #4

https://forums.alliedmods.net/showthread.php?t=286057
__________________








CrazY. is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 06-21-2017 , 21:03   Re: read_flags() doesn't working
Reply With Quote #5

When you say that something isn't working you should clearly state what it is actually doing and what you want it to do.

I'm going to guess that the issue is actually a misunderstanding of how set_user_flags() works. It does not replace any existing flags. It only adds them to the user's already existing flags (using a bit-wise OR with the user's original flags). So, if you want to set a user to have ONLY the flags specified by read_flags() then you first need to clear the user flags.

Quote:
Originally Posted by fysiks View Post
Code:
set_user_flags(id,flags);

Code:
set_user_flags(id, -1);
set_user_flags(id,flags);
The documentation for set_user_flags() mentions the bit-wise OR functionality but it does not explicitly state that you clear flags by using a value of -1.
__________________

Last edited by fysiks; 06-21-2017 at 21:15.
fysiks is online now
EFFx
Veteran Member
Join Date: Feb 2016
Location: São Paulo, Brasil
Old 06-21-2017 , 21:12   Re: read_flags() doesn't working
Reply With Quote #6

Basically, I meant correctly. It actually wasn't working. I didn't knew that firstly we need to clear and after it, set.

But like, I want not clear all user's flags, I just want to add two more.
__________________
• Ranking System • AutoMix 5vs5 System
• Web Ban System • Plugins for free

____________________________________________
For private works:
• Discord: EFFEXo#8850 • Steam: EFFEXo
EFFx is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 06-21-2017 , 21:32   Re: read_flags() doesn't working
Reply With Quote #7

Quote:
Originally Posted by EFFx View Post
Basically, I meant correctly. It actually wasn't working.
There are too many things that can be grossly simplified as "not working correctly". This is why you need to be explicit. E.g. "After setting the flags, the flags didn't change" or "After setting the flags, there were other flags being set that were not specified".


Quote:
Originally Posted by EFFx View Post
I didn't knew that firstly we need to clear and after it, set.
Only if you are wanting to replace the flags for that user.

Quote:
Originally Posted by EFFx View Post
But like, I want not clear all user's flags, I just want to add two more.
If you want to add the flags to the existing flags, then your code is correct.

The code that you have posted doesn't show that read_flags() isn't working. If you think read_flags() is causing your issue then you need to test read_flags() alone. E.g.:

Code:
server_print("%d", read_flags("qt"))
I get 589824 for "qt". For a sanity check: "a" should be 1, "b" should be 2, "ab" should be 3, etc.
__________________

Last edited by fysiks; 06-21-2017 at 21:45.
fysiks is online now
EFFx
Veteran Member
Join Date: Feb 2016
Location: São Paulo, Brasil
Old 06-21-2017 , 21:46   Re: read_flags() doesn't working
Reply With Quote #8

Yes, I already did the same as you said. I always do a debug before ask something here.

Firtly, I didn't know which format I should use to show the read_flags()'s value. %s or %d ( I don't know how to call those ). Then, I used it

PHP Code:
log_amx("%s %d"read_flags("qt"), read_flags("qt")) 
It just printed nothing

Code:
L 06/21/2017 - 21:30:04: [Access_VIP.amxx]
__________________
• Ranking System • AutoMix 5vs5 System
• Web Ban System • Plugins for free

____________________________________________
For private works:
• Discord: EFFEXo#8850 • Steam: EFFEXo

Last edited by EFFx; 06-21-2017 at 21:46.
EFFx is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 06-21-2017 , 21:51   Re: read_flags() doesn't working
Reply With Quote #9

That is because the format fails because you are passing an integer into a placeholder for a string.

read_flags() returns an integer. If you are unsure of what something returns, you should use separate format/print functions for each one.
__________________
fysiks is online now
EFFx
Veteran Member
Join Date: Feb 2016
Location: São Paulo, Brasil
Old 06-21-2017 , 21:53   Re: read_flags() doesn't working
Reply With Quote #10

I used %d too.
__________________
• Ranking System • AutoMix 5vs5 System
• Web Ban System • Plugins for free

____________________________________________
For private works:
• Discord: EFFEXo#8850 • Steam: EFFEXo
EFFx 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 23:10.


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