Skip to content

Commit e168426

Browse files
committed
fire_bullets event fixes
originally from #1350, we kind of forgot about it and OP deleted his repo the fixes consist of renaming the variable find injected in the callback function (stopping error spam as it was expected to be read as find_ammo) and adding some hackery to make the event work when in singleplayer also adding enums for the ammo names but many addon weapons I tested don't seem to work to begin with, maybe they don't call the FireBullets hook in the first place
1 parent 78d1f05 commit e168426

File tree

2 files changed

+53
-10
lines changed

2 files changed

+53
-10
lines changed

lua/pac3/core/client/parts/event.lua

Lines changed: 39 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1589,13 +1589,31 @@ PART.OldEvents = {
15891589

15901590
fire_bullets = {
15911591
operator_type = "string", preferred_operator = "find simple",
1592-
tutorial_explanation = "fire_bullets supposedly checks what types of bullets you're firing",
1592+
tutorial_explanation = "fire_bullets checks what types of bullets you're firing.\nDoesn't seem to work with many addon weapons. The event relies on the FireBullets hook",
15931593
arguments = {{find_ammo = "string"}, {time = "number"}},
1594-
callback = function(self, ent, find, time)
1594+
userdata = {{default = "AR2", enums = function()
1595+
local tbl = {}
1596+
for i=-1,512,1 do
1597+
local name = game.GetAmmoName(i)
1598+
if name then
1599+
tbl[name .. " (ID ="..i..")"] = name
1600+
end
1601+
end
1602+
return tbl
1603+
end}, {default = 0.1}},
1604+
callback = function(self, ent, find_ammo, time)
15951605
time = time or 0.1
15961606

15971607
ent = try_viewmodel(ent)
15981608

1609+
if game.SinglePlayer() then
1610+
if self:GetPlayerOwner() == pac.LocalPlayer then
1611+
if ent.pac_hide_bullets ~= ent:GetNWBool("pac_hide_bullets", false) then
1612+
net.Start("pac_hide_bullets_get") net.WriteBool(ent.pac_hide_bullets) net.SendToServer()
1613+
end
1614+
end
1615+
end
1616+
15991617
local data = ent.pac_fire_bullets
16001618
local b = false
16011619

@@ -3561,16 +3579,27 @@ pac.AddHook("EntityEmitSound", "emit_sound", function(data)
35613579
end
35623580
end)
35633581

3564-
pac.AddHook("EntityFireBullets", "firebullets", function(ent, data)
3565-
if not ent:IsValid() or not ent.pac_has_parts then return end
3566-
ent.pac_fire_bullets = {name = data.AmmoType, time = pac.RealTime, reset = true}
3582+
if game.SinglePlayer() then
3583+
net.Receive("pac_fire_bullets_for_singleplayer", function()
3584+
local ent = net.ReadEntity()
3585+
if not ent:IsValid() or not ent.pac_has_parts then return end
3586+
local ammo_type = net.ReadUInt(8)
3587+
ent.pac_fire_bullets = {name = game.GetAmmoName(ammo_type), time = pac.RealTime, reset = true}
35673588

3568-
pac.CallRecursiveOnAllParts("OnFireBullets")
3589+
pac.CallRecursiveOnAllParts("OnFireBullets")
3590+
end)
3591+
else
3592+
pac.AddHook("EntityFireBullets", "firebullets", function(ent, data)
3593+
if not ent:IsValid() or not ent.pac_has_parts then return end
3594+
ent.pac_fire_bullets = {name = data.AmmoType, time = pac.RealTime, reset = true}
35693595

3570-
if ent.pac_hide_bullets then
3571-
return false
3572-
end
3573-
end)
3596+
pac.CallRecursiveOnAllParts("OnFireBullets")
3597+
3598+
if ent.pac_hide_bullets then
3599+
return false
3600+
end
3601+
end)
3602+
end
35743603

35753604
--for regaining focus on cameras from first person, hacky thing to not loop through localparts every time
35763605
--only if the received command name matches that of a camera's linked command event

lua/pac3/core/server/net_messages.lua

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ util.AddNetworkString("pac.AllowPlayerButtons")
33
util.AddNetworkString("pac.BroadcastPlayerButton")
44
util.AddNetworkString("pac_chat_typing_mirror")
55
util.AddNetworkString("pac_chat_typing_mirror_broadcast")
6+
util.AddNetworkString("pac_fire_bullets_for_singleplayer")
7+
util.AddNetworkString("pac_hide_bullets_get")
68

79
do -- button event
810
net.Receive("pac.AllowPlayerButtons", function(length, client)
@@ -39,3 +41,15 @@ net.Receive("pac_chat_typing_mirror", function(len, ply)
3941
net.WriteEntity(ply)
4042
net.Broadcast()
4143
end)
44+
45+
if game.SinglePlayer() then
46+
hook.Add("EntityFireBullets", "pac_bullet_singleplayer_hack", function(ent, data)
47+
if ent:IsPlayer() then
48+
net.Start("pac_fire_bullets_for_singleplayer") net.WriteEntity(ent) net.WriteUInt(game.GetAmmoID(data.AmmoType),8) net.Broadcast()
49+
end
50+
if ent:GetNWBool("pac_hide_bullets", false) then return false end
51+
end)
52+
net.Receive("pac_hide_bullets_get", function(len, ply)
53+
ply:SetNWBool("pac_hide_bullets",net.ReadBool())
54+
end)
55+
end

0 commit comments

Comments
 (0)