Skip to content

Conversation

DispersiaRoleplay
Copy link

Description of Changes
Added full validation to the equip:harness server event to prevent runtime errors caused by missing or undefined item slot data. Introduced local variables for safer access to nested fields such as Player.PlayerData.items[slot].info.uses. Applied default value (Config.HarnessUses - 1) when uses data is not present, ensuring stability and continuity of harness logic. Prevented the script from crashing with attempt to index a nil value by checking all required fields before accessing them.

Testing
Changes were tested in-game in multiple scenarios: Harness item with no info.uses field: correctly initializes the value and does not crash. Harness item with uses = 1: removes the item as expected. Harness item with uses > 1: decreases the use count and updates inventory properly. No errors or crashes occurred during testing.

using main en.lua was translated to Ukrainian language.
using main en.lua was translated to Ukrainian language.

I have personally loaded this code into an updated qbcore project and checked all it's functionality
This code fit the style guidelines
This PR fit the contribution guidelines
Description of Changes
Added full validation to the equip:harness server event to prevent runtime errors caused by missing or undefined item slot data.
Introduced local variables for safer access to nested fields such as Player.PlayerData.items[slot].info.uses.
Applied default value (Config.HarnessUses - 1) when uses data is not present, ensuring stability and continuity of harness logic.
Prevented the script from crashing with attempt to index a nil value by checking all required fields before accessing them.

Testing
Changes were tested in-game in multiple scenarios:
Harness item with no info.uses field: correctly initializes the value and does not crash.
Harness item with uses = 1: removes the item as expected.
Harness item with uses > 1: decreases the use count and updates inventory properly.
No errors or crashes occurred during testing.
Copy link
Contributor

@Z3rio Z3rio left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Even though I do not personally love the idea of having the equip:harness event, as it is a bit questionable. That is not really this PR's fault.

Have a look at my feedback and I'd say this is good to merge after that.

Comment on lines +1 to +67
local Translations = {
afk = {
will_kick = "Ви AFK і будете кікнуті через ",
time_seconds = " секунд!",
time_minutes = " хвилину(и)!",
kick_message = "Вас було кікнуто за бездіяльність (AFK)"
},
wash = {
in_progress = "Авто миється...",
wash_vehicle = "[E] Помити авто",
wash_vehicle_target = "Помити авто",
dirty = "Авто не забруднене",
cancel = "Миття скасовано..."
},
consumables = {
eat_progress = "Їсте...",
drink_progress = "П'єте...",
liqour_progress = "Вживаєте алкоголь...",
coke_progress = "Швидке вдихання...",
crack_progress = "Курите крек...",
ecstasy_progress = "Ковтаєте пігулки...",
healing_progress = "Зцілення...",
meth_progress = "Курите жорсткий мет...",
joint_progress = "Підпалюєте косяк...",
use_parachute_progress = "Надягаєте парашут...",
pack_parachute_progress = "Пакуєте парашут...",
no_parachute = "У вас немає парашута!",
armor_full = "У вас вже достатньо броні!",
armor_empty = "На вас немає бронежилета...",
armor_progress = "Надягаєте бронежилет...",
heavy_armor_progress = "Надягаєте важкий бронежилет...",
remove_armor_progress = "Знімаєте бронежилет...",
canceled = "Скасовано..."
},
cruise = {
unavailable = "Круїз-контроль недоступний",
activated = "Круїз-контроль активовано",
deactivated = "Круїз-контроль вимкнено"
},
editor = {
started = "Запис розпочато!",
save = "Запис збережено!",
delete = "Запис видалено!",
editor = "До зустрічі, алігаторе!"
},
firework = {
place_progress = "Встановлення феєрверку...",
canceled = "Скасовано...",
time_left = "Запуск феєрверку через ~r~"
},
seatbelt = {
use_harness_progress = "Пристібання гоночного ременя",
remove_harness_progress = "Зняття гоночного ременя",
no_car = "Ви не в автомобілі."
},
teleport = {
teleport_default = "Скористатись ліфтом"
},
pushcar = {
stop_push = "[E] Зупинити штовхання"
}
}

Lang = Lang or Locale:new({
phrases = Translations,
warnOnMissing = true
})
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Put this in a different PR, this is not what this PR aims to do (supposedly)?
And fix the issues with it ofcourse, as it currently lacks the .lua extension.

Player.Functions.SetInventory(Player.PlayerData.items)
elseif Player.PlayerData.items[item.slot].info.uses == 1 then
elseif uses == 1 then
exports['qb-inventory']:RemoveItem(src, 'harness', 1, false, 'equip:harness')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
exports['qb-inventory']:RemoveItem(src, 'harness', 1, false, 'equip:harness')
exports['qb-inventory']:RemoveItem(src, 'harness', 1, slot, 'equip:harness')

We need to define the slot here, so another harness with full usage doesnt get removed forexample.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants