Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Grenades! #68

Open
wants to merge 44 commits into
base: main
Choose a base branch
from
Open

Grenades! #68

wants to merge 44 commits into from

Conversation

legokidlogan
Copy link
Member

Makes some improvements/fixes to the throwable and grenade bases, and adds some new grenades: discombob, impact discombob, cluster, super cluster, curse, and anti-gravity.

Requires CFC-Servers/cfc_ulx_commands#159 to be merged.

@legokidlogan legokidlogan added the enhancement New feature or request label Sep 26, 2024
@legokidlogan legokidlogan self-assigned this Sep 26, 2024
@legokidlogan legokidlogan marked this pull request as draft September 27, 2024 14:02
@legokidlogan legokidlogan marked this pull request as ready for review September 28, 2024 05:30
if SERVER then
function SWEP:CreateEntity()
if not CFCUlxCurse then
self:GetOwner():ChatPrint( "This server doesn't have the CFC ulx curse addon!" )
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the curse grenade logic handled directly in cfc_ulx_commands?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, the grenade handles its own logic. However, cfc_ulx_commands is where all the curses are. Can't have a curse grenade without the curses.

Copy link
Member

@brandonsturgeon brandonsturgeon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks okay. A few comments and improvements.

I think the Beep functionality should be moved to a method on the base grenade class, also.

Comment on lines +4 to +14
--[[
- util.BlastDamageInfo(), with damage callbacks.
- Do NOT call any damage-inflicting functions in the callbacks, it will cause feedback loops and/or misattribute the callback.
- If you need to inflict damage from the callbacks, use a timer, entity with a fuse, etc.

etdCallback: (optional) (function)
- A callback function that listens during EntityTakeDamage with HOOK_LOW.
- Whatever is returned by the function will be returned in the hook, if you need to block the normal damage event.
petdCallback: (optional) (function)
- A callback function that listens during PostEntityTakeDamage.
--]]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
--[[
- util.BlastDamageInfo(), with damage callbacks.
- Do NOT call any damage-inflicting functions in the callbacks, it will cause feedback loops and/or misattribute the callback.
- If you need to inflict damage from the callbacks, use a timer, entity with a fuse, etc.
etdCallback: (optional) (function)
- A callback function that listens during EntityTakeDamage with HOOK_LOW.
- Whatever is returned by the function will be returned in the hook, if you need to block the normal damage event.
petdCallback: (optional) (function)
- A callback function that listens during PostEntityTakeDamage.
--]]
--- Applies blast damage and optionally hooks into damage events.
---
--- @param dmgInfo CTakeDamageInfo The damage info object containing damage details.
--- @param pos Vector The position where the blast damage originates.
--- @param radius number The radius of the blast damage.
--- @param etdCallback function? A callback function for the `EntityTakeDamage` hook with `HOOK_LOW` priority.
--- If the callback returns a value, it will be used in the hook, which can be used to block the normal damage event.
--- Do NOT call any damage-inflicting functions in this callback to avoid feedback loops or misattribution.
--- @param petdCallback? function A callback function for the `PostEntityTakeDamage` hook.
--- Similar to `etdCallback`, but triggered after the entity takes damage.
---
--- **Note:** If you need to inflict additional damage from the callback, use a timer, entity with a fuse, or similar workaround.

Comment on lines +33 to +51
if SERVER and fuseOnImpact then
timer.Simple( 0, function()
if not IsValid( self ) then return end

local fuseShortened = false

function self:PhysicsCollide()
local fuseLeft = self._explodeDelay
if not fuseLeft then return end
if fuseShortened then return end

fuseShortened = true

if fuseLeft > fuseOnImpact then
self:SetTimer( fuseOnImpact )
end
end
end )
end
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this actually need a timer?

Suggested change
if SERVER and fuseOnImpact then
timer.Simple( 0, function()
if not IsValid( self ) then return end
local fuseShortened = false
function self:PhysicsCollide()
local fuseLeft = self._explodeDelay
if not fuseLeft then return end
if fuseShortened then return end
fuseShortened = true
if fuseLeft > fuseOnImpact then
self:SetTimer( fuseOnImpact )
end
end
end )
end
if not SERVER then return end
if not fuseOnImpact then return end
timer.Simple( 0, function()
if not IsValid( self ) then return end
local fuseShortened = false
function self:PhysicsCollide()
local fuseLeft = self._explodeDelay
if not fuseLeft then return end
if fuseShortened then return end
fuseShortened = true
if fuseLeft > fuseOnImpact then
self:SetTimer( fuseOnImpact )
end
end
end )

end
end

function ENT:CreateBubble()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: Could you localize angles/colors in here?

Comment on lines +94 to +134
function ENT:BubbleStartTouch( ent )
if not ent:IsPlayer() then return end
if not ent:Alive() then return end

-- Check if we're allowed to affect the player (there might be a build/pvp system, etc)
local allowed = false

hook.Add( "EntityTakeDamage", "CFC_PvPWeapons_AntiGravityGrenade_CheckIfDamageIsAllowed", function()
allowed = true

return true
end, HOOK_LOW )

local dmgInfo = DamageInfo()
dmgInfo:SetAttacker( self:GetOwner() )
dmgInfo:SetInflictor( self )
dmgInfo:SetDamage( 100 )
dmgInfo:SetDamageType( ent:InVehicle() and DMG_VEHICLE or DMG_GENERIC )

ent:TakeDamageInfo( dmgInfo )
hook.Remove( "EntityTakeDamage", "CFC_PvPWeapons_AntiGravityGrenade_CheckIfDamageIsAllowed" )

if not allowed then return end

-- Apply the effect
ent:SetGravity( self.GravityMult )

if ent:IsOnGround() then
ent:SetVelocity( Vector( 0, 0, self.PushStrength ) )
end

ent._cfcPvPWeapons_AntiGravityGrenade = self

local rf = RecipientFilter()
rf:AddPlayer( ent )

sound.Play( "ambient/machines/machine1_hit2.wav", ent:EyePos(), 75, 120 )
util.ScreenShake( ent:EyePos(), 3, 5, 1.5, 500, true, ent )

return true
end
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this is going to work like you think it will.

A much simpler and more reliable option:

  • Simply deal the damage here
  • Have a new PostEntityTakeDamage hook that checks for cfc_simple_ent_antigrav_grenade as the inflictor, and that took == true, and then run the second part of the effect

I believe the only difference will be that the bubbles will pop on non-pvpers, but I think that's fine

Comment on lines +127 to +131
local rf = RecipientFilter()
rf:AddPlayer( ent )

sound.Play( "ambient/machines/machine1_hit2.wav", ent:EyePos(), 75, 120 )
util.ScreenShake( ent:EyePos(), 3, 5, 1.5, 500, true, ent )
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you forget to use the recipientfilter here?

Comment on lines +157 to +167
if SERVER and self.Beep and self.Beep <= CurTime() then
self:EmitSound( "npc/scanner/combat_scan4.wav", 75, 120 )

local time = 1

if self._explodeTime and self._explodeTime - CurTime() <= 1.5 then
time = 0.3
end

self.Beep = CurTime() + time
end
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you move this to a ENT:Beep() function that handles the rate limiting and so forth

Comment on lines +31 to +36
if not setModelScale then
local entMeta = FindMetaTable( "Entity" )

-- Get the original function, in case the server wraps it for anticrash purposes.
setModelScale = entMeta._SetModelScale or entMeta.SetModelScale
end
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not just use the function, wrapped or not?

Comment on lines +138 to +140
-- Remove the bubble.
-- Without the extra 1-tick delay, this will sometime cause a MASSIVE lag spike due to the cosmetic bubbles being removed while SetModelScale's deltatime is still running.
-- No idea why that would happen, nor why it only happens with the cosmetic bubbles, but this fixes it.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you isolate and report this? Sounds like an easy bug report for rubat

self:SetMaterial( "models/weapons/w_models/cfc_frag_grenade/frag_grenade_cluster" )

if SERVER then
timer.Simple( 0, function()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this timer needed? You're just defining a method on the entity

ent:SetTimer( explodeDelay )
end

local physObj = ent:GetPhysicsObject()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: You can move this definition up above line 161

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants