Raised This Month: $106 Target: $400
 26% 

[HELP] Client Menu


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
SpirT
Member
Join Date: Sep 2018
Location: Portugal, From My Mom
Old 11-13-2018 , 13:12   [HELP] Client Menu
Reply With Quote #1

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!
__________________
SpirT is offline
Dragokas
Senior Member
Join Date: Nov 2017
Location: Ukraine
Old 11-13-2018 , 19:17   Re: [HELP] Client Menu
Reply With Quote #2

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 !"); 
            }
        }
    }

__________________
Expert of CMD/VBS/VB6. Malware analyst.
Dragokas is offline
Rowdy4E
New Member
Join Date: Nov 2018
Old 11-14-2018 , 10:43   Re: [HELP] Client Menu
Reply With Quote #3

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. Totenfluch made something similiar to what you want.

https://forums.alliedmods.net/showthread.php?t=292183
Rowdy4E is offline
Dragokas
Senior Member
Join Date: Nov 2017
Location: Ukraine
Old 11-14-2018 , 12:35   Re: [HELP] Client Menu
Reply With Quote #4

+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).
__________________
Expert of CMD/VBS/VB6. Malware analyst.

Last edited by Dragokas; 11-14-2018 at 12:35.
Dragokas is offline
SpirT
Member
Join Date: Sep 2018
Location: Portugal, From My Mom
Old 11-14-2018 , 15:07   Re: [HELP] Client Menu
Reply With Quote #5

Quote:
Originally Posted by Rowdy4E View Post
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. 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 is offline
SpirT
Member
Join Date: Sep 2018
Location: Portugal, From My Mom
Old 11-16-2018 , 11:19   Re: [HELP] Client Menu
Reply With Quote #6

Quote:
Originally Posted by Dragokas View Post
+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!
__________________
SpirT is offline
Dragokas
Senior Member
Join Date: Nov 2017
Location: Ukraine
Old 11-16-2018 , 11:48   Re: [HELP] Client Menu
Reply With Quote #7

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()
__________________
Expert of CMD/VBS/VB6. Malware analyst.

Last edited by Dragokas; 11-16-2018 at 11:51.
Dragokas is offline
SpirT
Member
Join Date: Sep 2018
Location: Portugal, From My Mom
Old 11-16-2018 , 12:32   Re: [HELP] Client Menu
Reply With Quote #8

Quote:
Originally Posted by Dragokas View Post
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?
__________________
SpirT is offline
Dragokas
Senior Member
Join Date: Nov 2017
Location: Ukraine
Old 11-16-2018 , 13:27   Re: [HELP] Client Menu
Reply With Quote #9

Show your code.
__________________
Expert of CMD/VBS/VB6. Malware analyst.
Dragokas is offline
Rowdy4E
New Member
Join Date: Nov 2018
Old 11-16-2018 , 15:59   Re: [HELP] Client Menu
Reply With Quote #10

Quote:
Originally Posted by SpirT View Post
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);
    } 

Last edited by Rowdy4E; 11-16-2018 at 16:02.
Rowdy4E 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 18:33.


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