krafttomten
Well-Known Member
Hello,
I have been stuck on this problem for too long now. I give up! Time to admit defeat and beg the gods of OTland for help.
Currently, the code I have gives the player the content of the chest as reward. But sometimes I want to give different rewards for different vocations. I have found similar threads on the subject, but the solutions I have found all rely on adding the item ID:s straight into the code, which basically means that I would need one script file for each quest. No good. I want standardized code for all quests, so much easier in the long run.
I'm thinking that this code only needs a small fix really, but I can't get my head around the LUA syntax to formulate the task properly.
I've been trying to combine container:getItem(index) with player:getVocation() and match them up that way but I don't get it to work.
If I get this to work then all l I would have to do to make a new quest would be to make a chest in RME, give it an actionid that runs this code and add the reward items inside the chest (in the correct order).
Any help would be appriciated!
Posting progress so far.
I'm trying a list of action ID's now. That way I can add many items to each vocation and it won't matter what order I place them inside the map editor
I have been stuck on this problem for too long now. I give up! Time to admit defeat and beg the gods of OTland for help.
Currently, the code I have gives the player the content of the chest as reward. But sometimes I want to give different rewards for different vocations. I have found similar threads on the subject, but the solutions I have found all rely on adding the item ID:s straight into the code, which basically means that I would need one script file for each quest. No good. I want standardized code for all quests, so much easier in the long run.
I'm thinking that this code only needs a small fix really, but I can't get my head around the LUA syntax to formulate the task properly.
Lua:
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) -- Here, instead of adding the chest content to the reward variable,
if not reward then -- I want it to add the first item in the chest to vocation 1,
break -- the second item to vocation 2, etc...
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
I've been trying to combine container:getItem(index) with player:getVocation() and match them up that way but I don't get it to work.
Lua:
item:getItem(player:getVocation())
If I get this to work then all l I would have to do to make a new quest would be to make a chest in RME, give it an actionid that runs this code and add the reward items inside the chest (in the correct order).
Any help would be appriciated!
Post automatically merged:
Posting progress so far.
Lua:
function onUse(cid, item, fromPosition, target, toPosition, isHotkey)
local chest = Container(item.uid)
local player = Player(cid)
local aids = { -- I'm trying to assign each number to one vocation (by index) here
[1] = 13001, --
[2] = 13002, --
[3] = 13003, --
[4] = 13004 --
}
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
if item.aid == aids.getPlayerVocation(cid) or item.aid == aids:getPlayerVocation(cid - 4) then -- This is where it breaks. I cannot
local reward = chest:getItem(i) -- call aids.getPlayerVocation(cid) because it is a Nil value. I'm trying to match it with
if not reward then -- the corresponding aid above (aids)
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
end
return true
end
I'm trying a list of action ID's now. That way I can add many items to each vocation and it won't matter what order I place them inside the map editor
Last edited: