forked from Simnation/Main
189 lines
9.2 KiB
Lua
189 lines
9.2 KiB
Lua
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 = {
|
|
-- Melee weapons
|
|
[GetHashKey('WEAPON_DAGGER')] = 'weapon_dagger',
|
|
[GetHashKey('WEAPON_BAT')] = 'weapon_bat',
|
|
[GetHashKey('WEAPON_BOTTLE')] = 'weapon_bottle',
|
|
[GetHashKey('WEAPON_CROWBAR')] = 'weapon_crowbar',
|
|
[GetHashKey('WEAPON_FLASHLIGHT')] = 'weapon_flashlight',
|
|
[GetHashKey('WEAPON_GOLFCLUB')] = 'weapon_golfclub',
|
|
[GetHashKey('WEAPON_HAMMER')] = 'weapon_hammer',
|
|
[GetHashKey('WEAPON_HATCHET')] = 'weapon_hatchet',
|
|
[GetHashKey('WEAPON_KNUCKLE')] = 'weapon_knuckle',
|
|
[GetHashKey('WEAPON_KNIFE')] = 'weapon_knife',
|
|
[GetHashKey('WEAPON_MACHETE')] = 'weapon_machete',
|
|
[GetHashKey('WEAPON_SWITCHBLADE')] = 'weapon_switchblade',
|
|
[GetHashKey('WEAPON_NIGHTSTICK')] = 'weapon_nightstick',
|
|
[GetHashKey('WEAPON_WRENCH')] = 'weapon_wrench',
|
|
[GetHashKey('WEAPON_BATTLEAXE')] = 'weapon_battleaxe',
|
|
[GetHashKey('WEAPON_POOLCUE')] = 'weapon_poolcue',
|
|
[GetHashKey('WEAPON_STONE_HATCHET')] = 'weapon_stone_hatchet',
|
|
|
|
-- Handguns
|
|
[GetHashKey('WEAPON_PISTOL')] = 'weapon_pistol',
|
|
[GetHashKey('WEAPON_PISTOL_MK2')] = 'weapon_pistol_mk2',
|
|
[GetHashKey('WEAPON_COMBATPISTOL')] = 'weapon_combatpistol',
|
|
[GetHashKey('WEAPON_APPISTOL')] = 'weapon_appistol',
|
|
[GetHashKey('WEAPON_STUNGUN')] = 'weapon_stungun',
|
|
[GetHashKey('WEAPON_PISTOL50')] = 'weapon_pistol50',
|
|
[GetHashKey('WEAPON_SNSPISTOL')] = 'weapon_snspistol',
|
|
[GetHashKey('WEAPON_SNSPISTOL_MK2')] = 'weapon_snspistol_mk2',
|
|
[GetHashKey('WEAPON_HEAVYPISTOL')] = 'weapon_heavypistol',
|
|
[GetHashKey('WEAPON_VINTAGEPISTOL')] = 'weapon_vintagepistol',
|
|
[GetHashKey('WEAPON_FLAREGUN')] = 'weapon_flaregun',
|
|
[GetHashKey('WEAPON_MARKSMANPISTOL')] = 'weapon_marksmanpistol',
|
|
[GetHashKey('WEAPON_REVOLVER')] = 'weapon_revolver',
|
|
[GetHashKey('WEAPON_REVOLVER_MK2')] = 'weapon_revolver_mk2',
|
|
[GetHashKey('WEAPON_DOUBLEACTION')] = 'weapon_doubleaction',
|
|
[GetHashKey('WEAPON_RAYPISTOL')] = 'weapon_raypistol',
|
|
[GetHashKey('WEAPON_CERAMICPISTOL')] = 'weapon_ceramicpistol',
|
|
[GetHashKey('WEAPON_NAVYREVOLVER')] = 'weapon_navyrevolver',
|
|
[GetHashKey('WEAPON_GADGETPISTOL')] = 'weapon_gadgetpistol',
|
|
[GetHashKey('WEAPON_STUNGUN_MP')] = 'weapon_stungun_mp',
|
|
|
|
-- Submachine Guns
|
|
[GetHashKey('WEAPON_MICROSMG')] = 'weapon_microsmg',
|
|
[GetHashKey('WEAPON_SMG')] = 'weapon_smg',
|
|
[GetHashKey('WEAPON_SMG_MK2')] = 'weapon_smg_mk2',
|
|
[GetHashKey('WEAPON_ASSAULTSMG')] = 'weapon_assaultsmg',
|
|
[GetHashKey('WEAPON_COMBATPDW')] = 'weapon_combatpdw',
|
|
[GetHashKey('WEAPON_MACHINEPISTOL')] = 'weapon_machinepistol',
|
|
[GetHashKey('WEAPON_MINISMG')] = 'weapon_minismg',
|
|
[GetHashKey('WEAPON_RAYCARBINE')] = 'weapon_raycarbine',
|
|
|
|
-- Shotguns
|
|
[GetHashKey('WEAPON_PUMPSHOTGUN')] = 'weapon_pumpshotgun',
|
|
[GetHashKey('WEAPON_PUMPSHOTGUN_MK2')] = 'weapon_pumpshotgun_mk2',
|
|
[GetHashKey('WEAPON_SAWNOFFSHOTGUN')] = 'weapon_sawnoffshotgun',
|
|
[GetHashKey('WEAPON_ASSAULTSHOTGUN')] = 'weapon_assaultshotgun',
|
|
[GetHashKey('WEAPON_BULLPUPSHOTGUN')] = 'weapon_bullpupshotgun',
|
|
[GetHashKey('WEAPON_MUSKET')] = 'weapon_musket',
|
|
[GetHashKey('WEAPON_HEAVYSHOTGUN')] = 'weapon_heavyshotgun',
|
|
[GetHashKey('WEAPON_DBSHOTGUN')] = 'weapon_dbshotgun',
|
|
[GetHashKey('WEAPON_AUTOSHOTGUN')] = 'weapon_autoshotgun',
|
|
[GetHashKey('WEAPON_COMBATSHOTGUN')] = 'weapon_combatshotgun',
|
|
|
|
-- Assault Rifles
|
|
[GetHashKey('WEAPON_ASSAULTRIFLE')] = 'weapon_assaultrifle',
|
|
[GetHashKey('WEAPON_ASSAULTRIFLE_MK2')] = 'weapon_assaultrifle_mk2',
|
|
[GetHashKey('WEAPON_CARBINERIFLE')] = 'weapon_carbinerifle',
|
|
[GetHashKey('WEAPON_CARBINERIFLE_MK2')] = 'weapon_carbinerifle_mk2',
|
|
[GetHashKey('WEAPON_ADVANCEDRIFLE')] = 'weapon_advancedrifle',
|
|
[GetHashKey('WEAPON_SPECIALCARBINE')] = 'weapon_specialcarbine',
|
|
[GetHashKey('WEAPON_SPECIALCARBINE_MK2')] = 'weapon_specialcarbine_mk2',
|
|
[GetHashKey('WEAPON_BULLPUPRIFLE')] = 'weapon_bullpuprifle',
|
|
[GetHashKey('WEAPON_BULLPUPRIFLE_MK2')] = 'weapon_bullpuprifle_mk2',
|
|
[GetHashKey('WEAPON_COMPACTRIFLE')] = 'weapon_compactrifle',
|
|
[GetHashKey('WEAPON_MILITARYRIFLE')] = 'weapon_militaryrifle',
|
|
[GetHashKey('WEAPON_HEAVYRIFLE')] = 'weapon_heavyrifle',
|
|
[GetHashKey('WEAPON_TACTICALRIFLE')] = 'weapon_tacticalrifle',
|
|
|
|
-- Light Machine Guns
|
|
[GetHashKey('WEAPON_MG')] = 'weapon_mg',
|
|
[GetHashKey('WEAPON_COMBATMG')] = 'weapon_combatmg',
|
|
[GetHashKey('WEAPON_COMBATMG_MK2')] = 'weapon_combatmg_mk2',
|
|
[GetHashKey('WEAPON_GUSENBERG')] = 'weapon_gusenberg',
|
|
|
|
-- Sniper Rifles
|
|
[GetHashKey('WEAPON_SNIPERRIFLE')] = 'weapon_sniperrifle',
|
|
[GetHashKey('WEAPON_HEAVYSNIPER')] = 'weapon_heavysniper',
|
|
[GetHashKey('WEAPON_HEAVYSNIPER_MK2')] = 'weapon_heavysniper_mk2',
|
|
[GetHashKey('WEAPON_MARKSMANRIFLE')] = 'weapon_marksmanrifle',
|
|
[GetHashKey('WEAPON_MARKSMANRIFLE_MK2')] = 'weapon_marksmanrifle_mk2',
|
|
[GetHashKey('WEAPON_PRECISIONRIFLE')] = 'weapon_precisionrifle',
|
|
|
|
-- Heavy Weapons
|
|
[GetHashKey('WEAPON_RPG')] = 'weapon_rpg',
|
|
[GetHashKey('WEAPON_GRENADELAUNCHER')] = 'weapon_grenadelauncher',
|
|
[GetHashKey('WEAPON_GRENADELAUNCHER_SMOKE')] = 'weapon_grenadelauncher_smoke',
|
|
[GetHashKey('WEAPON_MINIGUN')] = 'weapon_minigun',
|
|
[GetHashKey('WEAPON_FIREWORK')] = 'weapon_firework',
|
|
[GetHashKey('WEAPON_RAILGUN')] = 'weapon_railgun',
|
|
[GetHashKey('WEAPON_HOMINGLAUNCHER')] = 'weapon_hominglauncher',
|
|
[GetHashKey('WEAPON_COMPACTLAUNCHER')] = 'weapon_compactlauncher',
|
|
[GetHashKey('WEAPON_RAYMINIGUN')] = 'weapon_rayminigun',
|
|
[GetHashKey('WEAPON_EMPLAUNCHER')] = 'weapon_emplauncher',
|
|
|
|
-- Throwables
|
|
[GetHashKey('WEAPON_GRENADE')] = 'weapon_grenade',
|
|
[GetHashKey('WEAPON_BZGAS')] = 'weapon_bzgas',
|
|
[GetHashKey('WEAPON_MOLOTOV')] = 'weapon_molotov',
|
|
[GetHashKey('WEAPON_STICKYBOMB')] = 'weapon_stickybomb',
|
|
[GetHashKey('WEAPON_PROXMINE')] = 'weapon_proxmine',
|
|
[GetHashKey('WEAPON_SNOWBALL')] = 'weapon_snowball',
|
|
[GetHashKey('WEAPON_PIPEBOMB')] = 'weapon_pipebomb',
|
|
[GetHashKey('WEAPON_BALL')] = 'weapon_ball',
|
|
[GetHashKey('WEAPON_SMOKEGRENADE')] = 'weapon_smokegrenade',
|
|
[GetHashKey('WEAPON_FLARE')] = 'weapon_flare',
|
|
|
|
-- Miscellaneous
|
|
[GetHashKey('WEAPON_PETROLCAN')] = 'weapon_petrolcan',
|
|
[GetHashKey('WEAPON_FIREEXTINGUISHER')] = 'weapon_fireextinguisher',
|
|
[GetHashKey('WEAPON_HAZARDCAN')] = 'weapon_hazardcan',
|
|
[GetHashKey('WEAPON_FERTILIZERCAN')] = 'weapon_fertilizercan',
|
|
|
|
-- DLC Weapons
|
|
[GetHashKey('WEAPON_CANDYCANE')] = 'weapon_candycane',
|
|
[GetHashKey('WEAPON_METALDETECTOR')] = 'weapon_metaldetector',
|
|
|
|
-- Softair
|
|
[GetHashKey('WEAPON_AIRSOFTGLOCK20')] = 'weapon_airsoftglock20 ',
|
|
[GetHashKey('WEAPON_AIRSOFTR870')] = 'weapon_airsoftr870',
|
|
[GetHashKey('WEAPON_AIRSOFTR700')] = 'weapon_airsoftr700',
|
|
[GetHashKey('WEAPON_AIRSOFTMP5')] = 'weapon_airsoftmp5',
|
|
[GetHashKey('WEAPON_AIRSOFTMICROUZI')] = 'weapon_airsoftmircouzi',
|
|
[GetHashKey('WEAPON_AIRSFOTM249')] = 'weapon_airsoftm249',
|
|
[GetHashKey('WEAPON_AIRSOFTM4')] = 'weapon_airsoftm4',
|
|
[GetHashKey('WEAPON_AIRSOFTG36C')] = 'weapon_airsoftg36c',
|
|
[GetHashKey('WEAPON_AIRSOFTAK47')] = 'weapon_airsoftak47',
|
|
|
|
}
|
|
|
|
return weapons[hash]
|
|
end
|