• 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 [1.5] [Mehah] Correct way to call ExtendedOpcode, take json_data in another function

Error 502

Intermediate OT User
Joined
Sep 25, 2022
Messages
242
Solutions
8
Reaction score
149
Location
Chile
Hello, good afternoon.

I'm learning to modify modules. The following post caught my attention:

modify it a bit. I attach the code at the end:

and Works .


jugfosoccccccvb.gif


I don't have an updater on the client, so I preferred to send the array via ExtendedOpcode (for future array upgrades, without changing the client).

Thanks to discord user "Tofame" and his "Guide ExtendedOpcodes Explanation" + Oen's explanation: OTClient - Learning (https://otland.net/threads/learning.273475/#post-2634136)
try doing extendedOpcode.

but
Problem: I don't know how to call the onExtendedOpcode_OTC(protocol, code, buffer) here
Code:
connect(LocalPlayer, {
     onPositionChange = onExtendedOpcode_OTC--<---- here
   })
or How to get variables "json_data" from the function "function onExtendedOpcode_OTC(protocol, code, buffer)"
to use it in anotherfunction.

I tried multiple times but, I only got it to work with buttons(pressing), but I want to use the onPositionChange

example:
function anotherfunction()
local map = modules.game_interface.getMapPanel()

map:setMapShader(name) -- name global funtion ,from the information sent by the server
end

connect(LocalPlayer, {
onPositionChange =
anotherfunction--<---- here
})



Context:
array composed of:
Code:
local areas = {
{from = {x = XXX, y = YYY, z = Z}, to = {x = XXX, y = YYY, z =Z}, name = 'Map - Rain'},
From Position
To position
name of "MAP_SHADERS"


(try with user level knowledge of the lua language, convert variable "name" (coming from the array that the server sends with opcode) into a global variable with name = nil. before the code or other methods but at the time of the print, it sent me this information" userdata: 0x028375ebc258" )

MODULE:
Lua:
function init()
--ProtocolGame.registerExtendedOpcode(15, onExtendedOpcode_OTC)
   local map = modules.game_interface.getMapPanel()
    map:setMapShader('Default')

  connect(LocalPlayer, {
    onPositionChange = updatePosition
  })
  
end

function terminate()
--ProtocolGame.unregisterExtendedOpcode(15, onExtendedOpcode_OTC)
end


local areas = {
{from = {x = 500, y = 253, z = 7}, to = {x = 505, y = 260, z = 7}, name = 'Map - Rain'},
{from = {x = 506, y = 253, z = 7}, to = {x = 511, y = 260, z = 7}, name = 'Map - Snow'},
{from = {x = 512, y = 253, z = 7}, to = {x = 518, y = 260, z = 7}, name = 'Map - Fog'},
{from = {x = 519, y = 253, z = 7}, to = {x = 525, y = 260, z = 7}, name = 'Map - Gray Scale'},
{from = {x = 526, y = 253, z = 7}, to = {x = 532, y = 260, z = 7}, name = 'Map - Bloom'},
{from = {x = 533, y = 253, z = 7}, to = {x = 538, y = 260, z = 7}, name = 'Map - Sepia'},
{from = {x = 539, y = 253, z = 7}, to = {x = 543, y = 260, z = 7}, name = 'Map - Pulse'},
{from = {x = 544, y = 253, z = 7}, to = {x = 548, y = 260, z = 7}, name = 'Map - Old Tv'},
}
function isInRange(position, fromPosition, toPosition)
    return (position.x >= fromPosition.x and position.y >= fromPosition.y and position.z >= fromPosition.z and position.x <= toPosition.x and position.y <= toPosition.y and position.z <= toPosition.z)
end


function updatePosition()

  local player = g_game.getLocalPlayer()
  if not player then return end
  local pos = player:getPosition()
  if not pos then return end
 
  local name = 'Default'
 
  for _, TABLE in ipairs(areas) do
      if isInRange(pos, TABLE.from, TABLE.to) then
        name = TABLE.name
      end
  end
  
      local map = modules.game_interface.getMapPanel()
    map:setMapShader(name)
end
---------FAIL OPCODE
-- function onExtendedOpcode_OTC(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

    -- local player = g_game.getLocalPlayer()
  -- if not player then return end
  -- local pos = player:getPosition()
  -- if not pos then return end
  -- name = 'Default'
  -- for _, TABLE in ipairs(json_data) do
      -- if isInRange(pos, TABLE.from, TABLE.to) then
        -- name = TABLE.name
      -- end
  -- end
-- print(name)
-- print(json_data)
      -- local map = modules.game_interface.getMapPanel()
                    -- map:setMapShader(name).

-- end





SERVER :
Code:
player:registerEvent("ExtendedOpcode")
on login
+
Lua:
function onExtendedOpcode(player, opcode, buffer)
    if opcode == 15 then
local areas= {
{from = {x = 500, y = 253, z = 7}, to = {x = 505, y = 260, z = 7}, name = 'Map - Rain'},
{from = {x = 506, y = 253, z = 7}, to = {x = 511, y = 260, z = 7}, name = 'Map - Snow'},
{from = {x = 512, y = 253, z = 7}, to = {x = 518, y = 260, z = 7}, name = 'Map - Fog'},
{from = {x = 519, y = 253, z = 7}, to = {x = 525, y = 260, z = 7}, name = 'Map - Gray Scale'},
{from = {x = 526, y = 253, z = 7}, to = {x = 532, y = 260, z = 7}, name = 'Map - Bloom'},
{from = {x = 533, y = 253, z = 7}, to = {x = 538, y = 260, z = 7}, name = 'Map - Sepia'},
{from = {x = 539, y = 253, z = 7}, to = {x = 543, y = 260, z = 7}, name = 'Map - Pulse'},
{from = {x = 544, y = 253, z = 7}, to = {x = 548, y = 260, z = 7}, name = 'Map - Old Tv'},
}
        player:sendExtendedOpcode(15, json.encode(response))     
    end
end

Source: Module game _banana by Tofame Discord "ExtendedOpcodes Explanation,"
Module game_areas by Oen44 , ralke? "Change shader onPositionChange(player, newPos, oldPos)"
Server : nekiro 1.5 downgrade
OTClient: Mehah +2.6.2

Regards
 
Last edited:
Back
Top