• 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!
  • New resources must be posted under Resources tab. A discussion thread will be created automatically, you can't open threads manually anymore.

Action Vocation Chest

J.Dre

Unity Games
Joined
May 18, 2011
Messages
2,647
Solutions
3
Reaction score
648
Location
United States
Hey everyone,

I recently saw an outdated request thread for a chest that gives a different item to a different vocation. Thinking of those who may need such a thing, I decided to code an updated version. This will hopefully, help you decrease the amount of chests for a quest!

Tested on The Forgotten Server 0.3.7 (aka. 0.4)

data/actions/actions.xml
Code:
<action actionid="[COLOR="#0000FF"]ACTION_ID;[/COLOR]" event="script" value="[COLOR="#0000FF"]SCRIPT_NAME[/COLOR].lua"/>
data/actions/scripts/script.lua
Code:
local config = {
    [ACTION_ID] = {
        premiumOnly = false,
        storage = 15150,
        level = 20,
        t = {
            [{1, 5}] = {
                {ITEM_ID, COUNT}, {ITEM_ID, COUNT}
            },
            [{2, 6}] = {
                {ITEM_ID, COUNT}, {ITEM_ID, COUNT}
            },
            [{3, 7}] = {
                {ITEM_ID, COUNT}, {ITEM_ID, COUNT}
            },
            [{4, 8}] = {
                {ITEM_ID, COUNT}, {ITEM_ID, COUNT}
            }
        }
    }
}

function onUse(cid, item, fromPosition, itemEx, toPosition)
    local v = config[item.actionid]

    if(v.premiumOnly) then
        if(not isPremium(cid)) then
            doPlayerSendCancel(cid, "Sorry, you are not a Premium member.")
            return true
        end
    end

    if(getCreatureStorage(cid, v.storage) > 0) then
        doPlayerSendCancel(cid, "The " .. getItemName(item.uid) .. " is empty.")
        return true
    end

    if(getPlayerLevel(cid) < v.level) then
        doPlayerSendCancel(cid, "Sorry, not possible.")
        return true
    end

    for voc, k in pairs(v.t) do
        if(isInArray(voc, getPlayerVocation(cid))) then
            for i = 1, #k do
                local id = doCreateItemEx(k[i][1], k[i][2] or 1)
                if(doPlayerAddItemEx(cid, id) ~= RETURNVALUE_NOERROR) then
                    return doPlayerSendCancel(cid, #k == 1 and "You cannot carry this item." or "You cannot carry these items."), false
                end
            end
        
            doCreatureSetStorage(cid, v.storage, 1)
        
            local msg = "You have found"
            if #k > 0 then
                for p = 1, #k do
                    msg = msg .. " " .. k[p][2] .. " " .. (#k == 1 and "" .. getItemInfo(k[p][1]).name .. "" or "" .. getItemInfo(k[p][1]).plural .. "") .. " "
                end
            end
            
            doPlayerSendTextMessage(cid, MESSAGE_EVENT_ADVANCE, msg)
            doSendMagicEffect(getThingPosition(cid), CONST_ME_MAGIC_BLUE)
        end
    end
    return true
end

 
Last edited:
Nice work!
Always fun to see contributions :)
 
I could really use this if it had the configuration for more than one item. I need a chest at the start that is scripted to give out a basic set to each vocation. Hopefully you can finish it up soon!
 
I could really use this if it had the configuration for more than one item. I need a chest at the start that is scripted to give out a basic set to each vocation. Hopefully you can finish it up soon!

Consider it done. My apologies for it taking so long. I sort of changed priorities for a while. ^_^
 
I will be using this soon... as soon as I manage to compile the rev I need. Will be taking a look at your other releases :)
 
Sounds good. I'm here to help if you need it. :thumbup:
 
Last edited:
Having troubles with this.

When anyone opens the chest it says 'You cannot carry these items.' even if I change the items to gold coins and a rope it says this. This is on empty characters with nothing but a backpack and level 15.

Code:
<action actionid="21000" event="script" value="vocation_chest.lua"/>
Code:
local config = {
[21000] = {
premiumOnly = false,
storage = 45002,
level = 15,
t = {
[{1}] = {
{7457, 1}, {7464, 1}, {8819, 1}, {8820, 1}, {2190, 1}, {2175, 1}
},
[{2}] = {
{7457, 1}, {7464, 1}, {8819, 1}, {8820, 1}, {2182, 1}, {2175, 1}
},
[{3}] = {
{2645, 1}, {2647, 1}, {2483, 1}, {2480, 1}, {2384, 1}, {2382, 1}, {2380, 1}, {2512, 1}
},
[{4}] = {
{2643, 1}, {2649, 1}, {2467, 1}, {2461, 1}, {2403, 1}, {2399, 5}
},
[{5}] = {
{2643, 1}, {2649, 1}, {2467, 1}, {2461, 1}, {2455, 1}, {2543, 50}, {2456, 1}, {2544, 50}
},
[{6}] = {
{2645, 1}, {2647, 1}, {2483, 1}, {2480, 1}, {2377, 1}, {7381, 1}, {2381, 1}
},
[{7}] = {
{7457, 1}, {7464, 1}, {8819, 1}, {8820, 1}, {2182, 1}, {2175, 1}
},
[{8}] = {
{7457, 1}, {7464, 1}, {8819, 1}, {8820, 1}, {7633, 1}, {2175, 1}
},
[{17}] = {
{2645, 1}, {2647, 1}, {2483, 1}, {2480, 1}, {7854, 1}, {7749, 1}, {7883, 1}, {2512, 1}
},
[{19}] = {
{2643, 1}, {2649, 1}, {2467, 1}, {2461, 1}, {5897, 1}
},
[{20}] = {
{2645, 1}, {2647, 1}, {2483, 1}, {2480, 1}, {2320, 1}, {2512, 1}
},
[{58}] = {
{2643, 1}, {2649, 1}, {2467, 1}, {2461, 1}, {3964, 1}
}
}
}
}

function onUse(cid, item, fromPosition, itemEx, toPosition)
local v = config[item.actionid]

if(v.premiumOnly) then
if(not isPremium(cid)) then
doPlayerSendCancel(cid, "Sorry, you are not a Premium member.")
return true
end
end

if(getCreatureStorage(cid, v.storage) > 0) then
doPlayerSendCancel(cid, "The " .. getItemName(item.uid) .. " is empty.")
return true
end

if(getPlayerLevel(cid) < v.level) then
doPlayerSendCancel(cid, "Sorry, not possible.")
return true
end

for voc, k in pairs(v.t) do
if(isInArray(voc, getPlayerVocation(cid))) then
for i = 1, #k do
local id = doCreateItemEx(k[1], k[2] or 1)
if(doPlayerAddItemEx(cid, id) ~= RETURNVALUE_NOERROR) then
return doPlayerSendCancel(cid, #k == 1 and "You cannot carry this item." or "You cannot carry these items."), false
end
end

doCreatureSetStorage(cid, v.storage, 1)

local msg = "You have found"
if #k > 0 then
for p = 1, #k do
msg = msg .. " " .. k[p][2] .. " " .. (#k == 1 and "" .. getItemInfo(k[p][1]).name .. "" or "" .. getItemInfo(k[p][1]).plural .. "") .. " "
end
end

doPlayerSendTextMessage(cid, MESSAGE_EVENT_ADVANCE, msg)
doSendMagicEffect(getThingPosition(cid), CONST_ME_MAGIC_BLUE)
end
end
return true
end
Code:
[11:49:33.806] [Error - Action Interface]
[11:49:33.806] data/actions/scripts/vocation_chest.lua:onUse
[11:49:33.806] Description:
[11:49:33.806] (luaDoPlayerAddItemEx) Item not found
I also double checked the item id's in use, and could spawn them all using my gm.
Any suggestions?
 
Last edited:
Having troubles with this.

When anyone opens the chest it says 'You cannot carry these items.' even if I change the items to gold coins and a rope it says this. This is on empty characters with nothing but a backpack and level 15.

Code:
<action actionid="21000" event="script" value="vocation_chest.lua"/>
Code:
local config = {
[21000] = {
premiumOnly = false,
storage = 45002,
level = 15,
t = {
[{1}] = {
{7457, 1}, {7464, 1}, {8819, 1}, {8820, 1}, {2190, 1}, {2175, 1}
},
[{2}] = {
{7457, 1}, {7464, 1}, {8819, 1}, {8820, 1}, {2182, 1}, {2175, 1}
},
[{3}] = {
{2645, 1}, {2647, 1}, {2483, 1}, {2480, 1}, {2384, 1}, {2382, 1}, {2380, 1}, {2512, 1}
},
[{4}] = {
{2643, 1}, {2649, 1}, {2467, 1}, {2461, 1}, {2403, 1}, {2399, 5}
},
[{5}] = {
{2643, 1}, {2649, 1}, {2467, 1}, {2461, 1}, {2455, 1}, {2543, 50}, {2456, 1}, {2544, 50}
},
[{6}] = {
{2645, 1}, {2647, 1}, {2483, 1}, {2480, 1}, {2377, 1}, {7381, 1}, {2381, 1}
},
[{7}] = {
{7457, 1}, {7464, 1}, {8819, 1}, {8820, 1}, {2182, 1}, {2175, 1}
},
[{8}] = {
{7457, 1}, {7464, 1}, {8819, 1}, {8820, 1}, {7633, 1}, {2175, 1}
},
[{17}] = {
{2645, 1}, {2647, 1}, {2483, 1}, {2480, 1}, {7854, 1}, {7749, 1}, {7883, 1}, {2512, 1}
},
[{19}] = {
{2643, 1}, {2649, 1}, {2467, 1}, {2461, 1}, {5897, 1}
},
[{20}] = {
{2645, 1}, {2647, 1}, {2483, 1}, {2480, 1}, {2320, 1}, {2512, 1}
},
[{58}] = {
{2643, 1}, {2649, 1}, {2467, 1}, {2461, 1}, {3964, 1}
}
}
}
}

function onUse(cid, item, fromPosition, itemEx, toPosition)
local v = config[item.actionid]

if(v.premiumOnly) then
if(not isPremium(cid)) then
doPlayerSendCancel(cid, "Sorry, you are not a Premium member.")
return true
end
end

if(getCreatureStorage(cid, v.storage) > 0) then
doPlayerSendCancel(cid, "The " .. getItemName(item.uid) .. " is empty.")
return true
end

if(getPlayerLevel(cid) < v.level) then
doPlayerSendCancel(cid, "Sorry, not possible.")
return true
end

for voc, k in pairs(v.t) do
if(isInArray(voc, getPlayerVocation(cid))) then
for i = 1, #k do
local id = doCreateItemEx(k[1], k[2] or 1)
if(doPlayerAddItemEx(cid, id) ~= RETURNVALUE_NOERROR) then
return doPlayerSendCancel(cid, #k == 1 and "You cannot carry this item." or "You cannot carry these items."), false
end
end

doCreatureSetStorage(cid, v.storage, 1)

local msg = "You have found"
if #k > 0 then
for p = 1, #k do
msg = msg .. " " .. k[p][2] .. " " .. (#k == 1 and "" .. getItemInfo(k[p][1]).name .. "" or "" .. getItemInfo(k[p][1]).plural .. "") .. " "
end
end

doPlayerSendTextMessage(cid, MESSAGE_EVENT_ADVANCE, msg)
doSendMagicEffect(getThingPosition(cid), CONST_ME_MAGIC_BLUE)
end
end
return true
end
Code:
[11:49:33.806] [Error - Action Interface]
[11:49:33.806] data/actions/scripts/vocation_chest.lua:onUse
[11:49:33.806] Description:
[11:49:33.806] (luaDoPlayerAddItemEx) Item not found
I also double checked the item id's in use, and could spawn them all using my gm.
Any suggestions?
Code:
local id = doCreateItemEx(k[i][1], k[i][2] or 1)
 
Back
Top