-
-
Notifications
You must be signed in to change notification settings - Fork 2
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
base: main
Are you sure you want to change the base?
Grenades! #68
Conversation
if SERVER then | ||
function SWEP:CreateEntity() | ||
if not CFCUlxCurse then | ||
self:GetOwner():ChatPrint( "This server doesn't have the CFC ulx curse addon!" ) |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this 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.
--[[ | ||
- 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. | ||
--]] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
--[[ | |
- 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. |
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 |
There was a problem hiding this comment.
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?
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() |
There was a problem hiding this comment.
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?
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 |
There was a problem hiding this comment.
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 forcfc_simple_ent_antigrav_grenade
as the inflictor, and thattook == 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
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 ) |
There was a problem hiding this comment.
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?
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 |
There was a problem hiding this comment.
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
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 |
There was a problem hiding this comment.
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?
-- 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. |
There was a problem hiding this comment.
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() |
There was a problem hiding this comment.
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() |
There was a problem hiding this comment.
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
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.