-- 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.