Trying to display shield values as a number.

Everything about mods can be found here.

Moderator: Morax

Trying to display shield values as a number.

Postby Tanksy » 22 Jan 2017, 17:02

Hello again.

I'm trying to modify the UI to display the shield values in the same way that health values are displayed (EG: Roll over the unit, and you see the health as xxx/yyy, I'm trying to make the shield display the same.)

I have no idea what I'm doing, and I did some studies of the archived GPG posts (what remains of them anyway) and so far I've created a hook file under "lua/ui/game/unitview.lua" -- Here's the code I've written:

Code: Select all
do
   local originalCreateUI = CreateUI
   function createUI()
      originalCreateUI()
      
      controls.shield = UIUtil.CreateText(controls.shieldBar, '', 14, UIUtil.bodyFont)
   end

   local originalUpdateWindow = UpdateWindow(info)
   function UpdateWindow(info)
      originalUpdateWindow(info)
      
      if info.blueprintId == 'unknown' then
         return
      else
         if info.shieldRatio > 0 then
            controls.shieldBar:Show()
            controls.shieldBar:SetValue(info.shieldRatio)
            controls.shield:SetText(string.format("%d / %d", info.shield, info.maxShield))
         else
            controls.shieldBar:Hide()
         end
      end
   end
end


This completely breaks the game, seemingly. Hitting F9 and I get a mass of errors to do with "right", "top" etc "lazyvars", but right at the top of the pile of errors are things like "can't get global variable "info"" -- Which confuses me because I'm hooking into a script that should already have those variables set up after my code's inserted, right?
Tanksy
Avatar-of-War
 
Posts: 75
Joined: 31 Aug 2016, 11:39
Has liked: 1 time
Been liked: 14 times

Re: Trying to display shield values as a number.

Postby Myxir » 22 Jan 2017, 17:21

usually, if lazyvar complains, the UI components don't have defined positions
make sure you set the positions, the game code does this in a SetLayout function in another file
useful for this is the layouthelper lua file which contains a nice amount of helper functions for such stuff
Unhappy with balance http://i.imgur.com/q5G2BlM.png
User avatar
Myxir
Evaluator
 
Posts: 791
Joined: 09 Apr 2012, 14:01
Has liked: 94 times
Been liked: 306 times
FAF User Name: Washy (irc)

Re: Trying to display shield values as a number.

Postby Tanksy » 22 Jan 2017, 17:43

How do these components not have defined positions when my mod is simply hooking into what's already there? Shouldn't there already be defined positions and whatnot? I don't fully understand how useful hooking is and what I can and can't get away with.
Tanksy
Avatar-of-War
 
Posts: 75
Joined: 31 Aug 2016, 11:39
Has liked: 1 time
Been liked: 14 times

Re: Trying to display shield values as a number.

Postby Myxir » 22 Jan 2017, 18:35

oh if the control.shield and control.shieldBar are already there, that shouldn't be an issue
perhaps this line:
Code: Select all
local originalUpdateWindow = UpdateWindow(info)
Unhappy with balance http://i.imgur.com/q5G2BlM.png
User avatar
Myxir
Evaluator
 
Posts: 791
Joined: 09 Apr 2012, 14:01
Has liked: 94 times
Been liked: 306 times
FAF User Name: Washy (irc)

Re: Trying to display shield values as a number.

Postby Tanksy » 22 Jan 2017, 19:25

Wouldn't the info be coming from the script I hooked into?
Tanksy
Avatar-of-War
 
Posts: 75
Joined: 31 Aug 2016, 11:39
Has liked: 1 time
Been liked: 14 times

Re: Trying to display shield values as a number.

Postby KeyBlue » 22 Jan 2017, 19:29

you shouldn't add the (info) in that line.
Just like you didn't add () when saving the originalCreateUI

Need to have it like this probably :
Code: Select all
local originalUpdateWindow = UpdateWindow
User avatar
KeyBlue
Priest
 
Posts: 403
Joined: 28 Jan 2016, 01:06
Has liked: 140 times
Been liked: 93 times
FAF User Name: KeyBlue

Re: Trying to display shield values as a number.

Postby speed2 » 22 Jan 2017, 19:31

This saves the reference to the UpdateWindow function in local variable originalUpdateWindow
Code: Select all
local originalUpdateWindow = UpdateWindow


while this calls the function UpdateWindow with parametr info and if the function is returning some value, the value is saved in local variable originalUpdateWindow
Code: Select all
local originalUpdateWindow = UpdateWindow(info)


For hooking the first one is correct
User avatar
speed2
Contributor
 
Posts: 3189
Joined: 05 Jan 2013, 15:11
Has liked: 636 times
Been liked: 1119 times
FAF User Name: speed2

Re: Trying to display shield values as a number.

Postby KeyBlue » 22 Jan 2017, 22:34

btw, have you tried the 'Display more Units Stats' interface option in game?

I think this will provide what you want (among other stats)
User avatar
KeyBlue
Priest
 
Posts: 403
Joined: 28 Jan 2016, 01:06
Has liked: 140 times
Been liked: 93 times
FAF User Name: KeyBlue

Re: Trying to display shield values as a number.

Postby Tanksy » 22 Jan 2017, 22:44

Thanks for the suggestion KeyBlue but that option doesn't exist for me:

Image

Perhaps it exists in FAF, but I don't use it.

Thanks for the help Speed2, I'll try that out and see if it works out.

Ideally what I want to do is re-do parts of the UI, to show more unit info such as shield values, weapon damage and rate of fire. I would also like to extend the little pop-up box for the unit descriptions when you're mousing over them, so that It can make more use of the available space on screen rather than cramming the descriptions into a little box. Then finally if possible I'm going to try making the little box with unit info remain open for the selected unit -- sort of like in Age of Empires where you can always see the selected unit's stats, whilst still being able to have the mouseover tooltip of other units. It might be a hefty load of work though, I expect I'll have to re-write a lot of the UI but idk. I'll start with the shield values and see what else can be done.
Tanksy
Avatar-of-War
 
Posts: 75
Joined: 31 Aug 2016, 11:39
Has liked: 1 time
Been liked: 14 times


Return to Mods & Tools

Who is online

Users browsing this forum: No registered users and 1 guest