Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: kv: quests #2099

Merged
merged 8 commits into from
Mar 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions data-otservbr-global/scripts/actions/rookgaard/rapier_quest.lua
Original file line number Diff line number Diff line change
@@ -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
dudantas marked this conversation as resolved.
Show resolved Hide resolved
return true
end
player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "You have found a rapier.")
player:addItem(rewardId, 1)
player:questKV("rapier"):set("completed", true)
majestyotbr marked this conversation as resolved.
Show resolved Hide resolved
majestyotbr marked this conversation as resolved.
Show resolved Hide resolved
return true
end

rapierQuest:uid(14042)
rapierQuest:register()
4 changes: 4 additions & 0 deletions data-otservbr-global/startup/tables/chest.lua
Original file line number Diff line number Diff line change
Expand Up @@ -1186,4 +1186,8 @@ ChestUnique = {
itemId = 11810,
itemPos = { x = 33195, y = 31765, z = 1 },
},
[14042] = {
itemId = 2473,
itemPos = { x = 32099, y = 32198, z = 9 },
},
}
34 changes: 34 additions & 0 deletions data/libs/functions/player.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
majestyotbr marked this conversation as resolved.
Show resolved Hide resolved
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
Loading