loadedWeapons = {} currentWeapon = nil RegisterNetEvent("vrp-inventory:setWeaponState", function(x) loadedWeapons = x end) local weaponComps = { ["Flashlight"] = {"COMPONENT_AT_PI_FLSH_02", "COMPONENT_AT_AR_FLSH", "COMPONENT_AT_PI_FLSH", "COMPONENT_AT_PI_FLSH_03"}, ["Scope"] = {"COMPONENT_AT_SCOPE_MACRO_02", "COMPONENT_AT_SCOPE_SMALL_02", "COMPONENT_AT_SCOPE_MACRO", "COMPONENT_AT_SCOPE_MEDIUM", "COMPONENT_AT_SCOPE_LARGE", "COMPONENT_AT_SCOPE_SMALL"}, ["Grip"] = {"COMPONENT_AT_AR_AFGRIP", "COMPONENT_AT_AR_AFGRIP_02"}, ["Suppressor"] = {"COMPONENT_AT_PI_SUPP", "COMPONENT_AT_PI_SUPP_02", "COMPONENT_AT_AR_SUPP", "COMPONENT_AT_AR_SUPP_02", "COMPONENT_AT_SR_SUPP", "COMPONENT_AT_SR_SUPP_03"}, ["Extended"] = {"COMPONENT_MACHINEPISTOL_CLIP_02","COMPONENT_PISTOL_CLIP_02","COMPONENT_ASSAULTSHOTGUN_CLIP_02","COMPONENT_HEAVYSHOTGUN_CLIP_02","COMPONENT_PISTOL50_CLIP_02","COMPONENT_COMBATPISTOL_CLIP_02","COMPONENT_APPISTOL_CLIP_02","COMPONENT_COMBATPDW_CLIP_02","COMPONENT_SNSPISTOL_CLIP_02","COMPONENT_ASSAULTRIFLE_CLIP_02","COMPONENT_COMBATMG_CLIP_02","COMPONENT_MG_CLIP_02","COMPONENT_ASSAULTSMG_CLIP_02","COMPONENT_GUSENBERG_CLIP_02","COMPONENT_MICROSMG_CLIP_02","COMPONENT_BULLPUPRIFLE_CLIP_02","COMPONENT_COMPACTRIFLE_CLIP_02","COMPONENT_HEAVYPISTOL_CLIP_02","COMPONENT_VINTAGEPISTOL_CLIP_02","COMPONENT_CARBINERIFLE_CLIP_02","COMPONENT_ADVANCEDRIFLE_CLIP_02","COMPONENT_MARKSMANRIFLE_CLIP_02","COMPONENT_SMG_CLIP_02","COMPONENT_SPECIALCARBINE_CLIP_02"}, } function giveCompToWeap(uWeap, cmpTbl) Wait(150) for i = 1, #cmpTbl do for z = 1, #weaponComps[cmpTbl[i]] do if DoesWeaponTakeWeaponComponent(uWeap, weaponComps[cmpTbl[i]][z]) then GiveWeaponComponentToPed(PlayerPedId(), uWeap, weaponComps[cmpTbl[i]][z]) if HasPedGotWeaponComponent(PlayerPedId(), uWeap, weaponComps[cmpTbl[i]][z]) then goto skip end end ::skip:: end end end function vRPin.addAttachment(component) if not (component) then return end for i = 1, #weaponComps[component] or {} do if DoesWeaponTakeWeaponComponent(currentWeapon, weaponComps[component][i]) then GiveWeaponComponentToPed(PlayerPedId(), currentWeapon, weaponComps[component][i]) if HasPedGotWeaponComponent(PlayerPedId(), currentWeapon, weaponComps[component][i]) then if not loadedWeapons[currentWeapon] then loadedWeapons[currentWeapon] = {} end if not loadedWeapons[currentWeapon].attach then loadedWeapons[currentWeapon].attach = {} end for _, comp in pairs(loadedWeapons[currentWeapon].attach) do if comp == component then return end end loadedWeapons[currentWeapon].attach[#loadedWeapons[currentWeapon].attach+1] = component break end end end end function vRPin.getEquipedWeapon() return currentWeapon or false end local throwables = { ["WEAPON_MOLOTOV"] = true, ["WEAPON_THERMITE"] = true, ["WEAPON_STICKYBOMB"] = true, ["WEAPON_BZGAS"] = true, ["WEAPON_GRENADE"] = true, } for wep in pairs(throwables) do throwables[GetHashKey(wep)] = true end AddEventHandler("CEventGunShot", function(_, eventEntity) if eventEntity == PlayerPedId() then Wait(500) local arma = GetSelectedPedWeapon(eventEntity) local currentAmmo = GetAmmoInPedWeapon(eventEntity, GetHashKey(currentWeapon)) loadedWeapons[currentWeapon].ammo = currentAmmo if currentWeapon and currentAmmo <= 0 then ExecuteCommand('reload666') end end end) function vRPin.getState() return loadedWeapons[currentWeapon] or {} end function vRPin.equipWeapon(weapon) local ped = PlayerPedId() local selectedWeapon = GetSelectedPedWeapon(ped) if currentWeapon == weapon and not (selectedWeapon == GetHashKey('WEAPON_UNARMED')) and not (selectedWeapon == GetHashKey('parasuta')) then Citizen.Wait(1000) ClearPedTasks(ped) local currentAmmo = GetAmmoInPedWeapon(ped, GetHashKey(currentWeapon)) loadedWeapons[currentWeapon].ammo = currentAmmo RemoveWeaponFromPed(ped, GetHashKey(weapon)) if currentAmmo > 0 then INserver.removeWeapon({currentWeapon}) Citizen.Wait(250) loadedWeapons[currentWeapon].ammo = 0 end currentWeapon = nil else Citizen.Wait(250) ClearPedTasks(ped) RemoveAllPedWeapons(ped, true) SetWeaponsNoAutoswap(true) SetCanPedEquipWeapon(ped, GetHashKey(weapon), true) GiveWeaponToPed(ped, GetHashKey(weapon), 0, false, true) SetCurrentPedWeapon(ped, GetHashKey(weapon), true) SetCurrentPedVehicleWeapon(ped, GetHashKey(weapon)) currentWeapon = weapon if not loadedWeapons[currentWeapon] then loadedWeapons[currentWeapon] = {} end if (loadedWeapons[currentWeapon]?.ammo or 0) > 0 then SetPedAmmo(ped, GetHashKey(weapon), loadedWeapons[currentWeapon].ammo) RefillAmmoInstantly(ped) end if loadedWeapons[currentWeapon]?.attach then giveCompToWeap(currentWeapon, loadedWeapons[currentWeapon].attach) end Citizen.Wait(150) ExecuteCommand('reload666') RefillAmmoInstantly(ped) return true end end AddEventHandler("vrp:onPlayerLeaveVehicle", function() if currentWeapon then local ped = PlayerPedId() local wepKey = GetHashKey(currentWeapon) GiveWeaponToPed(ped, wepKey, 0, false, true) SetCurrentPedWeapon(ped, wepKey, true) SetPedAmmo(ped, wepKey, loadedWeapons[currentWeapon].ammo) RefillAmmoInstantly(ped) end end) local reloadCooldown = 0 RegisterCommand('reload666', function() if reloadCooldown > GetGameTimer() then return end reloadCooldown = GetGameTimer() + 1000 if currentWeapon ~= nil then local ped = PlayerPedId() local weaponHash = GetHashKey(currentWeapon) local magazineSize = GetMaxAmmoInClip(ped, weaponHash) local currentAmmo = GetAmmoInPedWeapon(ped, weaponHash) local toReload = magazineSize - currentAmmo if toReload > 0 then INserver.requestReload({currentWeapon, toReload}, function(ok, ammoAvailable) if ok then if not loadedWeapons[currentWeapon] then loadedWeapons[currentWeapon] = {} end if not loadedWeapons[currentWeapon].ammo then loadedWeapons[currentWeapon].ammo = 0 end local finAmmo = (currentAmmo + ammoAvailable) loadedWeapons[currentWeapon].ammo = finAmmo SetPedAmmo(ped, weaponHash, finAmmo) if IsPedInAnyVehicle(ped) then SetCurrentPedWeapon(ped, weaponHash, true) SetCurrentPedVehicleWeapon(ped, weaponHash) else MakePedReload(ped) end end end) end end end) RegisterKeyMapping('reload666', 'Reload your weapon', 'keyboard', 'R') CreateThread(function() while true do Wait(1) if currentWeapon ~= nil then if vRP.isInComa({}) or vRP.isHandcuffed{} or vRP.isJailed({}) then currentWeapon = nil RemoveAllPedWeapons(PlayerPedId(), true) end if IsPedSwimming(PlayerPedId()) then local currentAmmoo = GetAmmoInPedWeapon(PlayerPedId(), GetHashKey(string.upper(currentWeapon))) INserver.removeWeapon({currentWeapon}) currentWeapon = nil RemoveAllPedWeapons(PlayerPedId(), true) end if throwables[currentWeapon] then local mortiimatii = GetAmmoInPedWeapon(PlayerPedId(), GetHashKey(string.upper(currentWeapon))) if mortiimatii == 0 then INserver.removeThrowable({currentWeapon}) loadedWeapons[currentWeapon] = nil RemoveWeaponFromPed(PlayerPedId(), arma) currentWeapon = nil end end else Wait(1600) end end end)