• 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
296
Solutions
1
Reaction score
47
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...

oen432

Legendary OT User
Joined
Oct 3, 2014
Messages
1,462
Solutions
49
Reaction score
1,552
Location
Poland
GitHub
Oen44
This should help.
 
OP
OP
Helliot1

Helliot1

Owner of Empire Online
Joined
Jul 26, 2017
Messages
296
Solutions
1
Reaction score
47
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
 

Peonso

Godly Member
Joined
Jan 14, 2008
Messages
1,638
Solutions
27
Reaction score
1,314
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: 22 · VirusTotal
OP
OP
Helliot1

Helliot1

Owner of Empire Online
Joined
Jul 26, 2017
Messages
296
Solutions
1
Reaction score
47
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,
 

margoh

{{ user.title }}
Joined
Apr 1, 2013
Messages
780
Solutions
18
Reaction score
302
There is no need to send vocation via extended opcode. You can use onVocationChange inside OTC, and that should work.
 

oen432

Legendary OT User
Joined
Oct 3, 2014
Messages
1,462
Solutions
49
Reaction score
1,552
Location
Poland
GitHub
Oen44
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?
 

Sarah Wesker

ค∂vαηcε รүηтαx ❤
Support Team
Joined
Mar 16, 2017
Messages
1,040
Solutions
105
Reaction score
1,097
Location
London
GitHub
MillhioreBT
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

oen432

Legendary OT User
Joined
Oct 3, 2014
Messages
1,462
Solutions
49
Reaction score
1,552
Location
Poland
GitHub
Oen44
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.
 
OP
OP
Helliot1

Helliot1

Owner of Empire Online
Joined
Jul 26, 2017
Messages
296
Solutions
1
Reaction score
47
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:
Top