This repository has been archived by the owner on Jul 30, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 22
/
Copy pathclient.lua
74 lines (66 loc) · 2.61 KB
/
client.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
local QBCore = exports['qb-core']:GetCoreObject()
local attached_weapons = {}
local hotbar = {}
local sling = "Back"
local playerLoaded = false
Citizen.CreateThread(function()
while true do
if playerLoaded then
local me = PlayerPedId()
local items = QBCore.Functions.GetPlayerData().items
if items ~= nil then
hotbar = { items[1], items[2], items[3], items[4], items[5], items[41] }
for slot, item in pairs(hotbar) do
if item ~= nil and item.type == "weapon" and Config.compatable_weapon_hashes[item.name] ~= nil then
local wep_model = Config.compatable_weapon_hashes[item.name].model
local wep_hash = Config.compatable_weapon_hashes[item.name].hash
if not attached_weapons[wep_model] and GetSelectedPedWeapon(me) ~= wep_hash then
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)
end
end
end
for key, attached_object in pairs(attached_weapons) do
if GetSelectedPedWeapon(me) == attached_object.hash or not inHotbar(attached_object.hash) then -- equipped or not in weapon wheel
DeleteObject(attached_object.handle)
attached_weapons[key] = nil
end
end
end
end
Wait(500)
end
end)
function inHotbar(hash)
for slot, item in pairs(hotbar) do
if item ~= nil and item.type == "weapon" and Config.compatable_weapon_hashes[item.name] ~= nil then
if hash == GetHashKey(item.name) then
return true
end
end
end
return false
end
function AttachWeapon(attachModel,modelHash,boneNumber,x,y,z,xR,yR,zR)
local bone = GetPedBoneIndex(PlayerPedId(), 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)
}
AttachEntityToEntity(attached_weapons[attachModel].handle, PlayerPedId(), bone, x, y, z, xR, yR, zR, 1, 1, 0, 0, 2, 1)
end
RegisterNetEvent('mg-weapon-sling:client:changeSling')
AddEventHandler('mg-weapon-sling:client:changeSling', function()
if sling == "Back" then
sling = "Front"
else
sling = "Back"
end
end)
RegisterNetEvent('QBCore:Client:OnPlayerLoaded')
AddEventHandler('QBCore:Client:OnPlayerLoaded', function()
playerLoaded = true;
end)