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

TFS 1.X+ Extended OP Codes

Togu

Advanced OT User
Joined
Jun 22, 2018
Messages
308
Solutions
1
Reaction score
178
Location
Brazil
How do they work?
How do I use them?

I need to send a new information (like player attack speed) to the client.

Can someone give me a simple example of a custom extended op code working?
Or teach me the theory.
 
Extended opcodes will send a number or a string through the buffer parameter, so for example:

Lua:
player:sendExtendedOpcode(51, attackSpeed)

51 is the assigned opcode, which you want to make sure you're using an unused opcode (OTC uses 51-99 for custom opcodes) which can be viewed in OTC's gamelib/protocol.lua

Next you need to register the opcode inside of OTC and use the callback parameter to work with the buffer, for instance, to assign to a global or local variable to be used however, like so:

Lua:
ProtocolGame.registerExtendedOpcode(51, function(protocol, opcode, buffer)
    attackSpeed = buffer
end)

Then you may use the new variable however you need within OTC, but keep in mind you need to unregister the opcode before you can send a new one over and re-register it, like this:

Lua:
ProtocolGame.unregisterExtendedOpcode(51)

That's the gist of it, if you would like to send opcodes from client to server you would do this:

Lua:
local protocolGame = g_game.getProtocolGame()
if protocolGame then
    protocolGame:sendExtendedOpcode(51, attackSpeed)
end

And then retrieve in server sided through creaturescripts/extended_opcode.lua and read the buffer the same way.
 
Back
Top