• 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 OTCV8 Game_Areas onPositionChange doesnt apply text

Lopaskurwa

Active Member
Joined
Oct 6, 2017
Messages
873
Solutions
2
Reaction score
49
Hey not sure whats wrong or why it doesnt work, i tried adding prints to see if it evens calls the function onPositionChange, which it does, but for some reason it still doesnt apply text when entering area
Lua:
local areas = {
  {
    from = {x = 1009, y = 1016, z = 7},
    to = {x = 1013, y = 1020, z = 7},
    name = "First Area"
  },
  {
    from = {x = 1014, y = 1016, z = 7},
    to = {x = 1017, y = 1020, z = 7},
    name = "Second Area"
  },
  {
    from = {x = 1018, y = 1016, z = 7},
    to = {x = 1021, y = 1020, z = 7},
    name = "Third Area name but longer"
  },
  {
    from = {x = 1022, y = 1016, z = 7},
    to = {x = 1026, y = 1020, z = 7},
    name = "Fourth Arena name"
  }
}
local currentArea = ""

local window = nil
local nameLabel = nil
local fadeOutEvent = nil

function init()
  connect(
    g_game,
    {
      onGameStart = create,
      onGameEnd = destroy
    }
  )

  if g_game.isOnline() then
    create()
  end
end

function create()
  window = g_ui.loadUI("areas", modules.game_interface.getMapPanel())
  window:setOpacity(0)
  nameLabel = window:getChildById("name")

  connect(LocalPlayer, {onPositionChange = onPositionChange})
end

local function isInArea(position, fromPos, toPos)
  local x = position.x
  local y = position.y
  local z = position.z
  if z ~= fromPos.z and z ~= toPos.z then
    return false
  end

  if x >= fromPos.x and x <= toPos.x and y >= fromPos.y and y <= toPos.y then
    return true
  end

  return false
end

local function fadeOut()
  g_effects.fadeOut(window, 750)
  fadeOutEvent = nil
end

function onPositionChange(player, newPos, oldPos)
  for i = 1, #areas do
    local area = areas[i]
    if currentArea ~= area.name then
      if isInArea(newPos, area.from, area.to) then
        currentArea = area.name
        nameLabel:setText("Entering " .. area.name)
        window:setWidth(nameLabel:getText():len() * 8)
        g_effects.fadeIn(window, 750)
        if fadeOutEvent then
          removeEvent(fadeOutEvent)
        end
        fadeOutEvent = scheduleEvent(fadeOut, 3000)
        break
      end
    end
  end
end

function terminate()
  disconnect(
    g_game,
    {
      onGameStart = create,
      onGameEnd = destroy
    }
  )
  if window then
    destroy()
  end
end

function destroy()
  disconnect(LocalPlayer, {onPositionChange = onPositionChange})

  if window then
    window:destroy()
    window = nil
  end

  nameLabel = nil
  fadeOutEvent = nil
  currentArea = ""
end
 
You're checking that z is not fromPos.z AND toPos.z, which is obviously an issue.

Try this:
Lua:
local function isInArea(position, fromPos, toPos)
    return (
        position.x >= fromPos.x
        and position.x <= toPos.x
        and position.y >= fromPos.y
        and position.y <= toPos.y
        and position.z >= fromPos.z
        and position.z <= toPos.z
    )
end

For better debugging with prints, you should add a print after each progressive stage/block in the code, so add one after each if statement or for loop, therefore you know where it breaks and which if statement is false.
(p.s I haven't done this for my solution, I just checked over your code and noticed the z issue. So it may be useful to add prints if its still not fixed)
 
Last edited:
You're checking that z is not fromPos.z AND toPos.z, which is obviously an issue.

Try this:
Lua:
local function isInArea(position, fromPos, toPos)
    return (
        position.x >= fromPos.x
        and position.x <= toPos.x
        and position.y >= fromPos.y
        and position.y <= toPos.y
        and position.z >= fromPos.z
        and position.z <= toPos.z
    )
end

For better debugging with prints, you should add a print after each progressive stage/block in the code, so add one after each if statement or for loop, therefore you know where it breaks and which if statement is false.
(p.s I haven't done this for my solution, I just checked over your code and noticed the z issue. So it may be useful to add prints if its still not fixed)
Didnt helped added some prints aswell to see if it calls x,y,z which is does. Its weird that it says Is in Area: false when im in the area
Code:
Position:     663    419    7
From Position:     643    409    7
To Position:     662    423    7
Is in Area:     false
Position:     663    419    7
From Position:     1014    1016    7
To Position:     1017    1020    7
Is in Area:     false
Position:     663    419    7
From Position:     1018    1016    7
To Position:     1021    1020    7
Is in Area:     false
Position:     663    419    7
From Position:     1022    1016    7
To Position:     1026    1020    7
Is in Area:     false
Position:     662    419    7
From Position:     643    409    7
To Position:     662    423    7
Is in Area:     true
5
1
2
3
Position:     661    419    7
From Position:     1014    1016    7
To Position:     1017    1020    7
Is in Area:     false
Position:     661    419    7
From Position:     1018    1016    7
To Position:     1021    1020    7
Is in Area:     false
Position:     661    419    7
From Position:     1022    1016    7
To Position:     1026    1020    7
Is in Area:     false
Position:     660    419    7
From Position:     1014    1016    7
To Position:     1017    1020    7
Is in Area:     false
Position:     660    419    7
From Position:     1018    1016    7
To Position:     1021    1020    7
Is in Area:     false
Position:     660    419    7
From Position:     1022    1016    7
To Position:     1026    1020    7
Is in Area:     false
Position:     659    419    7
From Position:     1014    1016    7
To Position:     1017    1020    7
Is in Area:     false
Position:     659    419    7
From Position:     1018    1016    7
To Position:     1021    1020    7
Is in Area:     false
Position:     659    419    7
From Position:     1022    1016    7
To Position:     1026    1020    7
Is in Area:     false
Position:     658    419    7
From Position:     1014    1016    7
To Position:     1017    1020    7
Is in Area:     false
Position:     658    419    7
From Position:     1018    1016    7
To Position:     1021    1020    7
Is in Area:     false
Position:     658    419    7
From Position:     1022    1016    7
To Position:     1026    1020    7
Is in Area:     false
Position:     657    419    7
From Position:     1014    1016    7
To Position:     1017    1020    7
Is in Area:     false
Position:     657    419    7
From Position:     1018    1016    7
To Position:     1021    1020    7
Is in Area:     false
Position:     657    419    7
From Position:     1022    1016    7
To Position:     1026    1020    7
Is in Area:     false

Code:
local function isInArea(position, fromPos, toPos)
    print("Position: ", position.x, position.y, position.z)
    print("From Position: ", fromPos.x, fromPos.y, fromPos.z)
    print("To Position: ", toPos.x, toPos.y, toPos.z)

    local isInXRange = position.x >= fromPos.x and position.x <= toPos.x
    local isInYRange = position.y >= fromPos.y and position.y <= toPos.y
    local isInZRange = position.z >= fromPos.z and position.z <= toPos.z

    local result = isInXRange and isInYRange and isInZRange

    print("Is in Area: ", result)

    return result
end
Lua:
function onPositionChange(player, newPos, oldPos)
  for i = 1, #areas do
    local area = areas[i]
    if currentArea ~= area.name then
      if isInArea(newPos, area.from, area.to) then
          print(5)
        currentArea = area.name
        print(1)
        nameLabel:setText("Entering " .. area.name)
        print(2)
        window:setWidth(nameLabel:getText():len() * 8)
        print(3)
        g_effects.fadeIn(window, 750)
        if fadeOutEvent then
            print(4)
          removeEvent(fadeOutEvent)
        end
        fadeOutEvent = scheduleEvent(fadeOut, 3000)
        break
      end
    end
  end
end
 
well then, the issue is the nameLabel.

is the window fading in?
Like what? :confused: Add prints to it. PS it creates nothing at all no window no text

Code:
create function called
nameLabel found
NameLabel Position:     959    -3
NameLabel Size:     32    24

Lua:
function create()
  print("create function called")
 
  window = g_ui.loadUI("areas", modules.game_interface.getMapPanel())
  window:setOpacity(0)
  nameLabel = window:getChildById("name")
 
  if nameLabel then
    print("nameLabel found")
    print("NameLabel Position: ", nameLabel:getPosition().x, nameLabel:getPosition().y)
    print("NameLabel Size: ", nameLabel:getSize().width, nameLabel:getSize().height)
  else
    print("nameLabel not found")
  end

  connect(LocalPlayer, {onPositionChange = onPositionChange})
end
 
Last edited:
Im not 100% familiar with OTUI so someone else may be better suited for this.

Are you sure fadeIn changes opacity? As you are setting it to 0 to begin with.
 
Im not 100% familiar with OTUI so someone else may be better suited for this.

Are you sure fadeIn changes opacity? As you are setting it to 0 to begin with.
I played around with the values outcome is the same. Nothing changes still creates absolutely nothing
 
can i see your OTUI for "areas"

and are you getting any errors in your client terminal?
Terminal and log is clean, if showed anything would be way easier to fix if it but in this situation nothing :D
Lua:
Panel
  anchors.top: parent.top
  anchors.horizontalCenter: parent.horizontalCenter
  margin-top: 30
  height: 24
  image-source: /images/ui/menubox
  image-border: 3

  Label
    id: name
    anchors.fill: parent
    text-align: center
    name: Example Area Name
 
disable the fades, and give it some default text. Make sure it is definitely visible and rendering first, and you can see the label changing.
 
As I said dude, OTUI isnt my strong point from just reading. I would need to replicate your code and test for myself.

Maybe someone else here will have the time, or can spot the error just by examining the OTUI.
 
As I said dude, OTUI isnt my strong point from just reading. I would need to replicate your code and test for myself.

Maybe someone else here will have the time, or can spot the error just by examining the OTUI.
I guess time to wait :D
 
Still havent fixed it, but i assume the issue is a way of displaying text somehow so probably .otui file is incorrect?
 
It's probably the margin-top, if you have some top menu that will get in the way. Place margin-top: 90

Lua:
Panel
  anchors.top: parent.top
  anchors.horizontalCenter: parent.horizontalCenter
  margin-top: 90
  height: 24
  image-source: /images/ui/menubox
  image-border: 3

  Label
    id: name
    anchors.fill: parent
    text-align: center
    name: Example Area Name
 
Back
Top