• 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 Extended Opcode

Helliot1

Owner of Empire Online
Joined
Jul 26, 2017
Messages
315
Solutions
1
Reaction score
57
Hello guys, I'm trying to use extended opcode and I have some questions.

I need to get the player vocation every time that I log in so I put this inside my "creaturescripts/login.lua". But how can I read the extended opcode in my OTC module? Because I have a spell module for each vocation and I want it to open according to each vocation.

Lua:
-- Vocation
    local targetVocation = player:getVocation():getId()
   
    if not targetVocation then
        return true
    end
   
    if targetVocation == 1 then
        player:sendExtendedOpcode(12, 1)
        player:say("I'm a warrior!", TALKTYPE_MONSTER_SAY)
    elseif targetVocation == 2 then
        player:sendExtendedOpcode(12, 2)
        player:say("I'm a ranger!", TALKTYPE_MONSTER_SAY)
    elseif targetVocation == 3 then
        player:sendExtendedOpcode(12, 3)
        player:say("I'm a mage!", TALKTYPE_MONSTER_SAY)
    end
 
Last edited:
Solution
I think there are several alternatives, but since your question is direct and it is about how to read a client-side operation code, here I can show you a fairly easy and clear example:

Lua:
function init()
    connect(g_game, {
        onGameStart = testStart,
        onGameEnd = testEnd
    }, true)

end

function terminate()
    disconnect(g_game, {
        onGameStart = testStart,
        onGameEnd = testEnd
    })
end

function onRecvOpcode(protocol, opcode, packet)
    --opcode = 55
    --packet = tostring(player:getVocation():getId())
    --Here you should receive the data you sent from the server
    print(protocol, opcode, packet)
end

function testStart()
    ProtocolGame.registerExtendedOpcode(55, onRecvOpcode)
end

function...
This should help.
 
This should help.
Yes, I read but didn't understand...

Here I'm sending opcode to TFS... But I can't understand how I can read these opcode on OTC...
Lua:
    if targetVocation == 1 then
        player:sendExtendedOpcode(12, 1)
        player:say("I'm a warrior!", TALKTYPE_MONSTER_SAY)
    end
 
If you are at login screen there is no player online to send that extendedOpcode. What I did was to send name,level,vocation in the name string and parsed it through the client.
 

Attachments

  • Screenshot_20201206-010136_Chrome.jpg
    Screenshot_20201206-010136_Chrome.jpg
    139.3 KB · Views: 53 · VirusTotal
If you are at login screen there is no player online to send that extendedOpcode. What I did was to send name,level,vocation in the name string and parsed it through the client.

Thanks, Peonso!

I'm using otx/data/creaturescripts/scripts/login.lua in onLogin function so there is a player online and I validated this by "player:say".

I didn't understand what you did, I think my way will be better because I just need to read this opcode on OTC to put it into a function, but I don't know how to do it..

Lua:
    if targetVocation == 1 then
        player:sendExtendedOpcode(12, 1)
        player:say("I'm a warrior!", TALKTYPE_MONSTER_SAY)
    end

Test.png,
 
There is no need to send vocation via extended opcode. You can use onVocationChange inside OTC, and that should work.
 
There is no need to send vocation via extended opcode. You can use onVocationChange inside OTC, and that should work.
This. Just keep in mind it's using clientid from vocations.xml.
Yes, I read but didn't understand...
What you didn't understand? The part that says extended op codes are accepting only strings while you are trying to send a number?
 
I think there are several alternatives, but since your question is direct and it is about how to read a client-side operation code, here I can show you a fairly easy and clear example:

Lua:
function init()
    connect(g_game, {
        onGameStart = testStart,
        onGameEnd = testEnd
    }, true)

end

function terminate()
    disconnect(g_game, {
        onGameStart = testStart,
        onGameEnd = testEnd
    })
end

function onRecvOpcode(protocol, opcode, packet)
    --opcode = 55
    --packet = tostring(player:getVocation():getId())
    --Here you should receive the data you sent from the server
    print(protocol, opcode, packet)
end

function testStart()
    ProtocolGame.registerExtendedOpcode(55, onRecvOpcode)
end

function testEnd()
    ProtocolGame.unregisterExtendedOpcode(55)
end

server send to client:
Lua:
        local packet = NetworkMessage()
        packet:addByte(0x32) -- Extended Opcode (0x32 = 50 (in dec))
        packet:addByte(0x37) -- The Opcode of this Request (0x37 = 55 (in dec))
        packet:addString(tostring(player:getVocation():getId()))
        packet:sendToPlayer(player)
 
Solution
server send to client:
Lua:
        local packet = NetworkMessage()
        packet:addByte(0x32) -- Extended Opcode (0x32 = 50 (in dec))
        packet:addByte(0x37) -- The Opcode of this Request (0x37 = 55 (in dec))
        packet:addString(tostring(player:getVocation():getId()))
        packet:sendToPlayer(player)
Or just player:sendExtendedOpcode(55, tostring(player:getVocation():getId())).
Even so using event onVocationChange on client side is a better way.
 
I think there are several alternatives, but since your question is direct and it is about how to read a client-side operation code, here I can show you a fairly easy and clear example:

Lua:
function init()
    connect(g_game, {
        onGameStart = testStart,
        onGameEnd = testEnd
    }, true)

end

function terminate()
    disconnect(g_game, {
        onGameStart = testStart,
        onGameEnd = testEnd
    })
end

function onRecvOpcode(protocol, opcode, packet)
    --opcode = 55
    --packet = tostring(player:getVocation():getId())
    --Here you should receive the data you sent from the server
    print(protocol, opcode, packet)
end

function testStart()
    ProtocolGame.registerExtendedOpcode(55, onRecvOpcode)
end

function testEnd()
    ProtocolGame.unregisterExtendedOpcode(55)
end

server send to client:
Lua:
        local packet = NetworkMessage()
        packet:addByte(0x32) -- Extended Opcode (0x32 = 50 (in dec))
        packet:addByte(0x37) -- The Opcode of this Request (0x37 = 55 (in dec))
        packet:addString(tostring(player:getVocation():getId()))
        packet:sendToPlayer(player)

Thanks @Sarah Wesker. That was exactly what I was looking for!! Now I finished my module.
 
Last edited:
Back
Top