OTClient health bar question

Gesior.pl

Mega Noob&LOL 2012
Premium User
Joined
Sep 18, 2007
Messages
1,973
Reaction score
871
Location
PLand
About 'parallelogram':
Put almost-transparent image with only things you want to cover (part of bar start/end) and make it cover HP bar (place it on same position as HP bar, but after bar in .otui, so it will cover bar).
 
OP
Goku97

Goku97

Member
Joined
May 23, 2016
Messages
123
Reaction score
5
-empty-
 
Last edited:

margoh

{{ user.title }}
Joined
Apr 1, 2013
Messages
666
Reaction score
219
You can make function to clip image according to % of hp/mana

I did it like that
Lua:
function onHealthChange(localPlayer, health, maxHealth)
  local healthPercent = ((health*100)/maxHealth)
  local globalWidth = healthBar:getImageTextureWidth() -- 100%

  local sizePercent = ((healthPercent*globalWidth)/100) -- x%
  local percent = round(sizePercent, decimal)

  healthBar:setWidth(percent)
  healthBar:setImageClip('0 0 '.. percent ..' 14')
  healthLabel:setText(health .. ' / ' .. maxHealth)
end
And this function before init
Lua:
function round(val, decimal)
  if (decimal) then
    return math.floor( (val * 10^decimal) + 0.5) / (10^decimal)
  else
    return math.floor(val+0.5)
  end
end
P.s. healthLabel is element sticked to bar
 
Last edited:
OP
Goku97

Goku97

Member
Joined
May 23, 2016
Messages
123
Reaction score
5
-empty-
 
Last edited:

Gesior.pl

Mega Noob&LOL 2012
Premium User
Joined
Sep 18, 2007
Messages
1,973
Reaction score
871
Location
PLand
ONLY way to draw bar as you posted in first post is to create 2 images:
1. with full HP
2. with zero HP (transparent in place of HP)

Put full HP bar 'under' empty HP bar and clip 'full hp' bar to width equal to % of HP.
There is no access to 'draw engine' from LUA, so you can't write any algorithm that color pixels of your image to generate some weird shape - IT WOULD BE INTERESTING FEATURE!
Hmm.. generate texture (cached) in LUA and use it as part of UI. It would be great!

Clipped image is cached on next frame rendering, so until next HP change it won't use any extra CPU to draw it.
 
OP
Goku97

Goku97

Member
Joined
May 23, 2016
Messages
123
Reaction score
5
-empty-
 
Last edited:

margoh

{{ user.title }}
Joined
Apr 1, 2013
Messages
666
Reaction score
219
Check how health info is made.

Inside init.
Lua:
connect(LocalPlayer, { onNameChange = onNameChange })
Paste this in a place where it checks if game is online.
Lua:
onNameChange(player, g_game.getCharacterName())
Function.
Lua:
function onNameChange(player, name)
    characterName:setText(name)
end
 
OP
Goku97

Goku97

Member
Joined
May 23, 2016
Messages
123
Reaction score
5
-empty-
 
Last edited:

margoh

{{ user.title }}
Joined
Apr 1, 2013
Messages
666
Reaction score
219
Lua:
function onLevelChange(localPlayer, value, percent)
    rootpanel = modules.game_interface.getRootPanel()
    experienceBar = g_ui.createWidget('ExperienceBar', rootpanel)
    experienceBar:setPercent(percent)
    experienceBar:setText(percent .. '%')
    experienceBar:setTooltip(tr(experienceTooltip, percent, value+1))
end
Otui
Code:
ExperienceBar < ProgressBar
  id: experienceBar
  background-color: #B6E866
  anchors.bottom: gameBottomPanel.top
  anchors.left: gameLeftPanel.right
  anchors.right: gameRightPanel.left
  margin: 1
  margin-top: 3
 
OP
Goku97

Goku97

Member
Joined
May 23, 2016
Messages
123
Reaction score
5
-empty-
 
Last edited:
OP
Goku97

Goku97

Member
Joined
May 23, 2016
Messages
123
Reaction score
5
-empty-
 
Last edited:

4drik

Active Member
Joined
Jun 30, 2014
Messages
178
Reaction score
123
First of all, compose it in .otui, not in lua.
Then add IDs for all bars, labels etc.
Then instead of createWidget do getChildByID.

1. If the module is reloaded and not working correct, it means that there are problems in terminate/init functions, check other modules and find differences.
Instead of onNameChange I think you can use localPlayer:getName() (not sure what you need to achieve).

2. If you will build the healthhud in .otui to make level label near name - add to experienceBar, label or whatever you have an anchor, for example if you want on the right of CharacterName:
Code:
anchors.top: characterNameID.top
anchors.left: characterNameID.right
 

margoh

{{ user.title }}
Joined
Apr 1, 2013
Messages
666
Reaction score
219
You just have a typo in "refresh". Inside onNameChange you have (player, {...}). It should be localPlayer like on the rest of declared variables.
Inside onLevelChange the variable value is our current level.
 
OP
Goku97

Goku97

Member
Joined
May 23, 2016
Messages
123
Reaction score
5
-empty-
 
Last edited:
Top