darkangel1
New Member
- Joined
- Oct 31, 2023
- Messages
- 53
- Reaction score
- 4
Lua:
--[[
Anni-style chests.
This script goes into data/scripts as a .lua file
1) Place 2+ chests into map editor
2) Place Same ActionId onto all chests. (example: 45000)
3) Place UniqueId onto all chests. (example: 45001, 45002, 45003...)
4) Update config table here, to match the chests in map editor (ActionId, UniqueId's)
5) Update table with itemId's, count's and an unused storage number
6) Restart Server, and test
]]--
local index = rewardChests[ActionId] = {
----[actionId] = {
---- [uniqueId] = {itemId = ####, count = #},
---- [uniqueId] = {itemId = ####, count = #},
---- [uniqueId] = {itemId = ####, count = #},
---- [uniqueId] = {itemId = ####, count = #},
---- storage = #####
----},
[45000] = {
[45001] = {itemId = 2190, count = 1},
storage = 45000
},
[45002] = {
[45003] = {itemId = 2191, count = 1},
storage = 45002
}
}
local anni_style_chest = Action()
function anni_style_chest.onUse(player, item, fromPosition, target, toPosition, isHotkey)
local index = rewardChests[item:getActionId()][item:getUniqueId()]
if not index then
player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "Inform gamemaster of error with quest.")
print("Error: UniqueId does not exist in table.")
return true
end
if player:getStorageValue(index.storage) == 1 then
player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "It is empty.")
return true
end
local reward = ItemType(index.itemId)
local rewardWeight = reward:getWeight() * index.count
if rewardWeight > player:getFreeCapacity() then
player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "You have found a " .. reward:getName() .. " weighing " .. rewardWeight .. " oz. It's too heavy.")
return true
end
player:addItem(index.itemId, index.count, true)
player:setStorageValue(index.storage, 1)
player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "You have found a " .. reward:getName() .. ".")
return true
end
for v, k in pairs(rewardChests) do
anni_style_chest:aid(v)
end
anni_style_chest:register()