Jump to content

UI modding, can I get ID of currently active character?


Recommended Posts

Hello,

I'd been working on my modified Stealth ability, but was never satisfied with the fact, that it was a Special Ability, and not something you could trigger via Stealth button from the main Actionbar. Today I've found a potential solution to my problem, that doesn't even require EEEx, however due to my lack of experience with UI modding, I am not sure how to finalize my implementation.

I can overwrite the original action from

action "buttonArray:OnLButtonPressed(X)"

to

action "C:Eval('ReallyForceSpell(Myself,MY_STEALTH)', CHARACTER_ID)"

and it works well, but I need a way to dynamically pass that "CHARACTER_ID" value, which IESDP describes as:

Quote

CHARACTER_ID is an optional numeric parameter specifies the active party member for the script action.
The parameter expects the portrait slot index, starting with 0 for the first party member.

Do you know if such index is possible to get instantly, or if it can be somehow mapped from some other data?

PS. this CHARACTER_ID is an optional parameter, but its value is NOT current character ID if I don't provide it at all, so getting rid of it is not the solution.

 

Thank you very much for your help!

Link to comment

I assumed that it's doable in EEEx, thank you for giving me the exact solution :)

I still hope that it's possible to get proper ID value without EEEx, as it is unfortunately not compatible with MacOS and I'd really like to have a general implementation, not based on player's operating system.

Link to comment

Well, i think I have a solution, though it's not working in all cases. 

I have access to stuff like current character's name and HP, I also have a function Infinity_GetPortraitTooltip. So I can iterate over all portraits and compare the results (name, current and max HP) to determine CHARACTER_ID. Ofc if someone has 2 characters with the same name and HP, then it won't work properly, but I have no idea how to prevent that...

Link to comment

It turns out that characters[currentID] or characters[id] doesn't work as I hoped it would... So right now I can only compare names from Infinity_GetPortraitTooltip and Infinity_GetSelectedCharacterName. This works properly, but can still behave strangely if a player decides to create 2 characters with the same name. Is there really no way to get a better solution without EEEx?

Link to comment

Sorry to post another message here, but thanks to Pecca, the author of Infinite UI++, I now have a working solution, so maybe it will help someone else.

 

The main function for extracting current character id:

function getCurrentCharPortraitId()
  local idMapping = {}
  Infinity_UpdateLuaStats()
  local curCharId = id
  local i = 0
  while ( i < Infinity_GetNumCharacters()) do
    Infinity_OnPortraitLClick(i)
    Infinity_UpdateLuaStats()
    idMapping[id] = i
    i = i + 1
  end
  Infinity_OnPortraitLClick(idMapping[curCharId])
  return idMapping[curCharId]
end

It works properly, but has an unwanted subeffect of really clicking on all characters, which triggers selection sounds and subtitles to these sounds. To fix that, I implemented some functions to temporarily turn off both: sounds and feedback.

function getSelectionSoundsValues()
  panelID = 7
  soundOptions = {}
  soundOptions[5] = Infinity_GetOption(5, panelID) --  Character Subtitles option
  i = 58
  while (i < 61) do -- options 58, 59 and 60 control frequency of Selection Sounds, 60 = Never
    optionVal = Infinity_GetOption(i, panelID)
    if optionVal == 1 then
      soundOptions[i] = optionVal
    end
    i = i + 1
  end
  return soundOptions
end

function setOptionsValues(valuesTable, panel)
  for k, v in pairs(valuesTable) do
    Infinity_ChangeOption(k, v, panel)
  end   
end

function silentlyGetCurrentCharPortraitId()
  initialSoundOptions = getSelectionSoundsValues()
  noSoundOptions = {[5]=0, [60]=1} 
  setOptionsValues(noSoundOptions, 7)
  currentCharPortraitId = getCurrentCharPortraitId()
  setOptionsValues(initialSoundOptions, 7)
  return currentCharPortraitId
end

And finally my implementation for Stealth Button:

	button
	{
		area 353 1 52 52
		actionBar 5
		enabled "buttonArray:GetButtonEnabled(5)"
		tooltip lua "actionBarTooltip[5]"
		action "if buttonArray:GetButtonType(5) == 11 then -- type 11 means Stealth
              		charPortraitId = silentlyGetCurrentCharPortraitId()
              		command = 'ReallyForceSpell(' .. 'STEALTH' .. ', Myself)'
              		C:Eval(command, charPortraitId)
            	else
              		buttonArray:OnLButtonPressed(5)
            	end"
		actionAlt "buttonArray:OnRButtonPressed(5)"
	}

This still has 2 problems:

1. Using Stealth through keyboard button triggers the original Stealth
2. I am not sure how to block the spell from being cast once again, as disabling the button via Opcode doesn't really block it from triggering action function, however Stealth can just protect from itself for its duration, so it's not really important.

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