Action [MOD] Buy items, bp with items by lever (great config ) V1.0

Joined
Apr 17, 2008
Messages
1,922
Best answers
0
Reaction score
181
Location
Venezuela
Hello, i've rewrited my old "buy items by lever" script,here is:

How to config?
Lua:
uid = {
 --[uniqueID] = item to be buyed, item count, item charges, item cost, enable/disable backpack(true or false), itemid of backpack, how many backpacks will be buyed, enable/disable cap system(true or false, true = player can buy bp only if he have enough cap, false = player can buy bp ever)
			[5556] = {item = 2273, count = 1, charges = 2, cost = 50, backpack = false, backpackID = 0, ignoreCap = true},
			[5557] = {item = 2313, count = 1, charges = 3, cost = 200, backpack = false, backpackID = 0, ignoreCap = true},
			[5558] = {item = 2268, count = 1, charges = 3, cost = 250, backpack = false, backpackID = 0, ignoreCap = true},
			[5559] = {item = 2293, count = 1, charges = 3, cost = 200, backpack = false, backpackID = 0, ignoreCap = true},
			[5560] = {item = 2311, count = 1, charges = 10, cost = 75, backpack = false, backpackID = 0, ignoreCap = true},
			[5561] = {item = 2304, count = 1, charges = 4, cost = 150, backpack = false, backpackID = 0, ignoreCap = true},
			[5562] = {item = 2006, count = 1, charges = 7, cost = 110, backpack = false, backpackID = 0, ignoreCap = true},
			[5563] = {item = 7620, count = 20, charges = 1, cost = 1000, backpack = true, backpackID = 2001, ignoreCap = true},
			[5564] = {item = 2273, count = 20, charges = 2, cost = 1000, backpack = true, backpackID = 2002, ignoreCap = true},
			[5565] = {item = 2268, count = 20, charges = 3, cost = 5000, backpack = true, backpackID = 2003, ignoreCap = true},
			[5566] = {item = 2293, count = 20, charges = 3, cost = 4000, backpack = true, backpackID = 1999, ignoreCap = true},
			[5567] = {item = 2311, count = 20, charges = 10, cost = 1500, backpack = true, backpackID = 2001, ignoreCap = true},
			[5568] = {item = 2313, count = 20, charges = 3, cost = 4000, backpack = true, backpackID = 2001, ignoreCap = true},
			[5569] = {item = 2304, count = 20, charges = 4, cost = 3000, backpack = true, backpackID = 2000, ignoreCap = true},
			[5570] = {item = 3940, count = 1, charges = 1, cost = 20, backpack = false, backpackID = 0, ignoreCap = true},
			[5571] = {item = 2006, count = 1, charges = 7, cost = 110, backpack = false, backpackID = 0, ignoreCap = true},
			[5572] = {item = 2006, count = 1, charges = 7, cost = 110, backpack = false, backpackID = 0, ignoreCap = true}
		}
	
levers = {
	1945, --unused lever
	1946 --used lever
}
Script:
Just paste this in your mod folder:
Lua:
<?xml version="1.0" encoding="UTF-8"?>
<mod name="Buy item by lever" version="1.0" author="Darkhaos" contact="otland.net" enabled="yes">
	<config name="switch_items"><![CDATA[
		uid = {
			[5556] = {item = 2273, count = 1, charges = 2, cost = 50, backpack = false, backpackID = 0, ignoreCap = true},
			[5557] = {item = 2313, count = 1, charges = 3, cost = 200, backpack = false, backpackID = 0, ignoreCap = true},
			[5558] = {item = 2268, count = 1, charges = 3, cost = 250, backpack = false, backpackID = 0, ignoreCap = true},
			[5559] = {item = 2293, count = 1, charges = 3, cost = 200, backpack = false, backpackID = 0, ignoreCap = true},
			[5560] = {item = 2311, count = 1, charges = 10, cost = 75, backpack = false, backpackID = 0, ignoreCap = true},
			[5561] = {item = 2304, count = 1, charges = 4, cost = 150, backpack = false, backpackID = 0, ignoreCap = true},
			[5562] = {item = 2006, count = 1, charges = 7, cost = 110, backpack = false, backpackID = 0, ignoreCap = true},
			[5563] = {item = 7620, count = 20, charges = 1, cost = 1000, backpack = true, backpackID = 2001, ignoreCap = true},
			[5564] = {item = 2273, count = 20, charges = 2, cost = 1000, backpack = true, backpackID = 2002, ignoreCap = true},
			[5565] = {item = 2268, count = 20, charges = 3, cost = 5000, backpack = true, backpackID = 2003, ignoreCap = true},
			[5566] = {item = 2293, count = 20, charges = 3, cost = 4000, backpack = true, backpackID = 1999, ignoreCap = true},
			[5567] = {item = 2311, count = 20, charges = 10, cost = 1500, backpack = true, backpackID = 2001, ignoreCap = true},
			[5568] = {item = 2313, count = 20, charges = 3, cost = 4000, backpack = true, backpackID = 2001, ignoreCap = true},
			[5569] = {item = 2304, count = 20, charges = 4, cost = 3000, backpack = true, backpackID = 2000, ignoreCap = true},
			[5570] = {item = 3940, count = 1, charges = 1, cost = 20, backpack = false, backpackID = 0, ignoreCap = true},
			[5571] = {item = 2006, count = 1, charges = 7, cost = 110, backpack = false, backpackID = 0, ignoreCap = true},
			[5572] = {item = 2006, count = 1, charges = 7, cost = 110, backpack = false, backpackID = 0, ignoreCap = true}
		}
 
		levers = {
			1945,
			1946
		}
	]]></config>
	<action fromuid="5556" touid="5572" event="buffer"><![CDATA[
	domodlib('switch_items')
 
	if isInArray(levers, item.itemid) then
		doTransformItem(item.uid, (item.itemid == 1945 and 1946 or 1945)) 
		local item = uid[item.uid]
		if item then
			if item.backpack then
				if getPlayerMoney(cid) < item.cost then
					doPlayerSendCancel(cid, "You need " .. item.cost .. " gold coins to buy a backpack of " .. getItemNameById(item.item) .. ".")
					doSendMagicEffect(getCreaturePosition(cid), CONST_ME_POFF)
					return true
				end
 
				if not item.ignoreCap and getPlayerFreeCap(cid) < (getItemWeightById(item.backpackID, item.backpackCount) + getItemWeightById(item.item, item.count)) then
					doPlayerSendCancel(cid, "You don't have enough cap.")
					doSendMagicEffect(getCreaturePosition(cid), CONST_ME_POFF)
					return true
				end
 
				local deny = false
				if not isItemContainer(item.backpackID) then deny = true end
				if not deny then
					local container = doPlayerAddItem(cid, item.backpackID, 1)
					for i = 1, item.count do
						doAddContainerItem(container, item.item, item.charges)
					end
					doPlayerRemoveMoney(cid, item.cost)
					doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "You bought " .. item.count .. "x " .. getItemNameById(item.item) .. (item.count > 1 and "s" or "") .. ".")
					doSendMagicEffect(getCreaturePosition(cid), CONST_ME_MAGIC_GREEN)
				else
					error("[Warning - Error] Cannot add items in container id " .. item.backpackID .. ".")
				end
			else
				if getPlayerMoney(cid) < item.cost then
					doPlayerSendCancel(cid, "You need " .. item.cost .. " gold coins to buy " .. getItemArticleById(item.item) .. " " .. getItemNameById(item.item) .. ".")
					doSendMagicEffect(getCreaturePosition(cid), CONST_ME_POFF)
					return true
				end
 
				if not item.ignoreCap and getPlayerFreeCap(cid) < getItemWeightById(item.item, item.count) then
					doPlayerSendCancel(cid, "You don't have enough cap.")
					doSendMagicEffect(getCreaturePosition(cid), CONST_ME_POFF)
					return true
				end
 
				for i = 1, item.count do
					doPlayerAddItem(cid, item.item, item.charges)
				end
				doPlayerRemoveMoney(cid, item.cost)
				doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "You bought " .. item.count .. "x " .. getItemNameById(item.item) .. (item.count > 1 and "s" or "") .. ".")
				doSendMagicEffect(getCreaturePosition(cid), CONST_ME_MAGIC_GREEN)
			end
		end
	end
	]]></action>
</mod>
Enjoy!
 
Last edited:

Colandus

Advanced OT User
Joined
Jun 6, 2007
Messages
2,424
Best answers
18
Reaction score
165
Location
Sweden
rofl why you put all that code AGAIN ??

here shorter (no repetitive code):
Lua:
<?xml version="1.0" encoding="UTF-8"?>
<mod name="Buy item by lever" version="1.0" author="Darkhaos" contact="otland.net" enabled="yes">
        <config name="switch_items"><![CDATA[
                uid = {
                        [5556] = {item = 2273, count = 1, charges = 2, cost = 50, backpack = false, backpackID = 0, backpackCount = 0, cap = true},
                        [5557] = {item = 2313, count = 1, charges = 3, cost = 200, backpack = false, backpackID = 0, backpackCount = 0, cap = true},
                        [5558] = {item = 2268, count = 1, charges = 3, cost = 250, backpack = false, backpackID = 0, backpackCount = 0, cap = true},
                        [5559] = {item = 2293, count = 1, charges = 3, cost = 200, backpack = false, backpackID = 0, backpackCount = 0, cap = true},
                        [5560] = {item = 2311, count = 1, charges = 10, cost = 75, backpack = false, backpackID = 0, backpackCount = 0, cap = true},
                        [5561] = {item = 2304, count = 1, charges = 4, cost = 150, backpack = false, backpackID = 0, backpackCount = 0, cap = true},
                        [5562] = {item = 2006, count = 1, charges = 7, cost = 110, backpack = false, backpackID = 0, backpackCount = 0, cap = true},
                        [5563] = {item = 7620, count = 20, charges = 1, cost = 1000, backpack = true, backpackID = 2001, backpackCount = 1, cap = true},
                        [5564] = {item = 2273, count = 20, charges = 2, cost = 1000, backpack = true, backpackID = 2002, backpackCount = 1, cap = true},
                        [5565] = {item = 2268, count = 20, charges = 3, cost = 5000, backpack = true, backpackID = 2003, backpackCount = 1, cap = true},
                        [5566] = {item = 2293, count = 20, charges = 3, cost = 4000, backpack = true, backpackID = 1999, backpackCount = 1, cap = true},
                        [5567] = {item = 2311, count = 20, charges = 10, cost = 1500, backpack = true, backpackID = 2001, backpackCount = 1, cap = true},
                        [5568] = {item = 2313, count = 20, charges = 3, cost = 4000, backpack = true, backpackID = 2001, backpackCount = 1, cap = true},
                        [5569] = {item = 2304, count = 20, charges = 4, cost = 3000, backpack = true, backpackID = 2000, backpackCount = 1, cap = true},
                        [5570] = {item = 3940, count = 1, charges = 1, cost = 20, backpack = false, backpackID = 0, backpackCount = 0, cap = true},
                        [5571] = {item = 2006, count = 1, charges = 7, cost = 110, backpack = false, backpackID = 0, backpackCount = 0, cap = true},
                        [5572] = {item = 2006, count = 1, charges = 7, cost = 110, backpack = false, backpackID = 0, backpackCount = 0, cap = true}
                }
        
                levers = {
                        1945,
                        1946
                }
        ]]></config>
        <action fromuid="5556" touid="5572" event="buffer"><![CDATA[
        domodlib('switch_items')

        doTransformItem(item.uid, levers[item.itemid == levers[1] and 2 or 1])
                
        local item = uid[item.uid]
        if item then
                if item.backpack then
                        if getPlayerMoney(cid) < item.cost then
                                doPlayerSendCancel(cid, "You need " .. item.cost .. " gold coins to buy a backpack of " .. getItemNameById(item.item) .. ".")
                                doSendMagicEffect(getCreaturePosition(cid), CONST_ME_POFF)
                                return true
                        end

                        if item.cap and getPlayerFreeCap(cid) < (getItemWeightById(item.backpackID, item.backpackCount) + getItemWeightById(item.item, item.count)) then
                                doPlayerSendCancel(cid, "You don't have enough cap.")
                                doSendMagicEffect(getCreaturePosition(cid), CONST_ME_POFF)
                                return true
                        end

                        local container = doPlayerAddItem(cid, item.backpackID, item.backpackCount)
                        for i = 1, item.count do
                                doAddContainerItem(container, item.item, item.charges)
                        end
                        doPlayerRemoveMoney(cid, item.cost)
                        doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "Bought " .. item.count .. "x " .. getItemNameById(item.item) .. ".")
                        doSendMagicEffect(getCreaturePosition(cid), CONST_ME_MAGIC_GREEN)
                else
                        if getPlayerMoney(cid) < item.cost then
                                doPlayerSendCancel(cid, "You need " .. item.cost .. " gold coins to buy " .. getItemArticleById(item.item) .. " " .. getItemNameById(item.item) .. ".")
                                doSendMagicEffect(getCreaturePosition(cid), CONST_ME_POFF)
                                return true
                        end

                        if item.cap and getPlayerFreeCap(cid) < getItemWeightById(item.item, item.count) then
                                doPlayerSendCancel(cid, "You don't have enough cap.")
                                doSendMagicEffect(getCreaturePosition(cid), CONST_ME_POFF)
                                return true
                        end

                        for i = 1, item.count do
                                doPlayerAddItem(cid, item.item, item.charges)
                        end
                        doPlayerRemoveMoney(cid, item.cost)
                        doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "Bought " .. item.count .. "x " .. getItemNameById(item.item) .. ".")
                        doSendMagicEffect(getCreaturePosition(cid), CONST_ME_MAGIC_GREEN)
                end
        end
        ]]></action>
</mod>
 

Colandus

Advanced OT User
Joined
Jun 6, 2007
Messages
2,424
Best answers
18
Reaction score
165
Location
Sweden
i'll shorten it a bit more :p

but shouldn't you also use * 20 at the backpacks item prize check ?

if getPlayerMoney(cid) < item.cost then

should be
if getPlayerMoney(cid) < item.cost * 20 then

right ? as it will take 20 items? :p
 
OP
Darkhaos
Joined
Apr 17, 2008
Messages
1,922
Best answers
0
Reaction score
181
Location
Venezuela
i'll shorten it a bit more :p

but shouldn't you also use * 20 at the backpacks item prize check ?

if getPlayerMoney(cid) < item.cost then

should be
if getPlayerMoney(cid) < item.cost * 20 then

right ? as it will take 20 items? :p
The price of the items that will be buyed in backpack have the correct price (sorry my bad english Norf!)

For example:
Lua:
[5556] = {item = 2273, count = 1, charges = 2, cost = 50, backpack = false, backpackID = 0, backpackCount = 0, cap = true}, -- price for a uh
[5564] = {item = 2273, count = 20, charges = 2, cost = 1000, backpack = true, backpackID = 2002, backpackCount = 1, cap = true}, --price for a bp uh
 

cbrm

Top Class brunet scripter
Staff member
Global Moderator
Joined
Jan 6, 2009
Messages
6,585
Best answers
3
Reaction score
852
Location
Caribbean Sea
i get an empty bp :/
 

Exedion

Active Member
Joined
Jun 11, 2007
Messages
628
Best answers
0
Reaction score
28
is better make a function to buy in trade windows (like shop npc's) without npc (via actions, moveevents, talkactions, creaturescripts, etc...) it can be possible?
 

Listo

New Member
Joined
Aug 17, 2008
Messages
222
Best answers
0
Reaction score
0
Doesn't work for me :/
Error:
[18/12/2009 22:54:28] [Error - Action Interface]
[18/12/2009 22:54:28] buffer
[18/12/2009 22:54:28] Description:
[18/12/2009 22:54:28] [string "uid = {..."]:14: '}' expected near 'backpack'

[18/12/2009 22:54:28] [Error - Action Interface]
[18/12/2009 22:54:28] buffer
[18/12/2009 22:54:28] Description:
[18/12/2009 22:54:28] [string "loadBuffer"]:28: attempt to index global 'levers' (a nil value)
using latest tfs

my script;
<?xml version="1.0" encoding="UTF-8"?>
<mod name="Buy item by lever" version="1.0" author="Darkhaos" contact="otland.net" enabled="yes">
<config name="switch_items"><![CDATA[
uid = {
[5556] = {item = 2273, count = 1, charges = 2, cost = 50, backpack = false, backpackID = 0, backpackCount = 0, cap = true},
[5557] = {item = 2313, count = 1, charges = 3, cost = 200, backpack = false, backpackID = 0, backpackCount = 0, cap = true},
[5558] = {item = 2268, count = 1, charges = 3, cost = 250, backpack = false, backpackID = 0, backpackCount = 0, cap = true},
[5559] = {item = 2293, count = 1, charges = 3, cost = 200, backpack = false, backpackID = 0, backpackCount = 0, cap = true},
[5560] = {item = 2311, count = 1, charges = 10, cost = 75, backpack = false, backpackID = 0, backpackCount = 0, cap = true},
[5561] = {item = 2304, count = 1, charges = 4, cost = 150, backpack = false, backpackID = 0, backpackCount = 0, cap = true},
[5562] = {item = 2006, count = 1, charges = 7, cost = 110, backpack = false, backpackID = 0, backpackCount = 0, cap = true},
[5563] = {item = 7620, count = 20, charges = 1, cost = 1000, backpack = true, backpackID = 2001, backpackCount = 1, cap = true},
[5564] = {item = 2273, count = 20, charges = 2, cost = 1000, backpack = true, backpackID = 2002, backpackCount = 1, cap = true},
[5565] = {item = 7620, count = 20, charges = 10, cost = 1000, backpack = true, backpackID = 2003, backpackCount = 1, cap = true},
[5566] = {item = 7589, count = 20, charges = 10, cost = 2000, backpack = true, backpackID = 1999, backpackCount = 1, cap = true},
[5567] = {item = 7590, count = 20, charges = 10, cost = 5000, backpack = true, backpackID = 2001, backpackCount = 1, cap = true},
[5568] = {item = 7591, count = 20, charges = 10, cost = 4000 backpack = true, backpackID = 2001, backpackCount = 1, cap = true},
[5569] = {item = 7588, count = 20, charges = 10, cost = 2000, backpack = true, backpackID = 2000, backpackCount = 1, cap = true},
[5570] = {item = 7618, count = 20, charges = 10, cost = 1000, backpack = true, backpackID = 2000, backpackCount = 0, cap = true},
[5571] = {item = 8473, count = 20, charges = 10, cost = 6000, backpack = true, backpackID = 2000, backpackCount = 0, cap = true},
[5572] = {item = 2006, count = 1, charges = 7, cost = 110, backpack = false, backpackID = 0, backpackCount = 0, cap = true}
}

levers = {
1945,
1946
}
]]></config>
<action fromuid="5556" touid="5572" event="buffer"><![CDATA[
domodlib('switch_items')

if item.itemid == levers[1] then
doTransformItem(item.uid, levers[2])
local item = uid[item.uid]
if item then
if item.backpack then
if getPlayerMoney(cid) < item.cost then
doPlayerSendCancel(cid, "You need " .. item.cost .. " gold coins to buy a backpack of " .. getItemNameById(item.item) .. ".")
doSendMagicEffect(getCreaturePosition(cid), CONST_ME_POFF)
return true
end

if item.cap and getPlayerFreeCap(cid) < (getItemWeightById(item.backpackID, item.backpackCount) + getItemWeightById(item.item, item.count)) then
doPlayerSendCancel(cid, "You don't have enough cap.")
doSendMagicEffect(getCreaturePosition(cid), CONST_ME_POFF)
return true
end

local container = doPlayerAddItem(cid, item.backpackID, item.backpackCount)
for i = 1, item.count do
doAddContainerItem(container, item.item, item.charges)
end
doPlayerRemoveMoney(cid, item.cost)
doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "Bought " .. item.count .. "x " .. getItemNameById(item.item) .. ".")
doSendMagicEffect(getCreaturePosition(cid), CONST_ME_MAGIC_GREEN)
else
if getPlayerMoney(cid) < item.cost then
doPlayerSendCancel(cid, "You need " .. item.cost .. " gold coins to buy " .. getItemArticleById(item.item) .. " " .. getItemNameById(item.item) .. ".")
doSendMagicEffect(getCreaturePosition(cid), CONST_ME_POFF)
return true
end

if item.cap and getPlayerFreeCap(cid) < getItemWeightById(item.item, item.count) then
doPlayerSendCancel(cid, "You don't have enough cap.")
doSendMagicEffect(getCreaturePosition(cid), CONST_ME_POFF)
return true
end

for i = 1, item.count do
doPlayerAddItem(cid, item.item, item.charges)
end
doPlayerRemoveMoney(cid, item.cost)
doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "Bought " .. item.count .. "x " .. getItemNameById(item.item) .. ".")
doSendMagicEffect(getCreaturePosition(cid), CONST_ME_MAGIC_GREEN)
end
end
elseif item.itemid == levers[2] then
doTransformItem(item.uid, levers[1])
local item = uid[item.uid]
if item then
if item.backpack then
if getPlayerMoney(cid) < item.cost then
doPlayerSendCancel(cid, "You need " .. item.cost .. " gold coins to buy a backpack of " .. getItemNameById(item.item) .. ".")
doSendMagicEffect(getCreaturePosition(cid), CONST_ME_POFF)
return true
end

if item.cap and getPlayerFreeCap(cid) < (getItemWeightById(item.backpackID, item.backpackCount) + getItemWeightById(item.item, item.count)) then
doPlayerSendCancel(cid, "You don't have enough cap.")
doSendMagicEffect(getCreaturePosition(cid), CONST_ME_POFF)
return true
end

local container = doPlayerAddItem(cid, item.backpackID, item.backpackCount)
for i = 1, item.count do
doAddContainerItem(container, item.item, item.charges)
end
doPlayerRemoveMoney(cid, item.cost)
doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "Bought " .. item.count .. "x " .. getItemNameById(item.item) .. ".")
doSendMagicEffect(getCreaturePosition(cid), CONST_ME_MAGIC_GREEN)
else
if getPlayerMoney(cid) < item.cost then
doPlayerSendCancel(cid, "You need " .. item.cost .. " gold coins to buy " .. getItemArticleById(item.item) .. " " .. getItemNameById(item.item) .. ".")
doSendMagicEffect(getCreaturePosition(cid), CONST_ME_POFF)
return true
end

if item.cap and getPlayerFreeCap(cid) < getItemWeightById(item.item, item.count) then
doPlayerSendCancel(cid, "You don't have enough cap.")
doSendMagicEffect(getCreaturePosition(cid), CONST_ME_POFF)
return true
end

for i = 1, item.count do
doPlayerAddItem(cid, item.item, item.charges)
end
doPlayerRemoveMoney(cid, item.cost)
doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "Bought " .. item.count .. "x " .. getItemNameById(item.item) .. ".")
doSendMagicEffect(getCreaturePosition(cid), CONST_ME_MAGIC_GREEN)
end
end
end
]]></action>
</mod>
 

Sirion_Mido

Experienced Member
Joined
Jul 22, 2012
Messages
579
Best answers
0
Reaction score
43
Location
E-G-Y-P-T
what do i put on the action.xml?
WHAT DID YOU SAY? -.-
you must put it on mods
and call it levers.xml
and it will work fine

- - - Updated - - -

Doesn't work for me :/
Error:

using latest tfs

my script;
iam think you did something wrong during you configuare the script , so use the first post and try to configuare it again;/
 

Sirion_Mido

Experienced Member
Joined
Jul 22, 2012
Messages
579
Best answers
0
Reaction score
43
Location
E-G-Y-P-T
it make something wrong :D , it says error , item not found , that in levers line ;P
 

zbizu

Legendary OT User
Joined
Nov 22, 2010
Messages
2,570
Best answers
1
Reaction score
1,473
Location
Poland
Awesome one! I was looking for configurable levers shop and here it is! One file, easy to edit and supports backpacks!
I'm going to use is with major/minor tokens instead of money and make these tokens rare drop from mobs.
Tokens shop is best shop xD

After testing, I don't know why but original script had error: "duplicate registered id 1981"
after manually converting it to action works fine. Here is actions version without id transfer(anything with uid specified in actions.xml will work now)

epicshop.lua
Code:
function onUse(cid, item, frompos, itemEx, topos)
uid = {
			[5556] = {item = 2273, count = 1, charges = 2, cost = 50, backpack = false, backpackID = 0, ignoreCap = true},
			[5557] = {item = 2313, count = 1, charges = 3, cost = 200, backpack = false, backpackID = 0, ignoreCap = true},
			[5558] = {item = 2268, count = 1, charges = 3, cost = 250, backpack = false, backpackID = 0, ignoreCap = true},
			[5559] = {item = 2293, count = 1, charges = 3, cost = 200, backpack = false, backpackID = 0, ignoreCap = true},
			[5560] = {item = 2311, count = 1, charges = 10, cost = 75, backpack = false, backpackID = 0, ignoreCap = true},
			[5561] = {item = 2304, count = 1, charges = 4, cost = 150, backpack = false, backpackID = 0, ignoreCap = true},
			[5562] = {item = 2006, count = 1, charges = 7, cost = 110, backpack = false, backpackID = 0, ignoreCap = true},
			[5563] = {item = 7620, count = 20, charges = 1, cost = 1000, backpack = true, backpackID = 2001, ignoreCap = true},
			[5564] = {item = 2273, count = 20, charges = 2, cost = 1000, backpack = true, backpackID = 2002, ignoreCap = true},
			[5565] = {item = 2268, count = 20, charges = 3, cost = 5000, backpack = true, backpackID = 2003, ignoreCap = true},
			[5566] = {item = 2293, count = 20, charges = 3, cost = 4000, backpack = true, backpackID = 1999, ignoreCap = true},
			[5567] = {item = 2311, count = 20, charges = 10, cost = 1500, backpack = true, backpackID = 2001, ignoreCap = true},
			[5568] = {item = 2313, count = 20, charges = 3, cost = 4000, backpack = true, backpackID = 2001, ignoreCap = true},
			[5569] = {item = 2304, count = 20, charges = 4, cost = 3000, backpack = true, backpackID = 2000, ignoreCap = true},
			[5570] = {item = 3940, count = 1, charges = 1, cost = 20, backpack = false, backpackID = 0, ignoreCap = true},
			[5571] = {item = 2006, count = 1, charges = 7, cost = 110, backpack = false, backpackID = 0, ignoreCap = true},
			[5572] = {item = 2006, count = 1, charges = 7, cost = 110, backpack = false, backpackID = 0, ignoreCap = true}
		}
		
		local item = uid[item.uid]
		if item then
			if item.backpack then
				if getPlayerMoney(cid) < item.cost then
					doPlayerSendCancel(cid, "You need " .. item.cost .. " gold coins to buy a backpack of " .. getItemNameById(item.item) .. ".")
					doSendMagicEffect(getCreaturePosition(cid), CONST_ME_POFF)
					return true
				end
 
				if not item.ignoreCap and getPlayerFreeCap(cid) < (getItemWeightById(item.backpackID, item.backpackCount) + getItemWeightById(item.item, item.count)) then
					doPlayerSendCancel(cid, "You don't have enough cap.")
					doSendMagicEffect(getCreaturePosition(cid), CONST_ME_POFF)
					return true
				end
 
				local deny = false
				if not isItemContainer(item.backpackID) then deny = true end
				if not deny then
					local container = doPlayerAddItem(cid, item.backpackID, 1)
					for i = 1, item.count do
						doAddContainerItem(container, item.item, item.charges)
					end
					doPlayerRemoveMoney(cid, item.cost)
					doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "You bought " .. item.count .. "x " .. getItemNameById(item.item) .. (item.count > 1 and "s" or "") .. ".")
					doSendMagicEffect(getCreaturePosition(cid), CONST_ME_MAGIC_GREEN)
				else
					error("[Warning - Error] Cannot add items in container id " .. item.backpackID .. ".")
				end
			else
				if getPlayerMoney(cid) < item.cost then
					doPlayerSendCancel(cid, "You need " .. item.cost .. " gold coins to buy " .. getItemArticleById(item.item) .. " " .. getItemNameById(item.item) .. ".")
					doSendMagicEffect(getCreaturePosition(cid), CONST_ME_POFF)
					return true
				end
 
				if not item.ignoreCap and getPlayerFreeCap(cid) < getItemWeightById(item.item, item.count) then
					doPlayerSendCancel(cid, "You don't have enough cap.")
					doSendMagicEffect(getCreaturePosition(cid), CONST_ME_POFF)
					return true
				end
 
				for i = 1, item.count do
					doPlayerAddItem(cid, item.item, item.charges)
				end
				doPlayerRemoveMoney(cid, item.cost)
				doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "You bought " .. item.count .. "x " .. getItemNameById(item.item) .. (item.count > 1 and "s" or "") .. ".")
				doSendMagicEffect(getCreaturePosition(cid), CONST_ME_MAGIC_GREEN)
			end
		end
	end
actions.xml:
Code:
<action fromuid="5556" touid="5572" event="script" value="epicshop.lua"/>
 
Last edited:
Top