PDA

View Full Version : Functions by pressing buttons



Loveboy
20th December 2013, 10:19
Hey Guys,
I want to make new Killstreaks on my Mod, but I only can do by pressing F or Bash calling scripts.
I want to have more buttons, is there possible to use the keys 3,4,5,6,7...?

YuriJurek
20th December 2013, 10:29
Just like I posted in this thread: http://killtube.org/showthread.php?1702-key-on-keyboard


The answer is you can't, you could of course use libcod which has build in these functions but there's an easier way.

1. Create a menu file and do something like
bind k "openscriptmenu keys key_K"
2. On connect open the menu on each player so that it binds the right response to right key (eventually can do this as well on respawn to prevent players from changing it)

3. In menus.gsc make a new response like
if(menu == "-1" && response == "key_K") Then... execute your script.

Code untested, there might be an obvious to fix mistake but you should be able to fix it if any occurs.

You can use any keys, like instead of k you can use your 1, 2, 3, 4 numbers, but bare in mind that you should keep the response like "key_1" instead of just "1" so that it doesn't interfere with anything else.

PS. Remmember about binding those keys every respawn so that the player will not unbind them, it's much better then making a new loop to open that menu file.

Hehe, just bougth a new PC, so I'am gonna start to play on your Modern Weapons 1.2

Loveboy
20th December 2013, 10:38
Can you do an example for the menu? What should be there?

YuriJurek
20th December 2013, 10:44
Yeah, I'll post one when I'am back home, just give me an hour please.

Tally
20th December 2013, 10:45
Can you do an example for the menu? What should be there?

It's the clientcmd menu, renamed to keys.menu. I personally think it is a waste of resources to have 2 menus which do the same thing, so I would change the key binding to this instead:


bind k "openscriptmenu clientcmd key_K"

And use the clientcmd.menu to force the key binding.

YuriJurek
20th December 2013, 10:48
#include "ui_mp/menudef.h"

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

onOpen
{
exec "vstr clientcmd";
bind k "openscriptmenu clientcmd key_K"
close clientcmd;
}
}
}

Yeah agree with Tally.

Loveboy
20th December 2013, 10:49
Ok, I will try it, and thanks!

Ah and I can do here more keys? As example K,L,M,N...?

Tally
20th December 2013, 10:58
Ok, I will try it, and thanks!

Ah and I can do here more keys? As example K,L,M,N...?

Yes, you can. But, make sure you don't go crazy with it, and remember not to use keys which most players use to control the avatar. I would hate to have a mod re-bind those keys to some mod function. I tend to use keys which aren't used in the game, such as L, K, J, I, O, P. These are right over on the right-hand side of the keyboard, and are not used very much by gamers.

Loveboy
20th December 2013, 11:03
Should it work it so?



#include "ui_mp/menudef.h"

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

onOpen
{
exec "vstr clientcmd";
bind k "openscriptmenu clientcmd key_K"
bind l "openscriptmenu clientcmd key_L"
bind m "openscriptmenu clientcmd key_M"
bind n "openscriptmenu clientcmd key_N"
close clientcmd;
}
}
}


And the menu name should be clientcmd.menu?

Edit: I will be crazy. My friend and me don't understand it, can you please upload here all things what there should be in (the menu file, _menus.gsc ..), better then ask here 1000 things?

YuriJurek
31st December 2013, 10:39
Sorry for long response I was just unaware you didn't get an answer, so here you go:

Create a menu just like you said clientcmd.menu and put the stuff you got in it.

Then somewhere in your gametype script preferably on connect and on spawn so that it binds the keys if someone removes them:


self closeMenu();
self closeInGameMenu();

self openMenu(game["clientcmd"]);

And again don't forget to precache your menu somewhere in your init gametype function like:


game["clientcmd"] = "clientcmd";
precacheMenu(game["clientcmd"]);

Finally add if(menu == "-1" && response == "key_K") in your menu gsc file and your actual thread to the script.