Raised This Month: $ Target: $400
 0% 

Execute an console command trough a menu option


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
skorpion
Junior Member
Join Date: Mar 2016
Old 05-19-2016 , 15:49   Execute an console command trough a menu option
Reply With Quote #1

i've made a plugin for csgo that opens an menu when a players spawns,
it has a couple of options now added with
PHP Code:
AddMenuItem 
Now i would like to add a menu option that simply execute's
PHP Code:
sm_example 
in the console so it opens another plugin menu... is this possible and howso?

Thanks
skorpion is offline
KissLick
Veteran Member
Join Date: Nov 2012
Location: void
Old 05-19-2016 , 16:15   Re: Execute an console command trough a menu option
Reply With Quote #2

https://sm.alliedmods.net/new-api/ -> Search for command
__________________
Plugins: TeamGames
Includes: Menu stocks, ColorVariables, DownloadTableConfig

> No help through PM, make a topic.
KissLick is offline
skorpion
Junior Member
Join Date: Mar 2016
Old 05-19-2016 , 16:38   Re: Execute an console command trough a menu option
Reply With Quote #3

I cant find a command there, i don't know wich one to use this is the code of my menu
could someone pelase help me out how i put sm_example on a menu button?

PHP Code:
stock InitializeMenus()
{
    
g_PrimaryGunCount=0;
    
CheckCloseHandle(g_PrimaryMenu);
    
g_PrimaryMenu CreateMenu(MenuHandler_ChoosePrimaryMenuAction_Display|MenuAction_Select|MenuAction_Cancel);
    
SetMenuTitle(g_PrimaryMenu"Menu title");
    
AddMenuItem(g_PrimaryMenu"63""Random");
    
AddMenuItem(g_PrimaryMenu"sm_example""Example"); <-- this line doesn't work this way
    

Thanks in advance
skorpion is offline
KissLick
Veteran Member
Join Date: Nov 2012
Location: void
Old 05-19-2016 , 17:04   Re: Execute an console command trough a menu option
Reply With Quote #4

No, in menu handler (in your snippet MenuHandler_ChoosePrimary):
  • Check if the selected item is "sm_example"
    • FakeClientCommandEx(client, "sm_example")
__________________
Plugins: TeamGames
Includes: Menu stocks, ColorVariables, DownloadTableConfig

> No help through PM, make a topic.
KissLick is offline
Chaosxk
Veteran Member
Join Date: Aug 2010
Location: Westeros
Old 05-19-2016 , 17:40   Re: Execute an console command trough a menu option
Reply With Quote #5

You need a callback handler. Here's a snippet i wrote but it's in the newer syntax. Wrote some comments to help you understand.

Code:
void InitializeMenus() 
{ 
	g_PrimaryGunCount=0; 
	//CheckCloseHandle(g_PrimaryMenu); You don't need this, we delete the handle in the callback function
	Menu menu = new Menu(MenuHandler_ChoosePrimary, MenuAction_Display|MenuAction_Select|MenuAction_Cancel);
	menu.SetTitle("Menu title");
	menu.AddItem("63", "Random");
	menu.AddItem("1", "Example");	//1 is our info string and Example is our display string
	menu.AddItem("2", "Example2");	//2 is our info string and Example2 is our display string
	//our info string will help use determine which item they selected
}

//This is the callback function when we created the menu
public int MenuHandler_ChoosePrimary(Menu menu, MenuAction action, int param1, int param2)
{
	if (action == MenuAction_Select)	//They selected an item
	{
		char info[32];	//This is our info string
		menu.GetItem(param2, info, sizeof(info));	//We store our info string to info
		int select = StringToInt(info);		//we convert the info string to a number
		//we check here to see if info is sm_example, which means they selected item
		switch(select)
		{
			case 1:	FakeClientCommandEx(param1, "sm_example");		//This is menu.AddItem("1", "Example"); from before
			case 2: FakeClientCommandEx(param1, "sm_example2");		//This is menu.AddItem("2", "Example2"); from before
			case 63: FakeClientCommandEx(param1, "sm_random");		//This is menu.AddItem("63", "Random"); from before
		}
	}
	else if (action == MenuAction_End)	//They closed the menu
	{
		delete menu;	//We close the menu handle and set menu to null so there won't be any leaks
	}
}
__________________
Chaosxk is offline
skorpion
Junior Member
Join Date: Mar 2016
Old 05-20-2016 , 05:05   Re: Execute an console command trough a menu option
Reply With Quote #6

Chaosxk thanks alot for your reply
the newer syntax doesn't work for me, then i'll get alot of errors when i compile it, so i converted it to the old one.

this is my menu
PHP Code:
stock InitializeMenus()
{
    
g_PrimaryGunCount=0;
    
CheckCloseHandle(g_PrimaryMenu);
    
g_PrimaryMenu CreateMenu(MenuHandler_ChoosePrimaryMenuAction_Display|MenuAction_Select|MenuAction_Cancel);
    
SetMenuTitle(g_PrimaryMenu"SkorpionServers VIP menu");
    
AddMenuItem(g_PrimaryMenu"75""Execute sm_example");
    
AddMenuItem(g_PrimaryMenu"63""Random");

The "Random" option works just fine but i still cannot get it to execute sm_example..

this is my MenuHandler with your snippet added:
PHP Code:
{
    if (
action == MenuAction_Displayg_MenuOpen[param1] = true;
    else if (
action == MenuAction_Select)
    {
        new 
client_index param1;                        // <- from here
        
decl String:weapon_id[4];
        
GetMenuItem(menuparam2weapon_idsizeof(weapon_id));
        new 
weapon_index StringToInt(weapon_id16);

        
g_PlayerPrimary[client_index] = weapon_index;
        if (
Teams:GetClientTeam(client_index) > CS_TEAM_SPECTATORGivePrimary(client_index); //<-to here, works fine its for the random option and the option so players can chose their primary weapon.

        
char info[32];    //This is our info string
        
GetMenuItem(param2infosizeof(info));    //We store our info string to info
        
int select StringToInt(info);        //we convert the info string to a number
        //we check here to see if info is sm_example, which means they selected item
        
switch(select)
        {
            case 
75:    FakeClientCommandEx(param1"sm_example");        //This is menu.AddItem("1", "Example"); from before

        
}
    }
    else if (
action == MenuAction_Cancel)
    {
        
g_MenuOpen[param1] = false;
        if (
param2 == MenuCancel_Exit)    // CancelClientMenu sends MenuCancel_Interrupted reason
        
{
            if (
g_SecondaryMenu != INVALID_HANDLEDisplayMenu(g_SecondaryMenuparam1MENU_TIME_FOREVER);
        }
    }

the compiler gives me this error:
PHP Code:
Your plugin failed to compileRead the errors below:
SourcePawn Compiler 1.7.1
Copyright 
(c1997-2006 ITB CompuPhase
Copyright 
(c2004-2014 AlliedModders LLC

/home/groups/sourcemod/upload_tmp/phpYXEnxp.sp(379) : warning 213tag mismatch
/home/groups/sourcemod/upload_tmp/phpYXEnxp.sp(379) : error 035argument type mismatch (argument 2)
/
home/groups/sourcemod/upload_tmp/phpYXEnxp.sp(379) : error 035argument type mismatch (argument 3)

2 Errors

Last edited by skorpion; 05-20-2016 at 05:10.
skorpion is offline
Potato Uno
Veteran Member
Join Date: Jan 2014
Location: Atlanta, Georgia
Old 05-20-2016 , 11:49   Re: Execute an console command trough a menu option
Reply With Quote #7

What is line 379?
Potato Uno is offline
Chaosxk
Veteran Member
Join Date: Aug 2010
Location: Westeros
Old 05-20-2016 , 13:34   Re: Execute an console command trough a menu option
Reply With Quote #8

You didn't fully convert the menu handler to old syntax.

Code:
public MenuHandler_ChoosePrimary(Handle:menu, MenuAction:action, param1, param2)
{ 
    if (action == MenuAction_Display) g_MenuOpen[param1] = true; 
    else if (action == MenuAction_Select) 
    { 
        new client_index = param1;                        // <- from here 
        decl String:weapon_id[4]; 
        GetMenuItem(menu, param2, weapon_id, sizeof(weapon_id)); 
        new weapon_index = StringToInt(weapon_id, 16); 

        g_PlayerPrimary[client_index] = weapon_index; 
        if (Teams:GetClientTeam(client_index) > CS_TEAM_SPECTATOR) GivePrimary(client_index); //<-to here, works fine its for the random option and the option so players can chose their primary weapon. 

        String:info[32];    //This is our info string 
        GetMenuItem(param2, info, sizeof(info));    //We store our info string to info 
        new select = StringToInt(info);        //we convert the info string to a number 
        //we check here to see if info is sm_example, which means they selected item 
        switch(select) 
        { 
            case 75:    FakeClientCommandEx(param1, "sm_example");        //This is menu.AddItem("1", "Example"); from before 

        } 
    } 
    else if (action == MenuAction_Cancel) 
    { 
        g_MenuOpen[param1] = false; 
        if (param2 == MenuCancel_Exit)    // CancelClientMenu sends MenuCancel_Interrupted reason 
        { 
            if (g_SecondaryMenu != INVALID_HANDLE) DisplayMenu(g_SecondaryMenu, param1, MENU_TIME_FOREVER); 
        } 
    } 
}
__________________
Chaosxk is offline
Reply



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:44.


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