• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!

get vocation to client and another mana bar for each voc. Possible?

kermaxpl

Pora na Nonsens Scripter
Joined
Aug 21, 2012
Messages
121
Reaction score
7
Location
Poland
Hi is it possible to get player's vocation to client? Beacuse I want to make diffrent mana bars for each vocation.
 
Last edited:
Can u say something more? I'm newbie, but I learn fast ;)
I'm only want to change color of bar for voc 1, remove bar for voc 4 if it is possible, vocs 2, 3 will be as in orginal.
It can't be so hard.

I was trying to edit module:
This is my healthinfo.lua:
Code:
Icons = {}
Icons[1] = { tooltip = tr('You are poisoned'), path = '/images/game/states/poisoned', id = 'condition_poisoned' }
Icons[2] = { tooltip = tr('You are burning'), path = '/images/game/states/burning', id = 'condition_burning' }
Icons[4] = { tooltip = tr('You are electrified'), path = '/images/game/states/electrified', id = 'condition_electrified' }
Icons[8] = { tooltip = tr('You are drunk'), path = '/images/game/states/drunk', id = 'condition_drunk' }
Icons[16] = { tooltip = tr('You are protected by a magic shield'), path = '/images/game/states/magic_shield', id = 'condition_magic_shield' }
Icons[32] = { tooltip = tr('You are paralysed'), path = '/images/game/states/slowed', id = 'condition_slowed' }
Icons[64] = { tooltip = tr('You are hasted'), path = '/images/game/states/haste', id = 'condition_haste' }
Icons[128] = { tooltip = tr('You may not logout during a fight'), path = '/images/game/states/logout_block', id = 'condition_logout_block' }
Icons[256] = { tooltip = tr('You are drowning'), path = '/images/game/states/drowning', id = 'condition_drowning' }
Icons[512] = { tooltip = tr('You are freezing'), path = '/images/game/states/freezing', id = 'condition_freezing' }
Icons[1024] = { tooltip = tr('You are dazzled'), path = '/images/game/states/dazzled', id = 'condition_dazzled' }
Icons[2048] = { tooltip = tr('You are cursed'), path = '/images/game/states/cursed', id = 'condition_cursed' }
Icons[4096] = { tooltip = tr('You are strengthened'), path = '/images/game/states/strengthened', id = 'condition_strengthened' }
Icons[8192] = { tooltip = tr('You may not logout or enter a protection zone'), path = '/images/game/states/protection_zone_block', id = 'condition_protection_zone_block' }
Icons[16384] = { tooltip = tr('You are within a protection zone'), path = '/images/game/states/protection_zone', id = 'condition_protection_zone' }
Icons[32768] = { tooltip = tr('You are bleeding'), path = '/images/game/states/bleeding', id = 'condition_bleeding' }
Icons[65536] = { tooltip = tr('You are hungry'), path = '/images/game/states/hungry', id = 'condition_hungry' }

healthInfoWindow = nil
healthBar = nil
manaBar = nil
[COLOR="#FF0000"]enerBar = nil[/COLOR]
experienceBar = nil
soulLabel = nil
capLabel = nil
healthTooltip = 'Your character health is %d out of %d.'
manaTooltip = 'Your character mana is %d out of %d.'
experienceTooltip = 'You have %d%% to advance to level %d.'

function init()
  connect(LocalPlayer, { onHealthChange = onHealthChange,
                         onManaChange = onManaChange,
                         onLevelChange = onLevelChange,
                         onStatesChange = onStatesChange,
                         onSoulChange = onSoulChange,
                         onFreeCapacityChange = onFreeCapacityChange })

  connect(g_game, { onGameEnd = offline })

  healthInfoButton = modules.client_topmenu.addRightGameToggleButton('healthInfoButton', tr('Health Information'), '/images/topbuttons/healthinfo', toggle)
  healthInfoButton:setOn(true)

  healthInfoWindow = g_ui.loadUI('healthinfo', modules.game_interface.getRightPanel())
  healthInfoWindow:disableResize()
  healthBar = healthInfoWindow:recursiveGetChildById('healthBar')
  manaBar = healthInfoWindow:recursiveGetChildById('manaBar')
[COLOR="#FF0000"]  enerBar = healthInfoWindow:recursiveGetChildById('enerBar')[/COLOR]
  experienceBar = healthInfoWindow:recursiveGetChildById('experienceBar')
  soulLabel = healthInfoWindow:recursiveGetChildById('soulLabel')
  capLabel = healthInfoWindow:recursiveGetChildById('capLabel')

  -- load condition icons
  for k,v in pairs(Icons) do
    g_textures.preload(v.path)
  end

  if g_game.isOnline() then
    local localPlayer = g_game.getLocalPlayer()
    onHealthChange(localPlayer, localPlayer:getHealth(), localPlayer:getMaxHealth())
    onManaChange(localPlayer, localPlayer:getMana(), localPlayer:getMaxMana())
    onLevelChange(localPlayer, localPlayer:getLevel(), localPlayer:getLevelPercent())
    onStatesChange(localPlayer, localPlayer:getStates(), 0)
    onSoulChange(localPlayer, localPlayer:getSoul())
    onFreeCapacityChange(localPlayer, localPlayer:getFreeCapacity())
  end

  healthInfoWindow:setup()
end

function terminate()
  disconnect(LocalPlayer, { onHealthChange = onHealthChange,
                            onManaChange = onManaChange,
                            onLevelChange = onLevelChange,
                            onStatesChange = onStatesChange,
                            onSoulChange = onSoulChange,
                            onFreeCapacityChange = onFreeCapacityChange })

  disconnect(g_game, { onGameEnd = offline })

  healthInfoWindow:destroy()
  healthInfoButton:destroy()
end

function toggle()
  if healthInfoButton:isOn() then
    healthInfoWindow:close()
    healthInfoButton:setOn(false)
  else
    healthInfoWindow:open()
    healthInfoButton:setOn(true)
  end
end

function toggleIcon(bitChanged)
  local content = healthInfoWindow:recursiveGetChildById('conditionPanel')

  local icon = content:getChildById(Icons[bitChanged].id)
  if icon then
    icon:destroy()
  else
    icon = loadIcon(bitChanged)
    icon:setParent(content)
  end
end

function loadIcon(bitChanged)
  local icon = g_ui.createWidget('ConditionWidget', content)
  icon:setId(Icons[bitChanged].id)
  icon:setImageSource(Icons[bitChanged].path)
  icon:setTooltip(Icons[bitChanged].tooltip)
  return icon
end

function offline()
  healthInfoWindow:recursiveGetChildById('conditionPanel'):destroyChildren()
end

-- hooked events
function onMiniWindowClose()
  healthInfoButton:setOn(false)
end

function onHealthChange(localPlayer, health, maxHealth)
  healthBar:setText(health .. ' / ' .. maxHealth)
  healthBar:setTooltip(tr(healthTooltip, health, maxHealth))
  healthBar:setValue(health, 0, maxHealth)
end

function onManaChange(localPlayer, mana, maxMana)
  manaBar:setText(mana .. ' / ' .. maxMana)
  manaBar:setTooltip(tr(manaTooltip, mana, maxMana))
  manaBar:setValue(mana, 0, maxMana
[COLOR="#FF0000"]  enerBar:setText(mana .. ' / ' .. maxMana)
  enerBar:setTooltip(tr(manaTooltip, mana, maxMana))
  enerBar:setValue(mana, 0, maxMana)[/COLOR]
end

function onLevelChange(localPlayer, value, percent)
  experienceBar:setText(percent .. '%')
  experienceBar:setTooltip(tr(experienceTooltip, percent, value+1))
  experienceBar:setPercent(percent)
end

function onSoulChange(localPlayer, soul)
  soulLabel:setText(tr('Soul') .. ': ' .. soul)
end

function onFreeCapacityChange(player, freeCapacity)
  capLabel:setText(tr('Cap') .. ': ' .. freeCapacity)
end

function onStatesChange(localPlayer, now, old)
  if now == old then return end

  local bitsChanged = bit32.bxor(now, old)
  for i = 1, 32 do
    local pow = math.pow(2, i-1)
    if pow > bitsChanged then break end
    local bitChanged = bit32.band(bitsChanged, pow)
    if bitChanged ~= 0 then
      toggleIcon(bitChanged)
    end
  end
end

-- personalization functions
function hideLabels()
  local removeHeight = math.max(capLabel:getMarginRect().height, soulLabel:getMarginRect().height)
  capLabel:setOn(false)
  soulLabel:setOn(false)
  healthInfoWindow:setHeight(math.max(healthInfoWindow.minimizedHeight, healthInfoWindow:getHeight() - removeHeight))
end

function hideExperience()
  local removeHeight = experienceBar:getMarginRect().height
  experienceBar:setOn(false)
  healthInfoWindow:setHeight(math.max(healthInfoWindow.minimizedHeight, healthInfoWindow:getHeight() - removeHeight))
end

function setHealthTooltip(tooltip)
  healthTooltip = tooltip

  local localPlayer = g_game.getLocalPlayer()
  if localPlayer then
    healthBar:setTooltip(tr(healthTooltip, localPlayer:getHealth(), localPlayer:getMaxHealth()))
  end
end

function setManaTooltip(tooltip)
  manaTooltip = tooltip

  local localPlayer = g_game.getLocalPlayer()
  if localPlayer then
    manaBar:setTooltip(tr(manaTooltip, localPlayer:getMana(), localPlayer:getMaxMana()))
[COLOR="#FF0000"]	enerBar:setTooltip(tr(manaTooltip, localPlayer:getMana(), localPlayer:getMaxMana()))[/COLOR]
  end
end

function setExperienceTooltip(tooltip)
  experienceTooltip = tooltip

  local localPlayer = g_game.getLocalPlayer()
  if localPlayer then
    experienceBar:setTooltip(tr(experienceTooltip, localPlayer:getLevelPercent(), localPlayer:getLevel()+1))
  end
end


And healthinfo.otui:
Code:
HealthBar < ProgressBar
  id: healthBar
  background-color: #ff4444
  anchors.top: parent.top
  anchors.left: parent.left
  anchors.right: parent.right
  margin: 1

ManaBar < ProgressBar
  id: manaBar
  background-color: #4444ff
  anchors.top: prev.bottom
  anchors.left: parent.left
  anchors.right: parent.right
  margin: 1
  margin-top: 3
  
[COLOR="#FF0000"]EnerBar < ProgressBar
  id: enerBar
  background-color: #ffff33
  anchors.top: prev.bottom
  anchors.left: parent.left
  anchors.right: parent.right
  margin: 1
  margin-top: 3[/COLOR]
  
ExperienceBar < ProgressBar
  id: experienceBar
  background-color: #B6E866
  anchors.top: prev.bottom
  anchors.left: parent.left
  anchors.right: parent.right
  margin: 1
  margin-top: 3

SoulLabel < GameLabel
  id: soulLabel
  text-align: right
  color: white
  font: verdana-11px-rounded
  anchors.bottom: parent.bottom
  anchors.right: parent.right
  anchors.left: parent.horizontalCenter
  margin-top: 5
  margin-right: 3
  on: false

  $!on:
    visible: false
    margin-top: 0
    height: 0

CapLabel < GameLabel
  id: capLabel
  color: white
  font: verdana-11px-rounded
  anchors.bottom: parent.bottom
  anchors.left: parent.left
  anchors.right: parent.horizontalCenter
  margin-top: 5
  margin-left: 3
  on: true

  $!on:
    visible: false
    margin-top: 0
    height: 0

ConditionWidget < UIWidget
  size: 18 18

  $!first:
    margin-left: 2

MiniWindow
  icon: /images/topbuttons/healthinfo
  id: healthInfoWindow
  !text: tr('Health Info')
  height: 123
  @onClose: modules.game_healthinfo.onMiniWindowClose()
  &save: true

  MiniWindowContents
    HealthBar
    ManaBar
[COLOR="#FF0000"]	EnerBar[/COLOR]
    ExperienceBar
    Panel
      id: conditionPanel
      layout:
        type: horizontalBox
      height: 22
      margin-top: 4
      padding: 2
      anchors.top: prev.bottom
      anchors.left: parent.left
      anchors.right: parent.right
      border-width: 1
      border-color: #00000077
      background-color: #ffffff11
    SoulLabel
    CapLabel

To check vocation I can use this, but I still don't know how to hide unnecessary bar:
Lua:
localPlayer = g_game.getLocalPlayer()
if localPlayer:getVocation() == x then


In addition after these changes module isn't loaded and I have these in terminal(I have no idea why):
Code:
/game_healthinfo/healthinfo.lua:119: attempt to index global 'healthBar' (a nil value)
stack traceback:
	[C]: ?
	/game_healthinfo/healthinfo.lua:119: in function </game_healthinfo/healthinfo.lua:118>
ERROR: protected lua call failed: LUA ERROR:
/game_healthinfo/healthinfo.lua:140: attempt to index global 'capLabel' (a nil value)
stack traceback:
	[C]: ?
	/game_healthinfo/healthinfo.lua:140: in function </game_healthinfo/healthinfo.lua:139>
ERROR: protected lua call failed: LUA ERROR:
/game_healthinfo/healthinfo.lua:134: attempt to index global 'experienceBar' (a nil value)
stack traceback:
	[C]: ?
	/game_healthinfo/healthinfo.lua:134: in function </game_healthinfo/healthinfo.lua:133>
ERROR: protected lua call failed: LUA ERROR:
/game_healthinfo/healthinfo.lua:125: attempt to index global 'manaBar' (a nil value)
stack traceback:
	[C]: ?
	/game_healthinfo/healthinfo.lua:125: in function </game_healthinfo/healthinfo.lua:124>
ERROR: protected lua call failed: LUA ERROR:
/game_skills/skills.lua:92: attempt to index local 'skill' (a nil value)
stack traceback:
	[C]: ?
	/game_skills/skills.lua:92: in function 'setSkillValue'
	/game_skills/skills.lua:294: in function </game_skills/skills.lua:293>
ERROR: protected lua call failed: LUA ERROR:
/game_skills/skills.lua:76: attempt to index local 'skill' (a nil value)
stack traceback:
	[C]: ?
	/game_skills/skills.lua:76: in function 'setSkillBase'
	/game_skills/skills.lua:300: in function </game_skills/skills.lua:299>


I really need it.
 
Last edited:
Send onLogin additional data, parse it and store. And then just if(v==1)this else that. As long as you don't change vocations during gameplay this way is enough
 
I know how to get vocation but I don`t know how to set another bar for each.
 
Moze poszukaj po plikach w ktorym jest cos odpowiedzialnego za status health/many, dawaj na chwile w komentarz i sprawdzaj czy usunelo, jak tak to wtedy robisz nowy panel odpowiedzialny za to tylko juz wedlug wlasnej woli :)
 
A może tak przeczytaj cały post :p zrobiłem czy działają dwa nawet, ale wywaliło jakiś błąd ze skilli.

Still not solved
 
A sprawdzales czy wogole na oddzielnym nowym modzie w nowym panelu dziala?
// Zamiast korzystac z obecnego bar'a napisz nowy panel ;p i wtedy bedziesz wiedzial co jest zle, ja tak samo zrobilem jak minimape ekranowa pisalem i zakladki do mountow na 8.6
 
Last edited:
Chyba jestem zbyt dużym noob'em żeby napisać od nowa moda/moduł do otclient'a niestety :( a nie chciało by ci się za parę złotych tego zrobić dla mnie??
Bo za darmo raczej nie będzie ci się chciało :p
 
Last edited:
he said, he will try to make this for me and will post this, but we haven`t answer until now
 
Then go for it. Study, learn. Come back here with concrete doubts instead of begging bumps.
 
It wasn't so helpful it think... and don't contribute any new, but ok if anyone don't want to help.
 
Core devs are concentraded on the core and they don't have to do anything anyway
others don't have to do anything even more
You can find someone who will do it for money or do it yourself (or wait and pray), thats the nonwritten law of opentibia
 
I'm trying to do something new and I'm doing it on my own in general but when I need some help I only receive tips what I should do with my life. It is so demotivating.

I know you have better experience and you are more clever than me, but pls guys, if you think someone is so stupid to helping him you shuold not post.
Because if you will be a mentor all time, you will lose users, and OT universum will die. Sorry, sad but true.

New users need friendly teacher not harsh guru.
 
Last edited:
Back
Top Bottom