Detecting Keypress / Action

Discussions about Coding and Scripting
User avatar
ExpEM
Adept
Posts: 302
Joined: Wed Nov 09, 2016 1:48 am

Re: Detecting Keypress / Action

Post by ExpEM »

Hmm, i like this idea and tried to implement it. In the game's preferences for controls, what is the command for activating the selected item?
Using the game menu, "InventoryActivate" isn't listed. To access it you have to go into RawKeyBindings. By default it is set to 'Enter'.
Also, i am curious how to set an inventory item as selected for a given Pawn / PlayerPawn....
This shouldn't actually be a problem, only inventory items with bActivatable set to true can be interacted with and as UT doesn't use this functionality, none of the UT pickups (should) have it set as true.
Having looked at it some items do have it set to true... I'll get back to you on this one.
I see M_Selected, but is simply a localized name for an Inventory item it seems.
Hmm....

Code: Select all

Pawn Class
var travel Inventory	SelectedItem;	// currently selected inventory item
And is the proper way to ensure the Inventory item never is dropped, is to override the DropFrom and BecomePickup methods, and essentially make them empty?
Like all inventory, unless it is your active weapon, it will be destroyed when you die so no need to mess with anything.
Have a close look at the Stealth mutator and how it works.
This line:

Code: Select all

inv.RespawnTime = 0.0;
Stops the Stealth Inventory Item from respawning.

--------------------------------------------------------------------
I'm back.

In class Pawn

Code: Select all

// The player/bot wants to select next item
exec function NextItem()
{
	local Inventory Inv;

	if (SelectedItem==None) {
		SelectedItem = Inventory.SelectNext();
		Return;
	}
	if (SelectedItem.Inventory!=None)
		SelectedItem = SelectedItem.Inventory.SelectNext(); 
	else
		SelectedItem = Inventory.SelectNext();

	if ( SelectedItem == None )
		SelectedItem = Inventory.SelectNext();
}
In class Inventory

Code: Select all

//
// Select first activatable item.
//
function Inventory SelectNext()
{
	if ( bActivatable ) 
	{
		if ( M_Selected != "" )
			Pawn(Owner).ClientMessage(ItemName$M_Selected);
		return self;
	}
	if ( Inventory != None )
		return Inventory.SelectNext();
	else
		return None;
}
So... when your Mutator gives the Item to the player, your Item will become the first in the players inventory list that is activatable aka it will be the SelectedItem by default.
Picking up further items will add them later in the list but wont change what is selected.
In effect we can override the NextItem key (from pawn) in your inventory class just by modifying SelectNext in your inventory to always return itself.

Code: Select all

Psudo code
function Inventory SelectNext()
{
	return self;
}
Unfortunately, we can't override PrevItem in the PlayerPawn class as it doesn't call anything from Inventory. This is just something that can't be dummy proofed. :noidea
Signature goes here.
1337GameDev
Skilled
Posts: 198
Joined: Thu Apr 16, 2020 3:23 pm
Personal rank: GameDev

Re: Detecting Keypress / Action

Post by 1337GameDev »

sektor2111 wrote: Sat Mar 20, 2021 9:38 pm I would pay attention to not break Inventory chain - that's another linked list...

Key for activating an item goes somewhere in keys menu assignment - now, I don't know if I have bound something there because... usually I don't play games requiring this function...
I'll make sure to not break the linked list.

And "goes somewhere" is the part I'm having trouble with. What key binding entry is it?
User avatar
ExpEM
Adept
Posts: 302
Joined: Wed Nov 09, 2016 1:48 am

Re: Detecting Keypress / Action

Post by ExpEM »

1337GameDev wrote: Sun Mar 21, 2021 3:33 am
sektor2111 wrote: Sat Mar 20, 2021 9:38 pm I would pay attention to not break Inventory chain - that's another linked list...

Key for activating an item goes somewhere in keys menu assignment - now, I don't know if I have bound something there because... usually I don't play games requiring this function...
I'll make sure to not break the linked list.

And "goes somewhere" is the part I'm having trouble with. What key binding entry is it?
InventoryActivate isn't accessible from the menu in game, to change it go through the console. You can also use the console in the editor to do the same thing.
Signature goes here.
1337GameDev
Skilled
Posts: 198
Joined: Thu Apr 16, 2020 3:23 pm
Personal rank: GameDev

Re: Detecting Keypress / Action

Post by 1337GameDev »

ExpEM wrote: Sun Mar 21, 2021 4:45 am
1337GameDev wrote: Sun Mar 21, 2021 3:33 am
sektor2111 wrote: Sat Mar 20, 2021 9:38 pm I would pay attention to not break Inventory chain - that's another linked list...

Key for activating an item goes somewhere in keys menu assignment - now, I don't know if I have bound something there because... usually I don't play games requiring this function...
I'll make sure to not break the linked list.

And "goes somewhere" is the part I'm having trouble with. What key binding entry is it?
InventoryActivate isn't accessible from the menu in game, to change it go through the console. You can also use the console in the editor to do the same thing.
That's really dumb. What the hell. Why isn't it?
User avatar
ExpEM
Adept
Posts: 302
Joined: Wed Nov 09, 2016 1:48 am

Re: Detecting Keypress / Action

Post by ExpEM »

1337GameDev wrote: Sun Mar 21, 2021 4:52 am
ExpEM wrote: Sun Mar 21, 2021 4:45 am
1337GameDev wrote: Sun Mar 21, 2021 3:33 am
sektor2111 wrote: Sat Mar 20, 2021 9:38 pm I would pay attention to not break Inventory chain - that's another linked list...

Key for activating an item goes somewhere in keys menu assignment - now, I don't know if I have bound something there because... usually I don't play games requiring this function...
I'll make sure to not break the linked list.

And "goes somewhere" is the part I'm having trouble with. What key binding entry is it?
InventoryActivate isn't accessible from the menu in game, to change it go through the console. You can also use the console in the editor to do the same thing.
That's really dumb. What the hell. Why isn't it?
:noidea Epic decided we didn't need it because UT didn't use it?

Edit:
We probably wouldn't have it at all if UT wasn't built on top of Unreal.
Signature goes here.