Need help for adding flag and popup message to plugin

Тема в разделе "Запросы", создана пользователем BGKoKoOo, 27 мар 2015.

  1. BGKoKoOo

    BGKoKoOo

    Сообщения:
    33
    Симпатии:
    7
    Hello can you explain me how i can make the plugin to work with custom flag and popup message

    For example, players with custom flag T to have acces to the plugin, but players without the flag to not have and when say /admins or !admins to popup message (You dont have acces to the command)

    Код:
    #include <sourcemod>
    #pragma semicolon 1
    
    new Handle:AdminListEnabled = INVALID_HANDLE;
    new Handle:AdminListMode = INVALID_HANDLE;
    new Handle:AdminListMenu = INVALID_HANDLE;
    new Handle:AdminListAdminFlag = INVALID_HANDLE;
    
    #define PLUGIN_VERSION "1.4b"
    
    public Plugin:myinfo = 
    {
    	name = "Admin List",
    	author = "Fredd",
    	description = "prints admins to clients",
    	version = PLUGIN_VERSION,
    	url = "www.sourcemod.net"
    }
    
    public OnPluginStart()
    {
    	CreateConVar("adminlist_version", "1.4b", "Admin List Version", FCVAR_PLUGIN|FCVAR_SPONLY|FCVAR_REPLICATED|FCVAR_NOTIFY);
    	
    	AdminListEnabled = CreateConVar("adminlist_on", "1", "turns on and off admin list, 1=on ,0=off", FCVAR_PLUGIN);
    	AdminListMode = CreateConVar("adminlist_mode", "2", "mode that changes how the list appears. 1-Chat, 2-Panel", FCVAR_PLUGIN);
    	AdminListAdminFlag = CreateConVar("adminlist_adminflag", "b", "admin flag to use for list. must be in char format", FCVAR_PLUGIN);
    	
    	RegConsoleCmd("sm_admins", Command_Admins, "Displays Admins to players");
    	RegConsoleCmd("sm_root", Command_Admins, "Displays Admins to players");
    	
    	LoadTranslations("adminlist.phrases");
    	
    	AutoExecConfig(true, "adminlist");
    }
    
    public Action:Command_Admins(client, args)
    {
    	if (GetConVarBool(AdminListEnabled)) 
    	{
    		new bool:noadm= true;
    		switch(GetConVarInt(AdminListMode)) 
    		{
    			case 1:
    			{
    				decl String:AdminNames[MAXPLAYERS+1][MAX_NAME_LENGTH+1];
    				new count = 0;
    				for (new i = 1; i<=MaxClients; i++)
    				{
    					if(IsClientConnected(i) && IsClientInGame(i) && IsAdmin(i))
    					{
    						noadm = false;
    						GetClientName(i, AdminNames[count], sizeof(AdminNames[]));
    						count++;
    					}
    				}
    				if (noadm)
    				{
    					PrintToChat(client, "\x04[SM] \x01%t", "NoAdmins");
    					return Plugin_Handled;
    		
    				}
    				decl String:buffer[1024];
    				ImplodeStrings(AdminNames, count, "\x01,\x03 ", buffer, sizeof(buffer));
    				PrintToChat(client, "\x04[SM] \x01%t \x03%s", "OnlineChat", buffer);
    			}
    			case 2:
    			{
    				decl String:AdminName[MAX_NAME_LENGTH], String:admlist[128], String:noadms[128];
    				AdminListMenu = CreateMenu(MenuListHandler);
    				Format(admlist, sizeof(admlist), "%T", "OnlinePanel", client);
    				SetMenuTitle(AdminListMenu, admlist);							
    				for(new i = 1; i <= MaxClients; i++) 
    				{
    					if(IsClientConnected(i) && IsClientInGame(i) && IsAdmin(i)) 
    					{
    						noadm = false;
    						GetClientName(i, AdminName, sizeof(AdminName));
    						AddMenuItem(AdminListMenu, AdminName, AdminName);
    					} 
    				}
    				if (noadm)
    				{
    					Format(noadms, sizeof(noadms), "%T", "NoAdmins", client);
    					AddMenuItem(AdminListMenu, noadms, noadms);
    				}
    				SetMenuExitButton(AdminListMenu, true);
    				DisplayMenu(AdminListMenu, client, 15);
    			}
    		}
    	}
    	return Plugin_Handled;
    }
    public MenuListHandler(Handle:menu, MenuAction:action, param1, param2)
    {
    	if (action == MenuAction_End)
    		CloseHandle(menu);
    }
    
    stock bool:IsAdmin(client)
    {
    	decl String:flags[64];
    	GetConVarString(AdminListAdminFlag, flags, sizeof(flags));
    	new ibFlags = ReadFlagString(flags);
    	if ((GetUserFlagBits(client) & ibFlags) == ibFlags)
    		return true;
    	if (GetUserFlagBits(client) & ADMFLAG_ROOT)
    		return true;
    	return false;
    }
    Sorry for writting on english language but i am from Bulgaria and i dont speak russian.
     
  2. White Wolf

    White Wolf [] (int _n) -> double { return (_n % 2) == 0;}); Супер-модератор

    Сообщения:
    1.186
    Симпатии:
    411
    Changing PluginStart() function
    PHP:
    public OnPluginStart()
    {
        
    CreateConVar("adminlist_version""1.4b""Admin List Version"FCVAR_PLUGIN|FCVAR_SPONLY|FCVAR_REPLICATED|FCVAR_NOTIFY);
        
        
    AdminListEnabled CreateConVar("adminlist_on""1""turns on and off admin list, 1=on ,0=off"FCVAR_PLUGIN);
        
    AdminListMode CreateConVar("adminlist_mode""2""mode that changes how the list appears. 1-Chat, 2-Panel"FCVAR_PLUGIN);
        
    AdminListAdminFlag CreateConVar("adminlist_adminflag""b""admin flag to use for list. must be in char format"FCVAR_PLUGIN);
        
        
    RegAdminCmd("sm_admins"Command_AdminsADMFLAG_CUSTOM6"Displays Admins to players");
        
    RegAdminCmd("sm_root"Command_AdminsADMFLAG_CUSTOM6"Displays Admins to players");
        
        
    LoadTranslations("adminlist.phrases");
        
        
    AutoExecConfig(true"adminlist");
    }
    List of available flags here and their bitvalues: https://sm.alliedmods.net/api/index.php?fastload=file&id=28&
    And also we used RegAdminCmd to create admin command and ADMFLAG_CUSTOM6 as flag(t)
     
    BGKoKoOo нравится это.
  3. BGKoKoOo

    BGKoKoOo

    Сообщения:
    33
    Симпатии:
    7
    Work fine thanks. i have other question, can you add message into the sp so i can change ([SM] You do not have access to this command.)
     
  4. AlmazON

    AlmazON деревянный © yand3xmail

    Сообщения:
    4.506
    Симпатии:
    1.961
    PHP:
    #include <sourcemod>
    #pragma semicolon 1

    new Handle:AdminListEnabled INVALID_HANDLE;
    new 
    Handle:AdminListMode INVALID_HANDLE;
    new 
    Handle:AdminListMenu INVALID_HANDLE;
    new 
    Handle:AdminListAdminFlag INVALID_HANDLE;

    #define PLUGIN_VERSION "1.4b"

    public Plugin:myinfo 
    {
        
    name "Admin List",
        
    author "Fredd",
        
    description "prints admins to clients",
        
    version PLUGIN_VERSION,
        
    url "www.sourcemod.net"
    }

    public 
    OnPluginStart()
    {
        
    CreateConVar("adminlist_version""1.4b""Admin List Version"FCVAR_PLUGIN|FCVAR_SPONLY|FCVAR_REPLICATED|FCVAR_NOTIFY);
        
        
    AdminListEnabled CreateConVar("adminlist_on""1""turns on and off admin list, 1=on ,0=off"FCVAR_PLUGIN);
        
    AdminListMode CreateConVar("adminlist_mode""2""mode that changes how the list appears. 1-Chat, 2-Panel"FCVAR_PLUGIN);
        
    AdminListAdminFlag CreateConVar("adminlist_adminflag""b""admin flag to use for list. must be in char format"FCVAR_PLUGIN);
        
        
    RegConsoleCmd("sm_admins"Command_Admins"Displays Admins to players");
        
    RegConsoleCmd("sm_root"Command_Admins"Displays Admins to players");
        
        
    LoadTranslations("adminlist.phrases");
        
        
    AutoExecConfig(true"adminlist");
    }

    public 
    Action:Command_Admins(clientargs)
    {
        if (
    GetConVarBool(AdminListEnabled) && client
        {
            if(
    GetUserFlagBits(client) & ADMFLAG_CUSTOM6)
            {
                new 
    bool:noadmtrue;
                switch(
    GetConVarInt(AdminListMode))
                {
                    case 
    1:
                    {
                        
    decl String:AdminNames[MAXPLAYERS+1][MAX_NAME_LENGTH+1];
                        new 
    count 0;
                        for (new 
    1i<=MaxClientsi++)
                        {
                            if(
    IsClientConnected(i) && IsClientInGame(i) && IsAdmin(i))
                            {
                                
    noadm false;
                                
    GetClientName(iAdminNames[count], sizeof(AdminNames[]));
                                
    count++;
                            }
                        }
                        if (
    noadm)
                        {
                            
    PrintToChat(client"\x04[SM] \x01%t""NoAdmins");
                            return 
    Plugin_Handled;
                            
                        }
                        
    decl String:buffer[1024];
                        
    ImplodeStrings(AdminNamescount"\x01,\x03 "buffersizeof(buffer));
                        
    PrintToChat(client"\x04[SM] \x01%t \x03%s""OnlineChat"buffer);
                    }
                    case 
    2:
                    {
                        
    decl String:AdminName[MAX_NAME_LENGTH], String:admlist[128], String:noadms[128];
                        
    AdminListMenu CreateMenu(MenuListHandler);
                        
    Format(admlistsizeof(admlist), "%T""OnlinePanel"client);
                        
    SetMenuTitle(AdminListMenuadmlist);                            
                        for(new 
    1<= MaxClientsi++) 
                        {
                            if(
    IsClientConnected(i) && IsClientInGame(i) && IsAdmin(i)) 
                            {
                                
    noadm false;
                                
    GetClientName(iAdminNamesizeof(AdminName));
                                
    AddMenuItem(AdminListMenuAdminNameAdminName);
                            } 
                        }
                        if (
    noadm)
                        {
                            
    Format(noadmssizeof(noadms), "%T""NoAdmins"client);
                            
    AddMenuItem(AdminListMenunoadmsnoadms);
                        }
                        
    SetMenuExitButton(AdminListMenutrue);
                        
    DisplayMenu(AdminListMenuclient15);
                    }
                }
            }
            else 
    PrintToChat(client"[SM] You do not have access to this command.");
            
    //else PrintToChat(client, "\x04[SM] \x01%t", "NoAccess");
        
    }
        return 
    Plugin_Handled;
    }
    public 
    MenuListHandler(Handle:menuMenuAction:actionparam1param2)
    {
        if (
    action == MenuAction_End)
        
    CloseHandle(menu);
    }

    stock bool:IsAdmin(client)
    {
        
    decl String:flags[64];
        
    GetConVarString(AdminListAdminFlagflagssizeof(flags));
        new 
    ibFlags ReadFlagString(flags);
        if ((
    GetUserFlagBits(client) & ibFlags) == ibFlags)
        return 
    true;
        if (
    GetUserFlagBits(client) & ADMFLAG_ROOT)
        return 
    true;
        return 
    false;
    }
     
    BGKoKoOo нравится это.
  5. White Wolf

    White Wolf [] (int _n) -> double { return (_n % 2) == 0;}); Супер-модератор

    Сообщения:
    1.186
    Симпатии:
    411
    And [SM] You do not have access to this command. replace on what you need. And AlmazON forgot to replace this:
    PHP:
    RegConsoleCmd("sm_admins"Command_Admins"Displays Admins to players"); 
        
    RegConsoleCmd("sm_root"Command_Admins"Displays Admins to players");
    on this:
    PHP:
    RegAdminCmd("sm_admins"Command_AdminsADMFLAG_CUSTOM6"Displays Admins to players"); 
        
    RegAdminCmd("sm_root"Command_AdminsADMFLAG_CUSTOM6"Displays Admins to players");
     
    BGKoKoOo нравится это.
  6. BGKoKoOo

    BGKoKoOo

    Сообщения:
    33
    Симпатии:
    7
    Thank you. Will try later and post the results
     
  7. AlmazON

    AlmazON деревянный © yand3xmail

    Сообщения:
    4.506
    Симпатии:
    1.961
    Ничего я не забыл, он же хотел изменить только для одного плагина текст "У вас нет доступа к этой команде". Админ-команда здесь не нужна.
     
  8. White Wolf

    White Wolf [] (int _n) -> double { return (_n % 2) == 0;}); Супер-модератор

    Сообщения:
    1.186
    Симпатии:
    411
    AlmazON он спросил это.
     
  9. White Wolf

    White Wolf [] (int _n) -> double { return (_n % 2) == 0;}); Супер-модератор

    Сообщения:
    1.186
    Симпатии:
    411
    А если вывести
    PHP:
    ReplyToCommand(client"Bla-bla-bla");
    разве оно не должно будет заменить текст что стоит по умолчанию?
     
  10. AlmazON

    AlmazON деревянный © yand3xmail

    Сообщения:
    4.506
    Симпатии:
    1.961
    Нет. Получишь два: стандартное и своё)
     
    White Wolf нравится это.