AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Toggle ON/OFF (https://forums.alliedmods.net/showthread.php?t=203798)

Martz456 12-23-2012 12:27

Toggle ON/OFF
 
Is there a way to toggle a plugin flag?
I want it to be like this
ON = flag B and when I switch it to OFF = flag H
So if a user has flags "bcefjim" and doesn't have flag "H" that means he has no access to a specific thing in a menu or a command, unless I toggle it ON so it switches to flag "B", so he could access it.

Sorry if not understandable

Sylwester 12-23-2012 13:02

Re: Toggle ON/OFF
 
there are many ways to do it
PHP Code:

new g_access ADMIN_CFG

public toggle(){
    if(
g_access == ADMIN_CFG)
        
g_access ADMIN_RESERVATION
    
else
        
g_access ADMIN_CFG
}

public function(
id){
    if(! (
get_user_flags(id) & g_access))
        return  



Martz456 12-23-2012 14:12

Re: Toggle ON/OFF
 
So if I wanted to add a third item to my menu "Fun mode: ON/OFF" that switches Gravity and Invisibility required flags. ON = Immunity flag "a" and OFF = Super Admin flag "x"

It's definitely messed up, cause I don't know how to use that thing you gave me :/

PHP Code:

#include <amxmodx>  
#include <amxmisc>  
#include <fun>
#include <hamsandwich>  

#define SUPER_ADMIN_FLAG (1<<23) // flag "x"

new bool:Invisibility[32];  
new 
bool:Gravity[32];
new 
bool:Funmode[32]; 
new 
g_access SUPER_ADMIN_FLAG

public plugin_init()  
{  
    
RegisterHam(Ham_Spawn"player""Player_Spawn"1);
    
register_clcmd"say /fun","Fun_Menu");  
}  

public 
Fun_Menu(id)  
{  
    new 
menu menu_create("Fun Menu""menu_handler");  
    new 
szTemp[500];  
    
formatex(szTempcharsmax(szTemp), "Invisibility: \r[%s]"Invisibility[id] ? "ON" "OFF"); 
    
menu_additem(menuszTemp"1"ADMIN_IMMUNITY); 
    
formatex(szTempcharsmax(szTemp), "Gravity: \r[%s]"Gravity[id] ? "ON" "OFF");
    
menu_additem(menuszTemp"2"ADMIN_IMMUNITY);
    
formatex(szTempcharsmax(szTemp), "FUN Mode: \r[%s]"Funmode[id] ? "ON" "OFF");
    
menu_additem(menuszTemp"3"SUPER_ADMIN_FLAG);     
    
menu_setprop(menuMPROP_EXITMEXIT_ALL);  
      
    
menu_display(idmenu0);  
    return  
}  
public 
menu_handler(idmenuitem)  
{  
    if( 
item == MENU_EXIT )  
    {  
        
menu_destroy(menu);  
        return 
PLUGIN_HANDLED;  
    }  
    new 
data[6], szName[64];  
    new 
accesscallback;  
    
menu_item_getinfo(menuitemaccessdata,charsmax(data), szName,charsmax(szName), callback);  
     
    new 
key str_to_num(data); 
    switch(
key)     
    { 
    case 
1
    { 
    
set_user_renderingidkRenderFxGlowShell000kRenderTransAlphaInvisibility[id] ? 255:0);  
    
set_hudmessage(025500.030.2400.00.04.010.0,1)  
    
show_hudmessage(id,"Invisibility is %s",Invisibility[id] ? "OFF":"ON")  
    
Invisibility[id] = !Invisibility[id];  
    
Fun_Menu(id)  
    return 
PLUGIN_HANDLED;  
    } 
    case 
2
    { 
    
set_user_gravityidGravity[id] ? 1.0:0.2); 
    
set_hudmessage(025500.030.2400.00.04.010.0,1
    
show_hudmessage(id,"Gravity is %s",Gravity[id] ? "OFF":"ON"
    
Gravity[id] = !Gravity[id]; 
    
Fun_Menu(id
    return 
PLUGIN_HANDLED 
    

    case 
3:
    {
    
// I do not know what to put here :S
    
Funmode[id] = !Funmode[id];
    
Fun_Menu(id)
    return 
PLUGIN_HANDLED
    
}
    } 
    
    
    return 
PLUGIN_HANDLED;
}  

public 
client_connect(id)
{
    
Invisibility[id] = false;
    
set_user_renderingidkRenderFxGlowShell000kRenderTransAlpha255);  
    
Gravity[id] = false;
    
set_user_gravityid1.0); 
}

public 
Player_Spawn(id)
{
    if(
Gravity[id])
    {
        
set_user_gravity(id0.2);
    }
    if(
Invisibility[id])
    {
        
set_user_renderingidkRenderFxGlowShell000kRenderTransAlpha0);  
    }



Sylwester 12-23-2012 15:24

Re: Toggle ON/OFF
 
I never used new menu system. Example using old menu system:
PHP Code:

#include <amxmodx>
new bool:g_fun_mode

public plugin_init(){    
    
register_menucmd(register_menuid("\yFun Menu"), 1023"menu_handler")
    
register_clcmd("say /fun","Fun_Menu")
}

public 
Fun_Menu(id){
    new 
flags get_user_flags(id)
    new 
has_access =  flags & (g_fun_mode?ADMIN_IMMUNITY:SUPER_ADMIN_FLAG)
    new 
super_admin flags SUPER_ADMIN_FLAG
    
    
new poscache[512], keys = (1<<9)
    if(
super_admin)
        
keys |= 1<<2
    
if(has_access)
        
keys |= (1<<0)|(1<<1)
        
    
pos += formatex(cache[pos], sizeof(cache)-1-pos"\yFun Menu^n")
    
pos += formatex(cache[pos], sizeof(cache)-1-pos"%s1. Option 1^n"has_access?"\w":"\d")
    
pos += formatex(cache[pos], sizeof(cache)-1-pos"%s2. Option 2^n"has_access?"\w":"\d")
    
pos += formatex(cache[pos], sizeof(cache)-1-pos"%s3. Fun Mode [ %s%s ]^n"super_admin?"\w":"\d"g_fun_mode?"\yON":"\rOFF"super_admin?"\w":"\d")
    
pos += formatex(cache[pos], sizeof(cache)-1-pos"^n\w0. Exit")
    
show_menu(idkeyscache, -1)
}

public 
menu_handler(idkeys){
    new 
flags get_user_flags(id)
    new 
has_access =  flags & (g_fun_mode?ADMIN_IMMUNITY:SUPER_ADMIN_FLAG)
    new 
super_admin flags SUPER_ADMIN_FLAG
    
    
switch(keys){
        case 
0: {
            if(
has_access){
                
client_print(idprint_chat"Selected option 1")
            }
        }
        case 
1: {        
            if(
has_access){
                
client_print(idprint_chat"Selected option 2")
            }
        }
        case 
2: {
            if(
super_admin){
                
g_fun_mode = !g_fun_mode
            
}
        }
        default: return
    }
    
Fun_Menu(id)



Martz456 12-23-2012 15:40

Re: Toggle ON/OFF
 
damn, I don't know how to use the old one :S

fysiks 12-23-2012 20:46

Re: Toggle ON/OFF
 
  1. Funmode should not be an array: "new bool:Funmode = false;" (Change all references to it accordingly).
  2. Change "ADMIN_IMMUNITY" to "Funmode ? ADMIN_IMMUNITY : SUPER_ADMIN_FLAG"
  3. Done.

Martz456 12-24-2012 05:28

Re: Toggle ON/OFF
 
Quote:

Originally Posted by fysiks (Post 1859359)
  1. Funmode should not be an array: "new bool:Funmode = false;" (Change all references to it accordingly).
  2. Change "ADMIN_IMMUNITY" to "Funmode ? ADMIN_IMMUNITY : SUPER_ADMIN_FLAG"
  3. Done.

Thank you a lot!


All times are GMT -4. The time now is 13:41.

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