diff --git a/data-otservbr-global/scripts/actions/rookgaard/rapier_quest.lua b/data-otservbr-global/scripts/actions/rookgaard/rapier_quest.lua new file mode 100644 index 00000000000..20e6697d2f7 --- /dev/null +++ b/data-otservbr-global/scripts/actions/rookgaard/rapier_quest.lua @@ -0,0 +1,15 @@ +local rapierQuest = Action() + +function rapierQuest.onUse(player, item, fromPosition, target, toPosition, isHotkey) + local rewardId = 3272 + if not player:canGetReward(rewardId, "rapier") then + return true + end + player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "You have found a rapier.") + player:addItem(rewardId, 1) + player:questKV("rapier"):set("completed", true) + return true +end + +rapierQuest:uid(14042) +rapierQuest:register() diff --git a/data-otservbr-global/startup/tables/chest.lua b/data-otservbr-global/startup/tables/chest.lua index f5049f93f61..228e9ba2976 100644 --- a/data-otservbr-global/startup/tables/chest.lua +++ b/data-otservbr-global/startup/tables/chest.lua @@ -1186,4 +1186,8 @@ ChestUnique = { itemId = 11810, itemPos = { x = 33195, y = 31765, z = 1 }, }, + [14042] = { + itemId = 2473, + itemPos = { x = 32099, y = 32198, z = 9 }, + }, } diff --git a/data/libs/functions/player.lua b/data/libs/functions/player.lua index 2662db60d11..03e88d7ccca 100644 --- a/data/libs/functions/player.lua +++ b/data/libs/functions/player.lua @@ -966,3 +966,37 @@ do return true end end + +function Player:questKV(questName) + return self:kv():scoped("quests"):scoped(questName) +end + +function Player:canGetReward(rewardId, questName) + if self:questKV(questName):get("completed") then + self:sendTextMessage(MESSAGE_EVENT_ADVANCE, "The box is empty.") + return false + end + + local rewardItem = ItemType(rewardId) + if not rewardItem then + self:sendTextMessage(MESSAGE_EVENT_ADVANCE, "Reward item is wrong, please contact an administrator.") + return false + end + + local itemWeight = rewardItem:getWeight() / 100 + local baseMessage = "You have found a " .. rewardItem:getName() + local backpack = self:getSlotItem(CONST_SLOT_BACKPACK) + if not backpack or backpack:getEmptySlots(true) < 1 then + baseMessage = baseMessage .. ", but you have no room to take it." + self:sendTextMessage(MESSAGE_EVENT_ADVANCE, baseMessage) + return false + end + + if (self:getFreeCapacity() / 100) < itemWeight then + baseMessage = baseMessage .. ". Weighing " .. itemWeight .. " oz, it is too heavy for you to carry." + self:sendTextMessage(MESSAGE_EVENT_ADVANCE, baseMessage) + return false + end + + return true +end