Jump to content

[UI] Making Cheat key more accessible


Recommended Posts

I'm looking for a way to make one of cheat keys (specifically CTRL+P, screen lock) more accessible during play. By this I mean things like:

  • possibility to bind it to some hotkey
  • making button that would invoke it
  • applying it automatically on some condition (e.g. on character selection)

I'm totally new to UI modding so I don't know if this topic is something like "sure, can be done" or "maybe with EEEx" or "no way, forget it" type of thing. 

BTW Can you recommend any good resources for learning UI modding?

I'm targeting only EEs.

Link to comment

It seems that this topic is "no one knows" type of thing. :D 

Here is couple of my findings:

  • UI can be edited by altering UI.menu file. It can specify placement and visuals of buttons and what engine actions to perform on click, double click etc. Engine actions that are exposed are quite high level so we have something like "Infinity_OnPortraitDblClick(0)". However it is possible to execute console commands using C:{command} syntax and consequently, it can be used to execute script actions with C:Eval('..').
  • It is possible to extend existing behavior so replacing "Infinity_OnPortraitDblClick(0)" with "Infinity_OnPortraitDblClick(0) C:Eval('..')" would perform both actions.
  • I haven't tested adding new button, but is seems to be possible (for sure there are mods that add button during character creation).
  • In my case CTRL+P can be more or less replaced with C:Eval('ActionOverride(..., LockScroll())'), but it works a bit differently: for some buttons it adds lock scroll at the end of creature action list, for other buttons it overwrites action list with lock scroll action, I don't know why different buttons imply different behavior. CTRL+P seems to be more independent from creature action list.
  • Hotkeys are stored in BGEE.lua in lines like "{ 1, 1, 'Inventory', "ASSIGN_KEYS_PAGE_INVENTORY", '', 0, 105 },", it seems that first number is kind of id. But I have no idea how to extend it so it would execute some lua function or something like this.
  • There is also "HotKey(..)" script trigger, but no idea how I could track from scripts which creature is pointed by cursor.

It would be super cool to know how to execute CTRL+P behavior with console command (or other exposed function). It would basically solve my problem (putting aside hotkey possibility).

 

For resources I found:

Edited by marchitek
Link to comment

UI.MENU has Infinity_PressKeyboardButton() to emulate keypresses, but I think it only accepts "escape", "space", and single-character strings. So, no sending a "CTRL" character.

The LockScroll() action sets the same internal field as CTRL+P. The difference is that LockScroll() locks the viewport to the creature that executes the action, and CTRL+P uses whatever creature is currently under the cursor.

C:Eval() appends its action to the action queue of a creature, normally the creature currently under the cursor, though if a second parameter of [0-5] is given, it instead adds the action to the player in that portrait index. ActionOverride() clears any actions on the target creature that weren't from another ActionOverride().

Emulating CTRL+P with EEex is as simple as:

function LockScroll()

    local id = EEex_GameObject_GetUnderCursorID()
    if not EEex_GameObject_IsSpriteID(id) then
        id = -1
    end

    EngineGlobals.g_pBaldurChitin.m_pEngineWorld.m_scrollLockId = id
end
Link to comment
On 4/9/2023 at 1:15 AM, Bubb said:

C:Eval() appends its action to the action queue of a creature, normally the creature currently under the cursor, though if a second parameter of [0-5] is given, it instead adds the action to the player in that portrait index. ActionOverride() clears any actions on the target creature that weren't from another ActionOverride().

Ah, now all make sense. I was wondering why C:Eval('ActionOverride(..., LockScroll())') works differently when I apply it after dbl click on portrait and dbl click on "select all". But since hovering portrait is equivalent to hovering on creature, action override was skipped and action was applied at the end of action list instead of overwrite. 

 

On 4/9/2023 at 1:15 AM, Bubb said:

Emulating CTRL+P with EEex is as simple as:

function LockScroll()

    local id = EEex_GameObject_GetUnderCursorID()
    if not EEex_GameObject_IsSpriteID(id) then
        id = -1
    end

    EngineGlobals.g_pBaldurChitin.m_pEngineWorld.m_scrollLockId = id
end

Perfect! This runs much smoother and omits action list completely. So I can have two versions, one for non EEex and one for EEex installations. What is best way to detect if EEex is installed? Should it be done on installation time or rather in runtime?

Link to comment

Depends when you want your code to decide which method it is using. You can detect if EEex is installed in a .tp2 with:

MOD_IS_INSTALLED ~EEex.tp2~ ~0~

In the game's Lua environment, you can use:

if EEex_Active then
    -- EEex method
else
    -- Non-EEex method
end
Link to comment
19 hours ago, Bubb said:

Depends when you want your code to decide which method it is using. You can detect if EEex is installed in a .tp2 with:

MOD_IS_INSTALLED ~EEex.tp2~ ~0~

In the game's Lua environment, you can use:

if EEex_Active then
    -- EEex method
else
    -- Non-EEex method
end

Thanks!

 

One more (hopefully last) noob question, not related strictly to topic, but probably not worth new one. How could I make use of such lua functions in game script? I found EEex_LuaAction(..) action that seems to be able to take lua code as argument, but something like this EEex_LuaAction("DbfUnlockScroll()") is not working for me. I tried to put my DbfUnlockScroll function in files like DbfTest.lua, M_DbfTest.lua, EEex_DbfTest.lua but neither works. Console show  "attempt to call nil value", so it seems my function is just not visible inside EEex_LuaAction. So far I was able to use it inside UI.menu after appending it at the end of this file between ` signs. 

Link to comment
1 hour ago, Bubb said:

The engine automatically executes .lua files with the "M_" prefix, though remember that all engine files need to be 8 characters or less before the extension. So, try a shortened version of "M_DbfTest.lua".

Eh, I had a feeling that I am missing something simple. Thanks!

Link to comment

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...