-- I can add a lot more to this code if you want, just pm me and I will give you some ideas.
local oblisks = {
-- [ObliskID] = {aid = from, to}, items = {12 items} --
-- It is set up like this so we can save the items the player has used in the database.
-- If we don't do this we cannot stop the player from using the same item over and over 12 times.
[1] = {aid = {from = 11900, to = 11911}, items = {1111, 1111, 1111, 1111, 1111, 1111, 1111, 1111, 1111, 1111, 1111, 1111}},
[2] = {aid = {from = 11912, to = 11923}, items = {1111, 1111, 1111, 1111, 1111, 1111, 1111, 1111, 1111, 1111, 1111, 1111}},
[3] = {aid = {from = 11924, to = 11935}, items = {1111, 1111, 1111, 1111, 1111, 1111, 1111, 1111, 1111, 1111, 1111, 1111}},
[4] = {aid = {from = 11936, to = 11947}, items = {1111, 1111, 1111, 1111, 1111, 1111, 1111, 1111, 1111, 1111, 1111, 1111}}
}
local mainStorages = { -- This is used so we can remove all the storages that were needed to keep items saved in database.
-- This will make it so when a player has all items for an oblisk it will remove all 12 storages and save 1 that it can use to understand the player has all the items.
-- [ObliskID] = randomStorageValue
[1] = 11940,
[2] = 11941,
[3] = 11942,
[4] = 11943
}
local MESSAGETYPE = MESSAGE_STATUS_CONSOLE_ORANGE
local MESSAGESUCCESS = "You have sacrificed your item to the gods."
local teleportPos = Position(1000, 1000, 7)
function onUse(player, item, fromPosition, target, toPosition, isHotkey)
local TARGET = oblisks[target.itemid]
if not TARGET then return player:sendCancelMessage("Nothing interesting happened.") end
if TARGET.actionid == 0 then return player:sendCancelMessage("Nothing interesting happened.") end
if not isInArray(TARGET.items, item.itemid) then return player:sendCancelMessage("Nothing interesting happened.") end
local MAINSTORAGE = mainStorages[target.itemid]
if not MAINSTORAGE then return false end
local continue = true
for i = TARGET.aid.from, TARGET.aid.to do
if player:getStorageValue(i) == item.itemid then
continue = false
break
end
end
if not continue then return player:sendCancelMessage("You have already sacrificed this item.") end
if continue then
for i = TARGET.aid.from, TARGET.aid.to do
if player:getStorageValue(i) == -1 then
player:setStorageValue(i, item.itemid)
break
end
end
player:removeItem(item.uid, 1)
player:sendTextMessage(MESSAGETYPE, MESSAGESUCCESS)
local continue2 = true
for i = TARGET.aid.from, TARGET.aid.to do
if player:getStorageValue(i) == -1 then
continue2 = false
break
end
end
if continue2 then
for i = TARGET.aid.from, TARGET.aid.to do
player:setStorageValue(i, -1)
end
player:setStorageValue(MAINSTORAGE, 1)
local teleportPlayer = true
for i, v in ipairs(mainStorages) do
if player:getStorageValue(v) == -1 then
teleportPlayer = false
break
end
end
if teleportPlayer then
player:teleportTo(teleportPos)
end
end
end
return true
end