forked from Simnation/Main
ed
This commit is contained in:
parent
49a037f660
commit
1af392096b
5 changed files with 234 additions and 0 deletions
BIN
resources/[inventory]/cs_shops/ui/image/weapon_repair_kit.png
Normal file
BIN
resources/[inventory]/cs_shops/ui/image/weapon_repair_kit.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 97 KiB |
Binary file not shown.
After Width: | Height: | Size: 97 KiB |
103
resources/[inventory]/nordi_weapon_repair/client.lua
Normal file
103
resources/[inventory]/nordi_weapon_repair/client.lua
Normal file
|
@ -0,0 +1,103 @@
|
||||||
|
local QBCore = exports['qb-core']:GetCoreObject() -- Replace with your framework if different
|
||||||
|
|
||||||
|
-- Get current weapon in hand
|
||||||
|
RegisterNetEvent('weapon_repair:getWeaponInHand', function()
|
||||||
|
local ped = PlayerPedId()
|
||||||
|
local weapon = GetSelectedPedWeapon(ped)
|
||||||
|
|
||||||
|
if weapon ~= GetHashKey('WEAPON_UNARMED') then
|
||||||
|
local weaponName = GetWeaponNameFromHash(weapon)
|
||||||
|
if weaponName then
|
||||||
|
TriggerServerEvent('weapon_repair:repairWeapon', weaponName)
|
||||||
|
else
|
||||||
|
QBCore.Functions.Notify("Couldn't identify the weapon", "error")
|
||||||
|
end
|
||||||
|
else
|
||||||
|
QBCore.Functions.Notify("You don't have a weapon in your hand", "error")
|
||||||
|
end
|
||||||
|
end)
|
||||||
|
|
||||||
|
-- Play repair animation
|
||||||
|
RegisterNetEvent('weapon_repair:playRepairAnimation', function()
|
||||||
|
local ped = PlayerPedId()
|
||||||
|
|
||||||
|
-- Request animation dictionary
|
||||||
|
RequestAnimDict("mini@repair")
|
||||||
|
while not HasAnimDictLoaded("mini@repair") do
|
||||||
|
Wait(10)
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Play animation
|
||||||
|
TaskPlayAnim(ped, "mini@repair", "fixing_a_ped", 8.0, -8.0, -1, 49, 0, false, false, false)
|
||||||
|
|
||||||
|
-- Progress bar
|
||||||
|
QBCore.Functions.Progressbar("repair_weapon", "Repairing weapon...", 5000, false, true, {
|
||||||
|
disableMovement = true,
|
||||||
|
disableCarMovement = true,
|
||||||
|
disableMouse = false,
|
||||||
|
disableCombat = true,
|
||||||
|
}, {}, {}, {}, function() -- Done
|
||||||
|
ClearPedTasks(ped)
|
||||||
|
end, function() -- Cancel
|
||||||
|
ClearPedTasks(ped)
|
||||||
|
end)
|
||||||
|
end)
|
||||||
|
|
||||||
|
-- Helper function to convert weapon hash to name
|
||||||
|
function GetWeaponNameFromHash(hash)
|
||||||
|
local weapons = {
|
||||||
|
[GetHashKey('WEAPON_PISTOL')] = 'weapon_pistol',
|
||||||
|
[GetHashKey('WEAPON_COMBATPISTOL')] = 'weapon_combatpistol',
|
||||||
|
[GetHashKey('WEAPON_APPISTOL')] = 'weapon_appistol',
|
||||||
|
[GetHashKey('WEAPON_PISTOL50')] = 'weapon_pistol50',
|
||||||
|
[GetHashKey('WEAPON_SNSPISTOL')] = 'weapon_snspistol',
|
||||||
|
[GetHashKey('WEAPON_HEAVYPISTOL')] = 'weapon_heavypistol',
|
||||||
|
[GetHashKey('WEAPON_VINTAGEPISTOL')] = 'weapon_vintagepistol',
|
||||||
|
[GetHashKey('WEAPON_STUNGUN')] = 'weapon_stungun',
|
||||||
|
[GetHashKey('WEAPON_FLAREGUN')] = 'weapon_flaregun',
|
||||||
|
[GetHashKey('WEAPON_MARKSMANPISTOL')] = 'weapon_marksmanpistol',
|
||||||
|
[GetHashKey('WEAPON_REVOLVER')] = 'weapon_revolver',
|
||||||
|
[GetHashKey('WEAPON_MICROSMG')] = 'weapon_microsmg',
|
||||||
|
[GetHashKey('WEAPON_SMG')] = 'weapon_smg',
|
||||||
|
[GetHashKey('WEAPON_ASSAULTSMG')] = 'weapon_assaultsmg',
|
||||||
|
[GetHashKey('WEAPON_MG')] = 'weapon_mg',
|
||||||
|
[GetHashKey('WEAPON_COMBATMG')] = 'weapon_combatmg',
|
||||||
|
[GetHashKey('WEAPON_GUSENBERG')] = 'weapon_gusenberg',
|
||||||
|
[GetHashKey('WEAPON_ASSAULTRIFLE')] = 'weapon_assaultrifle',
|
||||||
|
[GetHashKey('WEAPON_CARBINERIFLE')] = 'weapon_carbinerifle',
|
||||||
|
[GetHashKey('WEAPON_ADVANCEDRIFLE')] = 'weapon_advancedrifle',
|
||||||
|
[GetHashKey('WEAPON_SPECIALCARBINE')] = 'weapon_specialcarbine',
|
||||||
|
[GetHashKey('WEAPON_BULLPUPRIFLE')] = 'weapon_bullpuprifle',
|
||||||
|
[GetHashKey('WEAPON_COMPACTRIFLE')] = 'weapon_compactrifle',
|
||||||
|
[GetHashKey('WEAPON_PUMPSHOTGUN')] = 'weapon_pumpshotgun',
|
||||||
|
[GetHashKey('WEAPON_SAWNOFFSHOTGUN')] = 'weapon_sawnoffshotgun',
|
||||||
|
[GetHashKey('WEAPON_BULLPUPSHOTGUN')] = 'weapon_bullpupshotgun',
|
||||||
|
[GetHashKey('WEAPON_ASSAULTSHOTGUN')] = 'weapon_assaultshotgun',
|
||||||
|
[GetHashKey('WEAPON_MUSKET')] = 'weapon_musket',
|
||||||
|
[GetHashKey('WEAPON_HEAVYSHOTGUN')] = 'weapon_heavyshotgun',
|
||||||
|
[GetHashKey('WEAPON_DBSHOTGUN')] = 'weapon_dbshotgun',
|
||||||
|
[GetHashKey('WEAPON_SNIPERRIFLE')] = 'weapon_sniperrifle',
|
||||||
|
[GetHashKey('WEAPON_HEAVYSNIPER')] = 'weapon_heavysniper',
|
||||||
|
[GetHashKey('WEAPON_MARKSMANRIFLE')] = 'weapon_marksmanrifle',
|
||||||
|
[GetHashKey('WEAPON_GRENADELAUNCHER')] = 'weapon_grenadelauncher',
|
||||||
|
[GetHashKey('WEAPON_RPG')] = 'weapon_rpg',
|
||||||
|
[GetHashKey('WEAPON_MINIGUN')] = 'weapon_minigun',
|
||||||
|
[GetHashKey('WEAPON_FIREWORK')] = 'weapon_firework',
|
||||||
|
[GetHashKey('WEAPON_RAILGUN')] = 'weapon_railgun',
|
||||||
|
[GetHashKey('WEAPON_HOMINGLAUNCHER')] = 'weapon_hominglauncher',
|
||||||
|
[GetHashKey('WEAPON_GRENADE')] = 'weapon_grenade',
|
||||||
|
[GetHashKey('WEAPON_STICKYBOMB')] = 'weapon_stickybomb',
|
||||||
|
[GetHashKey('WEAPON_PROXMINE')] = 'weapon_proxmine',
|
||||||
|
[GetHashKey('WEAPON_BZGAS')] = 'weapon_bzgas',
|
||||||
|
[GetHashKey('WEAPON_SMOKEGRENADE')] = 'weapon_smokegrenade',
|
||||||
|
[GetHashKey('WEAPON_MOLOTOV')] = 'weapon_molotov',
|
||||||
|
[GetHashKey('WEAPON_FIREEXTINGUISHER')] = 'weapon_fireextinguisher',
|
||||||
|
[GetHashKey('WEAPON_PETROLCAN')] = 'weapon_petrolcan',
|
||||||
|
[GetHashKey('WEAPON_SNOWBALL')] = 'weapon_snowball',
|
||||||
|
[GetHashKey('WEAPON_FLARE')] = 'weapon_flare',
|
||||||
|
[GetHashKey('WEAPON_BALL')] = 'weapon_ball',
|
||||||
|
-- Add any additional weapons your server uses
|
||||||
|
}
|
||||||
|
|
||||||
|
return weapons[hash]
|
||||||
|
end
|
20
resources/[inventory]/nordi_weapon_repair/fxmanifest.lua
Normal file
20
resources/[inventory]/nordi_weapon_repair/fxmanifest.lua
Normal file
|
@ -0,0 +1,20 @@
|
||||||
|
fx_version 'cerulean'
|
||||||
|
game 'gta5'
|
||||||
|
|
||||||
|
author 'Your Name'
|
||||||
|
description 'Weapon Repair Script for tgiann-inventory'
|
||||||
|
version '1.0.0'
|
||||||
|
|
||||||
|
shared_scripts {
|
||||||
|
'@qb-core/shared/locale.lua', -- Remove if not using QBCore
|
||||||
|
}
|
||||||
|
|
||||||
|
client_scripts {
|
||||||
|
'client.lua',
|
||||||
|
}
|
||||||
|
|
||||||
|
server_scripts {
|
||||||
|
'server.lua',
|
||||||
|
}
|
||||||
|
|
||||||
|
lua54 'yes'
|
111
resources/[inventory]/nordi_weapon_repair/server.lua
Normal file
111
resources/[inventory]/nordi_weapon_repair/server.lua
Normal file
|
@ -0,0 +1,111 @@
|
||||||
|
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)
|
Loading…
Add table
Add a link
Reference in a new issue