zbizu
Legendary OT User
Remember all those RPG games where you used to find chests with random loot in areas filled with enemies?
Well, this is what this script does adapted to multiplayer style of ot servers.
Warning! Set an unique id to the chest so no one will be able to move or take it!
So what this script does?
- a player opens a chest, it generates items inside, works as normal chest until certain time passes (1h in script, can be changed)
- if you or any player open that chest within that 1h - it behaves like a normal chest.
- if you or any other player open that chest after 1h passes, all items inside will be removed and new loot will be generated
What you can do with it?
- Generated items may depend on skills, quests done, level, storage-based luck stat, buffs etc.
- A chest can do other actions such as summoning something, inflicting damage, etc.
Warning!
Script may conflict with some questsystems.
Make sure to test this script with your questsystems before adding it to your server.
actions.xml
openworldchest.lua
Well, this is what this script does adapted to multiplayer style of ot servers.
Warning! Set an unique id to the chest so no one will be able to move or take it!
So what this script does?
- a player opens a chest, it generates items inside, works as normal chest until certain time passes (1h in script, can be changed)
- if you or any player open that chest within that 1h - it behaves like a normal chest.
- if you or any other player open that chest after 1h passes, all items inside will be removed and new loot will be generated
What you can do with it?
- Generated items may depend on skills, quests done, level, storage-based luck stat, buffs etc.
- A chest can do other actions such as summoning something, inflicting damage, etc.
Warning!
Script may conflict with some questsystems.
Make sure to test this script with your questsystems before adding it to your server.
actions.xml
Code:
<action actionid="7895" script="openworldchest.lua"/>
openworldchest.lua
Code:
if not worldchests then
worldchests = {}
end
if not table.find then
table.find = function(table, value)
for i, v in pairs(table) do
if v == value then
return i
end
end
return nil
end
end
function Container:clear()
for i = 0, self:getItemHoldingCount() - 1 do
self:getItem(0):remove()
end
return true
end
local interval = 3600 -- time to generate new loot (in seconds)
local actionid = 7895 -- actionid to assign in RME
local allowDuplicates = false -- for default setting
-- uid will serve as chest identificator. It will prevent moving the chest and will allow to make every chest script unique.
local defaultrewards = {
-- id, chance(100000 = 100.000%), countmax(default 1)
{2148, 45000, 50}, -- gold coin
{2152, 10000, 10}, -- platinum coin
{2398, 60000}, -- mace
{2187, 450}, -- wand of inferno
{2197, 3000} -- stone skin amulet
}
function onUse(player, item, fromPosition, target, toPosition, isHotkey)
if item.actionid ~= actionid then
return false
end
if not worldchests[item.uid] then
worldchests[item.uid] = 0
end
if os.time() < worldchests[item.uid] then
return false
end
worldchests[item.uid] = os.time() + interval
local c = Container(item.uid)
local clear = true -- put "clear = false" in your unique chest "if" statement if you plan to not use "return false"
-- unique chest action example
if item.uid == 27500 then
c:clear()
-- chest with gold in random amounts only
local newitem = defaultrewards[1]
for i = 1, math.random(1, 10) do
if math.random(1, 100000) < newitem[2] then
local count = 1
if newitem[3] then
count = math.random(1, newitem[3])
end
c:addItem(newitem[1], count)
end
end
-- clear = false -- see local clear
return false -- if you put return here, default action below won't be executed
end
-- you can put other unique chests here
-- if you forget return false, default action will also be executed
-- default action
local items = 0
local maxItems = math.random(0, 5)
local attempts = 0
local dupcheck = {}
if clear then
c:clear()
end
while (items <= maxItems) and (items <= #defaultrewards) and (attempts < 1000) do
local nid = math.random(1, #defaultrewards)
local newitem = defaultrewards[nid]
if allowDuplicates or not table.find(dupcheck, nid) then
if math.random(1, 100000) < newitem[2] then
local count = 1
if newitem[3] then
count = math.random(1, newitem[3])
end
c:addItem(newitem[1], count)
if not allowduplicates then
table.insert(dupcheck, nid)
end
items = items + 1
end
end
attempts = attempts + 1
end
return false
end