AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   read_flags() doesn't working (https://forums.alliedmods.net/showthread.php?t=298756)

EFFx 06-21-2017 20:36

read_flags() doesn't working
 
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.

CrazY. 06-21-2017 20:44

Re: set_user_flags() doesn't working
 
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

EFFx 06-21-2017 20:52

Re: set_user_flags() doesn't working
 
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

CrazY. 06-21-2017 21:01

Re: read_flags() doesn't working
 
https://forums.alliedmods.net/showthread.php?t=286057

fysiks 06-21-2017 21:03

Re: read_flags() doesn't working
 
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 (Post 1592283)
Code:

set_user_flags(id,flags);
:arrow:
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.

EFFx 06-21-2017 21:12

Re: read_flags() doesn't working
 
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.

fysiks 06-21-2017 21:32

Re: read_flags() doesn't working
 
Quote:

Originally Posted by EFFx (Post 2530560)
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 (Post 2530560)
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 (Post 2530560)
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.

EFFx 06-21-2017 21:46

Re: read_flags() doesn't working
 
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]

fysiks 06-21-2017 21:51

Re: read_flags() doesn't working
 
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.

EFFx 06-21-2017 21:53

Re: read_flags() doesn't working
 
I used %d too.


All times are GMT -4. The time now is 23:10.

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