J.Dre
Unity Games
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
data/actions/scripts/script.lua
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"/>
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: