From 34a73c9390726861b539c268228604095032dfbb Mon Sep 17 00:00:00 2001 From: Thomas Date: Sun, 7 Jul 2024 19:28:26 +0200 Subject: [PATCH 1/6] Update client.lua --- modules/weapon/client.lua | 47 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 46 insertions(+), 1 deletion(-) diff --git a/modules/weapon/client.lua b/modules/weapon/client.lua index 2234840..0321f4b 100644 --- a/modules/weapon/client.lua +++ b/modules/weapon/client.lua @@ -24,31 +24,76 @@ end function ThrowCurrentWeapon() if throwingWeapon then return end + local ped = PlayerPedId() local equipped, weaponHash = GetCurrentPedWeapon(ped, 1) local weapon = GetWeaponString(weaponHash) if not equipped or not weapon then return end + + local ammoCount = GetAmmoInPedWeapon(ped, weaponHash) throwingWeapon = true + CreateThread(function() PlayAnim(ped, "melee@thrown@streamed_core", "plyr_takedown_front", -8.0, 8.0, -1, 49) Wait(600) ClearPedTasks(ped) end) + Wait(550) + local coords = GetOffsetFromEntityInWorldCoords(ped, 0.0, 0.0, 1.0) local prop = GetWeaponObjectFromPed(ped, true) local model = GetEntityModel(prop) + RemoveWeaponFromPed(ped, weaponHash) SetCurrentPedWeapon(ped, `WEAPON_UNARMED`, true) DeleteEntity(prop) + prop = CreateProp(model, coords.x, coords.y, coords.z, true, false, true) SetEntityCoords(prop, coords.x, coords.y, coords.z) SetEntityHeading(prop, GetEntityHeading(ped) + 90.0) PerformPhysics(prop) - TriggerServerEvent("pickle_weaponthrowing:throwWeapon", {weapon = weapon, net_id = ObjToNet(prop)}) + + -- Add interaction to the thrown weapon + exports.interact:AddEntityInteraction({ + netId = ObjToNet(prop), + id = 'throwWeaponInteraction_' .. ObjToNet(prop), -- Unique ID for removing interactions + distance = 4.0, -- Optional interaction distance + interactDst = 3.0, -- Optional interaction trigger distance + ignoreLos = true, -- Optional ignore line of sight + options = { + { + label = 'Plukk opp', + action = function(entity, coords, args) + local ped = PlayerPedId() + if not IsPlayerDead(ped) and not IsPedInAnyVehicle(ped, true) then + for k, v in pairs(ThrownWeapons) do + if NetworkDoesNetworkIdExist(v.net_id) then + local entity = NetToObj(v.net_id) + ClearPedTasksImmediately(ped) + FreezeEntityPosition(ped, true) + PlayAnim(ped, "pickup_object", "pickup_low", -8.0, 8.0, -1, 49, 1.0) + Wait(800) + TriggerServerEvent("pickle_weaponthrowing:pickupWeapon", k) + Wait(800) + ClearPedTasks(ped) + FreezeEntityPosition(ped, false) + end + end + end + end, + }, + }, + }) + + TriggerServerEvent("pickle_weaponthrowing:throwWeapon", {weapon = weapon, net_id = ObjToNet(prop), ammo = ammoCount}) -- Include ammo count throwingWeapon = nil end +RegisterNetEvent("pickle_weaponthrowing:removeInteraction", function(netId) + exports.interact:RemoveEntityInteraction('throwWeaponInteraction_' .. netId) +end) + function OnPlayerDeath() if not Config.DeathDropsWeapon then return end local ped = PlayerPedId() From dccc73f6261d1160fe5a1d786c046925e1243441 Mon Sep 17 00:00:00 2001 From: Thomas Date: Sun, 7 Jul 2024 19:28:47 +0200 Subject: [PATCH 2/6] Update server.lua --- modules/weapon/server.lua | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/modules/weapon/server.lua b/modules/weapon/server.lua index 401d04f..89f09c4 100644 --- a/modules/weapon/server.lua +++ b/modules/weapon/server.lua @@ -17,7 +17,12 @@ RegisterNetEvent("pickle_weaponthrowing:pickupWeapon", function(weaponID) local source = source if not ThrownWeapons[weaponID] then return end local entity = NetworkGetEntityFromNetworkId(ThrownWeapons[weaponID].net_id) + + -- Trigger client event to remove the interaction + TriggerClientEvent("pickle_weaponthrowing:removeInteraction", -1, ThrownWeapons[weaponID].net_id) + DeleteEntity(entity) + -- Ensure AddWeapon now accounts for the ammo count AddWeapon(source, ThrownWeapons[weaponID]) ThrownWeapons[weaponID] = nil TriggerClientEvent("pickle_weaponthrowing:setWeaponData", -1, weaponID, nil) @@ -28,4 +33,4 @@ AddEventHandler("onResourceStop", function(name) for k,v in pairs(ThrownWeapons) do DeleteEntity(NetworkGetEntityFromNetworkId(v.net_id)) end -end) \ No newline at end of file +end) From 3e646c476952d003d8384b92f4fc9240391eccc5 Mon Sep 17 00:00:00 2001 From: Thomas Date: Sun, 7 Jul 2024 19:30:28 +0200 Subject: [PATCH 3/6] Update config.lua --- config.lua | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/config.lua b/config.lua index c37c2ae..8d74c7e 100644 --- a/config.lua +++ b/config.lua @@ -8,6 +8,8 @@ Config.DeathDropsWeapon = true -- Drops your current weapon upon death. Config.ThrowKeybind = "e" +Config.UseInteract = true + Config.Weapons = { -- Any weapon in this list is throwable. "WEAPON_DAGGER", "WEAPON_BAT", @@ -89,4 +91,4 @@ Config.Weapons = { -- Any weapon in this list is throwable. "WEAPON_HOMINGLAUNCHER", "WEAPON_COMPACTLAUNCHER", "WEAPON_RAYMINIGUN", -} \ No newline at end of file +} From 62fe290b5db42d0d733a9ec87f850550e2d0d744 Mon Sep 17 00:00:00 2001 From: Thomas Date: Sun, 7 Jul 2024 19:32:20 +0200 Subject: [PATCH 4/6] Update client.lua --- modules/weapon/client.lua | 112 ++++++++++++++++++++------------------ 1 file changed, 58 insertions(+), 54 deletions(-) diff --git a/modules/weapon/client.lua b/modules/weapon/client.lua index 0321f4b..6b81fa2 100644 --- a/modules/weapon/client.lua +++ b/modules/weapon/client.lua @@ -53,38 +53,40 @@ function ThrowCurrentWeapon() SetEntityCoords(prop, coords.x, coords.y, coords.z) SetEntityHeading(prop, GetEntityHeading(ped) + 90.0) PerformPhysics(prop) - + + if Config.interact then -- Add interaction to the thrown weapon - exports.interact:AddEntityInteraction({ - netId = ObjToNet(prop), - id = 'throwWeaponInteraction_' .. ObjToNet(prop), -- Unique ID for removing interactions - distance = 4.0, -- Optional interaction distance - interactDst = 3.0, -- Optional interaction trigger distance - ignoreLos = true, -- Optional ignore line of sight - options = { - { - label = 'Plukk opp', - action = function(entity, coords, args) - local ped = PlayerPedId() - if not IsPlayerDead(ped) and not IsPedInAnyVehicle(ped, true) then - for k, v in pairs(ThrownWeapons) do - if NetworkDoesNetworkIdExist(v.net_id) then - local entity = NetToObj(v.net_id) - ClearPedTasksImmediately(ped) - FreezeEntityPosition(ped, true) - PlayAnim(ped, "pickup_object", "pickup_low", -8.0, 8.0, -1, 49, 1.0) - Wait(800) - TriggerServerEvent("pickle_weaponthrowing:pickupWeapon", k) - Wait(800) - ClearPedTasks(ped) - FreezeEntityPosition(ped, false) + exports.interact:AddEntityInteraction({ + netId = ObjToNet(prop), + id = 'throwWeaponInteraction_' .. ObjToNet(prop), -- Unique ID for removing interactions + distance = 4.0, -- Optional interaction distance + interactDst = 3.0, -- Optional interaction trigger distance + ignoreLos = true, -- Optional ignore line of sight + options = { + { + label = 'Plukk opp', + action = function(entity, coords, args) + local ped = PlayerPedId() + if not IsPlayerDead(ped) and not IsPedInAnyVehicle(ped, true) then + for k, v in pairs(ThrownWeapons) do + if NetworkDoesNetworkIdExist(v.net_id) then + local entity = NetToObj(v.net_id) + ClearPedTasksImmediately(ped) + FreezeEntityPosition(ped, true) + PlayAnim(ped, "pickup_object", "pickup_low", -8.0, 8.0, -1, 49, 1.0) + Wait(800) + TriggerServerEvent("pickle_weaponthrowing:pickupWeapon", k) + Wait(800) + ClearPedTasks(ped) + FreezeEntityPosition(ped, false) + end end end - end - end, + end, + }, }, - }, - }) + }) + end TriggerServerEvent("pickle_weaponthrowing:throwWeapon", {weapon = weapon, net_id = ObjToNet(prop), ammo = ammoCount}) -- Include ammo count throwingWeapon = nil @@ -133,32 +135,34 @@ AddEventHandler('gameEventTriggered', function(event, args) OnPlayerDeath() end) -CreateThread(function() - while true do - local wait = 1000 - local ped = PlayerPedId() - if not IsPlayerDead(ped) and not IsPedInAnyVehicle(ped, true) then - for k,v in pairs(ThrownWeapons) do - if NetworkDoesNetworkIdExist(v.net_id) then - local entity = NetToObj(v.net_id) - local coords = GetEntityCoords(entity) - local dist = #(GetEntityCoords(ped) - coords) - if dist < 5.0 then - wait = 0 - if dist < 1.25 and not ShowInteractText(_L("pickup_weapon")) and IsControlJustPressed(1, 51) then - ClearPedTasksImmediately(ped) - FreezeEntityPosition(ped, true) - PlayAnim(ped, "pickup_object", "pickup_low", -8.0, 8.0, -1, 49, 1.0) - Wait(800) - TriggerServerEvent("pickle_weaponthrowing:pickupWeapon", k) - Wait(800) - ClearPedTasks(ped) - FreezeEntityPosition(ped, false) +if not Config.interact then + CreateThread(function() + while true do + local wait = 1000 + local ped = PlayerPedId() + if not IsPlayerDead(ped) and not IsPedInAnyVehicle(ped, true) then + for k,v in pairs(ThrownWeapons) do + if NetworkDoesNetworkIdExist(v.net_id) then + local entity = NetToObj(v.net_id) + local coords = GetEntityCoords(entity) + local dist = #(GetEntityCoords(ped) - coords) + if dist < 5.0 then + wait = 0 + if dist < 1.25 and not ShowInteractText(_L("pickup_weapon")) and IsControlJustPressed(1, 51) then + ClearPedTasksImmediately(ped) + FreezeEntityPosition(ped, true) + PlayAnim(ped, "pickup_object", "pickup_low", -8.0, 8.0, -1, 49, 1.0) + Wait(800) + TriggerServerEvent("pickle_weaponthrowing:pickupWeapon", k) + Wait(800) + ClearPedTasks(ped) + FreezeEntityPosition(ped, false) + end end end - end - end + end + end + Wait(wait) end - Wait(wait) - end -end) + end) +end From b10b73f53c6f76c97fd9c75de218bd7d9157bcf6 Mon Sep 17 00:00:00 2001 From: Thomas Date: Sun, 7 Jul 2024 19:32:31 +0200 Subject: [PATCH 5/6] Update config.lua --- config.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config.lua b/config.lua index 8d74c7e..0f22a44 100644 --- a/config.lua +++ b/config.lua @@ -8,7 +8,7 @@ Config.DeathDropsWeapon = true -- Drops your current weapon upon death. Config.ThrowKeybind = "e" -Config.UseInteract = true +Config.interact = true Config.Weapons = { -- Any weapon in this list is throwable. "WEAPON_DAGGER", From 032cb2472a92182edde1547a75f4c27f46399ed9 Mon Sep 17 00:00:00 2001 From: Thomas Date: Sun, 7 Jul 2024 19:35:38 +0200 Subject: [PATCH 6/6] Update server.lua --- modules/weapon/server.lua | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/modules/weapon/server.lua b/modules/weapon/server.lua index 89f09c4..19ea5c3 100644 --- a/modules/weapon/server.lua +++ b/modules/weapon/server.lua @@ -17,9 +17,11 @@ RegisterNetEvent("pickle_weaponthrowing:pickupWeapon", function(weaponID) local source = source if not ThrownWeapons[weaponID] then return end local entity = NetworkGetEntityFromNetworkId(ThrownWeapons[weaponID].net_id) - + + if Config.interact then -- Trigger client event to remove the interaction - TriggerClientEvent("pickle_weaponthrowing:removeInteraction", -1, ThrownWeapons[weaponID].net_id) + TriggerClientEvent("pickle_weaponthrowing:removeInteraction", -1, ThrownWeapons[weaponID].net_id) + end DeleteEntity(entity) -- Ensure AddWeapon now accounts for the ammo count