• 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 [1.2] 'outfit '(a nil value) -- custom vocation

Caduceus

Unknown Member
Joined
May 10, 2010
Messages
321
Solutions
2
Reaction score
24
Server Version: TFS 1.2

Script seems to work fine with a standard 4 vocation setup. However when I try to add additional vocation to the lineup, I run into some issues.

error
Code:
Lua Script Error: [Action Interface]
data/actions/scripts/custom/Vocation_addon.lua:onUse
data/actions/scripts/custom/Vocation_addon.lua:15: attempt to index local 'outfit' (a nil value)
stack traceback:
        [C]: in function '__index'
        data/actions/scripts/custom/Vocation_addon.lua:15: in function <data/actions/scripts/custom/Vocation_addon.lua:12>

script
Code:
local storage = 45554

local outfits = {
    {female = 138, male = 130, addon = 3}, -- 1
    {female = 148, male = 144, addon = 3}, -- 2
    {female = 137, male = 129, addon = 3}, -- 3
    {female = 139, male = 131, addon = 3}, -- 4
    {female = 142, male = 134, addon = 3}  -- 9 custom voc
}

local msg = ''
function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    if player:getStorageValue(storage) == 2 then
        local outfit = outfits[player:getVocation():getBase():getId()]
        player:addOutfitAddon(outfit.female, outfit.addon)
        player:addOutfitAddon(outfit.male, outfit.addon)
        msg = "You received a free addon!"
        player:setStorageValue(storage, 3)
    else
        msg = " The chest seems to be locked."
    end
  
    player:sendTextMessage(MESSAGE_INFO_DESCR, msg)
    return true
end
 
Last edited:
This is the issue
player:getVocation():getBase():getId()
You are trying to reference a index of the table which doesn't exist

Code:
local storage = 45554

local outfits = {
    [1] = {female = 138, male = 130, addon = 3}, -- 1
    [2] = {female = 148, male = 144, addon = 3}, -- 2
    [3] = {female = 137, male = 129, addon = 3}, -- 3
    [4] = {female = 139, male = 131, addon = 3}, -- 4
    [9] = {female = 142, male = 134, addon = 3}  -- 9 custom voc
}

local msg = ''
function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    if player:getStorageValue(storage) == 2 then
        local outfit = outfits[player:getVocation():getBase():getId()]
        player:addOutfitAddon(outfit.female, outfit.addon)
        player:addOutfitAddon(outfit.male, outfit.addon)
        msg = "You received a free addon!"
        player:setStorageValue(storage, 3)
    else
        msg = " The chest seems to be locked."
    end

    player:sendTextMessage(MESSAGE_INFO_DESCR, msg)
    return true
end
 
Last edited:
Back
Top