Hello guys,
Havn't released something in quite a while but thought this might be helpful for some people.
with the left lever you go back an item, middle you buy it and right one is to go forward.
It's important that you build the lever room exactly like the one on the picture because else the positions wont be working.
You can also do a lot of shops at once, they wont interfere with eachother.
Hope the rest explains itself.
Kind regards, Evil Hero.
Havn't released something in quite a while but thought this might be helpful for some people.
with the left lever you go back an item, middle you buy it and right one is to go forward.
Lua:
local shop =
{
[2453] = {gold = 1000},
[2474] = {gold = 2000},
[2475] = {gold = 2000},
[2476] = {gold = 2000},
[2477] = {gold = 2000},
[2478] = {gold = 2000},
[2479] = {gold = 2000},
[2472] = {gold = 2000},
[2473] = {gold = 3000}
-- edit this table with the items and the price for them.
}
local order = {2453, 2472, 2473, 2474, 2475, 2476, 2477, 2478, 2479} -- you just have to put all the itemids of the items from the shop in here, in this order the items will get shown once you pull a lever
local config =
{
level = 1, -- Level requirement to use the shop
buyLeverAID = 5000, -- actionid of the lever to buy the item
backLeverAID = 5001, -- actionid of the lever to go back an item
forwardLeverAID = 5002 -- actionid of the lever to go forward an item
}
function onUse(cid, item, fromPosition, itemEx, toPosition)
local function getItemPos()
local player = getThingPos(cid)
return {x = player.x, y = player.y - 3, z = player.z, stackpos = 255}
end
local showItem = getThingFromPos(getItemPos()).itemid
local uid = getThingFromPos(getItemPos()).uid
local function getIndex()
for a = 1, #order do
if order[a] == showItem then
return a
end
end
end
local function goBack()
return getIndex() == 1 and #order or (getIndex() - 1)
end
local function goForward()
return getIndex() == #order and 1 or (getIndex() + 1)
end
if getPlayerLevel(cid) < config.level and getPlayerGroupId(cid) < 3 then
doPlayerSendCancel(cid, "You do not have the required level to use this!")
return true
end
if not isInArray(order, showItem) then
local tempItem = doCreateItem(order[1], getItemPos())
doItemSetAttribute(tempItem, "description", "price: ".. shop[order[1]].gold .."")
return true
end
if item.actionid == config.buyLeverAID then
if getPlayerFreeCap(cid) >= getItemInfo(showItem).weight then
if doPlayerRemoveMoney(cid, shop[showItem].gold) then
doPlayerAddItem(cid, showItem, 1)
else
doPlayerSendCancel(cid, "You do not have enough gold to buy this.")
end
else
doPlayerSendCancel(cid, "You do not have enough cap to carry this.")
end
elseif item.actionid == config.backLeverAID then
doRemoveItem(uid, 1)
local tempItem = doCreateItem(order[goBack()], getItemPos())
doItemSetAttribute(tempItem, "description", "price: ".. shop[order[goBack()]].gold .."")
elseif item.actionid == config.forwardLeverAID then
doRemoveItem(uid, 1)
local tempItem = doCreateItem(order[goForward()], getItemPos())
doItemSetAttribute(tempItem, "description", "price: ".. shop[order[goForward()]].gold .."")
end
return true
end
It's important that you build the lever room exactly like the one on the picture because else the positions wont be working.
You can also do a lot of shops at once, they wont interfere with eachother.
Hope the rest explains itself.
Kind regards, Evil Hero.