Skip to content

Commit

Permalink
Feat: melhorias nas validações do farm com durabilidade
Browse files Browse the repository at this point in the history
  • Loading branch information
ggfto committed Dec 10, 2024
1 parent ae62dff commit 1144d1d
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 25 deletions.
66 changes: 41 additions & 25 deletions client/main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ local function stopFarm()
startFarm = false
tasking = false

lib.notify(
Utils.SendNotification(
{
type = "error",
description = locale("text.cancel_shift")
Expand Down Expand Up @@ -307,7 +307,7 @@ local function openPoint(point, itemName, item)
end,
function()
-- Cancel
lib.notify(
Utils.SendNotification(
{
description = locale("task.cancel_task"),
type = "error"
Expand All @@ -321,14 +321,15 @@ end
local function checkInteraction(point, item)
local collectItem = item["collectItem"] or {}
local collectItemName = collectItem["name"]
local collectItemDurability = collectItem["durability"]
if not playerFarm then
-- Verifica se o player está farmando agora
return false
end

if not (currentPoint == point) then
-- Verifica se o player está na zona correta
lib.notify(
Utils.SendNotification(
{
id = "farm:error.wrong_point",
title = locale("error.wrong_point_title"),
Expand All @@ -341,7 +342,7 @@ local function checkInteraction(point, item)

if IsPedInAnyVehicle(cache.ped, false) then
-- Verifica se o player esta em um veiculo
lib.notify(
Utils.SendNotification(
{
id = "farm:error.not_in_vehicle",
description = locale("error.not_in_vehicle"),
Expand All @@ -356,7 +357,7 @@ local function checkInteraction(point, item)
not IsVehicleModel(GetVehiclePedIsIn(PlayerPedId(), true), GetHashKey(playerFarm.config["vehicle"]))
then
-- Verifica se o player esta no veículo certo
lib.notify(
Utils.SendNotification(
{
id = "farm:error.incorrect_vehicle",
description = locale("error.incorrect_vehicle"),
Expand All @@ -367,10 +368,10 @@ local function checkInteraction(point, item)
end

if collectItemName then
local toolItem = exports.ox_inventory:Search("slots", collectItemName)
if not toolItem then
local toolItems = exports.ox_inventory:Search("slots", collectItemName)
if not toolItems then
-- Verifica se o player tem o item certo
lib.notify(
Utils.SendNotification(
{
id = "farm:error.no_item",
description = locale("error.no_item", collectItemName),
Expand All @@ -380,23 +381,38 @@ local function checkInteraction(point, item)
return false
end

for k, v in pairs(toolItem) do
if v.metadata and v.metadata.durability and v.metadata.durability >= (item.collectItem.durability or 0) then
toolItem = v
break
if collectItemDurability and collectItemDurability > 0 then
local toolItem
for k, v in pairs(toolItems) do
if v["metadata"] and v.metadata["durability"] and v.metadata.durability then
toolItem = v
break
end
end
end

if (toolItem.metadata.durability or 0) < (item["collectItem"]["durability"] or 0) then
-- Verifica se o item tem durabilidade
lib.notify(
{
id = "farm:error.low_durability",
description = locale("error.low_durability", Items[collectItemName].label),
type = "error"
}
)
return false
if toolItem then
if toolItem.metadata.durability < collectItemDurability then
-- Verifica se o item tem durabilidade
Utils.SendNotification(
{
id = "farm:error.low_durability",
description = locale("error.low_durability", Items[collectItemName].label),
type = "error"
}
)
return false
end
else
-- Verifica se o item configurado está correto
Utils.SendNotification(
{
id = "farm:error.invalid_item_type",
description = locale("error.invalid_item_type", collectItemName),
type = "error"
}
)
return false
end
end
end

Expand Down Expand Up @@ -489,7 +505,7 @@ local function startFarming(args)
end

currentSequence = 0
lib.notify(
Utils.SendNotification(
{
description = locale("text.start_shift", farmItem["customName"] or Items[itemName].label),
type = "info"
Expand All @@ -504,7 +520,7 @@ local function startFarming(args)
if amount >= 0 and pickedFarms >= amount then
startFarm = false
markerCoords = nil
lib.notify(
Utils.SendNotification(
{
description = locale("text.end_shift"),
type = "info"
Expand Down
11 changes: 11 additions & 0 deletions client/utils.lua
Original file line number Diff line number Diff line change
Expand Up @@ -202,4 +202,15 @@ function Utils.GetDefaultAnim(useEmoteMenu)
return DefaultAnimCmd
end

function Utils.SendNotification(data)
lib.notify(
{
id = data["id"] or nil,
title = data["title"] or nil,
description = data["description"] or nil,
type = data["type"] or "info"
}
)
end

return Utils
1 change: 1 addition & 0 deletions locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@
"error.invalid_item": "Item '%s' does not exist.",
"error.invalid_item_description": "Click to remove.",
"error.no_item": "You do not have the required item.",
"error.invalid_item_type": "Item type '%s' is invalid.",
"error.low_durability": "The item cannot be collected because %s's durability is too low.",
"error.wrong_point_title": "Invalid collection point!",
"error.wrong_point_message": "Am I in the correct location?",
Expand Down
1 change: 1 addition & 0 deletions locales/pt-br.json
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@
"error.invalid_item": "Item '%s' não existe.",
"error.invalid_item_description": "Clique para remover.",
"error.no_item": "Você não possui o item necessário.",
"error.invalid_item_type": "Tipo de item '%s' inválido.",
"error.low_durability": "O item não pode ser coletado porque a durabilidade de %s está muito baixa.",
"error.wrong_point_title": "Ponto de coleta inválido!",
"error.wrong_point_message": "Estou no local correto?",
Expand Down

0 comments on commit 1144d1d

Please sign in to comment.