binding keys to commands

  • Two Factor Authentication is now available on BeyondUnreal Forums. To configure it, visit your Profile and look for the "Two Step Verification" option on the left side. We can send codes via email (may be slower) or you can set up any TOTP Authenticator app on your phone (Authy, Google Authenticator, etc) to deliver codes. It is highly recommended that you configure this to keep your account safe.

Blödsinn machen

cannon fodder
Dec 4, 2001
68
0
0
Switzerland
dwmade.stormpages.com
sorry for this annoying query....
but, I want to bind commands to keys, and the only clue I have is that this somehow involves UTExtraKeyBindings. So I've got a bunch of labels and alias names, but how do I actually get an alias bound to a key?
please advise :hmm:
 

Papapishu

我是康
Jun 18, 2001
2,043
0
0
43
void
www.vovoid.com
Here's a good way to do it, it's stolen from "Carry The Flag" which btw is a great gametype... ;)
It uses the keybindings class and a mutator to get the input...

Code:
class CarryTFKeyBindings expands UTExtraKeyBindings;

defaultproperties
{
     SectionName="Carry The Flag"
     LabelList(0)="Pickup/Drop Flag"
     AliasNames(0)="mutate FlagToggle"
}
This is the UTExtraKeyBindings class, the sectionname, labellist and aliasnames is the place on the keybindings window this takes place, the label(s) of the different keys you want to bind, and then the alias(es) (commands) associated with those bindings.
Thisone makes room for one keybinding which on the menu is labeled "Pickup/Drop Flag" and that when you press the key sends the consolecommand "mutate FlagToggle"
That command calls the mutate exec function in this mutator:

Code:
function Mutate(string MutateString, PlayerPawn Sender)
{
    local FlagBase aBase;
    local CarryTFCTFFlag aFlag;
    local byte Team;
    
    if (MutateString ~= "FlagToggle")
    {
        if ( Sender.PlayerReplicationInfo.HasFlag != None )
        {
            if ( VSize(Sender.Location - CarryTFCTFFlag(Sender.PlayerReplicationInfo.HasFlag).HomeBase.Location) < Distance )
            {
                CarryTFCTFFlag(Sender.PlayerReplicationInfo.HasFlag).SendHome();
            }
            else
            {
                CarryTFCTFFlag(Sender.PlayerReplicationInfo.HasFlag).Throw();
            }
        }
        else
        {
            Team = Sender.PlayerReplicationInfo.Team;                
            aFlag = CarryTFCTFFlag(CTFReplicationInfo(Level.Game.GameReplicationInfo).FlagList[Team]);
            aBase = aFlag.HomeBase;
            if ( VSize(Sender.Location - aBase.Location) < Distance && aFlag.IsInState('Home') && bTakeFriendlyFlag)
            {
                aFlag.SetHolder(Sender);
                aFlag.bPickedUpManual = true;
            }
        }
    }
    if ( NextMutator != None )
		NextMutator.Mutate(MutateString, Sender);
}
Every mutator has the "mutate" function and you can send a specific command to the mutator that way.
The previous codesnipplet sent "mutate flagtoggle" which is captured here and you can see that when the function gets the parameter "flagtoggle" it runs some code, and this is where you put your code...

But the most important piece to make this work is that you must have the ability to bind your key, that is, the keybinding meny won't show up without a proper .int-file and that one goes like this:

Code:
[Public]
Object=(Name=CarryTFv102.CarryTFKeyBindings,Class=Class,MetaClass=UTMenu.UTExtraKeyBindings)
This tells UT how to handle the code, and draws the section and bindcontrolls correctly
Hope that helps :)
 

Captain Kewl

I know kewl.
Feb 13, 2001
794
0
0
IN YOUR HOUSE
Visit site
To further obfuscate: you can also set bindings in the console by typing

set input [key] [command]

So if you wanted to bind "mutate flagtoggle" to the "z" key, type:

set input z mutate flagtoggle
 

Papapishu

我是康
Jun 18, 2001
2,043
0
0
43
void
www.vovoid.com
well you don't have to use a mutator, you can make an exec function.
like:
exec function dosomething (myparams)
{
...
}
Then replace the mutate command with just "dosomething anything" or so...
I don't know if this really works, since I haven't tried it...
or you can use this code to make the gametype spawn a mutator that can do this if you find it simpler..
Code:
	local Mutator M, Last;
	local CarryTFMutator Mut;
	local class<Mutator> MutatorClass;

	Super.InitGame(Options, Error);

	MutatorClass = class<Mutator>(DynamicLoadObject("CarryTFv102.CarryTFMutator", class'Class'));

	for (M = BaseMutator; M != None; M = M.NextMutator)
	{
		if (M.class == MutatorClass)
		{
			Last.NextMutator = M.NextMutator;
			M.NextMutator = BaseMutator.NextMutator;
			BaseMutator.NextMutator = M;
			break;
		}
		else
		{
			Last = M;
		}
	}
	if (M == None)
	{
		M = Spawn(MutatorClass);
		M.NextMutator = BaseMutator.NextMutator;
		BaseMutator.NextMutator = M;
	}
(also taken from carry the flag.
This is called in the initgame function of your gametype and it spawns a mutator ascosiated with your gametype.
You can code that mutator to works as I said above...

To store your settings in a config file, I think you must declare your gametype with config like this:
class MyGameType extends DeathmatchPlus Config;
Then to make the variables be saved in the unrealtournament.ini file you use:
var() globalconfig int MyVar
or
var() config int MyVar;
I don't really know the difference, since both saves in the ini file...
It's saved under the sectionpattern:
[MyType.MyGame]

And about the console command, sure o can bind a key thatway, but newbies don't know about it which is why one have the settings windows ;)
 

Blödsinn machen

cannon fodder
Dec 4, 2001
68
0
0
Switzerland
dwmade.stormpages.com
thanks again for the code. I'll see what I can do (which is probably equivalent to nothing).
I think declaring a class as globalconfig as opposed to config will store variables in the unrealtournament.ini file instead of the YourPackageName.ini file. that, I'm afraid, is probably the extent of my unrealscripting ability.. :(