Elwyn
Well-Known Member
- Joined
- Aug 24, 2014
- Messages
- 212
- Reaction score
- 76
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:
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.
Create a reward.lua at actions/scripts and copy-paste the following code:
Code:
function onUse(cid, item, fromPosition, target, toPosition, isHotkey)
local chest = Container(item.uid)
local player = Player(cid)
if not chest or not player 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 start = player:getStorageValue(uniqueid) == -1 and 0 or player:getStorageValue(uniqueid)
for i = start, chest:getSize() do
local reward = chest:getItem(i)
if not reward then
break
end
local rewardWeight = reward.getWeight and reward:getWeight() or ItemType(reward:getId()):getWeight(reward:getCount())
if rewardWeight > player:getFreeCapacity() then
player:sendTextMessage(MESSAGE_INFO_DESCR, 'You have found a ' .. reward:getName() .. ' weighing ' .. rewardWeight/100 .. ' oz it\'s too heavy.')
player:setStorageValue(uniqueid, i)
break
else
reward = reward:clone()
if player:addItemEx(reward) ~= RETURNVALUE_NOERROR then
player:sendTextMessage(MESSAGE_INFO_DESCR, 'You have found a ' .. reward:getName() .. ' weighing ' .. rewardWeight/100 .. ' oz it\'s too heavy.')
break
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.
Last edited: