Raised This Month: $51 Target: $400
 12% 

Help With Executing command


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
mikmik02
Junior Member
Join Date: Dec 2017
Location: In My Basement
Old 12-19-2017 , 09:51   Help With Executing command
Reply With Quote #1

So to start of im new to sourcemod coding, I started doing a simplevipmenu thingi With the menu guide [https://wiki.alliedmods.net/Menus_St...od_Scripting)]. I got the menu itself to work but I need help making it execute the command that they select. Any suggsetions are appreciated. Full code is attatched.
Attached Files
File Type: sp Get Plugin or Get Source (simplevipmenu.sp - 160 views - 2.2 KB)
mikmik02 is offline
Send a message via Skype™ to mikmik02
mikmik02
Junior Member
Join Date: Dec 2017
Location: In My Basement
Old 12-19-2017 , 10:12   Re: Help With Executing command
Reply With Quote #2

To make it easyer here is the code.

Code:
#include <sourcemod>
#define CHOICE1 "sm_customknivesforvip1337"
#define CHOICE2 "sm_models"
#define CHOICE3 "#choice3"
#define MenuTitle "Vip Menu"
 
public Plugin:myinfo = 
{
	name = "Vip Menu",
	author = "liljekvist",
	description = "Simple Vip Menu",
	version = "6.969",
	url = "<- URL ->"
}

public void OnPluginStart()
{
	LoadTranslations("simplevipmenu.phrases");
	RegConsoleCmd("sm_vip", cmd_sm_vip);
}
 
public int MenuHandler1(Menu menu, MenuAction action, int param1, int param2)
{
	switch(action)
	{
		case MenuAction_Start:
		{
			PrintToServer("Displaying menu");
		}
 
		case MenuAction_Display:
		{
	 		char buffer[255];
			Format(buffer, sizeof(buffer), "%T", "Vote Nextmap", param1);
 
			Panel panel = view_as<Panel>(param2);
			panel.SetTitle(buffer);
			PrintToServer("Client %d was sent menu with panel %x", param1, param2);
		}
 
		case MenuAction_Select:
		{
			char info[32];
			menu.GetItem(param2, info, sizeof(info));
			if (StrEqual(info, CHOICE3))
			{
				PrintToServer("Client %d somehow selected %s despite it being disabled", param1, info);
			}
			else
			{
				PrintToServer("Client %d selected %s", param1, info);
			}
		}
 
		case MenuAction_Cancel:
		{
			PrintToServer("Client %d's menu was cancelled for reason %d", param1, param2);
		}
 
		case MenuAction_End:
		{
			delete menu;
		}
 
		case MenuAction_DrawItem:
		{
			int style;
			char info[32];
			menu.GetItem(param2, info, sizeof(info), style);
 
			if (StrEqual(info, CHOICE3))
			{
				return ITEMDRAW_DISABLED;
			}
			else
			{
				return style;
			}
		}
 
		case MenuAction_DisplayItem:
		{
			char info[32];
			menu.GetItem(param2, info, sizeof(info));
 
			char display[64];
 
			if (StrEqual(info, CHOICE3))
			{
				Format(display, sizeof(display), "%T", "Choice 3", param1);
				return RedrawMenuItem(display);
			}
		}
	}
 
	return 0;
}
 
public Action cmd_sm_vip(int client, int args)
{
	Menu menu = new Menu(MenuHandler1, MENU_ACTIONS_ALL);
	menu.SetTitle("%T", "Menu Title", LANG_SERVER);
	menu.AddItem(CHOICE1, "CustomKnifes");
	menu.AddItem(CHOICE2, "Models");
	menu.AddItem(CHOICE3, "Choice 3");
	menu.ExitButton = false;
	menu.Display(client, 10);
 
	return Plugin_Handled;
}

Last edited by mikmik02; 12-19-2017 at 10:13. Reason: Wrong Code
mikmik02 is offline
Send a message via Skype™ to mikmik02
8guawong
AlliedModders Donor
Join Date: Dec 2013
Location: BlackMarke7
Old 12-19-2017 , 12:37   Re: Help With Executing command
Reply With Quote #3

#define CHOICE3 "#choice3"

so what are we trying to execute?
__________________
8guawong is offline
Powerlord
AlliedModders Donor
Join Date: Jun 2008
Location: Seduce Me!
Old 12-19-2017 , 18:37   Re: Help With Executing command
Reply With Quote #4

The Menus Step By Step page has a bunch of things you won't necessarily need in your menu. I should know seeing as how I wrote that page.
__________________
Not currently working on SourceMod plugin development.
Powerlord is offline
mikmik02
Junior Member
Join Date: Dec 2017
Location: In My Basement
Old 12-22-2017 , 10:01   Re: Help With Executing command
Reply With Quote #5

Quote:
Originally Posted by 8guawong View Post
#define CHOICE3 "#choice3"

so what are we trying to execute?
I have updated the code and somewhat got it to work new code is
Code:
#include <sourcemod>
#define CHOICE1 "sm_customknivesforvip1337"
#define CHOICE2 "sm_models"
#define CHOICE3 "sm_mm"
#define MenuTitle "Vip Menu"

public Plugin:myinfo = 
{
	name = "Vip Menu",
	author = "liljekvist",
	description = "Simple Vip Menu",
	version = "6.969",
	url = "<- URL ->"
}

public void OnPluginStart()
{
	LoadTranslations("simplevipmenu.phrases");
	RegConsoleCmd("sm_vip", cmd_sm_vip);
}
 
public int MenuHandler1(Menu menu, MenuAction action, int param1, int param2)
{
	switch(action)
	{
		case MenuAction_Start:
		{
			PrintToServer("Displaying menu");
		}
 
		case MenuAction_Display:
		{
	 		char buffer[255];
			Format(buffer, sizeof(buffer), "%T", "Vote Nextmap", param1);
 
			Panel panel = view_as<Panel>(param2);
			panel.SetTitle(buffer);
			PrintToServer("Client %d was sent menu with panel %x", param1, param2);
		}
 
		case MenuAction_Select://SourceMod Batch Compiler
		{
			char info[32];
			menu.GetItem(param2, info, sizeof(info));
			if (StrEqual(info, CHOICE3))
			{
				PrintToServer("Client %d somehow selected %s despite it being disabled", param1, info);
			}
			else
			{
				PrintToServer("Client %d selected %s", param1, info);
			}
			if(action == MenuAction_Select)
				{             
			char sInfo[64];
			GetMenuItem(menu, param2, sInfo, sizeof(sInfo));   
			int param = StringToInt(sInfo);
			if(param == -1)
			{
				gI_Setting[] = 1;
				SetClientCookie(client, gH_Cookie, "1");
				CPrintToChat(client, "%t%t", prefix, "MENU_DISABLED");
			}
			else
			{							
			FakeClientCommand(client, menuItem[param][itemCommand]);
			//PrintToChatAll("itemName: %s | command: %s", menuItem[param][itemName], menuItem[param][itemCommand]);			
			}
			}
			else if(action == MenuAction_End)
			delete menu;
			else if(action == MenuAction_Cancel)
			gB_MenuOpen[client] = false;
			return 0;
			}
 
		case MenuAction_Cancel:
		{
			PrintToServer("Client %d's menu was cancelled for reason %d", param1, param2);
		}
 
		case MenuAction_End:
		{
			delete menu;
		}
 
		case MenuAction_DrawItem:
		{
			int style;
			char info[32];
			menu.GetItem(param2, info, sizeof(info), style);
 
			if (StrEqual(info, CHOICE3))
			{
				return ITEMDRAW_DISABLED;
			}
			else
			{
				return style;
			}
		}
 
		case MenuAction_DisplayItem:
		{
			char info[32];
			menu.GetItem(param2, info, sizeof(info));
 
			char display[64];
 
			if (StrEqual(info, CHOICE3))
			{
				Format(display, sizeof(display), "%T", "Choice 3", param1);
				return RedrawMenuItem(display);
			}
		}
	}
 
	return 0;
}
 
public Action cmd_sm_vip(int client, int args)
{
	Menu menu = new Menu(MenuHandler1, MENU_ACTIONS_ALL);
	menu.SetTitle("%T", "Menu Title", LANG_SERVER);
	menu.AddItem(CHOICE1, "CustomKnifes");
	menu.AddItem(CHOICE2, "Models");
	menu.AddItem(CHOICE3, "Choice 3");
	menu.ExitButton = false;
	menu.Display(client, 10);
 
	return Plugin_Handled;
}

Now im getting errors from compiler about
Code:
 FakeClientCommand(client, menuItem[param][itemCommand]);

The errors are as following
Code:
// C:\Users\mikae\Desktop\source\addons\sourcemod\scripting\simplevipmenu.sp(58) : warning 204: symbol is assigned a value that is never used: "param"
// C:\Users\mikae\Desktop\source\addons\sourcemod\scripting\simplevipmenu.sp(62) : error 029: invalid expression, assumed zero
// C:\Users\mikae\Desktop\source\addons\sourcemod\scripting\simplevipmenu.sp(62) : error 017: undefined symbol "client"
// C:\Users\mikae\Desktop\source\addons\sourcemod\scripting\simplevipmenu.sp(62) : error 017: undefined symbol "param"
// C:\Users\mikae\Desktop\source\addons\sourcemod\scripting\simplevipmenu.sp(62) : fatal error 190: too many error messages on one line
Any sugestions?

Last edited by mikmik02; 12-22-2017 at 10:02. Reason: Failed with tag
mikmik02 is offline
Send a message via Skype™ to mikmik02
8guawong
AlliedModders Donor
Join Date: Dec 2013
Location: BlackMarke7
Old 12-22-2017 , 10:26   Re: Help With Executing command
Reply With Quote #6

i don't think you are posting the whole code
i don't see where menuItem is declared
also you probably have an extra }
__________________
8guawong is offline
Psyk0tik
Veteran Member
Join Date: May 2012
Location: Homeless
Old 12-22-2017 , 12:10   Re: Help With Executing command
Reply With Quote #7

1. Don't use if(action == MenuAction_Select) WITHIN MenuAction_Select. That action is only called when a client actually selects one of the menu options.
2. I revised your code based on what you've given us to work with.
3. Another thing about that if(action == MenuAction_) part, your code was pretty redundant since the menu handler itself is already handling MenuAction_End and MenuAction_Cancel.
4. An alternative to if(action != MenuAction_Select) is MenuCancel_Timeout since you're only displaying it to the client for 10 seconds.
5. You have to define "client" in your menu handler if you're going to use it. I recommend using a for loop. (i.e. for(int i = 1; i <= MaxClients; i++))
6. I don't know what "param" was even used for. Since you have it in brackets, I'm guessing you mean to use char param[64]; instead of int param;? Since I also saw the if(param == -1), I say that you should probably give it an initial value and write up a code that tells the plugin when and what to add to that value.

Example:
Code:
int GetParamCount()
{
     int param = 0;
     for(int i = 1; i <= MaxClients; i++)
     {
          if(IsClientInGame(i) && IsClientConnected(i) && IsPlayerAlive(i))
          {
               paramcount++;
          }
     }

     return paramcount;
}
And thus, you can use:
Code:
int param = GetParamCount();
if(param == -1)
{
	gI_Setting[] = 1;
	SetClientCookie(client, gH_Cookie, "1");
	CPrintToChat(client, "%t%t", prefix, "MENU_DISABLED");
}
Now, again, I don't know what you're using "param" for so I'm taking guesses here.
7. I do not claim to have fixed your code. I only revised parts of it that I believe I knew how to.
8. SHOW US THE REST OF YOUR CODE.

Code:
public int MenuHandler1(Menu menu, MenuAction action, int param1, int param2)
{
	switch(action)
	{
		case MenuAction_Start:
		{
			PrintToServer("Displaying menu");
		}
		case MenuAction_Display:
		{
	 		char buffer[255];
			Format(buffer, sizeof(buffer), "%T", "Vote Nextmap", param1);
 
			Panel panel = view_as<Panel>(param2);
			panel.SetTitle(buffer);
			PrintToServer("Client %d was sent menu with panel %x", param1, param2);
		}
		case MenuAction_Select://SourceMod Batch Compiler
		{
			char info[32];
			menu.GetItem(param2, info, sizeof(info));
			if (StrEqual(info, CHOICE3))
			{
				PrintToServer("Client %d somehow selected %s despite it being disabled", param1, info);
			}
			else
			{
				PrintToServer("Client %d selected %s", param1, info);
			}
			gI_Setting[] = 1;
			SetClientCookie(client, gH_Cookie, "1");
			CPrintToChat(client, "%t%t", prefix, "MENU_DISABLED");
		}
		case MenuAction_Cancel:
		{
			gB_MenuOpen[client] = false;
			PrintToServer("Client %d's menu was cancelled for reason %d", param1, param2);
		}
		case MenuCancel_Timeout:
		{
			FakeClientCommand(client, menuItem[param][itemCommand]);
		}
		case MenuAction_End:
		{
			delete menu;
		}
		case MenuAction_DrawItem:
		{
			int style;
			char info2[32];
			menu.GetItem(param2, info2, sizeof(info2), style);
			if (StrEqual(info2, CHOICE3))
			{
				return ITEMDRAW_DISABLED;
			}
			else
			{
				return style;
			}
		}
		case MenuAction_DisplayItem:
		{
			char info3[32];
			menu.GetItem(param2, info3, sizeof(info3));
			char display[64];
			if (StrEqual(info3, CHOICE3))
			{
				Format(display, sizeof(display), "%T", "Choice 3", param1);
				return RedrawMenuItem(display);
			}
		}
	}
	return 0;
}
__________________
Psyk0tik is offline
mikmik02
Junior Member
Join Date: Dec 2017
Location: In My Basement
Old 12-22-2017 , 15:48   Re: Help With Executing command
Reply With Quote #8

Quote:
Originally Posted by Crasher_3637 View Post
1. Don't use if(action == MenuAction_Select) WITHIN MenuAction_Select. That action is only called when a client actually selects one of the menu options.
2. I revised your code based on what you've given us to work with.
3. Another thing about that if(action == MenuAction_) part, your code was pretty redundant since the menu handler itself is already handling MenuAction_End and MenuAction_Cancel.
4. An alternative to if(action != MenuAction_Select) is MenuCancel_Timeout since you're only displaying it to the client for 10 seconds.
5. You have to define "client" in your menu handler if you're going to use it. I recommend using a for loop. (i.e. for(int i = 1; i <= MaxClients; i++))
6. I don't know what "param" was even used for. Since you have it in brackets, I'm guessing you mean to use char param[64]; instead of int param;? Since I also saw the if(param == -1), I say that you should probably give it an initial value and write up a code that tells the plugin when and what to add to that value.

Example:
Code:
int GetParamCount()
{
     int param = 0;
     for(int i = 1; i <= MaxClients; i++)
     {
          if(IsClientInGame(i) && IsClientConnected(i) && IsPlayerAlive(i))
          {
               paramcount++;
          }
     }

     return paramcount;
}
And thus, you can use:
Code:
int param = GetParamCount();
if(param == -1)
{
	gI_Setting[] = 1;
	SetClientCookie(client, gH_Cookie, "1");
	CPrintToChat(client, "%t%t", prefix, "MENU_DISABLED");
}
Now, again, I don't know what you're using "param" for so I'm taking guesses here.
7. I do not claim to have fixed your code. I only revised parts of it that I believe I knew how to.
8. SHOW US THE REST OF YOUR CODE.

Code:
public int MenuHandler1(Menu menu, MenuAction action, int param1, int param2)
{
	switch(action)
	{
		case MenuAction_Start:
		{
			PrintToServer("Displaying menu");
		}
		case MenuAction_Display:
		{
	 		char buffer[255];
			Format(buffer, sizeof(buffer), "%T", "Vote Nextmap", param1);
 
			Panel panel = view_as<Panel>(param2);
			panel.SetTitle(buffer);
			PrintToServer("Client %d was sent menu with panel %x", param1, param2);
		}
		case MenuAction_Select://SourceMod Batch Compiler
		{
			char info[32];
			menu.GetItem(param2, info, sizeof(info));
			if (StrEqual(info, CHOICE3))
			{
				PrintToServer("Client %d somehow selected %s despite it being disabled", param1, info);
			}
			else
			{
				PrintToServer("Client %d selected %s", param1, info);
			}
			gI_Setting[] = 1;
			SetClientCookie(client, gH_Cookie, "1");
			CPrintToChat(client, "%t%t", prefix, "MENU_DISABLED");
		}
		case MenuAction_Cancel:
		{
			gB_MenuOpen[client] = false;
			PrintToServer("Client %d's menu was cancelled for reason %d", param1, param2);
		}
		case MenuCancel_Timeout:
		{
			FakeClientCommand(client, menuItem[param][itemCommand]);
		}
		case MenuAction_End:
		{
			delete menu;
		}
		case MenuAction_DrawItem:
		{
			int style;
			char info2[32];
			menu.GetItem(param2, info2, sizeof(info2), style);
			if (StrEqual(info2, CHOICE3))
			{
				return ITEMDRAW_DISABLED;
			}
			else
			{
				return style;
			}
		}
		case MenuAction_DisplayItem:
		{
			char info3[32];
			menu.GetItem(param2, info3, sizeof(info3));
			char display[64];
			if (StrEqual(info3, CHOICE3))
			{
				Format(display, sizeof(display), "%T", "Choice 3", param1);
				return RedrawMenuItem(display);
			}
		}
	}
	return 0;
}
Im 100% certain thats all of my code. The fun part is that this code compiled a few days ago after first posting this thread and is used on my server at the moment. To day i was just gonna add a Tab Comp Rank to the vip menu and it dident compile. I havent touched the code since it compiled so i dont understand. Plugin attached. I tried switching out the handeler to the code you gave me and the compilor gave me errors
Code:
 //// simplevipmenu.sp
// C:\Users\mikae\Desktop\sourcemod-1.8.0-git6039-windows\addons\sourcemod\scripting\simplevipmenu.sp(16) : error 001: expected token: ";", but found "-identifier-"
// C:\Users\mikae\Desktop\sourcemod-1.8.0-git6039-windows\addons\sourcemod\scripting\simplevipmenu.sp(22) : error 001: expected token: ";", but found "-identifier-"
// C:\Users\mikae\Desktop\sourcemod-1.8.0-git6039-windows\addons\sourcemod\scripting\simplevipmenu.sp(22) : error 010: invalid function or declaration
// C:\Users\mikae\Desktop\sourcemod-1.8.0-git6039-windows\addons\sourcemod\scripting\simplevipmenu.sp(22 -- 24) : error 010: invalid function or declaration
// C:\Users\mikae\Desktop\sourcemod-1.8.0-git6039-windows\addons\sourcemod\scripting\simplevipmenu.sp(22 -- 24) : fatal error 127: too many error messages on one line
Thanks for the suggestions anyway.
Attached Files
File Type: smx cgvipmenu.smx (4.8 KB, 71 views)
mikmik02 is offline
Send a message via Skype™ to mikmik02
Psyk0tik
Veteran Member
Join Date: May 2012
Location: Homeless
Old 12-22-2017 , 16:03   Re: Help With Executing command
Reply With Quote #9

Quote:
Originally Posted by mikmik02 View Post
Im 100% certain thats all of my code. The fun part is that this code compiled a few days ago after first posting this thread and is used on my server at the moment. To day i was just gonna add a Tab Comp Rank to the vip menu and it dident compile. I havent touched the code since it compiled so i dont understand. Plugin attached. I tried switching out the handeler to the code you gave me and the compilor gave me errors
Code:
 //// simplevipmenu.sp
// C:\Users\mikae\Desktop\sourcemod-1.8.0-git6039-windows\addons\sourcemod\scripting\simplevipmenu.sp(16) : error 001: expected token: ";", but found "-identifier-"
// C:\Users\mikae\Desktop\sourcemod-1.8.0-git6039-windows\addons\sourcemod\scripting\simplevipmenu.sp(22) : error 001: expected token: ";", but found "-identifier-"
// C:\Users\mikae\Desktop\sourcemod-1.8.0-git6039-windows\addons\sourcemod\scripting\simplevipmenu.sp(22) : error 010: invalid function or declaration
// C:\Users\mikae\Desktop\sourcemod-1.8.0-git6039-windows\addons\sourcemod\scripting\simplevipmenu.sp(22 -- 24) : error 010: invalid function or declaration
// C:\Users\mikae\Desktop\sourcemod-1.8.0-git6039-windows\addons\sourcemod\scripting\simplevipmenu.sp(22 -- 24) : fatal error 127: too many error messages on one line
Thanks for the suggestions anyway.
Please provide the source code so I or anyone else can take a look at what's wrong.
__________________
Psyk0tik is offline
mikmik02
Junior Member
Join Date: Dec 2017
Location: In My Basement
Old 12-22-2017 , 16:35   Re: Help With Executing command
Reply With Quote #10

This is where im at right now
Code:
#pragma semicolon 1
#include <sourcemod>
#include <adminmenu>

//----------------------------------//
// Plugin: Display of Information //
//----------------------------------//
public Plugin:myinfo =
{
name = "cgvipmenu",
author = "liljekvist",
description = "vip menu",
version = "6.9",
url = ""
};

//------------------//
// Plugin: Start //
//------------------//
public OnPluginStart()
{
// Generate In-game Command
RegConsoleCmd("sm_vip", Command_sm_vip, "opens vip menu");
}

//---------------------------//
// CONSOLE COMMAND OPTIONS //
//---------------------------//
public Action:Command_sm_vip(client, args)
{
MainMenu(client);
}

*/
MainMenu(client) {
new Handle:menu = CreateMenu(Handler_FirstMenu);
// MENU TITLE
SetMenuTitle(menu, "Vip Menu");


AddMenuItem(menu, "function1", "CustomKnifes");
AddMenuItem(menu, "function2", "Models");
AddMenuItem(menu, "function3", "More Comming Soon...");

// CREATE EXIT BUTTON
SetMenuExitBackButton(menu, true);

// SEND THE MENU TO THE CLIENT
// To: CLIENT | Time: Forever (0)
DisplayMenu(menu, client, 10);
}

public Handler_FirstMenu(Handle:menu, MenuAction:action, client, param) {
// IF CLIENT HITS CLOSEMENU OPTION
if(action == MenuAction_End) {
CloseHandle(menu);
}
// IF THEY SELECT A NONE EXISTANT BUTTON
if(action != MenuAction_Select) {
return;
}

decl String:selection[16];
GetMenuItem(menu, param, selection, sizeof(selection));
// -- Function 1
// If the client selects this button
if(StrEqual(selection, "function1")) {
// Do Something Here
// Example:
FakeClientCommandEx(client,"sm_customknivesforvip1337");
ClientCommand(client, "sm_customknivesforvip1337");
PrintToChat(client, "CustomKnifes Selected.");
}
// -- Function 2
// If the client selects this button
if(StrEqual(selection, "function2")) {
// Do Something Here
// Example:
FakeClientCommandEx(client,"sm_modelsforvip1337");
ClientCommand(client, "sm_modelsforvip1337");
PrintToChat(client, "Models Selected.");
}
// -- Function 3
// If the client selects this button
if(StrEqual(selection, "function3")) {
// Do Something Here
// Example:
PrintToChat(client, "Comming Soon I Said...");
}
}
mikmik02 is offline
Send a message via Skype™ to mikmik02
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 16:34.


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