• 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 Unable to send extended opcode

MorganaSacani

Active Member
Joined
Sep 20, 2022
Messages
87
Solutions
1
Reaction score
32
I'm trying to learn how to use extended opcode on my TFS 0.4, but I'm having the following problem:
Lua:
ERROR: Unable to send extended opcode 56, extended opcodes are not enabled on this server.

File from Otclient:
food_eater.lua:
Lua:
foodeaterButton = nil
foodeaterWindow = nil

local EAT_OPCODE = 56

function init()
    foodeaterButton = modules.client_topmenu.addRightGameToggleButton('foodeaterButton', tr('Food Eater'), '/images/topbuttons/food_eater', closing, false, 1)
    foodeaterButton:setOn(false)
    foodeaterWindow = g_ui.displayUI('food_eater')
    foodeaterWindow:setVisible(false) 
    
    allTabs = foodeaterWindow:recursiveGetChildById('allTabs')
    allTabs:setContentWidget(foodeaterWindow:getChildById('optionsTabContent'))
end

function terminate()
    foodeaterButton:destroy()
    foodeaterWindow:destroy()
end

function closing()
    if foodeaterButton:isOn() then
        foodeaterWindow:setVisible(false)
        foodeaterButton:setOn(false)
     else
        foodeaterWindow:setVisible(true)
        foodeaterButton:setOn(true)
    end
end

function banana()
    local protocolGame = g_game.getProtocolGame()
    if foodeaterButton:isOn() then
        if protocolGame then
            protocolGame:sendExtendedOpcode(EAT_OPCODE, 1)
        end
    else
        foodeaterWindow:setVisible(true)
        foodeaterButton:setOn(true)
    end
end

function melon()
    local protocolGame = g_game.getProtocolGame()
    if foodeaterButton:isOn() then
        if protocolGame then
            protocolGame:sendExtendedOpcode(EAT_OPCODE, 2)
        end
    else
        foodeaterWindow:setVisible(true)
        foodeaterButton:setOn(true)
    end
end

function cake()
    local protocolGame = g_game.getProtocolGame()
    if foodeaterButton:isOn() then
        if protocolGame then
            protocolGame:sendExtendedOpcode(EAT_OPCODE, 3)
        end
    else
        foodeaterWindow:setVisible(true)
        foodeaterButton:setOn(true)
    end
end

function onMiniWindowClose()
    foodeaterButton:setOn(false)
end

Files from my TFS 0.4:
creaturescripts.xml:
XML:
<event type="extendedopcode" name="foodeater" event="script" value="foodeater.lua"/>
login.lua:
Lua:
registerCreatureEvent(cid, "foodeater")
foodeater.lua:
Lua:
local EAT_OPCODE = 56

function onExtendedOpcode(cid, opcode, buffer)
    local banana = getPlayerItemCount(cid, 2676)
    local cake = getPlayerItemCount(cid, 6278)
    local melon = getPlayerItemCount(cid, 2680)
    local buf = tonumber(buffer)
    
    if opcode == EAT_OPCODE and buf == 1 and banana >= 1 then
        doCreatureSay(cid, "Omn, omn~! Banani!", TALKTYPE_MONSTER_SAY)
        doPlayerRemoveItem(cid, 2676, 1)
    elseif opcode == EAT_OPCODE and buf == 3 and cake >= 1 then
        doCreatureSay(cid, "Omn, omn~! Fat Boosting!", TALKTYPE_MONSTER_SAY)
        doPlayerRemoveItem(cid, 6278, 1)
    elseif opcode == EAT_OPCODE and buf == 2 and melon >= 1 then
        doCreatureSay(cid, "Omn, omn~! He?!", TALKTYPE_MONSTER_SAY)
        doPlayerRemoveItem(cid, 2680, 1)
    end
    return true
end
Post automatically merged:

Please close this.
I've solved in features.lua with:
Lua:
g_game.enableFeature(GameExtendedOpcode)
 
Last edited:
Back
Top