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

Do something in client because of globalevent

Joined
Jul 18, 2014
Messages
193
Solutions
2
Reaction score
15
I was wondering if there's a way to do something in client because of some action, globalevent, etc. For example, if a globalevent is executed, a custom window popup will show up (module).
In other words, a way to get control of the client with server functions.

Any idea?
Thanks.
 
I was wondering if there's a way to do something in client because of some action, globalevent, etc. For example, if a globalevent is executed, a custom window popup will show up (module).
In other words, a way to get control of the client with server functions.

Any idea?
Thanks.
Isn't that how it works? FYI box for example.
 
I was wondering if there's a way to do something in client because of some action, globalevent, etc. For example, if a globalevent is executed, a custom window popup will show up (module).
In other words, a way to get control of the client with server functions.

Any idea?
Thanks.

Yes, you can use extended opcodes to send a custom packet from the server to the client and vice-versa.
When you want to trigger this thing (whatever it is that you're triggering), you send a packet to the client; and on the client side, you make a function that receives this packet. Inside of this function, you write whatever you want the client to do when this packet is received. You can also insert data into your packet which will be received by the client, and then you can unpack this data there and use it if needed as well.

If you don't have extended opcode handling in your server, you can start by implementing this.
Then you can use this function to send stuff to the client.
Lua:
 doSendPlayerExtendedOpcode(cid, opcode, buffer)

In the client, you can register it via:
Lua:
ProtocolGame.registerExtendedOpcode(ExtendedID, functionName)
,
Where functionName is the function that will be called when this ID is received.

You also have to unregister it onGameEnd with:
Lua:
ProtocolGame.unregisterExtendedOpcode(ExtendedID, true)

And here's an example of a function that calls the openWindow function from a module called game_promotion:
Lua:
function OpenVocationWindow()
  modules.game_promotion.openWindow()
end

Make sure that opcodes which you add are not conflicting with existing ones, you can find them in your server and client sources in protocol related files.
 
Last edited:
Yes, you can use extended opcodes to send a custom packet from the server to the client and vice-versa.
When you want to trigger this thing (whatever it is that you're triggering), you send a packet to the client; and on the client side, you make a function that receives this packet. Inside of this function, you write whatever you want the client to do when this packet is received. You can also insert data into your packet which will be received by the client, and then you can unpack this data there and use it if needed as well.

If you don't have extended opcode handling in your server, you can start by implementing this.
Then you can use this function to send stuff to the client.
Lua:
 doSendPlayerExtendedOpcode(cid, opcode, buffer)

In the client, you can register it via:
Lua:
ProtocolGame.registerExtendedOpcode(ExtendedID, functionName)
,
Where functionName is the function that will be called when this ID is received.

You also have to unregister it onGameEnd with:
Lua:
ProtocolGame.unregisterExtendedOpcode(ExtendedID, true)

And here's an example of a function that calls the openWindow function from a module called game_promotion:
Lua:
function OpenVocationWindow()
  modules.game_promotion.openWindow()
end

Make sure that opcodes which you add are not conflicting with existing ones, you can find them in your server and client sources in protocol related files.
Nice! This is what I was looking for. Thanks!
 
Back
Top