local SETTINGS = { back_bone = 24816, x = 0.15, y = -0.18, z = -0.02, x_rotation = 0.0, y_rotation = 165.0, z_rotation = 0.0, compatable_weapon_hashes = { -- melee: --["prop_golf_iron_01"] = 1141786504, -- positioning still needs work --["w_me_bat"] = -1786099057, -- ["prop_ld_jerrycan_01"] = 883325847, -- assault rifles: ["w_ar_carbinerifle"] = -2084633992, ["w_ar_carbineriflemk2"] = GetHashKey("WEAPON_CARBINERIFLE_Mk2"), ["w_ar_assaultrifle"] = -1074790547, ["w_ar_specialcarbine"] = -1063057011, ["w_ar_bullpuprifle"] = 2132975508, ["w_ar_advancedrifle"] = -1357824103, -- sub machine guns: ["w_sb_microsmg"] = 324215364, ["w_sb_assaultsmg"] = -270015777, ["w_sb_smg"] = 736523883, ["w_sb_smgmk2"] = GetHashKey("WEAPON_SMGMk2"), ["w_sb_gusenberg"] = 1627465347, -- sniper rifles: ["w_sr_sniperrifle"] = 100416529, -- shotguns: ["w_sg_assaultshotgun"] = -494615257, ["w_sg_bullpupshotgun"] = -1654528753, ["w_sg_pumpshotgun"] = 487013001, ["w_sg_pumpshotgunmk2"] = 1432025498, ["w_ar_musket"] = -1466123874, ["w_sg_heavyshotgun"] = GetHashKey("WEAPON_HEAVYSHOTGUN"), -- ["w_sg_sawnoff"] = 2017895192 don't show, maybe too small? -- launchers: ["w_lr_firework"] = 2138347493 } } DisableControlAction(0, 20, true) local attached_weapons = {} local iattached = false Citizen.CreateThread(function() while true do local me = GetPlayerPed(-1) Wait(1) if (IsDisabledControlJustReleased(0 , 20)) then if iattached then SetCurrentPedWeapon(me, isweapon, true) for name, attached_object in pairs(attached_weapons) do DetachEntity(attached_object.handle) DeleteObject(attached_object.handle) end iattached = false else isweapon = GetSelectedPedWeapon(me) for wep_name, wep_hash in pairs(SETTINGS.compatable_weapon_hashes) do if wep_hash == GetSelectedPedWeapon(GetPlayerPed(-1)) then AttachWeapon(wep_name, wep_hash, SETTINGS.back_bone, SETTINGS.x, SETTINGS.y, SETTINGS.z, SETTINGS.x_rotation, SETTINGS.y_rotation, SETTINGS.z_rotation, isMeleeWeapon(wep_name)) SetCurrentPedWeapon(me, GetHashKey("WEAPON_UNARMED"), true) iattached = true end end end end end end) function AttachWeapon(attachModel,modelHash,boneNumber,x,y,z,xR,yR,zR, isMelee) local bone = GetPedBoneIndex(GetPlayerPed(-1), boneNumber) RequestModel(attachModel) while not HasModelLoaded(attachModel) do Wait(100) end attached_weapons[attachModel] = { hash = modelHash, handle = CreateObject(GetHashKey(attachModel), 1.0, 1.0, 1.0, true, true, false) } if isMelee then x = 0.11 y = -0.14 z = 0.0 xR = -75.0 yR = 185.0 zR = 92.0 end -- reposition for melee items if attachModel == "prop_ld_jerrycan_01" then x = x + 0.3 end AttachEntityToEntity(attached_weapons[attachModel].handle, GetPlayerPed(-1), bone, x, y, z, xR, yR, zR, 1, 1, 0, 0, 2, 1) end function isMeleeWeapon(wep_name) if wep_name == "prop_golf_iron_01" then return true elseif wep_name == "w_me_bat" then return true elseif wep_name == "prop_ld_jerrycan_01" then return true else return false end end