Skip to content

Commit 65ed7b5

Browse files
authored
fix: check quest reward nil value on setStorage (#3403)
1 parent 828e15b commit 65ed7b5

1 file changed

Lines changed: 14 additions & 4 deletions

File tree

data-otservbr-global/scripts/actions/system/quest_reward_common.lua

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ local achievementTable = {
5656
[6088] = "Annihilator",
5757
}
5858

59-
local function playerAddItem(params, item)
59+
local function playerAddItem(params, item, rewardIndex)
6060
local player = params.player
6161
if not checkWeightAndBackpackRoom(player, params.weight, params.message) then
6262
return false
@@ -92,6 +92,11 @@ local function playerAddItem(params, item)
9292
player:questKV(params.questName):set("params.questName", os.time() + params.time * 3600) -- multiplicação por hora
9393
end
9494
else
95+
if params.storage == nil then
96+
logger.warn("Storage key is nil for reward index {}, itemid {}", rewardIndex, params.itemid)
97+
return false
98+
end
99+
95100
player:setStorageValue(params.storage, 1)
96101
if params.timer then
97102
player:setStorageValue(params.timer, os.time() + params.time * 3600) -- multiplicação por hora
@@ -100,7 +105,7 @@ local function playerAddItem(params, item)
100105
return true
101106
end
102107

103-
local function playerAddContainerItem(params, item)
108+
local function playerAddContainerItem(params, item, rewardIndex)
104109
local player = params.player
105110

106111
local reward = params.containerReward
@@ -130,6 +135,11 @@ local function playerAddContainerItem(params, item)
130135
player:questKV(params.questName):set("params.questName", os.time() + params.time * 3600) -- multiplicação por hora
131136
end
132137
else
138+
if params.storage == nil then
139+
logger.warn("Storage key is nil for reward index {}, itemid {} in container", rewardIndex, params.itemid)
140+
return false
141+
end
142+
133143
player:setStorageValue(params.storage, 1)
134144
if params.timer then
135145
player:setStorageValue(params.timer, os.time() + params.time * 3600) -- multiplicação por hora
@@ -223,7 +233,7 @@ function questReward.onUse(player, item, fromPosition, itemEx, toPosition)
223233
else
224234
addItemParams.message = "You have found " .. itemArticle .. " " .. itemName
225235
end
226-
if not playerAddItem(addItemParams, item) then
236+
if not playerAddItem(addItemParams, item, i) then
227237
return true
228238
end
229239
end
@@ -242,7 +252,7 @@ function questReward.onUse(player, item, fromPosition, itemEx, toPosition)
242252
useKV = setting.useKV,
243253
}
244254

245-
if not playerAddContainerItem(addContainerItemParams, item) then
255+
if not playerAddContainerItem(addContainerItemParams, item, i) then
246256
return true
247257
end
248258
end

0 commit comments

Comments
 (0)