• 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 .otui and how to fetch?

Mjmackan

Mapper ~ Writer
Premium User
Joined
Jul 18, 2009
Messages
1,424
Solutions
15
Reaction score
176
Location
Sweden
So i followed this lil tutorial: OTClient - How to make a hud in otui (https://otland.net/threads/how-to-make-a-hud-in-otui.282980/) but i didn't succeed.
In not succeding Im talking about there's no image showing, as its suppose to show the window.png file.

This is my otui: (which otclient gives error of: ERROR: "Failed to import UI styles from 'timecheck.otui': OTML error in '/mods/game_timecheck/timecheck.otui:1': not a valid style declaration") I have no clue of why UIWidget isnt?
CSS:
UIWidget
  id: attributesId
  anchors.top: parent.top
  anchors.left: parent.left
  margin-top: 30
  margin-left: 30
  size: 100 190
  visible: false
  layout:
    type: verticalBox
   
  Label
    id: healthImage
    image-width: 60
    image-height: 60
    opacity: 0.4
    image-source: /images/ui/window
   
  Label
    id: healthId
    margin-top: 33
    margin-left: 6
    font: verdana-11px-rounded

This is my lua script:
Lua:
function init()
  ProtocolGame.registerExtendedOpcode(110, onExtendedOpcode)
  g_ui.importStyle('timecheck')
end

function terminate()
  ProtocolGame.unregisterExtendedOpcode(110, onExtendedOpcode)
end

function sendMyCode()
timechecking = g_ui.createWidget('timecheck', rootWidget)
timechecking:show()
timechecking:raise()
timechecking:focus()
  local myData = {
    a = "string",
    b = 123,
    c = {
      x = "string in table",
      y = 456
    }
  }

  local protocolGame = g_game.getProtocolGame()
  if protocolGame then
    protocolGame.sendExtendedOpCode(110, json.encode(myData))
  end
end

function onExtendedOpcode(protocol, code, buffer)
  local json_status, json_data =
    pcall(
    function()
      return json.decode(buffer)
    end
  )

  if not json_status then
    g_logger.error("[My Module] JSON error: " .. json_data)
    return false
  end
    print("hello papa")
  print(json_data.foo)
  print(json_data.bar)
end
 
MyUIClassWhateverName < UIWidget

and

g_ui.createWidget('MyUIClassWhateverName', rootWidget)
So like this? (it did not work)
Lua:
function init()
  ProtocolGame.registerExtendedOpcode(110, onExtendedOpcode)
end

function terminate()
  ProtocolGame.unregisterExtendedOpcode(110, onExtendedOpcode)
end

function sendMyCode()
g_ui.createWidget('MyUIClassWhateverName', rootWidget)
  local myData = {
    a = "string",
    b = 123,
    c = {
      x = "string in table",
      y = 456
    }
  }

  local protocolGame = g_game.getProtocolGame()
  if protocolGame then
    protocolGame.sendExtendedOpCode(110, json.encode(myData))
  end
end

function onExtendedOpcode(protocol, code, buffer)
  local json_status, json_data =
    pcall(
    function()
      return json.decode(buffer)
    end
  )

  if not json_status then
    g_logger.error("[My Module] JSON error: " .. json_data)
    return false
  end
    print("hello papa")
  print(json_data.foo)
  print(json_data.bar)
end
CSS:
MyUIClassWhateverName < UIWidget
  id: attributesId
  anchors.top: parent.top
  anchors.left: parent.left
  margin-top: 30
  margin-left: 30
  size: 100 190
  visible: false
  layout:
    type: verticalBox
    
  Label
    id: healthImage
    image-width: 60
    image-height: 60
    opacity: 0.4
    image-source: /images/ui/window
    
  Label
    id: healthId
    margin-top: 33
    margin-left: 6
    font: verdana-11px-rounded
 
Back
Top