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

[0.3.4] [Action]Simple script with coffin and item

Dymczas

New Member
Joined
Mar 8, 2009
Messages
105
Reaction score
0
Hello all ! I need this script for TFS 0.3.4 :
1. The player clicks on the coffin with uid 10000.
2. If player has the item 'xx' in backpack, he gets item 'yy' and item 'xx' is removed.
3. Player can't do the second time this quest.

Thanks ^^
Rep ++
 
Last edited:
Only one bug. When i haven't item in bp, it doesn't show 'You dont have item', it shows 'item name'.
EDIT. Could you remake it, when i have 2 items and click, it removes 2 items and add 2 another items ?
updated, hopefully it'll work

@edit, ok
Liken your tables and loops, Cykotitan.
Great work!
no loops here, yet
 
Last edited:
Code:
local t = {
	remove = {
		{2499, 1},
		{2500, 1}
	},
	add = {
		{2501, 1},
		{2502, 1},
		{2400, 1}
	},
	storage = 30045
}

function onUse(cid, item, fromPosition, itemEx, toPosition)
	if getPlayerStorageValue(cid, t.storage) < 1 then
		local v, w, h = "", 0, true
		for i = 1, #t.remove do
			if getPlayerItemCount(cid, t.remove[i][1]) < t.remove[i][2] then
				h = false
				break
			end
		end
		if h then
			for i = 1, #t.add do
				v = v .. (i == #t.add and " and " or i > 1 and ", " or "") .. (t.add[i][2] > 1 and t.add[i][2] or getItemInfo(t.add[i][1]).article) .. " " .. (t.add[i][2] > 1 and getItemInfo(t.add[i][1]).plural or getItemInfo(t.add[i][1]).name)
				w = w + getItemWeightById(t.add[i][1], t.add[i][2] or 1)
			end
			if getPlayerFreeCap(cid) >= w then
				for i = 1, #t.remove do
					doPlayerRemoveItem(cid, t.remove[i][1], t.remove[i][2] or 1)
				end
				for i = 1, #t.add do
					doPlayerAddItem(cid, t.add[i][1], t.add[i][2] or 1)
				end
				setPlayerStorageValue(cid, t.storage, 1)
				doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "You have found " .. v .. ".")
			else
				doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "You have found " .. v .. ". Weighing " .. w .. " oz it is too heavy.")
			end
		else
			for i = 1, #t.remove do
				v = v .. (i == #t.remove and " and " or i > 1 and ", " or "") .. (t.remove[i][2] > 1 and t.remove[i][2] or getItemInfo(t.remove[i][1]).article) .. " " .. (t.remove[i][2] > 1 and getItemInfo(t.remove[i][1]).plural or getItemInfo(t.remove[i][1]).name)
			end
			doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "You don't have " .. v .. ".")
		end
	else
		doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR,"You have already done this.")
	end
	return true
end
 
Code:
local t = {
	remove = {
		{2499, 1},
		{2500, 1}
	},
	add = {
		{2501, 1},
		{2502, 1},
		{2400, 1}
	},
	storage = 30045
}

function onUse(cid, item, fromPosition, itemEx, toPosition)
	if getPlayerStorageValue(cid, t.storage) < 1 then
		local v, w, h = "", 0, true
		for i = 1, #t.remove do
			if getPlayerItemCount(cid, t.remove[i][1]) < t.remove[i][2] then
				h = false
				break
			end
		end
		if h then
			for i = 1, #t.add do
				v = v .. (i == #t.add and " and " or i > 1 and ", " or "") .. (t.add[i][2] > 1 and t.add[i][2] or getItemInfo(t.add[i][1]).article) .. " " .. (t.add[i][2] > 1 and getItemInfo(t.add[i][1]).plural or getItemInfo(t.add[i][1]).name)
				w = w + getItemWeightById(t.add[i][1], t.add[i][2] or 1)
			end
			if getPlayerFreeCap(cid) >= w then
				for i = 1, #t.remove do
					doPlayerRemoveItem(cid, t.remove[i][1], t.remove[i][2] or 1)
				end
				for i = 1, #t.add do
					doPlayerAddItem(cid, t.add[i][1], t.add[i][2] or 1)
				end
				setPlayerStorageValue(cid, t.storage, 1)
				doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "You have found " .. v .. ".")
			else
				doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "You have found " .. v .. ". Weighing " .. w .. " oz it is too heavy.")
			end
		else
			for i = 1, #t.remove do
				v = v .. (i == #t.remove and " and " or i > 1 and ", " or "") .. (t.remove[i][2] > 1 and t.remove[i][2] or getItemInfo(t.remove[i][1]).article) .. " " .. (t.remove[i][2] > 1 and getItemInfo(t.remove[i][1]).plural or getItemInfo(t.remove[i][1]).name)
			end
			doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "You don't have " .. v .. ".")
		end
	else
		doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR,"You have already done this.")
	end
	return true
end
Do you study lua? :peace:
 
Back
Top