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

Lua how to add more vocations?

darkmu

Well-Known Member
Joined
Aug 26, 2007
Messages
274
Solutions
1
Reaction score
50
Location
Paraná,Brazil
This is my code, but.. when the player is promoted him not recieve the itens. Can u help me?

Code:
local config = {    
    storage = 15217,    
    items = {
        [1] = {            
            {2188, 1},    
        },
        [2] = {            
            {2185, 1},     
        },

        [3] = {            
            {7367, 10},                 
        },

        [4] = {            
            {7432, 1},     
            {8209, 1},     
            {8601, 1},     
        },

        default = {        
            {2160, 2},    
            
        }
    }

}

function onUse(player, item, fromPosition, target, toPosition, isHotkey)    
    if(item.uid == 37900) then
        if(player:getStorageValue(config.storage) == -1) then
            local bag = player:addItem(1987, 1)
            
            if (bag) then
                if player:getStorageValue(config.storage) < 1 then    
                    for _, item in pairs(config.items.default) do
                        player:addItem(item[1], item[2])
                    end
                end
            end
        
            local vocation = config.items[player:getVocation():getId()]
        
            if vocation then
                for _, item in pairs(vocation) do
                    bag:addItem(item[1], item[2])
                end            
            end        
            
            player:addMount(config.mount_id)
            player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "You found a bag and donkey mount.")
            player:getPosition():sendMagicEffect(32)
            player:setStorageValue(config.storage, 1)            
        else
            player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "The chest is empty.")
        end    
    end

    return true
end
 
This is my code, but.. when the player is promoted him not recieve the itens. Can u help me?

Code:
local config = {   
    storage = 15217,   
    items = {
        [1] = {           
            {2188, 1},   
        },
        [2] = {           
            {2185, 1},    
        },

        [3] = {           
            {7367, 10},                
        },

        [4] = {           
            {7432, 1},    
            {8209, 1},    
            {8601, 1},    
        },

        default = {       
            {2160, 2},   
           
        }
    }

}

function onUse(player, item, fromPosition, target, toPosition, isHotkey)   
    if(item.uid == 37900) then
        if(player:getStorageValue(config.storage) == -1) then
            local bag = player:addItem(1987, 1)
           
            if (bag) then
                if player:getStorageValue(config.storage) < 1 then   
                    for _, item in pairs(config.items.default) do
                        player:addItem(item[1], item[2])
                    end
                end
            end
       
            local vocation = config.items[player:getVocation():getId()]
       
            if vocation then
                for _, item in pairs(vocation) do
                    bag:addItem(item[1], item[2])
                end           
            end       
           
            player:addMount(config.mount_id)
            player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "You found a bag and donkey mount.")
            player:getPosition():sendMagicEffect(32)
            player:setStorageValue(config.storage, 1)           
        else
            player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "The chest is empty.")
        end   
    end

    return true
end
Either add all the vocations into your table, or reduce the vocation id by intervals of 4.

(assuming that all your vocations are static increases. 1->5->9 = sorcerer, master sorcerer, blah blah sorcerer)
Lua:
local vocation = config.items[player:getVocation():getId()] -- line 42 in your script
while vocation > 4 do
    vocation = vocation - 4
end
 
Back
Top