MorganaSacani
Active Member
- Joined
- Sep 20, 2022
- Messages
- 87
- Solutions
- 1
- Reaction score
- 32
Hello dear friends!
I managed to create a window that shows my character's attributes, but I don't know how to make the values of these attributes appear.
Here is the script I created for my Otclient:
On my server I created two functions to return me stamina attribute values:
I imagine that for me to receive information from the server to the Otclient, I need to create some script in creaturescripts.
I imagine on the server it should be something like sendExtendedOpcode, and maybe on the Otclient it's something like getExtendedOpcode.
Can someone help me? My server is a TFS 0.4
I managed to create a window that shows my character's attributes, but I don't know how to make the values of these attributes appear.
Here is the script I created for my Otclient:
Lua:
attributesWindow = nil
attributesButton = nil
function init()
connect(LocalPlayer, {
onHealthChange = onHealthChange,
})
connect(g_game, {
onGameStart = refresh,
onGameEnd = offline
})
attributesButton = modules.client_topmenu.addRightGameToggleButton('attributesButton', tr('Attributes'), '/images/topbuttons/attributes', toggle, false, 1)
attributesButton:setOn(true)
attributesWindow = g_ui.loadUI('attributes', modules.game_interface.getRightPanel())
attributesWindow:setup()
end
function terminate()
disconnect(LocalPlayer, {
onHealthChange = onHealthChange,
})
disconnect(g_game, {
onGameStart = refresh,
onGameEnd = offline
})
attributesWindow:destroy()
attributesButton:destroy()
end
function refresh()
local player = g_game.getLocalPlayer()
local protocolGame = g_game.getProtocolGame()
if not player then return end
onHealthChange(player, player:getHealth(), player:getMaxHealth())
onStaminaChange(player, "Here I need it to return the current value", "Here I need it to return the maximum value")
local contentsPanel = attributesWindow:getChildById('contentsPanel')
attributesWindow:setContentMinimumHeight(44)
attributesWindow:setContentMaximumHeight(390)
end
function toggle()
if attributesButton:isOn() then
attributesWindow:close()
attributesButton:setOn(false)
else
attributesWindow:open()
attributesButton:setOn(true)
end
end
function setAttributeValue(id, value)
local attribute = attributesWindow:recursiveGetChildById(id)
local widget = attribute:getChildById('value')
widget:setText(value)
end
function setAttributeColor(id, value)
local attribute = attributesWindow:recursiveGetChildById(id)
local widget = attribute:getChildById('value')
widget:setColor(value)
end
function resetAttributeColor(id)
local attribute = attributesWindow:recursiveGetChildById(id)
local widget = attribute:getChildById('value')
widget:setColor('#bbbbbb')
end
function checkAlert(id, value, maxValue, threshold, greaterThan)
if greaterThan == nil then greaterThan = false end
local alert = false
if type(maxValue) == 'boolean' then
if maxValue then
return
end
if greaterThan then
if value > threshold then
alert = true
end
else
if value < threshold then
alert = true
end
end
elseif type(maxValue) == 'number' then
if maxValue < 0 then
return
end
local percent = math.floor((value / maxValue) * 100)
if greaterThan then
if percent > threshold then
alert = true
end
else
if percent < threshold then
alert = true
end
end
end
if alert then
setAttributeColor(id, '#b22222') -- red
else
resetAttributeColor(id)
end
end
function onHealthChange(localPlayer, value, maxValue)
setAttributeValue('health', value)
checkAlert('health', value, maxValue, 30)
end
function onStaminaChange(localPlayer, value, maxValue)
setAttributeValue('stamina', value)
checkAlert('stamina', value, maxValue, 30)
end
On my server I created two functions to return me stamina attribute values:
Lua:
function getPlayerAttrMaxStamina(target) return getPlayerStorageValue(target, ATTR_MAX_STAMINA_STORAGE_ID) end
function getPlayerAttrStamina(target) return getPlayerStorageValue(target, ATTR_STAMINA_STORAGE_ID) end
I imagine that for me to receive information from the server to the Otclient, I need to create some script in creaturescripts.
I imagine on the server it should be something like sendExtendedOpcode, and maybe on the Otclient it's something like getExtendedOpcode.
Can someone help me? My server is a TFS 0.4