AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Solved Set player flags question (https://forums.alliedmods.net/showthread.php?t=335969)

iceeedr 01-17-2022 21:01

Set player flags question
 
I have a problem that is at least annoying, the flags are not being set in the players, tested on windows and linux.

Code:

amxx version
AMX Mod X 1.10.0.5461 (http://www.amxmodx.org)
Authors:
        David "BAILOPAN" Anderson, Pavol "PM OnoTo" Marko
        Felix "SniperBeamer" Geyer, Jonny "Got His Gun" Bergstrom
        Lukasz "SidLuke" Wlasinski, Christian "Basic-Master" Hammacher
        Borja "faluco" Ferrer, Scott "DS" Ehlert
Compiled: Dec  6 2021 17:37:35
Built from: https://github.com/alliedmodders/amxmodx/commit/ec82e3f3
Build ID: 5461:ec82e3f3
Core mode: JIT+ASM32

Code:

version
Protocol version 48
Exe version 1.1.2.7/Stdio (cstrike)
ReHLDS version: 3.10.0.759-dev
Build date: 15:34:13 Jun 22 2021 (2628)
Build from: https://github.com/dreamstalker/rehlds/commit/ad6f6ad

Code:

Currently loaded plugins:
      description  stat pend  file                  vers          src  load  unload
 [ 1] AMX Mod X    RUN  -    amxmodx_mm.dll        v1.10.0.5461  ini  Start ANY
 [ 2] Ham Sandwich  RUN  -    hamsandwich_amxx.dll  v1.10.0.5461  pl1  ANY  ANY
 [ 3] CSX          RUN  -    csx_amxx.dll          v1.10.0.5461  pl1  ANY  ANY
 [ 4] FakeMeta      RUN  -    fakemeta_amxx.dll    v1.10.0.5461  pl1  ANY  ANY
4 plugins, 4 running

Code:

Currently loaded plugins:
      id  name                    version    author            url                              file        status 
 [  1] 0  Admin Base              1.10.0.546  AMXX Dev Team                                      admin.amxx  running 
 [  2] 1  Admin Commands          1.10.0.546  AMXX Dev Team                                      admincmd.am  running 
 [  3] 2  Admin Help              1.10.0.546  AMXX Dev Team                                      adminhelp.a  running 
 [  4] 3  Slots Reservation      1.10.0.546  AMXX Dev Team                                      adminslots.  running 
 [  5] 4  Multi-Lingual System    1.10.0.546  AMXX Dev Team                                      multilingua  running 
 [  6] 5  Menus Front-End        1.10.0.546  AMXX Dev Team                                      menufront.a  running 
 [  7] 6  Commands Menu          1.10.0.546  AMXX Dev Team                                      cmdmenu.amx  running 
 [  8] 7  Players Menu            1.10.0.546  AMXX Dev Team                                      plmenu.amxx  running 
 [  9] 8  Maps Menu              1.10.0.546  AMXX Dev Team                                      mapsmenu.am  running 
 [ 10] 9  Plugin Menu            1.10.0.546  AMXX Dev Team                                      pluginmenu.  running 
 [ 11] 10  Admin Chat              1.10.0.546  AMXX Dev Team                                      adminchat.a  running 
 [ 12] 11  Anti Flood              1.10.0.546  AMXX Dev Team                                      antiflood.a  running 
 [ 13] 12  Scrolling Message      1.10.0.546  AMXX Dev Team                                      scrollmsg.a  running 
 [ 14] 13  Info. Messages          1.10.0.546  AMXX Dev Team                                      imessage.am  running 
 [ 15] 14  Admin Votes            1.10.0.546  AMXX Dev Team                                      adminvote.a  running 
 [ 16] 15  NextMap                1.10.0.546  AMXX Dev Team                                      nextmap.amx  running 
 [ 17] 16  Nextmap Chooser        1.10.0.546  AMXX Dev Team                                      mapchooser.  running 
 [ 18] 17  TimeLeft                1.10.0.546  AMXX Dev Team                                      timeleft.am  running 
 [ 19] 18  Pause Plugins          1.10.0.546  AMXX Dev Team                                      pausecfg.am  running 
 [ 20] 19  Stats Configuration    1.10.0.546  AMXX Dev Team                                      statscfg.am  running 
 [ 21] 20  StatsX                  1.10.0.546  AMXX Dev Team                                      statsx.amxx  paused 
 [ 22] 21  Tag VIP                1.0        iceeedR                                            TagImputer.  running 
22 plugins, 21 running

PHP Code:

#include <amxmodx>
#include <amxmisc>
#include <fakemeta>
#define CC_COLORS_TYPE CC_COLORS_SHORT
#include <cromchat>

#define PLUGIN  "Tag VIP"
#define VERSION "1.0"
#define AUTHOR  "iceeedR"

enum cVars
{
        
VarChatPrefix[MAX_NAME_LENGTH],
        
VarClanPrefix[MAX_NAME_LENGTH],
        
VarFlags[MAX_NAME_LENGTH]
}

new 
gCvars[cVars]
new 
g_szPlayerName[MAX_PLAYERS 1]

public 
plugin_init()
{
        
register_plugin(PLUGINVERSIONAUTHOR)

        
bind_pcvar_string(create_cvar("vip_chatprefix""iceeedR", .description "Prefix do chat."), gCvars[VarChatPrefix], charsmax(gCvars[VarChatPrefix]))
        
bind_pcvar_string(create_cvar("vip_prefix""iceeedR - ", .description "Tag do clan."), gCvars[VarClanPrefix], charsmax(gCvars[VarClanPrefix]))
        
bind_pcvar_string(create_cvar("vip_flags""b", .description "Flags que o VIP recebe."), gCvars[VarFlags], charsmax(gCvars[VarFlags]))

        
AutoExecConfig()

        
register_saycmd("tag""setTag")
}

public 
OnConfigsExecuted()
{
        
CC_SetPrefix(fmt("^4[^3%s^4]^1"gCvars[VarChatPrefix]))
}

public 
setTag(id)
{
        
remove_user_flags(id, -1)

        new 
flags get_user_flags(id), sflags[MAX_NAME_LENGTH]
        
get_flags(flagssflagscharsmax(sflags))
        
log_amx("[1] My flags are now %s"sflags)

        if(
containi(g_szPlayerName[id], gCvars[VarClanPrefix]) != -1)
        {
                
replace(g_szPlayerName[id], charsmax(g_szPlayerName), gCvars[VarClanPrefix], "")
                
set_user_info(id"name"g_szPlayerName[id])
                
set_user_flags(idADMIN_USER)
        }
        else
        {
                new 
szFullName[MAX_NAME_LENGTH]
                
formatex(szFullNamecharsmax(szFullName), "%s %s"gCvars[VarClanPrefix], g_szPlayerName[id])
                
copy(g_szPlayerName[id], charsmax(g_szPlayerName), szFullName)

                
set_user_info(id"name"szFullName)

                
log_amx("[2] Read flags = %i"read_flags(gCvars[VarFlags]))

                
set_user_flags(idread_flags(gCvars[VarFlags]))

                
log_amx("[3] Setting flags = %s"gCvars[VarFlags])
        }

        
get_flags(flagssflagscharsmax(sflags))
        
log_amx("[4] My flags are %s"sflags)

        return 
PLUGIN_HANDLED
}

public 
client_putinserver(id)
{
        
get_user_name(idg_szPlayerName[id], charsmax(g_szPlayerName))

        new 
flags get_user_flags(id), sflags[MAX_NAME_LENGTH]
        
get_flags(flagssflagscharsmax(sflags))

        
log_amx("[0] My entrance flags are %s"sflags)
}

stock register_saycmd(const szSayCmd[], const szFunc[], iFlags = -1, const szInfo[] = ""FlagManager = -1bool:bInfoML false)
{
        new const 
szPrefix[][] = { "say /""say_team /""say .""say_team ." };

        for(new 
iszTemp[32]; sizeof(szPrefix); i++)
        {
                
formatex(szTempcharsmax(szTemp), "%s%s"szPrefix[i], szSayCmd);
                
register_clcmd(szTempszFunciFlagsszInfoFlagManagerbInfoML);
        }


Edit: If I print the cvar "gCvars[VarFlags]" the "b" flag is displayed normally. So the problem doesn't seem to be the "empty" cvar.

Code:

Connection to Steam servers successful.
  VAC secure mode is activated.
L 01/18/2022 - 01:49:13: [TagImputer.amxx] [0] My entrance flags are z
L 01/18/2022 - 01:49:18: [TagImputer.amxx] [1] My flags are now
L 01/18/2022 - 01:49:18: [TagImputer.amxx] [2] Read flags = 2
L 01/18/2022 - 01:49:18: [TagImputer.amxx] [3] Setting flags = b
L 01/18/2022 - 01:49:18: [TagImputer.amxx] [4] My flags are
amx_who

Clients on server:
 #  nick            authid              userid  imm  res  access
 1  teste -  Aposen  STEAM_0:1:56888062  1        No    No    z
Total 1
L 01/18/2022 - 01:49:24: [admincmd.amxx] Cmd: "Counter-Strike 1.6 Server<0><><>" ask for players list


fysiks 01-17-2022 22:07

Re: Set player flags question
 
So, what is the value of read_flags(gCvars[VarFlags])?

iceeedr 01-17-2022 22:26

Re: Set player flags question
 
Quote:

Originally Posted by fysiks (Post 2768690)
So, what is the value of read_flags(gCvars[VarFlags])?

Post updated.

fysiks 01-17-2022 23:21

Re: Set player flags question
 
I don't see in the code where you're printing out the value of read_flags() and it's certainly not where it needs to be to actually help debug your code. It need to be before your print "[2]". Set the read_flags() value to a variable, print it and then use it in set_user_flags().

iceeedr 01-17-2022 23:50

Re: Set player flags question
 
Quote:

Originally Posted by fysiks (Post 2768695)
I don't see in the code where you're printing out the value of read_flags() and it's certainly not where it needs to be to actually help debug your code. It need to be before your print "[2]". Set the read_flags() value to a variable, print it and then use it in set_user_flags().

I just hadn't updated the code in the post, look again. Taking advantage, I updated the log.

Shadows Adi 01-18-2022 08:43

Re: Set player flags question
 
Quote:

Originally Posted by iceeedr (Post 2768685)
I have a problem that is at least annoying, the flags are not being set in the players, tested on windows and linux.

1. After changing the player's name, the admin core plugin reloads his access: https://github.com/alliedmodders/amx....sma#L768-L781

2.
Code:
public setTag(id) {              /* Why do you remove the player's flags? */         remove_user_flags(id, -1)        new flags = get_user_flags(id), sflags[MAX_NAME_LENGTH]         get_flags(flags, sflags, charsmax(sflags))         log_amx("[1] My flags are now %s", sflags)         if(containi(g_szPlayerName[id], gCvars[VarClanPrefix]) != -1)         {                 replace(g_szPlayerName[id], charsmax(g_szPlayerName), gCvars[VarClanPrefix], "")                 set_user_info(id, "name", g_szPlayerName[id])                 set_user_flags(id, ADMIN_USER)         }         else         {                 new szFullName[MAX_NAME_LENGTH]                 formatex(szFullName, charsmax(szFullName), "%s %s", gCvars[VarClanPrefix], g_szPlayerName[id])                 copy(g_szPlayerName[id], charsmax(g_szPlayerName), szFullName)                 set_user_info(id, "name", szFullName)                 log_amx("[2] Read flags = %i", read_flags(gCvars[VarFlags]))                 set_user_flags(id, read_flags(gCvars[VarFlags]))                 log_amx("[3] Setting flags = %s", gCvars[VarFlags])         }         /* You still get the inital value of flags, you need to get them again */         flags = get_user_flags(id)         get_flags(flags, sflags, charsmax(sflags))         log_amx("[4] My flags are %s", sflags)         return PLUGIN_HANDLED }

iceeedr 01-18-2022 09:43

Re: Set player flags question
 
1 - I really didn't think about that case, I set a task and it's working.

2 - set_user_flags just adds the selected flags to the existing ones and I don't want ADMIN_USER so I remove them all before setting, problem solved.

Bugsy 01-18-2022 10:38

Re: Set player flags question
 
Yes, set_user_flags() should be named add_user_flags(), as it's a bit misleading at face value.

fysiks 01-18-2022 22:54

Re: Set player flags question
 
Quote:

Originally Posted by Bugsy (Post 2768736)
Yes, set_user_flags() should be named add_user_flags(), as it's a bit misleading at face value.

Well, kind of but not necessarily. Flags are stored as bits. "Setting bits" is simply OR'ing them and that operation doesn't remove any other bits.

Bugsy 01-19-2022 00:30

Re: Set player flags question
 
Quote:

Originally Posted by fysiks (Post 2768794)
Well, kind of but not necessarily. Flags are stored as bits. "Setting bits" is simply OR'ing them and that operation doesn't remove any other bits.

Agree, it depends on your interpretation of what 'set' means.

"Set the flags I gave you as the players flags"
or
"Set the flags I gave you to true but leave the others as is" (what set_user_flags() does)

I personally think it would have been better to have:
  • set_user_flags() - Clear all existing bits and set only the bits passed
  • add_user_flags() - Keep existing bits and add only the bits passed


All times are GMT -4. The time now is 11:29.

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