darkangel1
New Member
- Joined
- Oct 31, 2023
- Messages
- 53
- Reaction score
- 4
Hello community, how to add the number of items from a chest. I used this script, but I still got 1 throwing star, not 100
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 rewardChests = {
----[actionId] = {
---- [uniqueId] = {itemId = ####, count = #},
---- [uniqueId] = {itemId = ####, count = #},
---- [uniqueId] = {itemId = ####, count = #},
---- [uniqueId] = {itemId = ####, count = #},
---- storage = #####
----},
[45000] = { -- 45000 as Action id on ALL 3 chests
[45001] = {itemId = 2190, count = 1}, --45001 as UNIQUE id on chest for item 2190
[45002] = {itemId = 2191, count = 1}, --45002 as UNIQUE id on chest for item 2191
[45003] = {itemId = 2399, count = 100}, --45003 as UNIQUE id on chest for item 2399
storage = 45000
}
}
function 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
Attachments
-
45004.png565.3 KB · Views: 11 · VirusTotal