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

Chest for Each Vocation

Andrekkzie

New Member
Joined
Sep 12, 2010
Messages
64
Reaction score
2
I want when i finish a quest that the chest give and item for each vocation
Example:
Pally - Crossbow
Knight - Sword
 
Lua:
local cfg = {
storage = 9999, -- change storage to whatever you want it.
knight = 1234, -- item id of the item to give to knights.
sorc = 1234, -- item id of the item to give to sorcs
druid = 1234, -- item id of the item to give to druids.
pally = 1234 -- item id of the item to give to paladins.
}

local vocs = {
Sorc = {1, 5},
Druid = {2, 6},
Paladin = {3, 7},
knight = {4, 8}
}

function onUse(cid, item, fromPosition, itemEx, toPosition)
	if getPlayerStorageValue(cid, cfg.storage) <= 0 then
		if getPlayerVocation(cid) == vocs.sorc then
			doPlayerAddItem(cid, cfg.sorc, 1)
		elseif getPlayerVocation(cid) == vocs.druid then
			doPlayerAddItem(cid, cfg.druid, 1)
		elseif getPlayerVocation(cid) == cfg.Paladin then
			doPlayerAddItem(cid, cfg.pally, 1)
		elseif getPlayerVocation(cid) == vocs.knight then
			doPlayerAddItem(cid, cfg.knight, 1)
		end
		setPlayerStorageValue(cid, cfg.storage, 1)
	else
		doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "You have already completed this quest.")
	end
return TRUE
end


didnt realize what i was doing there lmao edited
Try that. let me know if it works or not.
 
Last edited:
Here is with capacity check:
Lua:
--- Coded by Znote ---- r2 - otland.net
-- Changelog: Added capacity calculator. Now also work with promoted vocations. (sorc = vocation 1 & 5).
---- CONFIG
-- Storage value not in use:
local storage = 80010
 
-- Item Sorcerer get:
local sorcItem = 2160
local sorcCount = 1
 
-- Item Druid get:
local druidItem = 2160
local druidCount = 1
 
-- Item Paladin get:
local pallyItem = 2160
local pallyCount = 1
 
-- Item Knight get:
local knightItem = 2160
local knightCount = 1
----- END CONFIG
 
if getPlayerStorageValue(cid,storage) < 1 then
	local freecap = getPlayerFreeCap(cid)
 
	if getPlayerVocation(cid) == 1 or if getPlayerVocation(cid) == 5 then
		local itemcap = getItemInfo(sorcItem).weight * sorcCount
		if freecap > itemcap then
			local itemname = getItemInfo(sorcItem).name
			doPlayerAddItem(cid, sorcItem,sorcCount)
			setPlayerStorageValue(cid,storage, 1)
			doPlayerSendTextMessage(cid, 13, "Congratulations, you found a"..itemname..".")
		else
			local capcalk = (itemcap - freecap)
			doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_RED, "You found "..itemname..", but you need "..capcalk.." more free cap before you can carry it.")
			return true
		end -- freecap > itemcap
		return true
	end -- sorcerer
	if getPlayerVocation(cid) == 2 or if getPlayerVocation(cid) == 6 then
		local itemcap = getItemInfo(druidItem).weight * druidCount
		if freecap > itemcap then
			local itemname = getItemInfo(druidItem).name
			doPlayerAddItem(cid, druidItem,druidCount)
			setPlayerStorageValue(cid,storage, 1)
			doPlayerSendTextMessage(cid, 13, "Congratulations, you found a"..itemname..".")
		else
			local capcalk = (itemcap - freecap)
			doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_RED, "You found "..itemname..", but you need "..capcalk.." more free cap before you can carry it.")
			return true
		end -- freecap > itemcap
		return true
	end -- druid
	if getPlayerVocation(cid) == 3 or if getPlayerVocation(cid) == 7 then
		local itemcap = getItemInfo(pallyItem).weight * pallyCount
		if freecap > itemcap then
			local itemname = getItemInfo(pallyItem).name
			doPlayerAddItem(cid, pallyItem,pallyCount)
			setPlayerStorageValue(cid,storage, 1)
			doPlayerSendTextMessage(cid, 13, "Congratulations, you found a"..itemname..".")
		else
			local capcalk = (itemcap - freecap)
			doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_RED, "You found "..itemname..", but you need "..capcalk.." more free cap before you can carry it.")
			return true
		end -- freecap > itemcap
		return true
	end -- pally
	if getPlayerVocation(cid) == 4 or if getPlayerVocation(cid) == 8 then
		local itemcap = getItemInfo(knightItem).weight * knightCount
		if freecap > itemcap then
			local itemname = getItemInfo(knightItem).name
			doPlayerAddItem(cid, knightItem,knightCount)
			setPlayerStorageValue(cid,storage, 1)
			doPlayerSendTextMessage(cid, 13, "Congratulations, you found a"..itemname..".")
		else
			local capcalk = (itemcap - freecap)
			doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_RED, "You found "..itemname..", but you need "..capcalk.." more free cap before you can carry it.")
			return true
		end -- freecap > itemcap
	end -- pally
	return true
else
	doPlayerSendTextMessage(cid, 21, "You have already done this quest.")
	return true
end
 
Last edited:
name the script like vocationchest

then put this in actions.xml

XML:
 	<action uniqueid="7777" event="script" value="vocationchest.lua"
then in the map editor, change the chests unique id to '7777' or whatever else u change it to.
 
?!!
Lua:
local t = {
	[isSorcerer] = 2160,
	[isDruid] = 2160,
	[isPaladin] = 2455,
	[isKnight] = 2376
}

function onUse(cid, item, fromPosition, itemEx, toPosition)
	if getCreatureStorage(cid, 345) == -1 then
		for k, v in pairs(t) do
			if k(cid) then
				local it = getItemInfo(v)
				local s = 'You have found ' .. it.article .. ' ' .. it.name
				if getPlayerFreeCap(cid) < it.weight then
					s = s .. '. Weighing ' .. it.weight .. ' oz it is too heavy.'
				elseif doPlayerAddItemEx(cid, doCreateItemEx(v)) ~= RETURNVALUE_NOERROR then
					s = s .. ', but you have no room to take it.'
				else
					s = s .. '.'
					doCreatureSetStorage(cid, 345, 1)
				end
				doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, s)
				break
			end
		end
	else
		doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, 'The ' .. getItemInfo(item.itemid).name .. ' is empty.')
	end
	return true
end
 
?!!
Lua:
local t = {
	[isSorcerer] = 2160,
	[isDruid] = 2160,
	[isPaladin] = 2455,
	[isKnight] = 2376
}

function onUse(cid, item, fromPosition, itemEx, toPosition)
	if getCreatureStorage(cid, 345) == -1 then
		for k, v in pairs(t) do
			if k(cid) then
				local it = getItemInfo(v)
				local s = 'You have found ' .. it.article .. ' ' .. it.name
				if getPlayerFreeCap(cid) < it.weight then
					s = s .. '. Weighing ' .. it.weight .. ' oz it is too heavy.'
				elseif doPlayerAddItemEx(cid, doCreateItemEx(v)) ~= RETURNVALUE_NOERROR then
					s = s .. ', but you have no room to take it.'
				else
					s = s .. '.'
					doCreatureSetStorage(cid, 345, 1)
				end
				doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, s)
				break
			end
		end
	else
		doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, 'The ' .. getItemInfo(item.itemid).name .. ' is empty.')
	end
	return true
end

how add more items?
 
This should work.

Lua:
local t = {
	[isSorcerer] = {2160, 2152, 2148},
	[isDruid] = {2160, 2152, 2148},
	[isPaladin] = {2160, 2152, 2148},
	[isKnight] = {2160, 2152, 2148}
}
 
function onUse(cid, item, fromPosition, itemEx, toPosition)
	if getCreatureStorage(cid, 345) == -1 then
		for k, v in pairs(t) do
			for i = 1, #v do
				if k(cid) then
					local it = getItemInfo(v[i])
					local s = 'You have found ' .. it.article .. ' ' .. it.name
					if getPlayerFreeCap(cid) < it.weight then
						s = s .. '. Weighing ' .. it.weight .. ' oz it is too heavy.'
					elseif doPlayerAddItemEx(cid, doCreateItemEx(v[i])) ~= RETURNVALUE_NOERROR then
						s = s .. ', but you have no room to take it.'
					else
						s = s .. '.'
						doCreatureSetStorage(cid, 345, 1)
					end
					doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, s)
					break
				end
			end
		end
	else
		doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, 'The ' .. getItemInfo(item.itemid).name .. ' is empty.')
	end
	return true
end

J.Dre
 
What will happen if player have no cap for 2 items (which are in chest) but only for 1 item?? Player get storage and won't to get second item.

You should to check that player have cap for all items and then add all to player and set storage.
 
Last edited:
Back
Top