├── fxmanifest.lua ├── server.lua ├── README.md ├── config.lua └── client.lua /fxmanifest.lua: -------------------------------------------------------------------------------- 1 | fx_version 'cerulean' 2 | game 'gta5' 3 | 4 | description 'QB-Weapons' 5 | version '1.0.0' 6 | 7 | shared_scripts { 8 | 'config.lua' 9 | } 10 | 11 | server_script 'server.lua' 12 | client_script 'client.lua' 13 | -------------------------------------------------------------------------------- /server.lua: -------------------------------------------------------------------------------- 1 | local QBCore = exports['qb-core']:GetCoreObject() 2 | 3 | QBCore.Commands.Add("sling", "Change weapon sling position", {}, false, function(source, args) 4 | TriggerClientEvent("mg-weapon-sling:client:changeSling", source) 5 | end) 6 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # fjh-sling 2 | Simple weapons slings for the qbcore framework. Will put any weapon that is in the inventory hotbar on the players body. 3 | 4 | [Support my Projects](https://ko-fi.com/fjhstudios) 5 | 6 | [Discord](https://discord.gg/CN8chwsK7E) 7 | 8 | [Preview](https://i.imgur.com/XeFO0SH.mp4) 9 | 10 | ### Installation 11 | 12 | Add ``start fjh-sling`` or ``ensure fjh-sling`` to your server.cfg or mods.cfg if you use one. 13 | 14 | ### Config file 15 | If you want to add other weapons add them to the `config.lua` file in the same way weapons are added there now. The first value needs the be the item name from qbcore shared.lua otherwise it cannot find the weapon. 16 | 17 | ### Commands 18 | `/sling` - Toggle if the sling should be in the front or back of the body. For the weapon to switch just take it out and put it away again. 19 | 20 | ### Idle usage 21 | ![Resmon](https://i.imgur.com/D3mqhNe.png) 22 | -------------------------------------------------------------------------------- /config.lua: -------------------------------------------------------------------------------- 1 | Config = { 2 | Positions = { 3 | ["Back"] = { 4 | bone = 24816, 5 | x = 0.275, 6 | y = -0.15, 7 | z = -0.02, 8 | x_rotation = 0.0, 9 | y_rotation = 165.0, 10 | z_rotation = 0.0 11 | }, 12 | ["Front"] = { 13 | bone = 10706, 14 | x = 0.0, 15 | y = 0.19, 16 | z = -0.25, 17 | x_rotation = 0.0, 18 | y_rotation = 75.0, 19 | z_rotation = 180.0 20 | } 21 | }, 22 | 23 | compatable_weapon_hashes = { 24 | -- assault rifles: 25 | ["weapon_carbinerifle"] = { model = "w_ar_carbinerifle", hash = -2084633992}, 26 | ["weapon_carbinerifle_mk2"] = { model = "w_ar_carbineriflemk2", hash = GetHashKey("WEAPON_CARBINERIFLE_MK2")}, 27 | ["weapon_assaultrifle"] = { model = "w_ar_assaultrifle", hash = -1074790547}, 28 | ["weapon_specialcarbine"] = { model = "w_ar_specialcarbine", hash = -1063057011}, 29 | ["weapon_bullpuprifle"] = { model = "w_ar_bullpuprifle", hash = 2132975508}, 30 | ["weapon_advancedrifle"] = { model = "w_ar_advancedrifle", hash = -1357824103}, 31 | -- sub machine guns: 32 | ["weapon_microsmg"] = { model = "w_sb_microsmg", hash = 324215364}, 33 | ["weapon_assaultsmg"] = { model = "w_sb_assaultsmg", hash = -270015777}, 34 | ["weapon_smg"] = { model = "w_sb_smg", hash = 736523883}, 35 | ["weapon_smgmk2"] = { model = "w_sb_smgmk2", hash = GetHashKey("WEAPON_SMG_MK2")}, 36 | ["weapon_gusenberg"] = { model = "w_sb_gusenberg", hash = 1627465347}, 37 | -- sniper rifles: 38 | ["weapon_sniperrifle"] = { model = "w_sr_sniperrifle", hash = 100416529}, 39 | -- shotguns: 40 | ["weapon_assaultshotgun"] = { model = "w_sg_assaultshotgun", hash = -494615257}, 41 | ["weapon_bullpupshotgun"] = { model = "w_sg_bullpupshotgun", hash = -1654528753}, 42 | ["weapon_pumpshotgun"] = { model = "w_sg_pumpshotgun", hash = 487013001}, 43 | ["weapon_musket"] = { model = "w_ar_musket", hash = -1466123874}, 44 | ["weapon_heavyshotgun"] = { model = "w_sg_heavyshotgun", hash = GetHashKey("WEAPON_HEAVYSHOTGUN")}, 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /client.lua: -------------------------------------------------------------------------------- 1 | local QBCore = exports['qb-core']:GetCoreObject() 2 | local attached_weapons = {} 3 | local hotbar = {} 4 | local sling = "Back" 5 | local playerLoaded = false 6 | 7 | Citizen.CreateThread(function() 8 | while true do 9 | if playerLoaded then 10 | local me = PlayerPedId() 11 | local items = QBCore.Functions.GetPlayerData().items 12 | if items ~= nil then 13 | hotbar = { items[1], items[2], items[3], items[4], items[5], items[41] } 14 | for slot, item in pairs(hotbar) do 15 | if item ~= nil and item.type == "weapon" and Config.compatable_weapon_hashes[item.name] ~= nil then 16 | local wep_model = Config.compatable_weapon_hashes[item.name].model 17 | local wep_hash = Config.compatable_weapon_hashes[item.name].hash 18 | 19 | if not attached_weapons[wep_model] and GetSelectedPedWeapon(me) ~= wep_hash then 20 | AttachWeapon(wep_model, wep_hash, Config.Positions[sling].bone, Config.Positions[sling].x, Config.Positions[sling].y, Config.Positions[sling].z, Config.Positions[sling].x_rotation, Config.Positions[sling].y_rotation, Config.Positions[sling].z_rotation) 21 | end 22 | end 23 | end 24 | for key, attached_object in pairs(attached_weapons) do 25 | if GetSelectedPedWeapon(me) == attached_object.hash or not inHotbar(attached_object.hash) then -- equipped or not in weapon wheel 26 | DeleteObject(attached_object.handle) 27 | attached_weapons[key] = nil 28 | end 29 | end 30 | end 31 | end 32 | Wait(500) 33 | end 34 | end) 35 | 36 | function inHotbar(hash) 37 | for slot, item in pairs(hotbar) do 38 | if item ~= nil and item.type == "weapon" and Config.compatable_weapon_hashes[item.name] ~= nil then 39 | if hash == GetHashKey(item.name) then 40 | return true 41 | end 42 | end 43 | end 44 | return false 45 | end 46 | 47 | function AttachWeapon(attachModel,modelHash,boneNumber,x,y,z,xR,yR,zR) 48 | local bone = GetPedBoneIndex(PlayerPedId(), boneNumber) 49 | RequestModel(attachModel) 50 | while not HasModelLoaded(attachModel) do 51 | Wait(100) 52 | end 53 | 54 | attached_weapons[attachModel] = { 55 | hash = modelHash, 56 | handle = CreateObject(GetHashKey(attachModel), 1.0, 1.0, 1.0, true, true, false) 57 | } 58 | 59 | AttachEntityToEntity(attached_weapons[attachModel].handle, PlayerPedId(), bone, x, y, z, xR, yR, zR, 1, 1, 0, 0, 2, 1) 60 | end 61 | 62 | RegisterNetEvent('mg-weapon-sling:client:changeSling') 63 | AddEventHandler('mg-weapon-sling:client:changeSling', function() 64 | if sling == "Back" then 65 | sling = "Front" 66 | else 67 | sling = "Back" 68 | end 69 | end) 70 | 71 | RegisterNetEvent('QBCore:Client:OnPlayerLoaded') 72 | AddEventHandler('QBCore:Client:OnPlayerLoaded', function() 73 | playerLoaded = true; 74 | end) 75 | --------------------------------------------------------------------------------