diff --git a/resources/[inventory]/cs_shops/config/config.lua b/resources/[inventory]/cs_shops/config/config.lua index 01552876c..6ed4a4ac8 100644 --- a/resources/[inventory]/cs_shops/config/config.lua +++ b/resources/[inventory]/cs_shops/config/config.lua @@ -658,7 +658,7 @@ CodeStudio.Products = { itemInfo = "", }, ['drill'] = { - itemName = "Flex", + itemName = "Schlagbohrmaschine", itemStock = 150, itemPrice = 800, itemInfo = "", @@ -669,7 +669,7 @@ CodeStudio.Products = { itemPrice = 40, itemInfo = "", }, - ['knife'] = { + ['weapon_knife'] = { itemName = "Messer", itemStock = 150, itemPrice = 600, diff --git a/resources/[jobs]/[weapons]/force-sling/client/utils.lua b/resources/[jobs]/[weapons]/force-sling/client/utils.lua index 85eafdc73..ffd93192a 100644 --- a/resources/[jobs]/[weapons]/force-sling/client/utils.lua +++ b/resources/[jobs]/[weapons]/force-sling/client/utils.lua @@ -2,66 +2,89 @@ Utils = {} function Utils:CreateAndAttachWeapon(weaponName, weaponVal, coords, playerPed) if Sling.currentAttachedAmount >= Config.MaxWeaponsAttached then - Sling:Debug("warn", "Max weapons attached reached") + Debug("warn", "Max weapons attached reached") return false end if not weaponVal or not weaponVal.name then - Sling:Debug("error", "Invalid weapon data") + Debug("error", "Invalid weapon data") return false end - local weaponObject = CreateWeaponObject(weaponVal.name, 0, coords.coords.x, coords.coords.y, coords.coords.z, true, 1.0, - 0) + -- Initialize the cached attachments for this weapon if it doesn't exist + if not Sling.cachedAttachments[weaponName] then + Sling.cachedAttachments[weaponName] = {} + end + + local weaponObject = CreateWeaponObject(weaponVal.name, 0, coords.coords.x, coords.coords.y, coords.coords.z, true, 1.0, 0) if not weaponObject then - Sling:Debug("error", "Failed to create weapon object") + Debug("error", "Failed to create weapon object") return false end if NetworkGetEntityIsNetworked(weaponObject) then NetworkUnregisterNetworkedEntity(weaponObject) end + SetEntityCollision(weaponObject, false, false) + if Config.UseWeaponAttachments then weaponVal.attachments = Inventory:GetWeaponAttachment(weaponName) end - for _, component in pairs(weaponVal.attachments) do + + for _, component in pairs(weaponVal.attachments or {}) do GiveWeaponComponentToWeaponObject(weaponObject, component) end + lib.requestModel(weaponVal.model) - local placeholder = CreateObjectNoOffset(weaponVal.model, coords.coords.x, coords.coords.y, coords.coords.z, true, - true, false) + + local placeholder = CreateObjectNoOffset(weaponVal.model, coords.coords.x, coords.coords.y, coords.coords.z, true, true, false) SetEntityCollision(placeholder, false, false) SetEntityAlpha(placeholder, 0, false) - AttachEntityToEntity(placeholder, playerPed, GetPedBoneIndex(playerPed, (coords.boneId or DEFAULT_BONE)), - coords.coords.x, coords.coords.y, coords.coords.z, coords.rot.x, coords.rot.y, coords.rot.z, true, true, false, - true, 2, true) - AttachEntityToEntity(weaponObject, placeholder, GetEntityBoneIndexByName(placeholder, "gun_root"), 0.0, 0.0, 0.0, 0.0, - 0.0, 0.0, true, true, false, true, 2, true) + + local boneIndex = GetPedBoneIndex(playerPed, (coords.boneId or DEFAULT_BONE)) + + AttachEntityToEntity(placeholder, playerPed, boneIndex, + coords.coords.x, coords.coords.y, coords.coords.z, + coords.rot.x, coords.rot.y, coords.rot.z, + true, true, false, true, 2, true) + + AttachEntityToEntity(weaponObject, placeholder, GetEntityBoneIndexByName(placeholder, "gun_root"), + 0.0, 0.0, 0.0, + 0.0, 0.0, 0.0, + true, true, false, true, 2, true) + Sling.cachedAttachments[weaponName].obj = weaponObject Sling.cachedAttachments[weaponName].placeholder = placeholder Sling.currentAttachedAmount = Sling.currentAttachedAmount + 1 + SetModelAsNoLongerNeeded(weaponVal.model) - if NetworkGetEntityOwner(playerPed) == PlayerId() then - Sling:SyncWeaponAttachment(weaponName, weaponVal, coords, 'attach') - end return true end function Utils:DeleteWeapon(weaponName) - local attachment = Sling.cachedAttachments[weaponName] - if NetworkGetEntityIsNetworked(attachment.obj) then - NetworkUnregisterNetworkedEntity(attachment.obj) - end - DeleteObject(attachment.obj) - if IsEntityAttachedToAnyPed(attachment.placeholder) then - DetachEntity(attachment.placeholder, true, false) - end - DeleteObject(attachment.placeholder) - Sling.currentAttachedAmount = Sling.currentAttachedAmount - 1 + if not Sling.cachedAttachments[weaponName] then return end - if NetworkGetEntityOwner(cache.ped) == PlayerId() then - Sling:SyncWeaponAttachment(weaponName, nil, nil, 'detach') + local attachment = Sling.cachedAttachments[weaponName] + + if attachment.obj and DoesEntityExist(attachment.obj) then + if NetworkGetEntityIsNetworked(attachment.obj) then + NetworkUnregisterNetworkedEntity(attachment.obj) + end + DeleteObject(attachment.obj) end + + if attachment.placeholder then + if IsEntityAttachedToAnyPed(attachment.placeholder) then + DetachEntity(attachment.placeholder, true, false) + end + if DoesEntityExist(attachment.placeholder) then + DeleteObject(attachment.placeholder) + end + end + + Sling.cachedAttachments[weaponName] = nil + Sling.currentAttachedAmount = math.max(0, Sling.currentAttachedAmount - 1) end +