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.