• 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!

OTClient createWidget is it possible to display text on x,y,z

henkas

Well-Known Member
Joined
Jul 8, 2015
Messages
1,051
Solutions
5
Reaction score
62
Hello is it possible to display without any source changes or stuff like that to display text trough otclient on x,y,z with createWidget? Basically a tile widgets i heard that its unique system and not really possible without writing a custom shit for it
 
You could add a check in this function: otclientv8/modules/game_walking/walking.lua at master · OTAcademy/otclientv8 (https://github.com/OTAcademy/otclientv8/blob/master/modules/game_walking/walking.lua#L342)

LUA:
function checkTargetPosition(newPos)
  local targetPositions = {
    {x = 32000, y = 32000, z = 7},
  }

  for _, target in ipairs(targetPositions) do
    if newPos.x == target.x and newPos.y == target.y and newPos.z == target.z then
      print("Current Player Pos: X=" .. target.x .. " Y=" .. target.y .. " Z=" .. target.z)
      return true
    end
  end
  return false
end

If you would add checkTargetPosition(newPos) to onWalk and replace the print with a UI widget that should pop up, it should work.
 
You could add a check in this function: otclientv8/modules/game_walking/walking.lua at master · OTAcademy/otclientv8 (https://github.com/OTAcademy/otclientv8/blob/master/modules/game_walking/walking.lua#L342)

LUA:
function checkTargetPosition(newPos)
  local targetPositions = {
    {x = 32000, y = 32000, z = 7},
  }

  for _, target in ipairs(targetPositions) do
    if newPos.x == target.x and newPos.y == target.y and newPos.z == target.z then
      print("Current Player Pos: X=" .. target.x .. " Y=" .. target.y .. " Z=" .. target.z)
      return true
    end
  end
  return false
end

If you would add checkTargetPosition(newPos) to onWalk and replace the print with a UI widget that should pop up, it should work
Yikes that means it will be executed every time on step, and UI widget im talking displaying text ON TILE not on UI
 
Yikes that means it will be executed every time on step, and UI widget im talking displaying text ON TILE not on UI
Step thing is something you wouldn't be able to avoid. You could send a text message on screen, console or just a UI widget however everything is most likely possible.
 
Step thing is something you wouldn't be able to avoid. You could send a text message on screen, console or just a UI widget however everything is most likely possible.
You dont understand what i mean im talking about text on tile not on ui widget, console or screen
 
You dont understand what i mean im talking about text on tile not on ui widget, console or screen
This must be handled server-side, as the client-side game screen uses mouse positions (x, y) for height and width, not map-like coordinates.

Edit:
Why not handle this on the server side instead of asking if its even possible on the client side?
 
This must be handled server-side, as the client-side game screen uses mouse positions (x, y) for height and width, not map-like coordinates.

Edit:
Why not handle this on the server side instead of asking if its even possible on the client side?
Server side what you mean exactly must be done?
 
you do not specify which client you use
mehah:

example:
LUA:
local tile = g_map.getTile(g_game.getLocalPlayer():getPosition())
local widget = g_ui.createWidget('Panel')
widget:setSize({width = 90,height = 22})
widget:setText("OTC Redemption")
widget:setFont("terminus-10px")
widget:setBackgroundColor('#111111cc')
widget:setMarginBottom(40)
tile:attachWidget(widget)

putconsole.gif


otcv8:

I have no examples
 
you do not specify which client you use
mehah:

example:
LUA:
local tile = g_map.getTile(g_game.getLocalPlayer():getPosition())
local widget = g_ui.createWidget('Panel')
widget:setSize({width = 90,height = 22})
widget:setText("OTC Redemption")
widget:setFont("terminus-10px")
widget:setBackgroundColor('#111111cc')
widget:setMarginBottom(40)
tile:attachWidget(widget)

putconsole.gif


otcv8:
Using otclientv8. Isnt it like creature based <span>getLocalPlayer</span> how would you do that on x,y,z instead of ataching it from player
 
it was just an example the argument is a position.
LUA:
local tilePos = {x = 111, y = 222, z = 7}
local tile = g_map.getTile(tilePos)
So whats wrong with this code doesnt display shit
LUA:
local positions = {
    {pos = {x = 114, y = 184, z = 7}, text = "OTC Redemption"},
    {pos = {x = 120, y = 185, z = 7}, text = "Hello World"},
    {pos = {x = 130, y = 190, z = 7}, text = "Another Message"},
    {pos = {x = 140, y = 195, z = 7}, text = "OTClient Rocks!"}
}

for _, entry in ipairs(positions) do
    local tilePos = entry.pos
    local tile = g_map.getTile(tilePos)
    
    if tile then
        local widget = g_ui.createWidget('Panel')
        widget:setSize({width = 90, height = 22})
        widget:setText(entry.text)
        widget:setFont("terminus-10px")
        widget:setBackgroundColor('#111111cc')
        widget:setMarginBottom(40)
        tile:setWidget(widget)
    else
        print("Tile not found at position:", tilePos.x, tilePos.y, tilePos.z)
    end
end
 
1. Needs better mapping instead of looping though all values, maybe unique hashing of position?
2. Can be sent from server with a tile, can be sent as a table from server, or this table can already exist in client (like you do now)
3. The idea of onWalk above is bad and wont work
3.1 You need your own callback onTileParsed or w/e, Tiles in OTC are not persistent and so are not tile widgets.

That's all you need, good luck.
 
Last edited:
1. Needs better mapping instead of looping though all values, maybe unique hashing of position?
2. Can be sent from server with a tile, can be sent as a table from server, or this table can already exist in client (like you do now)
3. The idea of onWalk above is bad and wont work
3.1 You need your own callback onTileParsed or w/e, Tiles in OTC are not persistent and so are not tile widgets.

That's all you need, good luck.
creaturescript, registered on login
LUA:
function onExtendedOpcode(player, opcode, result)
    -- Table of positions and text to send
    local tileData = {
        {x = 114, y = 184, z = 7, text = "OTC Redemption"},
        {x = 120, y = 185, z = 7, text = "Hello World"},
        {x = 130, y = 190, z = 7, text = "Another Message"},
        {x = 140, y = 195, z = 7, text = "OTClient Rocks!"}
    }

    local dataString = ""
    for _, entry in ipairs(tileData) do
        dataString = dataString .. entry.x .. "," .. entry.y .. "," .. entry.z .. "," .. entry.text .. ";"
    end
   
    player:sendExtendedOpcode(76, dataString)
end
LUA:
local tileTextData = {}

function init()
    ProtocolGame.registerExtendedOpcode(76, handleTileTextData)
end

function terminate()
    ProtocolGame.unregisterExtendedOpcode(76)
end

function handleTileTextData(_, _, data)
    local positions = {}
   
    for entry in data:gmatch("[^;]+") do
        local x, y, z, text = entry:match("([^,]+),([^,]+),([^,]+),(.+)")
        if x and y and z and text then
            table.insert(positions, {x = tonumber(x), y = tonumber(y), z = tonumber(z), text = text})
        end
    end
   
    tileTextData = {}
    for _, posData in ipairs(positions) do
        local hash = getTileHash(posData.x, posData.y, posData.z)
        tileTextData[hash] = posData.text
    end

    createWidgetsForTiles()
end

function createWidgetsForTiles()
    for _, posData in pairs(tileTextData) do
        local tilePos = {x = posData.x, y = posData.y, z = posData.z}
        local widget = g_ui.createWidget('Panel')
        widget:setSize({width = 150, height = 22})  -- Adjust size as necessary
        widget:setText(posData.text)
        widget:setFont("terminus-10px")
        widget:setBackgroundColor('#111111cc')
        widget:setMarginBottom(40)
        widget:setVisible(true)
    end
end

function getTileHash(x, y, z)
    return tostring(x) .. "," .. tostring(y) .. "," .. tostring(z)
end
No errors but cant get this shit to work lol
 
creaturescript, registered on login
LUA:
function onExtendedOpcode(player, opcode, result)
    -- Table of positions and text to send
    local tileData = {
        {x = 114, y = 184, z = 7, text = "OTC Redemption"},
        {x = 120, y = 185, z = 7, text = "Hello World"},
        {x = 130, y = 190, z = 7, text = "Another Message"},
        {x = 140, y = 195, z = 7, text = "OTClient Rocks!"}
    }

    local dataString = ""
    for _, entry in ipairs(tileData) do
        dataString = dataString .. entry.x .. "," .. entry.y .. "," .. entry.z .. "," .. entry.text .. ";"
    end
 
    player:sendExtendedOpcode(76, dataString)
end
LUA:
local tileTextData = {}

function init()
    ProtocolGame.registerExtendedOpcode(76, handleTileTextData)
end

function terminate()
    ProtocolGame.unregisterExtendedOpcode(76)
end

function handleTileTextData(_, _, data)
    local positions = {}
 
    for entry in data:gmatch("[^;]+") do
        local x, y, z, text = entry:match("([^,]+),([^,]+),([^,]+),(.+)")
        if x and y and z and text then
            table.insert(positions, {x = tonumber(x), y = tonumber(y), z = tonumber(z), text = text})
        end
    end
 
    tileTextData = {}
    for _, posData in ipairs(positions) do
        local hash = getTileHash(posData.x, posData.y, posData.z)
        tileTextData[hash] = posData.text
    end

    createWidgetsForTiles()
end

function createWidgetsForTiles()
    for _, posData in pairs(tileTextData) do
        local tilePos = {x = posData.x, y = posData.y, z = posData.z}
        local widget = g_ui.createWidget('Panel')
        widget:setSize({width = 150, height = 22})  -- Adjust size as necessary
        widget:setText(posData.text)
        widget:setFont("terminus-10px")
        widget:setBackgroundColor('#111111cc')
        widget:setMarginBottom(40)
        widget:setVisible(true)
    end
end

function getTileHash(x, y, z)
    return tostring(x) .. "," .. tostring(y) .. "," .. tostring(z)
end
No errors but cant get this shit to work lol

you forgot numerous things.
widget:setPosition() and tile and tile:attach
Also, tiles erase the widget once you get away from it, so you need a way to create and reattach that widget

but for me, what you need to accomplish seems easier dealt throught server-side? just loop a text with
Game.sendAnimatedText()
 

Attachments

Last edited:
you forgot numerous things.
widget:setPosition() and tile and tile:attach
Also, tiles erase the widget once you get away from it, so you need a way to create and reattach that widget

but for me, what you need to accomplish seems easier dealt throught server-side? just loop a text with
Game.sendAnimatedText()
What you mean ''tile and tile:attach''. Game.sendAnimatedText() is limited doing it trough client side i can customize it way more without using that nasty Game.sendAnimatedText()
 
So whats wrong with this code doesnt display shit
LUA:
local positions = {
    {pos = {x = 114, y = 184, z = 7}, text = "OTC Redemption"},
    {pos = {x = 120, y = 185, z = 7}, text = "Hello World"},
    {pos = {x = 130, y = 190, z = 7}, text = "Another Message"},
    {pos = {x = 140, y = 195, z = 7}, text = "OTClient Rocks!"}
}

for _, entry in ipairs(positions) do
    local tilePos = entry.pos
    local tile = g_map.getTile(tilePos)
   
    if tile then
        local widget = g_ui.createWidget('Panel')
        widget:setSize({width = 90, height = 22})
        widget:setText(entry.text)
        widget:setFont("terminus-10px")
        widget:setBackgroundColor('#111111cc')
        widget:setMarginBottom(40)
        tile:setWidget(widget)
    else
        print("Tile not found at position:", tilePos.x, tilePos.y, tilePos.z)
    end
end

on this code there's both of them and you posted it
local tile = g_map.getTile(tilePos)
tile:setWidget(widget)
 
Hello is it possible to display without any source changes or stuff like that to display text trough otclient on x,y,z with createWidget? Basically a tile widgets i heard that its unique system and not really possible without writing a custom shit for it
OTCv8 has built-in support for tile widgets. You don't need source edits to make it work.
Eh, ffs, I didn't even bother to scroll and read more posts...
 
OTCv8 has built-in support for tile widgets. You don't need source edits to make it work.
Eh, ffs, I didn't even bother to scroll and read more posts...
Yea managed to do it, the shit is hella glitched up it needs floor check and etc weird behaviour my code is just to trash :D
 
Back
Top