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

Is there a way to send extended opcodes from client to server?

Joined
Jul 18, 2014
Messages
193
Solutions
2
Reaction score
15
I want to send extended opcodes from otclient to server, for example, I click on a client button and I want the server to know that I clicked on that button to perform an action in server.

Any idea?
Thanks.
 
-- Note, we use the opcode id as 52


-- Client: At any mode lua script file
Lua:
local protocolGame = g_game.getProtocolGame()
if protocolGame then
  local myValue = math.random(1, 2)
  protocolGame:sendExtendedOpcode(52, myValue)
end

-- Server: creaturescripts.xml
XML:
<event type="extendedopcode" name="MyOpcodeNameRegister" script="myopcode.lua" />

-- Server: myopcode.lua
Lua:
function onExtendedOpcode(player, opcode, buffer)
  if opcode == 52 then
    local myValue = tonumber(buffer)
    if myValue == 1 then
      player:say("My value is one.", TALKTYPE_SAY)
    elseif myValue == 2 then
      player:say("My value is two.", TALKTYPE_SAY)
    else
      player:say("My value is undefined.", TALKTYPE_SAY)
    end
  end
end

-- Server: Any lua script file
Lua:
player:registerEvent("MyOpcodeNameRegister")


-- When you register this with player:registerEvent(...) and, then, when the player receives the protocol message with id 52, it will check if the buffer has value 1, 2 or anything else.
 
-- Note, we use the opcode id as 52


-- Client: At any mode lua script file
Lua:
local protocolGame = g_game.getProtocolGame()
if protocolGame then
  local myValue = math.random(1, 2)
  protocolGame:sendExtendedOpcode(52, myValue)
end

-- Server: creaturescripts.xml
XML:
<event type="extendedopcode" name="MyOpcodeNameRegister" script="myopcode.lua" />

-- Server: myopcode.lua
Lua:
function onExtendedOpcode(player, opcode, buffer)
  if opcode == 52 then
    local myValue = tonumber(buffer)
    if myValue == 1 then
      player:say("My value is one.", TALKTYPE_SAY)
    elseif myValue == 2 then
      player:say("My value is two.", TALKTYPE_SAY)
    else
      player:say("My value is undefined.", TALKTYPE_SAY)
    end
  end
end

-- Server: Any lua script file
Lua:
player:registerEvent("MyOpcodeNameRegister")


-- When you register this with player:registerEvent(...) and, then, when the player receives the protocol message with id 52, it will check if the buffer has value 1, 2 or anything else.

Awesome! Thank you so much :)
 
Back
Top