AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Is it possible fail state ? (https://forums.alliedmods.net/showthread.php?t=276719)

Awesome_man 12-27-2015 01:48

Is it possible fail state ?
 
Is it possible that if certain steamid is not an admins or say removed from user.ini then the plugin should not work

i mean if particular steamid is not an admins or not in user.ini the plugin should disabled and should not work

wickedd 12-27-2015 03:24

Re: Is it possible fail state ?
 
Why?

addons_zz 12-27-2015 04:08

Re: Is it possible fail state ?
 
Quote:

Originally Posted by Awesome_man (Post 2376721)
Is it possible that if certain steamid is not an admins or say removed from user.ini then the plugin should not work

i mean if particular steamid is not an admins or not in user.ini the plugin should disabled and should not work

Sure. Just detect the user and pause(...) the plugin using the flag:
Quote:

Originally Posted by https://www.amxmodx.org/api/amxmodx/pause
"d" - stop plugin, making it unavailable to unpause


siriusmd99 12-27-2015 04:39

Re: Is it possible fail state ?
 
PHP Code:


#include <amxmodx>
#include <amxmisc>
  
#define PLUGIN "My Plugin"
#define VERSION "1.0"
#define AUTHOR "siriudmd99"

#define STEAMID "your steamid"
#define FLAGS "abcdefghijklmnopqrstu"
  

public plugin_init() {

    
register_plugin(PLUGINVERSIONAUTHOR)
          
    if(!
is_auth_admin)                   
                 
set_fail_state("[%s] You're not allowed to use this plugin!"PLUGIN)

}

bool:is_auth_admin(){
    
    static 
u_Flagsu_Countu_Acces
    u_Count
=admins_num()
      
    for (new 
0u_Count; ++i)
    {
        
u_Flags=admins_lookup(i,AdminProp_Flags);
u_Access=admins_lookup(i,AdminProp_Access);
admins_lookup(i,AdminProp_Auth,AuthData,charsmax(AuthData));

        if (
u_Flags FLAG_AUTHID) && (equal(STEAMAuthData)) && (equal(FLAGS,u_Access)) return true;
            
    }

return 
false;



Instead of "your steamid" put steam which you would like to check.
Edit: if you want to stop other plugins then use server_cmd("amx_pausecfg stop plugin_name.amxx") instead of set fail state.

Awesome_man 12-27-2015 04:39

Re: Is it possible fail state ?
 
Quote:

Originally Posted by addons_zz (Post 2376745)
Sure. Just detect the user and pause(...) the plugin using the flag:

can you show post an example code ?

Awesome_man 12-27-2015 04:49

Re: Is it possible fail state ?
 
Quote:

Originally Posted by siriusmd99 (Post 2376756)
PHP Code:


#include <amxmodx>
#include <amxmisc>
  
#define PLUGIN "My Plugin"
#define VERSION "1.0"
#define AUTHOR "siriudmd99"

#define STEAMID "your steamid"
#define FLAGS "abcdefghijklmnopqrstu"
  

public plugin_init() {

    
register_plugin(PLUGINVERSIONAUTHOR)
          
    if(!
is_auth_admin)                   
                 
set_fail_state("[%s] You're not allowed to use this plugin!"PLUGIN)

}

bool:is_auth_admin(){
    
    static 
u_Flagsu_Countu_Acces
    u_Count
=admins_num()
      
    for (new 
0u_Count; ++i)
    {
        
u_Flags=admins_lookup(i,AdminProp_Flags);
u_Access=admins_lookup(i,AdminProp_Access);
admins_lookup(i,AdminProp_Auth,AuthData,charsmax(AuthData));

        if (
u_Flags FLAG_AUTHID) && (equal(STEAMAuthData)) && (equal(FLAGS,u_Access)) return true;
            
    }

return 
false;



Instead of "your steamid" put steam which you would like to check.
Edit: if you want to stop other plugins then use server_cmd("amx_pausecfg stop plugin_name.amxx") instead of set fail state.

Suppose there is a plugin named "abc.amxx" "ghj.amxx" how can dey be paused if particular steamid not an admin in user.ini file ?

siriusmd99 12-27-2015 04:56

Re: Is it possible fail state ?
 
I said you. Just put your steamid in define at the top of the plugin and replace set fail state with the stop command above .

addons_zz 12-27-2015 06:05

Re: Is it possible fail state ?
 
Try this:

Code:
/** AMX Mod X Script  *  *  This program is free software; you can redistribute it and/or modify it  *  under the terms of the GNU General Public License as published by the  *  Free Software Foundation; either version 2 of the License, or ( at  *  your option ) any later version.  *  *  This program is distributed in the hope that it will be useful, but  *  WITHOUT ANY WARRANTY; without even the implied warranty of  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  *  See the GNU General Public License for more details.  *  *  You should have received a copy of the GNU General Public License  *  along with this program.  If not, see <http://www.gnu.org/licenses/>.  *  * ***********************************************************    */ #include <amxmodx> #include <amxmisc> new Trie:g_black_list /*  * Called just after server activation.  */ public plugin_init() {     register_plugin( "Cool Plugin", "1.0", "Addons zz" )         g_black_list = TrieCreate()         TrieSetCell( g_black_list, "STEAM_0:1:xxxxxxxx", 1 )     TrieSetCell( g_black_list, "STEAM_0:1:xxxxxxxx", 1 )     TrieSetCell( g_black_list, "STEAM_0:1:xxxxxxxx", 1 )     TrieSetCell( g_black_list, "STEAM_0:1:xxxxxxxx", 1 )     TrieSetCell( g_black_list, "STEAM_0:1:xxxxxxxx", 1 )     TrieSetCell( g_black_list, "STEAM_0:1:xxxxxxxx", 1 )     TrieSetCell( g_black_list, "STEAM_0:1:xxxxxxxx", 1 ) } /*  * Called when all plugins went through plugin_init()  */ public plugin_cfg() {     new string_steam_ID[ 32 ]         copy( string_steam_ID, charsmax( string_steam_ID ), "STEAM_0:1:xxxxxxxx" )         if( TrieKeyExists( g_black_list, string_steam_ID ) )     {         pause( "d", "my_bad_pluing.amxx" );         pause( "d", "my_more_bad_pluing.amxx" );     } } /*  * Called just before server deactivation and subsequent unloading of the  * plugin.  */ public plugin_end() {     TrieDestroy( g_black_list ) }

Here is a function from the default plugin AMXX "admin.sma" to load admins from "users.ini":
Code:
loadSettings(szFilename[]) {     new File=fopen(szFilename,"r");         if (File)     {         new Text[512];         new Flags[32];         new Access[32]         new AuthData[44];         new Password[32];                 while (!feof(File))         {             fgets(File,Text,sizeof(Text)-1);                         trim(Text);                         // comment             if (Text[0]==';')             {                 continue;             }                         Flags[0]=0;             Access[0]=0;             AuthData[0]=0;             Password[0]=0;                         // not enough parameters             if (parse(Text,AuthData,sizeof(AuthData)-1,Password,sizeof(Password)-1,Access,sizeof(Access)-1,Flags,sizeof(Flags)-1) < 2)             {                 continue;             }                         admins_push(AuthData,Password,read_flags(Access),read_flags(Flags));             AdminCount++;         }                 fclose(File);     }     if (AdminCount == 1)     {         server_print("[AMXX] %L", LANG_SERVER, "LOADED_ADMIN");     }     else     {         server_print("[AMXX] %L", LANG_SERVER, "LOADED_ADMINS", AdminCount);     }         return 1; }


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

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