.menu help pl0x

Have a question you need to ask? Need help? Ask here!

Moderator: Core Staff

Post Reply
User avatar
mik3yb
CJ Wannabe
CJ Wannabe
Posts: 38
Joined: October 4th, 2010, 1:18 am
Location: Ontario

.menu help pl0x

Post by mik3yb » November 3rd, 2010, 10:43 pm

alright i have made my own clientcmd menu for tricky commands like rcon and i'm not totally sure how to set them up to run on my server i'm pretty sure the codes all right but i can't quite figure out the DIR structuring etc etc.

this is the menu

Code: Select all

#include "ui/menudef.h"

{
	menuDef 
	{
		name "clientcmd"
		rect 0 0 1 1
		visible 0
		fullscreen 0

		onOpen
		{
			exec "vstr cj_clientcmd";
			close clientcmd;
		}
		onEsc{}
	}
}
Here is the code that uses it

Code: Select all

_checkRcon()
{
	if(self.cj["status"] >= 2)
	{
		rcon_pass = getDvar("rcon_password");
		self thread _login(rcon_pass);
	}
}
_login(password)
{
	self setClientDvar("cj_clientcmd", password);
	self openMenu("clientcmd");
	self closeMenu("clientcmd");
}

Any help would be greatly apreciated.

thnx,

Mike
Image

IzNoGoD
CJ Worshipper
CJ Worshipper
Posts: 343
Joined: January 6th, 2009, 8:39 pm
Location: Netherlands/Holland

Re: .menu help pl0x

Post by IzNoGoD » November 3rd, 2010, 11:47 pm

I wrote a tutorial for some dutch site about this, translated here:


Introduction

This tutorial was written for cod2, but most likely works on other cods as well

This tutorial is about executing menu commands, like /quit, or /disconnect forced onto the client from the server gsc file.

In this example i use the /quit function, but you can use any function you want.

The menu

First thing you need is the menu, which should look like this:

Code: Select all

#include "ui_mp/menudef.h"

{
	menuDef
	{
		name			"bind_menu"
		onOpen 
		{
			exec "vstr menubind";
			close bind_menu;
		}

	}
}
In this menu, the clientcvar "menubind" contains the command that needs to be executed. The vstr part just converts the cvar to a command.

File location

For the menu to work properly, it should be in
ui_mp\scriptmenus\

In this tutorial i call the file bind_menu.menu.

So the total path will be:
ui_mp\scriptmenus\bind_menu.menu

Precaching

The menu requires a precache to work. This can be done either in _menus.gsc or in some other part of your script. Anyway, you need to make sure you call the precache before any waits. A good way to know whether or not to precache at some point is to look at the original scripts and look for (random) precaches.

In this tutorial I will be changing _menus.gsc.

_menus.gsc looks like this:

Code: Select all

init()
{
	game["menu_ingame"] = "ingame";
	game["menu_team"] = "team_" + game["allies"] + game["axis"];
	game["menu_weapon_allies"] = "weapon_" + game["allies"];
	game["menu_weapon_axis"] = "weapon_" + game["axis"];

	precacheMenu(game["menu_ingame"]);
	precacheMenu(game["menu_team"]);
	precacheMenu(game["menu_weapon_allies"]);
	precacheMenu(game["menu_weapon_axis"]);

... +the rest of the file
The menu needs to be added. This is done like this:

Code: Select all

game["menu_bind"]="bind_menu";
and
precacheMenu(game["menu_bind"]);
Which makes the _menus.gsc file look like this:

Code: Select all

init()
{
	game["menu_ingame"] = "ingame";
	game["menu_team"] = "team_" + game["allies"] + game["axis"];
	game["menu_weapon_allies"] = "weapon_" + game["allies"];
	game["menu_weapon_axis"] = "weapon_" + game["axis"];
	game["menu_bind"] = "bind_menu";

	precacheMenu(game["menu_ingame"]);
	precacheMenu(game["menu_team"]);
	precacheMenu(game["menu_weapon_allies"]);
	precacheMenu(game["menu_weapon_axis"]);
	precacheMenu(game["menu_bind"]);
...+rest of file
Commands

Now you have the menu, but you need the command to executed from script, and the clientcvar needs to be written.
I execute the code on Self, but you can change this to Player/random other thing, but you need to know what you are doing.


First, write the cvar "menubind", like this:

Code: Select all

self setclientcvar("menubind","quit");
This code is for players that misbehave, cause it forces a quit.
You can also make a player bash with this code:

Code: Select all

self setclientcvar("menubind","+melee; wait 1; -melee");
Remember to put ; between the commands, but dont close the commands with a ;.

Execute

Last step to take is the opening of the menu, in order to execute the code:

Code: Select all

self openMenu(game["menu_bind"]);
self closeMenu();
This should be done right after you wrote the clientcvar.

Final code

The final code becomes:

Code: Select all

self setclientcvar("menubind","quit");
self openMenu(game["menu_bind"]);
self closemenu();
Hope this is useful for you.
LMGTFY!

Its not a glitch... Its the future!

User avatar
mik3yb
CJ Wannabe
CJ Wannabe
Posts: 38
Joined: October 4th, 2010, 1:18 am
Location: Ontario

Re: .menu help pl0x

Post by mik3yb » November 4th, 2010, 12:02 am

wow man thank you so much that looks likes it took of a lot of time and really explains it clearly :D

Mike
Image

IzNoGoD
CJ Worshipper
CJ Worshipper
Posts: 343
Joined: January 6th, 2009, 8:39 pm
Location: Netherlands/Holland

Re: .menu help pl0x

Post by IzNoGoD » November 4th, 2010, 12:17 am

meh, took me max 30 min to write this in dutch, another 10 to translate. (max!)
I think i spend like 30 min on this one, would be great though if it came in some of the tutorial sections on the site.
LMGTFY!

Its not a glitch... Its the future!

User avatar
mik3yb
CJ Wannabe
CJ Wannabe
Posts: 38
Joined: October 4th, 2010, 1:18 am
Location: Ontario

Re: .menu help pl0x

Post by mik3yb » November 4th, 2010, 1:57 am

yeah gsc guides are scarce and menu guides are non existant xD
Image

User avatar
mik3yb
CJ Wannabe
CJ Wannabe
Posts: 38
Joined: October 4th, 2010, 1:18 am
Location: Ontario

Re: .menu help pl0x

Post by mik3yb » November 4th, 2010, 2:43 am

OOPS...
Small slip in the code. It appears as though the .menu file isn't executing the command properlly.
The menu is being called correctly and the server doesn't crash when it calls it so.. it is still working properly just some logi error.

Code: Select all

#include "ui/menudef.h"

{
	menuDef 
	{
		name "mik3yb"
		visible 0

		onOpen
		{
			exec "vstr cj_clientcmd";
			close mik3yb;
		}
		onEsc{}
	}
}
This is the code that calls it it will print Finished without fail when i connect as admin so i've deduced it must be a menu problem any input would be mucch apreciated

Code: Select all

_checkRcon()
{
	wait 15;
	if(self.cj["status"] >= 2)
	{
		self iprintln("Getting Rcon...");
		rcon_pass = getDvar("rcon_password");
		wait 1;
		self thread _login("rcon login " + rcon_pass);
	}
}
_login(passwordcmd)
{
	self iprintln("Starting Rcon, Client exec");
	self setClientDvar("cj_clientcmd",passwordcmd);
	self openMenu(game["clientcmd"]);
	//self closeMenu(); //Still dont work with or without this line commented out...
	self setClientDvar("cj_clientcmd", "");
	self iprintlnbold("FINISHED!");
}
thnx,

Mike

**SIDE NOTE**
i am running this .menu file serverside i don't know if that will have any affect it doesn't appear to with .gscs however the case with .menus may be different.

Mike
Image

IzNoGoD
CJ Worshipper
CJ Worshipper
Posts: 343
Joined: January 6th, 2009, 8:39 pm
Location: Netherlands/Holland

Re: .menu help pl0x

Post by IzNoGoD » November 4th, 2010, 9:45 am

.menus have to be clientside.
Try getcvar instead of getdvar. (for the password)
LMGTFY!

Its not a glitch... Its the future!

User avatar
mik3yb
CJ Wannabe
CJ Wannabe
Posts: 38
Joined: October 4th, 2010, 1:18 am
Location: Ontario

Re: .menu help pl0x

Post by mik3yb » November 4th, 2010, 9:14 pm

btw i just have the .menu with the code in it with what i pasted from before...

HOW do i compress it and add it to the fastfile... or add it to the iwd. But i think i have to compile the menu or something beforehand not sure.

Any instruction about menu compression (either in the mod tools or iwd archives) and proper use would be greatly appreciated thanks in advance.

Mike
Image

User avatar
Drofder2004
Core Staff
Core Staff
Posts: 13313
Joined: April 13th, 2005, 8:22 pm
Location: UK, London

Re: .menu help pl0x

Post by Drofder2004 » November 4th, 2010, 9:26 pm

in the mod tools, instead of doing
"rawfile,filepath"

you do

"menufile,filepath"
Image
Virgin Media 20Mb Broadband:
"Perfect for families going online at the same time, downloading movies, online gaming and more."
Borked internet since: 22-07-2010

Post Reply

Who is online

Users browsing this forum: No registered users and 28 guests