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

Solved Trying to convert old script to 1.1

Caduceus

Unknown Member
Joined
May 10, 2010
Messages
321
Solutions
2
Reaction score
24
I am trying to convert some of my old script to 1.1. I can only get the chest to give items for vocation 1, no others. It is supposed to give items based on vocation. I know it's far from right.

Code:
function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    if player:getStorageValue(15483) == 1 then
        player:sendTextMessage(MESSAGE_INFO_DESCR, "chest is empty.")
    elseif player:getStorageValue(15483) <= 1 and player:getVocation():getId() ~= 1 then
        player:sendTextMessage(MESSAGE_INFO_DESCR, "You have found some useful gear!")
            player:addItem(2190)
            player:addItem(8900)
        player:setStorageValue(15483, 1)
    else
        player:sendTextMessage(MESSAGE_INFO_DESCR, "Something went wrong.")
       end

function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    if player:getStorageValue(15483) == 1 then
        player:sendTextMessage(MESSAGE_INFO_DESCR, "chest is empty.")
    elseif player:getStorageValue(15483) <= 1 and player:getVocation():getId() ~= 2 then
        player:sendTextMessage(MESSAGE_INFO_DESCR, "You have found some useful gear!")
            player:addItem(2182)
            player:addItem(8900)
        player:setStorageValue(15483, 1)
    else
        player:sendTextMessage(MESSAGE_INFO_DESCR, "Something went wrong.")
    end

function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    if player:getStorageValue(15483) == 1 then
        player:sendTextMessage(MESSAGE_INFO_DESCR, "chest is empty.")
        elseif player:getStorageValue(15483) <= 1 and player:getVocation():getId() ~= 3 then
        player:sendTextMessage(MESSAGE_INFO_DESCR, "You have found some useful gear!")
            player:addItem(2456)
            player:addItem(2544)
        player:setStorageValue(15483, 1)
    else
        player:sendTextMessage(MESSAGE_INFO_DESCR, "Something went wrong.")
    end

function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    if player:getStorageValue(15483) == 1 then
        player:sendTextMessage(MESSAGE_INFO_DESCR, "chest is empty.")
        elseif player:getStorageValue(15483) <= 1 and player:getVocation():getId() ~= 4 then
        player:sendTextMessage(MESSAGE_INFO_DESCR, "You have found some useful gear!")
            player:addItem(2448)
            player:addItem(2526)
        player:setStorageValue(15483, 1)
    else
        player:sendTextMessage(MESSAGE_INFO_DESCR, "Something went wrong.")
    end

return true
            end
        end
    end
end
 
Last edited:
Try changing this:
Code:
player:getVocation():getId()
to:
Code:
player:getVocation():getBase():getId()
 
@imkingran I get this error onUse
Code:
Lua Script Error: [Action Interface]
data/actions/scripts/custom/voc_start_weapon.lua:onUse
data/actions/scripts/custom/voc_start_weapon.lua:4: attempt to call meth
od 'getBase' (a nil value)
stack traceback:
        [C]: in function 'getBase'
        data/actions/scripts/custom/Starter_weapon_voc_based.lua:4: in function
<data/actions/scripts/custom/voc_start_weapon.lua:1>
 
Last edited:
@imkingran I get this error onUse
Code:
Lua Script Error: [Action Interface]
data/actions/scripts/custom/voc_start_weapon.lua:onUse
data/actions/scripts/custom/voc_start_weapon.lua:4: attempt to call meth
od 'getBase' (a nil value)
stack traceback:
        [C]: in function 'getBase'
        data/actions/scripts/custom/Starter_weapon_voc_based.lua:4: in function
<data/actions/scripts/custom/voc_start_weapon.lua:1>

Add this to your global.lua and then execute the command /reload global and try again.

Code:
function Vocation.getBase(self)
    local demotion = self:getDemotion()
    while demotion do
        local tmp = demotion:getDemotion()
        if not tmp then
            return demotion
        end
        demotion = tmp
    end
    return self
end
 
I am still only receiving gear for sorc. The storage is working, added the function to my global, restarted, and no errors on console.

Code:
function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    if player:getStorageValue(15483) == 1 then
        player:sendTextMessage(MESSAGE_INFO_DESCR, "chest is empty.")
    elseif player:getStorageValue(15483) <= 1 and player:getVocation():getBase():getId() ~= 1 then
        player:sendTextMessage(MESSAGE_INFO_DESCR, "You have found some useful gear!")
            player:addItem(2190)
            player:addItem(8900)
        player:setStorageValue(15483, 1)
    else
        player:sendTextMessage(MESSAGE_INFO_DESCR, "Something went wrong.")
       end

    if player:getStorageValue(15483) == 1 then
        player:sendTextMessage(MESSAGE_INFO_DESCR, "chest is empty.")
    elseif player:getStorageValue(15483) <= 1 and player:getVocation():getBase():getId() ~= 2 then
        player:sendTextMessage(MESSAGE_INFO_DESCR, "You have found some useful gear!")
            player:addItem(2182)
            player:addItem(8900)
        player:setStorageValue(15483, 1)
    else
        player:sendTextMessage(MESSAGE_INFO_DESCR, "Something went wrong.")
    end

    if player:getStorageValue(15483) == 1 then
        player:sendTextMessage(MESSAGE_INFO_DESCR, "chest is empty.")
        elseif player:getStorageValue(15483) <= 1 and player:getVocation():getBase():getId() ~= 3 then
        player:sendTextMessage(MESSAGE_INFO_DESCR, "You have found some useful gear!")
            player:addItem(2456)
            player:addItem(2544)
        player:setStorageValue(15483, 1)
    else
        player:sendTextMessage(MESSAGE_INFO_DESCR, "Something went wrong.")
    end

    if player:getStorageValue(15483) == 1 then
        player:sendTextMessage(MESSAGE_INFO_DESCR, "chest is empty.")
        elseif player:getStorageValue(15483) <= 1 and player:getVocation():getBase():getId() ~= 4 then
        player:sendTextMessage(MESSAGE_INFO_DESCR, "You have found some useful gear!")
            player:addItem(2448)
            player:addItem(2526)
        player:setStorageValue(15483, 1)
    else
        player:sendTextMessage(MESSAGE_INFO_DESCR, "Something went wrong.")
    end

return true

end
 
Last edited:
Code:
local storage = 15483

local vocations = {
    {2190, 8900}, -- 1
    {2182, 8900}, -- 2
    {2456, 2544}, -- 3
    {2448, 2526}  -- 4
}

local msg = ''
function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    if player:getStorageValue(storage) < 1 then
        for vocId, items in ipairs(vocations) do
            if player:getVocation():getBase():getId() == vocId then
                for i = 1, #items do
                    player:addItem(items[i])
                end
                msg = "You have found some useful gear!"
            end
        end
        player:setStorageValue(storage, 1)
    else
        msg = "chest is empty."
    end
    player:sendTextMessage(MESSAGE_INFO_DESCR, msg)
    return true
end
 
Last edited:
@Codex NG

not sure what this means.
Code:
[Warning - Event::checkScript] Can not load script: scripts/custom/Starter_weapo
n_voc_based.lua
data/actions/scripts/custom/Starter_weapon_voc_based.lua:14: 'do' expected near
'if'
 
Last edited:
Back
Top