Jknot
Member
na both u guys are the reason it's fixed u both deserve credit thanks Razor for helping mebeat me to it xD
na both u guys are the reason it's fixed u both deserve credit thanks Razor for helping mebeat me to it xD
xD no problem, I figured it was something like a typo, that's why I asked about it existingna both u guys are the reason it's fixed u both deserve credit thanks Razor for helping me
REWARD AND REWARDS ARE TWO DIFFERENT THINGS LOL
You can only have one of each unique id. If you want to be able to give different items for different vocations, you either need a different chest for each and maybe limit access to the rooms for each vocation, or you need a modified script to check which vocation is opening the chest and yield different items accordingly.@Elwyn
LMAO! xD. thanks for the script this saves me allot of scripts BUT
If you use the same uniqueid for two different chests, you'll get a warning when starting up the server and the player will only be able to open one of the two chests. < THIS doesnt work for me
my tibia strangely only makes 1 chest with that unique id while in my remeres i made 2 chests with the same unique id. i made a video can u help me?
i need it so that i can make a set for each vocation instead that the player takes all items/chests
enlarge for better view + set quality better ofc.
Any idea how to make keys with action id or books with description inside?
Change
toCode:player:addItem(reward:getId(), reward:getCount())
Code:player:addItem(reward:getId(), reward:getCount()):setActionId(reward:getActionId())
13:43 You see a wooden key (Key:0).
It weighs 1.00 oz.
Item ID: 2087
Position: 394, 95, 10
if reward:getActionId() > 1000 then
player:addItem(reward:getId(), reward:getCount()):setActionId(reward:getActionId())
else
player:addItem(reward:getId(), reward:getCount())
end
if reward:getWeight() > player:getFreeCapacity() then
player:sendTextMessage(MESSAGE_INFO_DESCR, 'You have found a ' .. reward:getName() .. ' weighing ' .. reward:getWeight()/100 .. ' oz it\'s too heavy.')
player:setStorageValue(uniqueid, i)
break
else
local reward_container = Container(reward:getUniqueId())
if reward_container then
reward_container = reward_container:clone()
reward_container:moveTo(player)
else
if reward:getActionId() > 1000 then
player:addItem(reward:getId(), reward:getCount()):setActionId(reward:getActionId())
else
player:addItem(reward:getId(), reward:getCount())
end
end
local reward_msg = reward:getArticle() .. ' ' .. reward:getName()
if reward:getCount() > 1 then
reward_msg = reward:getCount() .. ' ' .. reward:getPluralName()
end
player:sendTextMessage(MESSAGE_INFO_DESCR, 'You have found ' .. reward_msg .. '.')
player:setStorageValue(uniqueid, -2)
end
end
function onUse(player, item, fromPosition, target, toPosition, isHotkey)
local chest = Container(item.uid)
if not chest then
return true
end
local actionid = chest:getActionId()
if (actionid < 1000) then
return false
end
if player:getStorageValue(actionid) == -2 then
player:sendTextMessage(MESSAGE_INFO_DESCR, "It is empty.")
return true
end
local reward = nil
local start = player:getStorageValue(actionid) == -1 and 0 or player:getStorageValue(actionid)
for i = start, chest:getSize() do
reward = chest:getItem(i)
if not reward then
break
end
if reward:getWeight() > player:getFreeCapacity() then
player:sendTextMessage(MESSAGE_INFO_DESCR, 'You have found a ' .. reward:getName() .. ' weighing ' .. reward:getWeight()/100 .. ' oz it\'s too heavy.')
player:setStorageValue(actionid, i)
break
else
local reward_container = Container(reward:getUniqueId())
if reward_container then
reward_container = reward_container:clone()
reward_container:moveTo(player)
else
if reward:getActionId() > 1000 then
player:addItem(reward:getId(), reward:getCount()):setActionId(reward:getActionId())
else
player:addItem(reward:getId(), reward:getCount())
end
end
local reward_msg = reward:getArticle() .. ' ' .. reward:getName()
if reward:getCount() > 1 then
reward_msg = reward:getCount() .. ' ' .. reward:getPluralName()
end
player:sendTextMessage(MESSAGE_INFO_DESCR, 'You have found ' .. reward_msg .. '.')
player:setStorageValue(actionid, -2)
end
end
if actionid == 5500 then
player:setStorageValue(actionid, 0)
end
return true
end
<action itemid="1740" script="reward.lua" />
Lua Script Error: [Action Interface]
data/actions/scripts/reward.lua : onUse
data/actions/scripts/reward.lua:9: attempt to index local 'player' (a number value)
stack traceback:
[C]: in function '__index'
data/actions/scripts/reward.lua:9: in function <data/actions/scripts/reward.lua:1>
It's meant to help mappers who doesn't know Lua, so they can make their quest chest reward without the help of scripters.
Create a reward.lua at actions/scripts and copy-paste the following code:
Then register at actions.xml using the following tag:Code:function onUse(player, item, fromPosition, target, toPosition, isHotkey) local chest = Container(item.uid) if not chest then return true end local uniqueid = chest:getUniqueId() if player:getStorageValue(uniqueid) == -2 then player:sendTextMessage(MESSAGE_INFO_DESCR, "It is empty.") return true end local reward = nil local start = player:getStorageValue(uniqueid) == -1 and 0 or player:getStorageValue(uniqueid) for i = start, chest:getSize() do reward = chest:getItem(i) if not reward then break end if reward:getWeight() > player:getFreeCapacity() then player:sendTextMessage(MESSAGE_INFO_DESCR, 'You have found a ' .. reward:getName() .. ' weighing ' .. reward:getWeight()/100 .. ' oz it\'s too heavy.') player:setStorageValue(uniqueid, i) break else local reward_container = Container(reward:getUniqueId()) if reward_container then reward_container = reward_container:clone() reward_container:moveTo(player) else player:addItem(reward:getId(), reward:getCount()) end local reward_msg = reward:getArticle() .. ' ' .. reward:getName() if reward:getCount() > 1 then reward_msg = reward:getCount() .. ' ' .. reward:getPluralName() end player:sendTextMessage(MESSAGE_INFO_DESCR, 'You have found ' .. reward_msg .. '.') player:setStorageValue(uniqueid, -2) end end return true end
Code:<action actionid="15000" script="reward.lua"/>
To use it, when mapping your quest, create a chest and change its actionid to 15000 and give a uniqueid to it. Remember to not use a uniqueid that's already in use, and only use uniqueid whose the storage of the same value is not being used.
If you use the same uniqueid for two different chests, you'll get a warning when starting up the server and the player will only be able to open one of the two chests.
Lua Script Error: [Action Interface]
data/actions/scripts/reward.lua: onUse
data/actions/scripts/reward.lua:21: attempt to call method 'getWeight' (a nil value)
stack traceback:
[C]: in function 'getWeight'
data/actions/scripts/reward.lua:21: in function <data/actions/scripts/reward.lua:1>
Thanks, @Elwyn , for the fast reply ^^
I tested the new code and what happens is, the reward chest will open to the first character, and the rewarded items will be there. But after that, it won't open again untill a server restart.
Restarting the server, the chest will open again to the first character (even if it's the same character who received the rewarded items before).
The error I get now it:
Code:Lua Script Error: [Action Interface] data/actions/scripts/reward.lua: onUse data/actions/scripts/reward.lua:21: attempt to call method 'getWeight' (a nil value) stack traceback: [C]: in function 'getWeight' data/actions/scripts/reward.lua:21: in function <data/actions/scripts/reward.lua:1>