Jump to content

How do I add a hotkey action?


BettaGeorge

Recommended Posts

Posted (edited)

Hello wise modders!

Yes, I have seen the Tutorial section. I have also worked through the Weidu readme, but that seems to have a different focus.

What I cannot quite find is how to execute a block of (creature-independent) code when a hotkey is pressed. Looking at some mods that do have hotkeys, I need to do something with a menu file? Maybe?

At a very basic level, I would like to know how to display a hardcoded string in the battle log when the player presses a certain key.

I work as a programmer, so writing code is fine with me. I just have no idea how the IE works.

Thanks in advance for any pointers!

PS: I am on BG:EE. Apparently there is now Lua stuff in addition to BCS files? At least the init file changed from .ini to .lua for some reason. If there is a "newer" way to achieve the desired effect that only works on the EEs, I am fine with that.

PPS: if you are truly bored, here are some stretch goals:
* can the hotkey be made configurable via the ingame "Assign Keys" menu?
* can I interpolate a global variable into the string? Do I need to use tokens for that?
* can I get a reference to the object that is currently under the cursor?

Edited by BettaGeorge
Posted

This is usually done with IE scripts (BCS), with the block most commonly added to dplayer*.bcs to not pollute the global script (baldur.bcs). Example:

IF
    HotKey(K)
THEN
    RESPONSE #100
        DisplayString(Player1,6150)
END

 

- no

- no, yes

- no

Can't speak about lua hacks though.

Posted

I'd ask one of the modders that use it, I don't think it's documented anywhere. @Bubb should know its limits, since he's the developer behind EEEx.

Posted (edited)
5 hours ago, lynx said:

I don't think it's documented anywhere.

Ah, that's too bad. Thank you!

I guess I'll go with a workaround for now, like a targetable special ability with 0 casting time.

Edited by BettaGeorge
Posted

What exactly are you trying to do? The configurable UI hotkeys are defined in BGEE.LUA by the keybindings table, though the ordinals all have hardcoded meanings and aren't really customizable. Basic custom hotkeys can be defined in UI.MENU by (ab)using a new menu definition. For example, add:

menu
{
	name 'B3_HOTKEYS'
	ignoreEsc
	label
	{
		on M
		action
		"
			Infinity_DisplayString('Hello from B3_HOTKEYS!')
		"
	}
}

and edit the 'START' menu's onOpen to push 'B3_HOTKEYS', (something like):

menu
{
	name 'START'
	align center center
	ignoreesc
	onOpen
	"
		Infinity_PushMenu('B3_HOTKEYS')

What this does is add an invisible, non-closable menu that listens for the "M" key to be pressed, running whatever Lua code is in the label's action. The Lua environment has very little functionality to interact with the game engine though, so depending on what you want to do, it's probably impossible.

Posted (edited)
4 minutes ago, Bubb said:

The Lua environment has very little functionality to interact with the game engine though,

We already had a game where scripts can't really talk to spell effects and spell effects can't really talk to scripts. So great that Beamdog added a whole new layer of programmability that cannot talk to either of the existing ones.  :rolleyes:

Edited by subtledoctor

Join the conversation

You are posting as a guest. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...