Raised This Month: $32 Target: $400
 8% 

A code that disables a plugin for anyone but admins


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
GlobalPlague
Senior Member
Join Date: Feb 2016
Location: Pluto
Old 03-24-2022 , 17:06   A code that disables a plugin for anyone but admins
Reply With Quote #1

Hello. Can someone help me write a code that disables plugins for all players who don't have an admin flag like the following (this is from users.ini):

"Name" "Password" "abcdefghijklmnopqrstu" "a"

I want to be able to use the code for every plugin i want to be disabled.

Here is an example of a code that disables the bonus box plugin during any mode that isn't "Normal Infection". So, can someone edit this code, so it can work for admins, too? I need a similar code that disables the plugin for anyone who isn't admin.

Code:
public zp_round_started(gamemode)
{
    if (gamemode != MODE_INFECTION)
    {
        remove_task(1337)

        new entity
        while ((entity = find_ent_by_class(entity, "info_present")) > 0)
        {
            entity_set_int(entity, EV_INT_flags, FL_KILLME)
            entity_set_int(entity, EV_INT_effects, EF_NODRAW)
            entity_set_int(entity, EV_INT_solid, SOLID_NOT)
        }
    }
}
The plugin i want to be disabled for non-admin players is the following: https://pastebin.com/Vk8pDQ17

This is a nanosuit that is given automatically to all players, regardless of whether or not they are normal players, vips, or admins.

How do i make the nanosuit to be given only to players who are admins?

One more question. Check the above code again. How can i make it to disable the nanosuit during certain game modes? I see the code uses a check to detect which game mode is played, and then says "remove_task(1337)" in order to remove "task 1337", which is the task that spawns the boxes.

The problem is that i can't find the task that gives nanosuits, meaning i can't write such a code to disable the nanosuit plugin during certain game modes. Can you also make a code that disables the nanosuit plugin during certain modes? For example, make a code that disables the nanosuit during Assassin mode.

Last edited by GlobalPlague; 03-24-2022 at 17:15.
GlobalPlague is offline
iceeedr
Veteran Member
Join Date: Apr 2017
Location: Brazil
Old 03-24-2022 , 18:14   Re: A code that disables a plugin for anyone but admins
Reply With Quote #2

Code:
is_user_admin(index)
https://www.amxmodx.org/api/amxmisc/is_user_admin
__________________


Quote:
Originally Posted by fysiks View Post
Please stop trying to help. You appear to just be posting random stuff. Wait until you actually understand more about AMX Mod X and how the game works.
https://iceeedr.com.br/
iceeedr is offline
Send a message via Skype™ to iceeedr
kww
Senior Member
Join Date: Feb 2021
Location: Russia
Old 03-25-2022 , 02:29   Re: A code that disables a plugin for anyone but admins
Reply With Quote #3

or this for certain level:
if(get_user_flags(id) & level) {}

levels:
PHP Code:
#define ADMIN_ALL           0       /* everyone */
#define ADMIN_IMMUNITY      (1<<0)  /* flag "a" */
#define ADMIN_RESERVATION   (1<<1)  /* flag "b" */
#define ADMIN_KICK          (1<<2)  /* flag "c" */
#define ADMIN_BAN           (1<<3)  /* flag "d" */
#define ADMIN_SLAY          (1<<4)  /* flag "e" */
#define ADMIN_MAP           (1<<5)  /* flag "f" */
#define ADMIN_CVAR          (1<<6)  /* flag "g" */
#define ADMIN_CFG           (1<<7)  /* flag "h" */
#define ADMIN_CHAT          (1<<8)  /* flag "i" */
#define ADMIN_VOTE          (1<<9)  /* flag "j" */
#define ADMIN_PASSWORD      (1<<10) /* flag "k" */
#define ADMIN_RCON          (1<<11) /* flag "l" */
#define ADMIN_LEVEL_A       (1<<12) /* flag "m" */
#define ADMIN_LEVEL_B       (1<<13) /* flag "n" */
#define ADMIN_LEVEL_C       (1<<14) /* flag "o" */
#define ADMIN_LEVEL_D       (1<<15) /* flag "p" */
#define ADMIN_LEVEL_E       (1<<16) /* flag "q" */
#define ADMIN_LEVEL_F       (1<<17) /* flag "r" */
#define ADMIN_LEVEL_G       (1<<18) /* flag "s" */
#define ADMIN_LEVEL_H       (1<<19) /* flag "t" */
#define ADMIN_MENU          (1<<20) /* flag "u" */
#define ADMIN_BAN_TEMP      (1<<21) /* flag "v" */
#define ADMIN_ADMIN         (1<<24) /* flag "y" */
#define ADMIN_USER          (1<<25) /* flag "z" */ 
__________________
Now working on: Side Weapons (Very lazy, tbh)
Avatar source: https://bit.ly/3BAk19g
Discord: kww#9951

Last edited by kww; 03-25-2022 at 02:30.
kww is offline
GlobalPlague
Senior Member
Join Date: Feb 2016
Location: Pluto
Old 03-26-2022 , 07:49   Re: A code that disables a plugin for anyone but admins
Reply With Quote #4

Quote:
Originally Posted by kww View Post
or this for certain level:
if(get_user_flags(id) & level) {}

levels:
PHP Code:
#define ADMIN_ALL           0       /* everyone */
#define ADMIN_IMMUNITY      (1<<0)  /* flag "a" */
#define ADMIN_RESERVATION   (1<<1)  /* flag "b" */
#define ADMIN_KICK          (1<<2)  /* flag "c" */
#define ADMIN_BAN           (1<<3)  /* flag "d" */
#define ADMIN_SLAY          (1<<4)  /* flag "e" */
#define ADMIN_MAP           (1<<5)  /* flag "f" */
#define ADMIN_CVAR          (1<<6)  /* flag "g" */
#define ADMIN_CFG           (1<<7)  /* flag "h" */
#define ADMIN_CHAT          (1<<8)  /* flag "i" */
#define ADMIN_VOTE          (1<<9)  /* flag "j" */
#define ADMIN_PASSWORD      (1<<10) /* flag "k" */
#define ADMIN_RCON          (1<<11) /* flag "l" */
#define ADMIN_LEVEL_A       (1<<12) /* flag "m" */
#define ADMIN_LEVEL_B       (1<<13) /* flag "n" */
#define ADMIN_LEVEL_C       (1<<14) /* flag "o" */
#define ADMIN_LEVEL_D       (1<<15) /* flag "p" */
#define ADMIN_LEVEL_E       (1<<16) /* flag "q" */
#define ADMIN_LEVEL_F       (1<<17) /* flag "r" */
#define ADMIN_LEVEL_G       (1<<18) /* flag "s" */
#define ADMIN_LEVEL_H       (1<<19) /* flag "t" */
#define ADMIN_MENU          (1<<20) /* flag "u" */
#define ADMIN_BAN_TEMP      (1<<21) /* flag "v" */
#define ADMIN_ADMIN         (1<<24) /* flag "y" */
#define ADMIN_USER          (1<<25) /* flag "z" */ 
This method doesn't work.

So, here is what i did.

I opened the plugin: https://pastebin.com/Vk8pDQ17

Then, i found this segment of the code:

PHP Code:
public client_connect(id) {
    
    
NanoSuit_Player_HasNano[id] = false;
    
    
client_cmd(id,"cl_sidespeed %f"get_pcvar_float(pcNanoSuit_Speed_Speed))
    
client_cmd(id,"cl_forwardspeed %f",get_pcvar_float(pcNanoSuit_Speed_Speed))
    
client_cmd(id,"cl_backspeed %f",get_pcvar_float(pcNanoSuit_Speed_Speed))
    
    if (
get_pcvar_num(pcNanoSuit_Price) == 0)   
    {
        if (!
is_user_bot(id))
        {
            
NanoSuit_Player_HasNano[id] = true;
            
NanoSuit_Player_Active[id] = 1;
            
NanoSuit_Reset(id);
            
NanoSuit_Player_Energy[id] = get_pcvar_float(pcNanoSuit_Energy);
            
fm_set_user_health(idget_pcvar_num(pcNanoSuit_Health))
        }
        
        if(
is_user_bot(id) && get_pcvar_num(pcNanoSuit_Bot_Allow) == 1)
        {
            
NanoSuit_Player_HasNano[id] = true;
            
NanoSuit_Player_Active[id] = 1;
            
NanoSuit_Reset(id);
            
NanoSuit_Player_Energy[id] = get_pcvar_float(pcNanoSuit_Energy);
            
fm_set_user_health(idget_pcvar_num(pcNanoSuit_Health))
            
remove_task(id TASK_BOT_USE)
            
set_task(60.0,"NanoSuit_Bot_Functions",id TASK_BOT_USE)
        }
    }
    

And, i added this at the bottom of the above code:

PHP Code:
if(get_user_flags(id) != ADMIN_ALL) {}
        return 
So, now it looks like this:

Code:
public client_connect(id) {
    
    NanoSuit_Player_HasNano[id] = false;
    
    client_cmd(id,"cl_sidespeed %f", get_pcvar_float(pcNanoSuit_Speed_Speed))
    client_cmd(id,"cl_forwardspeed %f",get_pcvar_float(pcNanoSuit_Speed_Speed))
    client_cmd(id,"cl_backspeed %f",get_pcvar_float(pcNanoSuit_Speed_Speed))
    
    if (get_pcvar_num(pcNanoSuit_Price) == 0)   
    {
        if (!is_user_bot(id))
        {
            NanoSuit_Player_HasNano[id] = true;
            NanoSuit_Player_Active[id] = 1;
            NanoSuit_Reset(id);
            NanoSuit_Player_Energy[id] = get_pcvar_float(pcNanoSuit_Energy);
            fm_set_user_health(id, get_pcvar_num(pcNanoSuit_Health))
        }
        
        if(is_user_bot(id) && get_pcvar_num(pcNanoSuit_Bot_Allow) == 1)
        {
            NanoSuit_Player_HasNano[id] = true;
            NanoSuit_Player_Active[id] = 1;
            NanoSuit_Reset(id);
            NanoSuit_Player_Energy[id] = get_pcvar_float(pcNanoSuit_Energy);
            fm_set_user_health(id, get_pcvar_num(pcNanoSuit_Health))
            remove_task(id + TASK_BOT_USE)
            set_task(60.0,"NanoSuit_Bot_Functions",id + TASK_BOT_USE)
        }

	if(get_user_flags(id) != ADMIN_ALL) {}
		return
    }
    
}
However, it didn't work. I joined as an admin, and then as a non-admin, and i still had nanosuit, even when i joined as a non-admin.

Would someone give me more details about how to make this plugin to be available only for amins?

Last edited by GlobalPlague; 03-26-2022 at 07:51.
GlobalPlague is offline
Dyaus
Member
Join Date: Aug 2021
Old 03-26-2022 , 12:15   Re: A code that disables a plugin for anyone but admins
Reply With Quote #5

don't use ADMIN_ALL use another flag , also use & not != ( noticed it later)

Last edited by Dyaus; 03-27-2022 at 08:31. Reason: noticed he used != not &
Dyaus is offline
kww
Senior Member
Join Date: Feb 2021
Location: Russia
Old 03-26-2022 , 17:17   Re: A code that disables a plugin for anyone but admins
Reply With Quote #6

Quote:
Originally Posted by GlobalPlague View Post
This method doesn't work.
Should we teach you how to use curly brackets?
If userid have mentioned flag then code in curly brackets will be executed
PHP Code:
/**
 * Returns the client's admin flags as a bitflag sum.
 *
 * @note For a list of possible flags, see the ADMIN_* constants in amxconst.inc
 * @note AMXX stores multiple sets of flags internally, but only flag set
 *       0 is actively used. You should not change the value of the second
 *       parameter from the default.
 *
 * @param index     Client index, 0 to set flags of server
 * @param id        Flag set id, ranging from 0 to 31
 *
 * @return          Bitflag sum of client's admin flags
 * @error           If the index is not within the range of 0 to MaxClients, an
 *                  error will be thrown.
 */
native get_user_flags(indexid 0); 
so you could use this contruction:
PHP Code:
if(!get_user_flags(id) & ADMIN_RCON// put here your requred flag (admin's or vip's flag, whatever u need)
    
return 
or as iceedr suggested before:
PHP Code:
/**
 * Returns if the client has any admin flags set
 *
 * @param id    Client index
 *
 * @return      1 if client has any admin flags, 0 otherwise
 */
stock is_user_admin(id)
{
    new 
__flags get_user_flags(id);
    return (
__flags && !(__flags ADMIN_USER));

It is shorter and basically works as my variant but you can't specify the flag.
If player haven't flag "z" (normal user) and have any other flag set then execute
PHP Code:
if(!is_user_admin(id))
    return 
__________________
Now working on: Side Weapons (Very lazy, tbh)
Avatar source: https://bit.ly/3BAk19g
Discord: kww#9951

Last edited by kww; 03-26-2022 at 17:23.
kww is offline
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:25.


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