• 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 otclient sending packets

Mjmackan

Mapper ~ Writer
Premium User
Joined
Jul 18, 2009
Messages
1,424
Solutions
15
Reaction score
176
Location
Sweden
Yo, trying to send packets from server to otclient but i get nothing at all when im checking TFS(TFS 1.3) console, nor ctrl+t on otclient.
I have added json to server(TFS 1.3) & client. Was there anything source-related needed as well? I've been checking multiple threads so far without success.

Code from server side: (Yes it prints "we trying", but nothing else)
Lua:
function CountdownText(time, character, endText)
local player = Player(character)
local insideADungeon = 42999
if not player then return false end
 if player:getStorageValue(insideADungeon) >= 1 then
 

        local response = {
            foo = "Hello",
            bar = "World"
        }
        print("we trying")
        player:sendExtendedOpcode(110, json.encode(response))
    if time > 0 then
    local minutes = string.format("%02.f", math.floor(time/60))
    local seconds = string.format("%02.f", math.floor(time - minutes*60))
        player:sendTextMessage(MESSAGE_STATUS_SMALL, "[You have " .. minutes .. "m and " .. seconds .. "s left!]")
        addEvent(CountdownText, 1 * 1000, time - 1, player:getId(), endText)
    if time == 30 then
        player:sendTextMessage(MESSAGE_STATUS_WARNING, "Warning! You only have 30 seconds left!!")
    end
    else
        CountdownText(endText)
        player:teleportTo({x = 1025, y = 1010, z = 7})
        player:sendTextMessage(MESSAGE_STATUS_WARNING, "You didnt succeed, try again.")
    end
 end
end

Code in client:
Lua:
function init()
  ProtocolGame.registerExtendedOpcode(110, onExtendedOpcode)
end

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

function sendMyCode()
  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("alo?")
  print(json_data.foo)
  print(json_data.bar)
end
 
Last edited:
Do you have extended opcode feature enabled in your OTClient features.lua?
g_game.enableFeature(GameExtendedOpcode)


If not, it will appear to the server as if it's just a regular client, not OTC and won't send/receive opcodes.
 
Do you have extended opcode feature enabled in your OTClient features.lua?
g_game.enableFeature(GameExtendedOpcode)


If not, it will appear to the server as if it's just a regular client, not OTC and won't send/receive opcodes.
Yep thats correct, I got GameExtendedOpcode enabled.
Edit: I changed autoload inside .otmod from false to true and now everything works as its suppose to.
 
Last edited:
Back
Top