AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Plugin/Gameplay Ideas and Requests (https://forums.alliedmods.net/forumdisplay.php?f=60)
-   -   [HELP] Client Menu (https://forums.alliedmods.net/showthread.php?t=312035)

SpirT 11-13-2018 12:12

[HELP] Client Menu
 
So hi guys. Today i need a help. I'm doing something for my community and its a very important thing.

I wanna give a client VIP permissions (only root admins can do it) on a menu. I already done this

PHP Code:

#pragma semicolon 1

#define DEBUG

#define PLUGIN_AUTHOR "SpirTBBX"
#define PLUGIN_VERSION "1.0.0"

#include <sourcemod>
#include <sdktools>

#pragma newdecls required

public Plugin myinfo 
{
    
name "VIP Permissions",
    
author PLUGIN_AUTHOR,
    
description "Root can give VIP permission to client in game",
    
version PLUGIN_VERSION,
    
url ""
};

public 
void OnPluginStart()
{
    
RegAdminCmd("sm_perm"perm_cmdADMFLAG_ROOT"Perms Menu Command");
    
CreatePermsMenu();
    
CreateClientMenu();
}

public 
Action perm_cmd(int clientint args)
{
    
CreateClientMenu().Display(clientMENU_TIME_FOREVER); /* all clients in game */
    
CreatePermsMenu();
}

public 
Action CreateClientMenu()
{
    
Menu ccm = new Menu(handler2MENU_ACTIONS_ALL);
    
ccm.SetTitle("All Clients Name Menu");
    
ccm.ExitButton true;
        
/* Other part of code im asking */
}

public 
Action CreatePermsMenu()
{
    
Menu cpm = new Menu(handler1MENU_ACTIONS_ALL);
    
cpm.SetTitle("Permissions Menu");
    
cpm.AddItem("vip""VIP");
    
cpm.ExitBackButton true;
    
cpm.ExitButton true;
    
    return 
cpm;
}

public 
int handler1(Menu cpmMenuAction actionint client /* param1 */int item /* param2 */)
{
    
char choice[32]; /* on client select on menu (variable) */
    
char clientname[32]; /* client who the flag was give */
    
cpm.GetItem(itemchoicesizeof(choice));
    if (
action == MenuAction_Select)
    {
        if (
StrEqual(choice"vip"))
        {
            
AddUserFlags(clientADMFLAG_CUSTOM1);
            
PrintToChat(client"Congrats! VIP was given to %s !"clientname);
        }
    }
    else if (
action == MenuAction_Cancel)
    {
        
delete cpm;
        
CreateClientMenu().Display(clientMENU_TIME_FOREVER);
    }
    else if (
action == MenuAction_End)
    {
        
delete cpm;
    }
}

public 
int handler2(Menu ccmMenuAction actionint client /* param1 */int item /* param2 */)
{
    
char choice[32];
        
/* Other part of code im asking */


Can someone do the menu for me with the clients in game?
And obviously check if all the other things are correct.
Then reply when its done or PM me the code!

Thanks for the attention!

Dragokas 11-13-2018 18:17

Re: [HELP] Client Menu
 
You have some errors:
You create "Menu" type but return "Action" type instead.
Actually, I see no reason to pre-call it without caching to global variable if that was your reason.

Also, you don't need explicitly call "delete menu" (twice) bacause it is already called when "MenuAction_End" msg is come in your callback.

ADMFLAG_CUSTOM1. Correct tags are: https://sm.alliedmods.net/new-api/admin/AdminFlag
Also, ExitButton is true by default.
GetItem should be called e.g. on MenuAction_Select msg.

A bit rewritten code:
PHP Code:

#pragma newdecls required
#pragma semicolon 1

#define DEBUG 1

#define PLUGIN_AUTHOR "SpirTBBX"
#define PLUGIN_VERSION "1.0.0"

#include <sourcemod>
//#include <sdktools>

public Plugin myinfo =
{
    
name "VIP Permissions"
    
author PLUGIN_AUTHOR
    
description "Root can give VIP permission to client in game"
    
version PLUGIN_VERSION
    
url "" 
}; 

public 
void OnPluginStart()
{
    
RegAdminCmd("sm_perm"perm_cmdADMFLAG_ROOT"Perms Menu Command");
}

public 
Action perm_cmd(int clientint args
{
    
ShowMenuMain(client);
}

void ShowMenuMain(int client)
{
    
Menu menu = new Menu(MenuHandler_MainMenuMENU_ACTIONS_DEFAULT);
    
menu.SetTitle("Main menu");
    
menu.AddItem("vip""Set VIP");
    
menu.Display(clientMENU_TIME_FOREVER);
}

public 
int MenuHandler_MainMenu(Menu menuMenuAction actionint param1int param2)
{
    switch (
action)
    {
        case 
MenuAction_End:
            
delete menu;
        
        case 
MenuAction_Select:
        {
            
int client param1;
            
int ItemIndex param2;
            
            
char sItem[32];
            
menu.GetItem(ItemIndexsItemsizeof(sItem));
            
            if (
StrEqual(sItem"vip"))
                
ShowMenuAssignVIP(client);
        }
    }
}

void ShowMenuAssignVIP(int client)
{
    
char sDisplay[50], sIdx[5];
    
Menu menu = new Menu(MenuHandler_AssignVIPMENU_ACTIONS_DEFAULT);
    
menu.SetTitle("Select client to assign VIP");
    for (
int i 1<= MaxClientsi++)
    {
        if (
IsClientInGame(i) && !IsFakeClient(i))
        {
            
IntToString(isIdxsizeof(sIdx));
            
Format(sDisplaysizeof(sDisplay), " %N"i);
            
menu.AddItem(sIdxsDisplay);
        }
    }
    
menu.ExitBackButton true;
    
menu.Display(clientMENU_TIME_FOREVER);
}

public 
int MenuHandler_AssignVIP(Menu menuMenuAction actionint param1int param2)
{
    switch (
action)
    {
        case 
MenuAction_End:
            
delete menu;
        
        case 
MenuAction_Cancel:
            if (
param2 == MenuCancel_ExitBack)
                
ShowMenuMain(param1);
        
        case 
MenuAction_Select:
        {
            
int client param1;
            
int ItemIndex param2;
            
            
char sClient[5];
            
menu.GetItem(ItemIndexsClientsizeof(sClient));
            
            
int i StringToInt(sClient);
            if (
IsClientInGame(i) && !IsFakeClient(i))
            {
                
AddUserFlags(iAdmin_Custom1); 
                
PrintToChat(client"VIP was given to %N !"i);
                
PrintToChat(i"Congrats! VIP was given to you !"); 
            }
        }
    }



Rowdy4E 11-14-2018 09:43

Re: [HELP] Client Menu
 
If you will grant vip through this menu what you made the VIP will lasts only until he disconnects or until map change. Adding VIP through MySQL Database is better option for you. :wink: Totenfluch made something similiar to what you want.

https://forums.alliedmods.net/showthread.php?t=292183

Dragokas 11-14-2018 11:35

Re: [HELP] Client Menu
 
+1, you need DB, KeyValues (depending on how many users) or direct editing the admins_simple.ini file (if you prever VIPs based on admin flags), like this one (code for removing only).

SpirT 11-14-2018 14:07

Re: [HELP] Client Menu
 
Quote:

Originally Posted by Rowdy4E (Post 2623999)
If you will grant vip through this menu what you made the VIP will lasts only until he disconnects or until map change. Adding VIP through MySQL Database is better option for you. :wink: Totenfluch made something similiar to what you want.

https://forums.alliedmods.net/showthread.php?t=292183

Yes i want. The guys done that ok thanks. And my server has mysql so yeah thanks

SpirT 11-16-2018 10:19

Re: [HELP] Client Menu
 
Quote:

Originally Posted by Dragokas (Post 2624017)
+1, you need DB, KeyValues (depending on how many users) or direct editing the admins_simple.ini file (if you prever VIPs based on admin flags), like this one (code for removing only).

So hi again. I diceded to do this...

PHP Code:

char path[512];
FormatEx(pathsizeof(path), "addons/sourcemod/configs/admin_simple.ini");
if (!
FileExists(path))
{
        
char steamid[32];
        
GetClientAuthId(clientAuthId_Steam2steamidsizeof(steamid));
        
OpenFile(path"r+"false);
        
WriteFileLine("%s" "20:ao", ... , steamid);
        
WriteFileLine(
                
PrintToChat(client"Congrats! VIP was given to %s!"clientname);


But i got some errors

Code:


error 035: argument type mismatch (argument 1)

warning 215: expression has no effect

error 029: invalid expression, assumed zero

error 029: invalid expression, assumed zero

fatal error 190: too many error messages on one line

How do i fix this?

Thanks for all your help and others as well! :)

Dragokas 11-16-2018 10:48

Re: [HELP] Client Menu
 
Code:

if (!FileExists(path))
??? It almost always exist. In 99 % cases your code will not work.

https://sm.alliedmods.net/new-api/files/WriteFileLine
1-st argument is a handle.

"%s" "20:ao", ... - what is this?
WriteFileLine( - and what is this?

You should write correctly. Handle, "string". Or Handle, "specifiers(s)", arg(s)

char path[512]; - use PLATFORM_MAX_PATH const
FormatEx - in the non-performance critical places it's better to use Format()

SpirT 11-16-2018 11:32

Re: [HELP] Client Menu
 
Quote:

Originally Posted by Dragokas (Post 2624317)
Code:

if (!FileExists(path))
??? It almost always exist. In 99 % cases your code will not work.

https://sm.alliedmods.net/new-api/files/WriteFileLine
1-st argument is a handle.

"%s" "20:ao", ... - what is this?
WriteFileLine( - and what is this?

You should write correctly. Handle, "string". Or Handle, "specifiers(s)", arg(s)

char path[512]; - use PLATFORM_MAX_PATH const
FormatEx - in the non-performance critical places it's better to use Format()

Thanks again! When i Handle hndl is says what i can't use Handle has value!

How do i fix it?

Dragokas 11-16-2018 12:27

Re: [HELP] Client Menu
 
Show your code.

Rowdy4E 11-16-2018 14:59

Re: [HELP] Client Menu
 
Quote:

Originally Posted by SpirT (Post 2624308)
So hi again. I diceded to do this...

PHP Code:

char path[512];
FormatEx(pathsizeof(path), "addons/sourcemod/configs/admin_simple.ini");
if (!
FileExists(path))
{
        
char steamid[32];
        
GetClientAuthId(clientAuthId_Steam2steamidsizeof(steamid));
        
OpenFile(path"r+"false);
        
WriteFileLine("%s" "20:ao", ... , steamid);
        
WriteFileLine(
                
PrintToChat(client"Congrats! VIP was given to %s!"clientname);


But i got some errors

Code:


error 035: argument type mismatch (argument 1)

warning 215: expression has no effect

error 029: invalid expression, assumed zero

error 029: invalid expression, assumed zero

fatal error 190: too many error messages on one line

How do i fix this?

Thanks for all your help and others as well! :)


Code should look like this:

PHP Code:

    char path[512];
    
BuildPath(Path_SMpathsizeof(path), "configs/admins_simple.ini");
    if (
FileExists(path)) 
    { 
        
char steamid[32]; 
        
GetClientAuthId(clientAuthId_Steam2steamidsizeof(steamid));
        
Handle file OpenFile(path"a");
        
WriteFileLine(file"\"%s\" \"20:ao\""steamid);
        
delete file;
        
        
PrintToChatAll("Congrats! VIP was given to %N!"client);
    } 



All times are GMT -4. The time now is 16:07.

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