Raised This Month: $32 Target: $400
 8% 

calling a command with menus


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
sukodaime
Junior Member
Join Date: May 2021
Old 07-18-2021 , 15:31   calling a command with menus
Reply With Quote #1

Code:
#pragma semicolon 1
#define DEBUG
#define PLUGIN_AUTHOR "Me :D"
#define PLUGIN_VERSION "1.0"
#include <sourcemod>
#include <sdktools>

int active = 0; 
int doneactive = 0;
public OnPluginStart()
{
	active = 0;
	doneactive = 0;
	RegAdminCmd("sm_grav",gravv, ADMFLAG_ROOT);
	RegAdminCmd("sm_menus",menuss, ADMFLAG_ROOT);
	HookEvent("round_end", OnRoundEnd, EventHookMode_PostNoCopy);
	HookEvent("round_start", OnRoundStart, EventHookMode_PostNoCopy);
	
}
public Action:gravv(client, args)
{
	if(active!=0){
		PrintToChat(client, "Cant be  done again while its active");
		return;
	}
	active = 1;
	PrintToChatAll("gravity will be 100 later this round");

}

public OnRoundEnd(Handle:event, const String:name[], bool:dontBroadcast){
	if(doneactive!=0){
		if(active==1){
			ServerCommand("sm_cvar sv_gravity 800");
		}
		active = 0;
		doneactive = 0;
	}
}
public OnRoundStart(Handle:event, const String:name[], bool:dontBroadcast){
	if(active==1){
		ServerCommand("sm_cvar sv_gravity 100");
		
		doneactive = 1;
	}
}
public Action menuss(int client,int args){
	Menu menu = new Menu(Menu_Callback);
	menu.SetTitle("gravactive");
	menu.AddItem("grav", "gravity");
	menu.Display(client, MENU_TIME_FOREVER);
	return Plugin_Handled;
}
public int Menu_Callback(Menu menu, MenuAction action,int param1,int param2){
	switch (action){
		case MenuAction_Select:
		{
			char item[64];
			menu.GetItem(param2, item, sizeof(item));
			
			if(StrEqual(item,"grav")){
				ServerCommand("sm_grav");
			}
			
		}
		case MenuAction_End:
		{
			delete menu;
		}
		
	}
}
this says "Cant be done again while its active" if i type !grav again while its active but if i make it active with menu it doesn't say "Cant be done again while its active" (it says gravity will be 100 later this round when first i make from menu but it doesn't say cat be done again while its active when i do it second time)
sukodaime is offline
Bacardi
Veteran Member
Join Date: Jan 2010
Location: mom's basement
Old 07-18-2021 , 19:31   Re: calling a command with menus
Reply With Quote #2

What would happen if you replace
Code:
ServerCommand("sm_grav");

to

FakeClientCommandEx(param1, "sm_grav");
__________________
Do not Private Message @me
Bacardi is offline
sukodaime
Junior Member
Join Date: May 2021
Old 07-19-2021 , 10:09   Re: calling a command with menus
Reply With Quote #3

Quote:
Originally Posted by Bacardi View Post
What would happen if you replace
Code:
ServerCommand("sm_grav");

to

FakeClientCommandEx(param1, "sm_grav");
ohhh i see...
thanks the client was console then that why it didn't say it to me
sukodaime is offline
sukodaime
Junior Member
Join Date: May 2021
Old 07-19-2021 , 10:25   Re: calling a command with menus
Reply With Quote #4

can i pass a second userid somehow to the menu?
sukodaime is offline
Bacardi
Veteran Member
Join Date: Jan 2010
Location: mom's basement
Old 07-19-2021 , 11:53   Re: calling a command with menus
Reply With Quote #5

I don't fully understand... can you tell what you try accomplish ?

Now, who ever use command in a round, server will change gravity on next round_start.
At round_end, server change gravity back.
Bacardi is offline
sukodaime
Junior Member
Join Date: May 2021
Old 07-19-2021 , 13:00   Re: calling a command with menus
Reply With Quote #6

Quote:
Originally Posted by Bacardi View Post
I don't fully understand... can you tell what you try accomplish ?

Now, who ever use command in a round, server will change gravity on next round_start.
At round_end, server change gravity back.
plugin works nice but i wanted to know if i can pass another value to the menucallback internally
i mean param1 is client right i want to make param3 another client but without a global variable
sukodaime is offline
Bacardi
Veteran Member
Join Date: Jan 2010
Location: mom's basement
Old 07-19-2021 , 13:26   Re: calling a command with menus
Reply With Quote #7

param1 has different meaning in each MenuAction.
You need look what it will offer in each MenuAction case.
Code:
Example:
MenuAction_Select = An item was selected (param1=client, param2=item)
MenuAction_Cancel = The menu was cancelled (param1=client, param2=reason)

MenuAction_End = A menu display has fully ended.
      param1 is the MenuEnd reason, and if it's MenuEnd_Cancelled, then
      param2 is the MenuCancel reason from MenuAction_Cancel.



You can continue creating new menu, select player ?
PHP Code:
...
public 
Action menuss(int client,int args){
    
Menu menu = new Menu(Menu_Callback);
    
menu.SetTitle("gravactive");
    
menu.AddItem("grav""gravity");
    
menu.Display(clientMENU_TIME_FOREVER);
    return 
Plugin_Handled;
}
public 
int Menu_Callback(Menu menuMenuAction action,int param1,int param2){
    switch (
action){
        case 
MenuAction_Select:
        {
            
char item[64];
            
menu.GetItem(param2itemsizeof(item));
            
            if(
StrEqual(item,"grav")){
                
//ServerCommand("sm_grav");
                
Menu menu2 = new Menu(Menu_targets_Callback);
                
menu2.SetTitle("gravactive");
                
AddTargetsToMenu(menu2param1truefalse);
                
menu2.Display(param1MENU_TIME_FOREVER);
            }
            
        }
        case 
MenuAction_End:
        {
            
delete menu;
        }
        
    }
}

public 
int Menu_targets_Callback(Menu menuMenuAction action,int param1,int param2){
    switch (
action){
        case 
MenuAction_Select:
        {
            
char item[64];
            
menu.GetItem(param2itemsizeof(item));
            
            
int userid StringToInt(item);

            
PrintToServer("- userid %i"userid);
            
FakeClientCommandEx(GetClientOfUserId(userid), "kill");
        }
        case 
MenuAction_End:
        {
            
delete menu;
        }
        
    }

__________________
Do not Private Message @me
Bacardi 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 04:13.


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