forked from Simnation/Main
111 lines
3.9 KiB
Lua
111 lines
3.9 KiB
Lua
local QBCore = exports['qb-core']:GetCoreObject() -- Replace with your framework if different
|
|
|
|
-- Configuration
|
|
local Config = {
|
|
RepairKit = {
|
|
item = "weapon_repair_kit",
|
|
removeOnUse = true,
|
|
repairAmount = 100, -- How much to repair (0-100)
|
|
},
|
|
Notifications = {
|
|
noWeapon = "You don't have a weapon in your hand to repair",
|
|
repaired = "Weapon repaired successfully",
|
|
noRepairKit = "You need a repair kit to repair weapons",
|
|
alreadyRepaired = "This weapon is already in good condition"
|
|
}
|
|
}
|
|
|
|
-- Register usable item
|
|
QBCore.Functions.CreateUseableItem(Config.RepairKit.item, function(source)
|
|
local src = source
|
|
local Player = QBCore.Functions.GetPlayer(src)
|
|
|
|
if not Player then return end
|
|
|
|
-- Check if player has the repair kit
|
|
if not exports["tgiann-inventory"]:HasItem(src, Config.RepairKit.item, 1) then
|
|
TriggerClientEvent('QBCore:Notify', src, Config.Notifications.noRepairKit, 'error')
|
|
return
|
|
end
|
|
|
|
-- Trigger client to get current weapon
|
|
TriggerClientEvent('weapon_repair:getWeaponInHand', src)
|
|
end)
|
|
|
|
-- Event to repair weapon
|
|
RegisterNetEvent('weapon_repair:repairWeapon', function(weaponName)
|
|
local src = source
|
|
local Player = QBCore.Functions.GetPlayer(src)
|
|
|
|
if not Player then return end
|
|
|
|
-- Check if player has the repair kit
|
|
if not exports["tgiann-inventory"]:HasItem(src, Config.RepairKit.item, 1) then
|
|
TriggerClientEvent('QBCore:Notify', src, Config.Notifications.noRepairKit, 'error')
|
|
return
|
|
end
|
|
|
|
-- Get all player items
|
|
local playerItems = exports["tgiann-inventory"]:GetPlayerItems(src)
|
|
local weaponFound = false
|
|
|
|
-- Loop through items to find the weapon
|
|
for slot, itemData in pairs(playerItems) do
|
|
if itemData.name == weaponName then
|
|
-- Check if weapon needs repair
|
|
local durability = itemData.info and itemData.info.durabilityPercent or 100
|
|
|
|
if durability >= 100 then
|
|
TriggerClientEvent('QBCore:Notify', src, Config.Notifications.alreadyRepaired, 'error')
|
|
return
|
|
end
|
|
|
|
-- Repair the weapon
|
|
local success = exports["tgiann-inventory"]:RepairWeapon(src, slot, Config.RepairKit.repairAmount)
|
|
|
|
if success then
|
|
-- Remove repair kit if configured
|
|
if Config.RepairKit.removeOnUse then
|
|
exports["tgiann-inventory"]:RemoveItem(src, Config.RepairKit.item, 1)
|
|
end
|
|
|
|
TriggerClientEvent('QBCore:Notify', src, Config.Notifications.repaired, 'success')
|
|
|
|
-- Play repair animation
|
|
TriggerClientEvent('weapon_repair:playRepairAnimation', src)
|
|
end
|
|
|
|
weaponFound = true
|
|
break
|
|
end
|
|
end
|
|
|
|
if not weaponFound then
|
|
TriggerClientEvent('QBCore:Notify', src, Config.Notifications.noWeapon, 'error')
|
|
end
|
|
end)
|
|
|
|
-- Function to repair all weapons in inventory (admin command)
|
|
RegisterCommand('repairallweapons', function(source, args)
|
|
local src = source
|
|
local Player = QBCore.Functions.GetPlayer(src)
|
|
|
|
if not Player then return end
|
|
|
|
-- Check if player is admin
|
|
if Player.PlayerData.permission ~= "admin" and Player.PlayerData.permission ~= "god" then
|
|
return
|
|
end
|
|
|
|
local playerItems = exports["tgiann-inventory"]:GetPlayerItems(src)
|
|
local weaponsRepaired = 0
|
|
|
|
for slot, itemData in pairs(playerItems) do
|
|
if string.match(itemData.name, "weapon_") then
|
|
exports["tgiann-inventory"]:RepairWeapon(src, slot, 100)
|
|
weaponsRepaired = weaponsRepaired + 1
|
|
end
|
|
end
|
|
|
|
TriggerClientEvent('QBCore:Notify', src, "Repaired " .. weaponsRepaired .. " weapons", 'success')
|
|
end, false)
|