Raised This Month: $51 Target: $400
 12% 

[REQ] Small ADMIN_LEVEL help


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Versus1994
Senior Member
Join Date: Jan 2013
Old 01-20-2018 , 08:19   [REQ] Small ADMIN_LEVEL help
Reply With Quote #1

Hi guys,

I'm having trouble adding a ADMIN_LEVEL requirement for a command to remove a prefix on plugin: https://forums.alliedmods.net/showthread.php?t=183491

So basicaly what I need is so that only people with ADMIN_BAN level could take off their prefixes by writting /prefix.
And if there is no ADMIN_BAN level - the prefix stays on and there is text "You don't have ..".

Here is the code of the plugin:

PHP Code:
#include <amxmodx>
#include <amxmisc>
#include <celltrie>
#include <cstrike>

#define VERSION "4.0"
#define FLAG_LOAD ADMIN_CFG
#define MAX_PREFIXES 33
#define MAX_BAD_PREFIXES 100

new g_bad_prefixg_listeng_listen_flagg_customg_custom_flagg_say_charactersg_prefix_characters;
new 
pre_ips_count 0pre_names_count 0pre_steamids_countpre_flags_count 0bad_prefix_count 0itemp_cvar[2];
new 
configs_dir[64], file_prefixes[128], file_bad_prefixes[128], text[128], prefix[32], type[2], key[32], lengthline 0error[256];
new 
g_saytxtg_maxplayersCsTeams:g_team;
new 
g_typed[192], g_message[192], g_name[32];
new 
Trie:pre_ips_collectTrie:pre_names_collectTrie:pre_steamids_collectTrie:pre_flags_collectTrie:bad_prefixes_collectTrie:client_prefix;
new 
str_id[16], temp_key[35], temp_prefix[32], temp_value;
new 
bool:g_toggle[33];

new const 
say_team_info[2][CsTeams][] =
{
    {
"*SPEC* ""*DEAD* ""*DEAD* ""*SPEC* "},
    {
""""""""}
}

new const 
sayteam_team_info[2][CsTeams][] =
{
    {
"(Spectator) ""*DEAD*(Terrorist) ""*DEAD*(Counter-Terrorist) ""(Spectator) "},
    {
"(Spectator) ""(Terrorist) ""(Counter-Terrorist) ""(Spectator) "}
}

new const 
forbidden_say_symbols[] = {
    
"/",
    
"!",
    
"%",
    
"$"
}

new const 
forbidden_prefixes_symbols[] = {
    
"/",
    
"\",
    "
%",
    "
$",
    "
.",
    "
:",
    "
?",
    "
!",
    "
@",
    "
#",
    
"%"
}

new const 
separator[] = "************************************************"
new const in_prefix[] = "[AdminPrefixes]"

public plugin_init()
{
    
register_plugin("Admin Prefixes"VERSION"m0skVi4a ;]")

    
g_bad_prefix register_cvar("ap_bad_prefixes""1")
    
g_listen register_cvar("ap_listen""1")
    
g_listen_flag register_cvar("ap_listen_flag""a")
    
g_custom register_cvar("ap_custom_current""1")
    
g_custom_flag register_cvar("ap_custom_current_flag""b")
    
g_say_characters register_cvar("ap_say_characters""1")
    
g_prefix_characters register_cvar("ap_prefix_characters""1")

    
g_saytxt get_user_msgid ("SayText")
    
g_maxplayers get_maxplayers()

    
register_concmd("ap_reload_prefixes""LoadPrefixes")
    
register_concmd("ap_reload_badprefixes""LoadBadPrefixes")
    
register_concmd("ap_put""SetPlayerPrefix")
    
register_clcmd("say""HookSay")
    
register_clcmd("say_team""HookSayTeam")

    
pre_ips_collect TrieCreate()
    
pre_names_collect TrieCreate()
    
pre_steamids_collect TrieCreate()
    
pre_flags_collect TrieCreate()
    
bad_prefixes_collect TrieCreate()
    
client_prefix TrieCreate()

    
register_dictionary("admin_prefixes.txt")

    
get_configsdir(configs_dircharsmax(configs_dir))
    
formatex(file_prefixescharsmax(file_prefixes), "%s/ap_prefixes.ini"configs_dir)
    
formatex(file_bad_prefixescharsmax(file_bad_prefixes), "%s/ap_bad_prefixes.ini"configs_dir)

    
LoadPrefixes(0)
    
LoadBadPrefixes(0)
}
    
public 
LoadPrefixes(id)
{
    if(!(
get_user_flags(id) & FLAG_LOAD))
    {
        
console_print(id"%L"LANG_SERVER"PREFIX_PERMISSION"in_prefix)
        return 
PLUGIN_HANDLED
    
}

    
TrieClear(pre_ips_collect)
    
TrieClear(pre_names_collect)
    
TrieClear(pre_steamids_collect)
    
TrieClear(pre_flags_collect)

    
line 0length 0pre_flags_count 0pre_ips_count 0pre_names_count 0;

    if(!
file_exists(file_prefixes)) 
    {
        
formatex(errorcharsmax(error), "%L"LANG_SERVER"PREFIX_NOT_FOUND"in_prefixfile_prefixes)
        
set_fail_state(error)
    }

    
server_print(separator)

    while(
read_file(file_prefixesline++ , textcharsmax(text), length) && (pre_ips_count pre_names_count pre_steamids_count pre_flags_count) <= MAX_PREFIXES)
    {
        if(!
text[0] || text[0] == '^n' || text[0] == ';' || (text[0] == '/' && text[1] == '/'))
            continue

        
parse(texttypecharsmax(type), keycharsmax(key), prefixcharsmax(prefix))
        
trim(prefix)

        if(!
type[0] || !prefix[0] || !key[0])
            continue

        
replace_all(prefixcharsmax(prefix), "!g""^x04")
        
replace_all(prefixcharsmax(prefix), "!t""^x03")
        
replace_all(prefixcharsmax(prefix), "!n""^x01")

        switch(
type[0])
        {
            case 
'f':
            {
                
pre_flags_count++
                
TrieSetString(pre_flags_collectkeyprefix)
                
server_print("%L"LANG_SERVER"PREFIX_LOAD_FLAG"in_prefixprefixkey[0])
            }
            case 
'i':
            {
                
pre_ips_count++
                
TrieSetString(pre_ips_collectkeyprefix)
                
server_print("%L"LANG_SERVER"PREFIX_LOAD_IP"in_prefixprefixkey)
            }
            case 
's':
            {
                
pre_steamids_count++
                
TrieSetString(pre_steamids_collectkeyprefix)
                
server_print("%L"LANG_SERVER"PREFIX_LOAD_STEAMID"in_prefixprefixkey)
            }
            case 
'n':
            {
                
pre_names_count++
                
TrieSetString(pre_names_collectkeyprefix)
                
server_print("%L"LANG_SERVER"PREFIX_LOAD_NAME"in_prefixprefixkey)
            }
            default:
            {
                continue
            }
        }
    }

    if(
pre_flags_count <= && pre_ips_count <= && pre_steamids_count <= && pre_names_count <= 0)
    {
        
server_print("%L"LANG_SERVER"PREFIX_NO"in_prefix)
    }

    
get_user_name(idg_namecharsmax(g_name))
    
server_print("%L"LANG_SERVER"PREFIX_LOADED_BY"in_prefixg_name)
    
console_print(id"%L"LANG_SERVER"PREFIX_LOADED"in_prefix)

    
server_print(separator)

    for(new 
1<= g_maxplayersi++)
    {
        
num_to_str(istr_idcharsmax(str_id))
        
TrieDeleteKey(client_prefixstr_id)
        
PutPrefix(i)
    }

    return 
PLUGIN_HANDLED
}

public 
LoadBadPrefixes(id)
{
    if(!
get_pcvar_num(g_bad_prefix))
    {
        
console_print(id"%L"LANG_SERVER"BADP_OFF"in_prefix)
        return 
PLUGIN_HANDLED
    
}

    if(!(
get_user_flags(id) & FLAG_LOAD))
    {
        
console_print(id"%L"LANG_SERVER"BADP_PERMISSION"in_prefix)
        return 
PLUGIN_HANDLED
    
}

    
TrieClear(bad_prefixes_collect)

    
line 0length 0bad_prefix_count 0;

    if(!
file_exists(file_bad_prefixes)) 
    {
        
console_print(id"%L"LANG_SERVER"BADP_NOT_FOUND"in_prefixfile_bad_prefixes)
        return 
PLUGIN_HANDLED        
    
}

    
server_print(separator)

    while(
read_file(file_bad_prefixesline++ , textcharsmax(text), length) && bad_prefix_count <= MAX_BAD_PREFIXES)
    {
        if(!
text[0] || text[0] == '^n' || text[0] == ';' || (text[0] == '/' && text[1] == '/'))
            continue

        
parse(textprefixcharsmax(prefix))

        if(!
prefix[0])
            continue

        
bad_prefix_count++
        
TrieSetCell(bad_prefixes_collectprefix1)
        
server_print("%L"LANG_SERVER"BADP_LOAD"in_prefixprefix)
    }

    if(
bad_prefix_count <= 0)
    {
        
server_print("%L"LANG_SERVER"BADP_NO"in_prefix)
    }

    
get_user_name(idg_namecharsmax(g_name))
    
server_print("%L"LANG_SERVER"BADP_LOADED_BY"in_prefixg_name)
    
console_print(id"%L"LANG_SERVER"BADP_LOADED"in_prefix)

    
server_print(separator)

    return 
PLUGIN_HANDLED
}

public 
client_putinserver(id)
{
    
g_toggle[id] = true
    num_to_str
(idstr_idcharsmax(str_id))
    
TrieSetString(client_prefixstr_id"")
    
PutPrefix(id)
}

public 
HookSay(id)
{
    
read_args(g_typedcharsmax(g_typed))
    
remove_quotes(g_typed)

    
trim(g_typed)

    if(
equal(g_typed"") || !is_user_connected(id))
        return 
PLUGIN_HANDLED_MAIN

    
if(equal(g_typed"/prefix"))
    {
        if(
g_toggle[id])
        {
            
g_toggle[id] = false
            client_print
(idprint_chat"%L"LANG_SERVER"PREFIX_OFF"in_prefix)
        }
        else
        {
            
g_toggle[id] = true
            client_print
(idprint_chat"%L"LANG_SERVER"PREFIX_ON"in_prefix)
        }

        return 
PLUGIN_HANDLED_MAIN
    
}

    if(!
g_toggle[id])
        return 
PLUGIN_CONTINUE

    num_to_str
(idstr_idcharsmax(str_id))

    if((
TrieGetString(client_prefixstr_idtemp_prefixcharsmax(temp_prefix)) && get_pcvar_num(g_say_characters) == 1) || (!TrieGetString(client_prefixstr_idtemp_prefixcharsmax(temp_prefix)) && get_pcvar_num(g_say_characters) == 2) || get_pcvar_num(g_say_characters) == 3)
    {
        if(
check_say_characters(g_typed))
            return 
PLUGIN_HANDLED_MAIN
    
}

    
get_user_name(idg_namecharsmax(g_name))

    
g_team cs_get_user_team(id)

    if(
temp_prefix[0])
    {
        
formatex(g_messagecharsmax(g_message), "^1%s^4%s^3 %s :^1 %s"say_team_info[is_user_alive(id)][g_team], temp_prefixg_nameg_typed)
    }
    else
    {
        
formatex(g_messagecharsmax(g_message), "^1%s^3%s :^1 %s"say_team_info[is_user_alive(id)][g_team], g_nameg_typed)
    }

    
get_pcvar_string(g_listen_flagtemp_cvarcharsmax(temp_cvar))

    for(new 
1<= g_maxplayersi++)
    {
        if(!
is_user_connected(i))
            continue

        if(
is_user_alive(id) && is_user_alive(i) || !is_user_alive(id) && !is_user_alive(i) || get_pcvar_num(g_listen) && get_user_flags(i) & read_flags(temp_cvar))
        {
            
send_message(g_messageidi)
        }
    }

    return 
PLUGIN_HANDLED_MAIN
}

public 
HookSayTeam(id)
{
    
read_args(g_typedcharsmax(g_typed))
    
remove_quotes(g_typed)

    
trim(g_typed)

    if(
equal(g_typed"") || !is_user_connected(id))
        return 
PLUGIN_HANDLED_MAIN

    
if(equal(g_typed"/prefix"))
    {
        if(
g_toggle[id])
        {
            
g_toggle[id] = false
            client_print
(idprint_chat"%L"LANG_SERVER"PREFIX_OFF"in_prefix)
        }
        else
        {
            
g_toggle[id] = true
            client_print
(idprint_chat"%L"LANG_SERVER"PREFIX_ON"in_prefix)
        }

        return 
PLUGIN_HANDLED_MAIN
    
}

    if(!
g_toggle[id])
        return 
PLUGIN_CONTINUE

    num_to_str
(idstr_idcharsmax(str_id))

    if((
TrieGetString(client_prefixstr_idtemp_prefixcharsmax(temp_prefix)) && get_pcvar_num(g_say_characters) == 1) || (!TrieGetString(client_prefixstr_idtemp_prefixcharsmax(temp_prefix)) && get_pcvar_num(g_say_characters) == 2) || get_pcvar_num(g_say_characters) == 3)
    {
        if(
check_say_characters(g_typed))
            return 
PLUGIN_HANDLED_MAIN
    
}

    
get_user_name(idg_namecharsmax(g_name))

    
g_team cs_get_user_team(id)

    if(
temp_prefix[0])
    {
        
formatex(g_messagecharsmax(g_message), "^1%s^4%s^3 %s :^1 %s"sayteam_team_info[is_user_alive(id)][g_team], temp_prefixg_nameg_typed)
    }
    else
    {
        
formatex(g_messagecharsmax(g_message), "^1%s^3%s :^1 %s"sayteam_team_info[is_user_alive(id)][g_team], g_nameg_typed)
    }

    
get_pcvar_string(g_listen_flagtemp_cvarcharsmax(temp_cvar))

    for(new 
1<= g_maxplayersi++)
    {
        if(!
is_user_connected(i))
            continue

        if(
get_user_team(id) == get_user_team(i) || get_pcvar_num(g_listen) && get_user_flags(i) & read_flags(temp_cvar))
        {
            if(
is_user_alive(id) && is_user_alive(i) || !is_user_alive(id) && !is_user_alive(i) || get_pcvar_num(g_listen) && get_user_flags(i) & read_flags(temp_cvar))
            {
                
send_message(g_messageidi)
            }
        }
    }

    return 
PLUGIN_HANDLED_MAIN
}

public 
SetPlayerPrefix(id)
{
    if(!
get_pcvar_num(g_custom) || !get_pcvar_string(g_custom_flagtemp_cvarcharsmax(temp_cvar)))
    {
        
console_print(id"%L"LANG_SERVER"CUSTOM_OFF"in_prefix)
        return 
PLUGIN_HANDLED
    
}

    if(!(
get_user_flags(id) & read_flags(temp_cvar)))
    {
        
console_print(id"%L"LANG_SERVER"CUSTOM_PERMISSION"in_prefix)
        return 
PLUGIN_HANDLED
    
}

    new 
input[128], target;
    new 
arg_type[2], arg_prefix[32], arg_key[35];
    new 
temp_str[16];

    
read_args(inputcharsmax(input))
    
remove_quotes(input)
    
parse(inputarg_typecharsmax(arg_type), arg_keycharsmax(arg_key), arg_prefixcharsmax(arg_prefix))
    
trim(arg_prefix)

    if(
get_pcvar_num(g_bad_prefix) && is_bad_prefix(arg_prefix) && !equali(arg_prefix""))
    {
        
console_print(id"%L"LANG_SERVER"CUSTOM_FORBIDDEN"in_prefixarg_prefix)
        return 
PLUGIN_HANDLED
    
}

    if(
get_pcvar_num(g_prefix_characters) && check_prefix_characters(arg_prefix))
    {
        
console_print(id"%L"LANG_SERVER"CUSTOM_SYMBOL"in_prefixarg_prefixforbidden_prefixes_symbols[i])
        return 
PLUGIN_HANDLED
    
}

    switch(
arg_type[0])
    {
        case 
'f':
        {
            
target 0
            temp_str 
"Flag"
        
}
        case 
'i':
        {
            
target find_player("d"arg_key)
            
temp_str "IP"
        
}
        case 
's':
        {
            
target find_player("c"arg_key)
            
temp_str "SteamID"
        
}
        case 
'n':
        {
            
target find_player("a"arg_key)
            
temp_str "Name"
        
}
        default:
        {
            
console_print(id"%L"LANG_SERVER"CUSTOM_INVALID"in_prefixarg_type)
            return 
PLUGIN_HANDLED
        
}
    }

    
get_user_name(idg_namecharsmax(g_name))

    if(
equali(arg_prefix""))
    {
        
find_and_delete(arg_typearg_key)

        if(
target)
        {
            
PutPrefix(target)
        }
        
        
console_print(id"%L"LANG_SERVER"CUSTOM_REMOVE"in_prefixtemp_strarg_key)
        
server_print("%L"LANG_SERVER"CUSTOM_REMOVE_INFO"in_prefixg_nametemp_strarg_key)
        return 
PLUGIN_HANDLED
    
}

    
find_and_delete(arg_typearg_key)

    
formatex(textcharsmax(text), "^"%s^" ^"%s^" ^"%s^""arg_typearg_keyarg_prefix)
    
write_file(file_prefixestext, -1)

    switch(
arg_type[0])
    {
        case 
'f':
        {
            
TrieSetString(pre_flags_collectarg_keyarg_prefix)
        }
        case 
'i':
        {
            
TrieSetString(pre_ips_collectarg_keyarg_prefix)
        }
        case 
's':
        {
            
TrieSetString(pre_steamids_collectarg_keyarg_prefix)
        }
        case 
'n':
        {
            
TrieSetString(pre_names_collectarg_keyarg_prefix)
        }
    }

    if(
target)
    {
        
num_to_str(targetstr_idcharsmax(str_id))
        
TrieSetString(client_prefixstr_idarg_prefix)
    }

    
console_print(id"%L"LANG_SERVER"CUSTOM_CHANGE"in_prefixtemp_strarg_keyarg_prefix)
    
server_print("%L"LANG_SERVER"CUSTOM_CHANGE_INFO"in_prefixg_nametemp_strarg_keyarg_prefix

    return 
PLUGIN_HANDLED
}

public 
client_infochanged(id)
{
    if(!
is_user_connected(id))
        return 
PLUGIN_CONTINUE

    
new g_old_name[32];

    
get_user_info(id"name"g_namecharsmax(g_name))
    
get_user_name(idg_old_namecharsmax(g_old_name))

    if(!
equal(g_nameg_old_name))
    {
        
num_to_str(idstr_idcharsmax(str_id))
        
TrieSetString(client_prefixstr_id"")
        
set_task(0.5"PutPrefix"id)
        return 
PLUGIN_HANDLED
    
}

    return 
PLUGIN_CONTINUE
}

public 
PutPrefix(id)
{
    
num_to_str(idstr_idcharsmax(str_id))
    
TrieSetString(client_prefixstr_id"")

    new 
sflags[32], temp_flag[2];
    
get_flags(get_user_flags(id), sflagscharsmax(sflags))

    for(new 
0<= charsmax(sflags); i++)
    {
        
formatex(temp_flagcharsmax(temp_flag), "%c"sflags[i])

        if(
TrieGetString(pre_flags_collecttemp_flagtemp_prefixcharsmax(temp_prefix)))
        {
            
TrieSetString(client_prefixstr_idtemp_prefix)
        }
    }

    
get_user_ip(idtemp_keycharsmax(temp_key), 1)

    if(
TrieGetString(pre_ips_collecttemp_keytemp_prefixcharsmax(temp_prefix)))
    {
        
TrieSetString(client_prefixstr_idtemp_prefix)
    }

    
get_user_authid(idtemp_keycharsmax(temp_key))

    if(
TrieGetString(pre_steamids_collecttemp_keytemp_prefixcharsmax(temp_prefix)))
    {
        
TrieSetString(client_prefixstr_idtemp_prefix)
    }

    
get_user_name(idtemp_keycharsmax(temp_key))

    if(
TrieGetString(pre_names_collecttemp_keytemp_prefixcharsmax(temp_prefix)))
    {
        
TrieSetString(client_prefixstr_idtemp_prefix)
    }

    return 
PLUGIN_HANDLED
}

send_message(const message[], const id, const i)
{
    
message_begin(MSG_ONEg_saytxt, {000}, i)
    
write_byte(id)
    
write_string(message)
    
message_end()
}

bool:check_say_characters(const check_message[])
{
    for(new 
0charsmax(forbidden_say_symbols); i++)
    {
        if(
check_message[0] == forbidden_say_symbols[i])
        {
            return 
true
        
}
    }
    return 
false
}

bool:check_prefix_characters(const check_prefix[])
{
    for(
0charsmax(forbidden_prefixes_symbols); i++)
    {
        if(
containi(check_prefixforbidden_prefixes_symbols[i]) != -1)
        {
            return 
true
        
}
    }
    return 
false
}

bool:is_bad_prefix(const check_prefix[])
{
    if(
TrieGetCell(bad_prefixes_collectcheck_prefixtemp_value))
    {
        return 
true
    
}
    return 
false
}

find_and_delete(const arg_type[], const arg_key[])
{
    
line 0length 0;

    while(
read_file(file_prefixesline++ , textcharsmax(text), length))
    {
        if(!
text[0] || text[0] == '^n' || text[0] == ';' || (text[0] == '/' && text[1] == '/'))
            continue

        
parse(texttypecharsmax(type), keycharsmax(key), prefixcharsmax(prefix))
        
trim(prefix)

        if(!
type[0] || !prefix[0] || !key[0])
            continue
            
        if(!
equal(arg_typetype) || !equal(arg_keykey))
            continue
            
        
write_file(file_prefixes""line 1)
    }
    
    switch(
arg_type[0])
    {
        case 
'f':
        {
            
TrieDeleteKey(pre_flags_collectarg_key)
        }
        case 
'i':
        {
            
TrieDeleteKey(pre_ips_collectarg_key)
        }
        case 
's':
        {
            
TrieDeleteKey(pre_steamids_collectarg_key)
        }
        case 
'n':
        {
            
TrieDeleteKey(pre_names_collectarg_key)
        }
    }

Would be awesome if someone could help.

Last edited by Versus1994; 01-20-2018 at 08:20.
Versus1994 is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 01-20-2018 , 11:09   Re: [REQ] Small ADMIN_LEVEL help
Reply With Quote #2

PHP Code:
register_clcmd"remprefix" "RemovePrefix" ADMIN_BAN "Removes a players prefix" );

public 
RemovePrefixid level cid )
{
    if ( !
cmd_accessid level cid ) )
    {
        
client_printid print_console "You do not have access" );
        return 
PLUGIN_HANDLED;
    }
    
    
client_printid print_console "You have access" );
    
    return 
PLUGIN_HANDLED;

__________________

Last edited by Bugsy; 01-20-2018 at 11:10.
Bugsy is offline
Versus1994
Senior Member
Join Date: Jan 2013
Old 01-20-2018 , 11:26   Re: [REQ] Small ADMIN_LEVEL help
Reply With Quote #3

Quote:
Originally Posted by Bugsy View Post
PHP Code:
register_clcmd"remprefix" "RemovePrefix" ADMIN_BAN "Removes a players prefix" );

public 
RemovePrefixid level cid )
{
    if ( !
cmd_accessid level cid ) )
    {
        
client_printid print_console "You do not have access" );
        return 
PLUGIN_HANDLED;
    }
    
    
client_printid print_console "You have access" );
    
    return 
PLUGIN_HANDLED;

Sorry, I did not understand how to add this into the code.

Would this work?

PHP Code:
public HookSay(id)
{
    
read_args(g_typedcharsmax(g_typed))
    
remove_quotes(g_typed)

    
trim(g_typed)

    if(
equal(g_typed"") || !is_user_connected(id))
        return 
PLUGIN_HANDLED_MAIN

    
if(equal(g_typed"/prefix") || & IMMUNE_FLAG)
    {
        if(
g_toggle[id])
        {
            
g_toggle[id] = false
            client_print
(idprint_chat"%L"LANG_SERVER"PREFIX_OFF"in_prefix)
        }
        else
        {
            
g_toggle[id] = true
            client_print
(idprint_chat"%L"LANG_SERVER"PREFIX_ON"in_prefix)
        }

        return 
PLUGIN_HANDLED_MAIN
    

I added define to the IMMUNE_FLAG.
Versus1994 is offline
Versus1994
Senior Member
Join Date: Jan 2013
Old 01-20-2018 , 11:30   Re: [REQ] Small ADMIN_LEVEL help
Reply With Quote #4

Or:

PHP Code:
if(equal(g_typed"/prefix") || !(get_user_flags(id) & IMMUNE_FLAG

Last edited by Versus1994; 01-20-2018 at 11:30.
Versus1994 is offline
Old 01-20-2018, 12:22
OciXCrom
This message has been deleted by OciXCrom.
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 01-20-2018 , 12:59   Re: [REQ] Small ADMIN_LEVEL help
Reply With Quote #5

You could also do the below but I think it is cleaner to define the access flag when defining the command in register_clcmd() as shown above.
PHP Code:
if ( !( get_user_flagsid ) & ADMIN_BAN ) )
{
     
//No access

__________________

Last edited by Bugsy; 01-20-2018 at 13:00.
Bugsy is offline
Versus1994
Senior Member
Join Date: Jan 2013
Old 01-20-2018 , 13:33   Re: [REQ] Small ADMIN_LEVEL help
Reply With Quote #6

Made it like this:
PHP Code:
public HookSay(id)
{
    
read_args(g_typedcharsmax(g_typed))
    
remove_quotes(g_typed)

    
trim(g_typed)

    if(
equal(g_typed"") || !is_user_connected(id))
        return 
PLUGIN_HANDLED_MAIN

    
if(equal(g_typed"/prefix") || !( get_user_flagsid ) & ADMIN_BAN ))
    {
        if(
g_toggle[id])
        {
            
g_toggle[id] = false
            client_print
(idprint_chat"%L"LANG_SERVER"PREFIX_OFF"in_prefix)
        }
        else
        {
            
g_toggle[id] = true
            client_print
(idprint_chat"%L"LANG_SERVER"PREFIX_ON"in_prefix)
        }
        return 
PLUGIN_HANDLED_MAIN
    
}
    else
    {
    
client_printid print_chat "You do not have access." ); 
    } 
Compiles but if you don't have the ADMIN_BAN flag anything you write in chat shows only the message off:

PHP Code:
client_print(idprint_chat"%L"LANG_SERVER"PREFIX_OFF"in_prefix
If you have the flag the /prefix command works but you also get the message:
PHP Code:
client_printid print_chat "You do not have access." ); 
On every text written in chat.
Versus1994 is offline
Versus1994
Senior Member
Join Date: Jan 2013
Old 01-22-2018 , 07:56   Re: [REQ] Small ADMIN_LEVEL help
Reply With Quote #7

Any ideas?
Versus1994 is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 01-22-2018 , 17:38   Re: [REQ] Small ADMIN_LEVEL help
Reply With Quote #8

You need to enforce that they HAVE the flag. Your code requires they do not have it to reach that code.

Change
PHP Code:
//if g_typed equals '/prefix' OR user does not have ban flag
if(equal(g_typed"/prefix") || !( get_user_flagsid ) & ADMIN_BAN )) 
to
PHP Code:
//if g_typed equals '/prefix' AND user has ban flag
if(equal(g_typed"/prefix") && ( get_user_flagsid ) & ADMIN_BAN ) ) 
__________________

Last edited by Bugsy; 01-22-2018 at 17:40.
Bugsy is offline
Versus1994
Senior Member
Join Date: Jan 2013
Old 01-22-2018 , 18:53   Re: [REQ] Small ADMIN_LEVEL help
Reply With Quote #9

Thank you!

But still when you write anything else than "/prefix" with ADMIN_BAN it prints:

PHP Code:
client_printid print_chat "You do not have access." ); 
How could I fix it?
Versus1994 is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 01-22-2018 , 19:24   Re: [REQ] Small ADMIN_LEVEL help
Reply With Quote #10

Quote:
Originally Posted by Versus1994 View Post
Thank you!

But still when you write anything else than "/prefix" with ADMIN_BAN it prints:

PHP Code:
client_printid print_chat "You do not have access." ); 
How could I fix it?
You need to separate the "/prefix" check and permission check.
PHP Code:
public HookSay(id

    
read_argsg_typed charsmaxg_typed ) ) 
    
    
remove_quotes(g_typed
    
    
trimg_typed 

    if ( !
g_typed] ) 
        return 
PLUGIN_HANDLED;
    
    if ( 
equalg_typed "/prefix" ) )
    {
        if ( 
get_user_flagsid ) & ADMIN_BAN 
        { 
            
client_print(idprint_chat"%L"LANG_SERVERg_toggle[id] ? "PREFIX_OFF" "PREFIX_ON" in_prefix
            
g_toggle[id] = !g_toggle[id];
        } 
        else 
        { 
            
client_printid print_chat "You do not have access." );  
        }  
    }
    
    return 
PLUGIN_HANDLED;

__________________

Last edited by Bugsy; 01-22-2018 at 21:53.
Bugsy 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 09:22.


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