From fa345caec4261e83b4837f9844ba49c5f2155b19 Mon Sep 17 00:00:00 2001 From: unknao Date: Thu, 18 Apr 2024 14:37:34 +0300 Subject: [PATCH 1/4] Fix "fire_bullets" event from erroring. --- lua/pac3/core/client/parts/event.lua | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/lua/pac3/core/client/parts/event.lua b/lua/pac3/core/client/parts/event.lua index 79945b4bf..7b719ee01 100644 --- a/lua/pac3/core/client/parts/event.lua +++ b/lua/pac3/core/client/parts/event.lua @@ -1462,8 +1462,8 @@ PART.OldEvents = { operator_type = "string", preferred_operator = "find simple", tutorial_explanation = "fire_bullets supposedly checks what types of bullets you're firing", arguments = {{find_ammo = "string"}, {time = "number"}}, - callback = function(self, ent, find, time) - time = time or 0.1 + callback = function(self, ent, find_ammo, time) + local time = time or 0.1 ent = try_viewmodel(ent) @@ -3382,10 +3382,6 @@ pac.AddHook("EntityFireBullets", "firebullets", function(ent, data) ent.pac_fire_bullets = {name = data.AmmoType, time = pac.RealTime, reset = true} pac.CallRecursiveOnAllParts("OnFireBullets") - - if ent.pac_hide_bullets then - return false - end end) --for regaining focus on cameras from first person, hacky thing to not loop through localparts every time From 28b7b5d2dfe127ff3d4f6cd7c6758fcaae92d399 Mon Sep 17 00:00:00 2001 From: unknao Date: Fri, 19 Apr 2024 11:32:59 +0300 Subject: [PATCH 2/4] remove the local --- lua/pac3/core/client/parts/event.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lua/pac3/core/client/parts/event.lua b/lua/pac3/core/client/parts/event.lua index 7b719ee01..eb71c1bc2 100644 --- a/lua/pac3/core/client/parts/event.lua +++ b/lua/pac3/core/client/parts/event.lua @@ -1463,7 +1463,7 @@ PART.OldEvents = { tutorial_explanation = "fire_bullets supposedly checks what types of bullets you're firing", arguments = {{find_ammo = "string"}, {time = "number"}}, callback = function(self, ent, find_ammo, time) - local time = time or 0.1 + time = time or 0.1 ent = try_viewmodel(ent) From 7657713c2ff12ba88c2410e17d40626d90000610 Mon Sep 17 00:00:00 2001 From: pingu7867 Date: Tue, 4 Jun 2024 22:11:46 -0400 Subject: [PATCH 3/4] undelete the hide bullets return --- lua/pac3/core/client/parts/event.lua | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lua/pac3/core/client/parts/event.lua b/lua/pac3/core/client/parts/event.lua index eb71c1bc2..878e04129 100644 --- a/lua/pac3/core/client/parts/event.lua +++ b/lua/pac3/core/client/parts/event.lua @@ -3380,7 +3380,9 @@ end) pac.AddHook("EntityFireBullets", "firebullets", function(ent, data) if not ent:IsValid() or not ent.pac_has_parts then return end ent.pac_fire_bullets = {name = data.AmmoType, time = pac.RealTime, reset = true} - + if ent.pac_hide_bullets then + return false + end pac.CallRecursiveOnAllParts("OnFireBullets") end) From 0f9b73f22fc1c246c6d795ac83b01d316b5cb212 Mon Sep 17 00:00:00 2001 From: pingu7867 Date: Sun, 28 Jul 2024 20:40:15 -0400 Subject: [PATCH 4/4] fire bullets singleplayer hack fix I found that the hook is ineffective on singleplayer, so some networking was needed and add enum builder for bullet types, as well as some defaults --- lua/pac3/core/client/parts/event.lua | 37 +++++++++++++++++++++------ lua/pac3/core/server/net_messages.lua | 14 ++++++++++ 2 files changed, 43 insertions(+), 8 deletions(-) diff --git a/lua/pac3/core/client/parts/event.lua b/lua/pac3/core/client/parts/event.lua index 878e04129..949520906 100644 --- a/lua/pac3/core/client/parts/event.lua +++ b/lua/pac3/core/client/parts/event.lua @@ -1462,10 +1462,21 @@ PART.OldEvents = { operator_type = "string", preferred_operator = "find simple", tutorial_explanation = "fire_bullets supposedly checks what types of bullets you're firing", arguments = {{find_ammo = "string"}, {time = "number"}}, + userdata = {{default = "AR2", enums = function() + local tbl = {} + for i=-1,512,1 do + local name = game.GetAmmoName(i) + if name then + tbl[name .. " (ID ="..i..")"] = name + end + end + return tbl + end}, {default = 0.1}}, callback = function(self, ent, find_ammo, time) time = time or 0.1 ent = try_viewmodel(ent) + if game.SinglePlayer() and ent.pac_hide_bullets ~= ent:GetNWBool("pac_hide_bullets", false) then net.Start("pac_hide_bullets_get") net.WriteBool(ent.pac_hide_bullets) net.SendToServer() end local data = ent.pac_fire_bullets local b = false @@ -3377,14 +3388,24 @@ pac.AddHook("EntityEmitSound", "emit_sound", function(data) end end) -pac.AddHook("EntityFireBullets", "firebullets", function(ent, data) - if not ent:IsValid() or not ent.pac_has_parts then return end - ent.pac_fire_bullets = {name = data.AmmoType, time = pac.RealTime, reset = true} - if ent.pac_hide_bullets then - return false - end - pac.CallRecursiveOnAllParts("OnFireBullets") -end) +if game.SinglePlayer() then + net.Receive("pac_fire_bullets_for_singleplayer", function() + local ent = net.ReadEntity() + if not ent:IsValid() or not ent.pac_has_parts then return end + local ammo_type = net.ReadUInt(8) + ent.pac_fire_bullets = {name = game.GetAmmoName(ammo_type), time = pac.RealTime, reset = true} + pac.CallRecursiveOnAllParts("OnFireBullets") + end) +else + pac.AddHook("EntityFireBullets", "firebullets", function(ent, data) + if not ent:IsValid() or not ent.pac_has_parts then return end + ent.pac_fire_bullets = {name = data.AmmoType, time = pac.RealTime, reset = true} + pac.CallRecursiveOnAllParts("OnFireBullets") + if ent.pac_hide_bullets then + return false + end + end) +end --for regaining focus on cameras from first person, hacky thing to not loop through localparts every time --only if the received command name matches that of a camera's linked command event diff --git a/lua/pac3/core/server/net_messages.lua b/lua/pac3/core/server/net_messages.lua index 2f37bc6b4..3a22e417f 100644 --- a/lua/pac3/core/server/net_messages.lua +++ b/lua/pac3/core/server/net_messages.lua @@ -3,6 +3,8 @@ util.AddNetworkString("pac.AllowPlayerButtons") util.AddNetworkString("pac.BroadcastPlayerButton") util.AddNetworkString("pac_chat_typing_mirror") util.AddNetworkString("pac_chat_typing_mirror_broadcast") +util.AddNetworkString("pac_fire_bullets_for_singleplayer") +util.AddNetworkString("pac_hide_bullets_get") do -- button event net.Receive("pac.AllowPlayerButtons", function(length, client) @@ -39,3 +41,15 @@ net.Receive("pac_chat_typing_mirror", function(len, ply) net.WriteEntity(ply) net.Broadcast() end) + +if game.SinglePlayer() then + hook.Add("EntityFireBullets", "pac_bullet_singleplayer_hack", function(ent, data) + if ent:IsPlayer() then + net.Start("pac_fire_bullets_for_singleplayer") net.WriteEntity(ent) net.WriteUInt(game.GetAmmoID(data.AmmoType),8) net.Broadcast() + end + if ent:GetNWBool("pac_hide_bullets", false) then return false end + end) + net.Receive("pac_hide_bullets_get", function(len, ply) + ply:SetNWBool("pac_hide_bullets",net.ReadBool()) + end) +end \ No newline at end of file