Throw shit @ ppl. Arguably most important feature

This commit is contained in:
Fesiug 2024-01-15 18:55:19 -05:00
parent 2adaecd312
commit 49d60b9ecb
9 changed files with 157 additions and 19 deletions

View File

@ -1,3 +1,59 @@
AddCSLuaFile()
SWEP.Type = "anim" ENT.Type = "anim"
SWEP.Base = "base_anim" ENT.Base = "base_anim"
ENT.RenderGroup = RENDERGROUP_BOTH
function ENT:Initialize()
self.DieTime = CurTime() + 3
end
function ENT:InitSpecial( model )
self:SetModel( model )
-- Physics stuff
self:SetMoveType( MOVETYPE_VPHYSICS )
self:SetSolid( SOLID_VPHYSICS )
-- Init physics only on server, so it doesn't mess up physgun beam
if ( SERVER ) then self:PhysicsInit( SOLID_VPHYSICS ) end
self:SetCollisionGroup( COLLISION_GROUP_PROJECTILE )
-- Make prop to fall on spawn
self:PhysWake()
if SERVER then
local p = self:GetPhysicsObject()
p:SetMass( 0 )
end
end
function ENT:Think()
if SERVER and self.DieTime <= CurTime() then
self:Remove()
end
end
function ENT:PhysicsCollide( data, phys )
if ( data.Speed > 200 ) and data.DeltaTime > 0.2 then
local ent = data.HitEntity
print(ent:Health())
if ent:IsValid() and ent:Health() > 0 then
ent:EmitSound( ")benny/violence/bodysplat_mix2.ogg", 70, 100, 1 )
local dmg = DamageInfo()
dmg:SetDamageType( DMG_CLUB )
dmg:SetDamage( 25 )
dmg:SetAttacker( self:GetOwner() )
dmg:SetInflictor( self )
print( data.HitSpeed, data.HitSpeed:Length() )
dmg:SetDamageForce( data.HitSpeed*-10 )
dmg:SetDamagePosition( data.HitPos )
ent:TakeDamageInfo( dmg )
else
self:EmitSound( "physics/metal/weapon_impact_hard1.wav" )
end
end
end

View File

@ -1,2 +1,3 @@
SWEP.Base = "b-item" ENT.Base = "b-item"

View File

@ -4,6 +4,8 @@ ENT.Base = "base_nextbot"
ENT.Spawnable = true ENT.Spawnable = true
ENT.BennyNPC = true ENT.BennyNPC = true
ENT.AutomaticFrameAdvance = true
function ENT:Nick() function ENT:Nick()
return "GEN#" .. self:EntIndex() return "GEN#" .. self:EntIndex()
end end
@ -343,11 +345,11 @@ function ENT:OnEntitySightLost( ent )
self.bSeeing[ent] = nil self.bSeeing[ent] = nil
end end
local wide, tall = 12/2, 64 local wide, tall = 16/2, 64
local b1 = Vector( wide, wide, tall ) local b1 = Vector( wide, wide, tall )
local b2 = Vector( -wide, -wide, 0 ) local b2 = Vector( -wide, -wide, 0 )
local wide, tall = 48/2, 96 local wide, tall = 48/2, 80
local s1 = Vector( wide, wide, tall ) local s1 = Vector( wide, wide, tall )
local s2 = Vector( -wide, -wide, 0 ) local s2 = Vector( -wide, -wide, 0 )
@ -360,6 +362,13 @@ function ENT:Initialize()
self:SetShouldServerRagdoll( false ) self:SetShouldServerRagdoll( false )
self:SetFOV( 90 ) self:SetFOV( 90 )
self:SetMaxHealth( 100 )
self:SetHealth( 100 )
self:SetCollisionGroup( COLLISION_GROUP_NPC )
if SERVER then self:PhysicsInitShadow( true, true ) end
self:SetState("idle") self:SetState("idle")
self.Team = nil self.Team = nil
@ -458,4 +467,8 @@ function ENT:Think()
end end
end end
net.SendPVS(self:GetPos()) net.SendPVS(self:GetPos())
self:NextThink( CurTime() )
if CLIENT then self:SetNextClientThink( CurTime() ) end
return true
end end

View File

@ -0,0 +1,34 @@
function SWEP:Drop( hand )
if self:bWepClass( hand ) then
local p = self:GetOwner()
self:EmitSound( "weapons/slam/throw.wav", 70, 100, 1, CHAN_STATIC )
if SERVER then
local throw = ents.Create( "b-item" )
throw:SetPos( p:EyePos() + p:EyeAngles():Forward()*16 )
throw:SetAngles( p:EyeAngles() )
throw:SetOwner( p )
throw:InitSpecial(self:bWepClass( hand ).WModel)
throw:SetPhysicsAttacker( p )
throw:Spawn()
local throwp = throw:GetPhysicsObject()
assert( throwp:IsValid(), "Benny Drop: Physics object invalid" )
throwp:SetVelocityInstantaneous( (p:EyeAngles()+Angle(-7,0,0)):Forward()*1000 )
if self:bWepClass( hand ).ClassName == "m16a2" then
throwp:SetAngleVelocityInstantaneous( Vector( 360*-0.2, 360*1, 360*0 ) )
else
throwp:SetAngleVelocityInstantaneous( Vector( 360*-0.25, 360*10, 360*0.25 ) )
end
end
if SERVER or CLIENT and IsFirstTimePredicted() then
--InvDiscard( p, self:bGetInvID( hand ) )
end
self:SetJustThrew( CurTime() + 0.25 )
self:SetJustThrewHand( hand )
self:bWepTable( hand ).Thrown = true
p:AddVCDSequenceToGestureSlot( GESTURE_SLOT_JUMP, p:SelectWeightedSequence( ACT_HL2MP_GESTURE_RANGE_ATTACK_MELEE ), 0, true )
end
end

View File

@ -1,11 +1,13 @@
function SWEP:PrimaryAttack() function SWEP:PrimaryAttack()
if self:bWepTable( self:hFlipHand( false ) ) and self:bWepTable( self:hFlipHand( false ) ).Thrown then return true end
self:BFireLogic( self:hFlipHand( false ) ) self:BFireLogic( self:hFlipHand( false ) )
return true return true
end end
function SWEP:SecondaryAttack() function SWEP:SecondaryAttack()
if self:bWepTable( self:hFlipHand( true ) ) and self:bWepTable( self:hFlipHand( true ) ).Thrown then return true end
self:BFireLogic( self:hFlipHand( true ) ) self:BFireLogic( self:hFlipHand( true ) )
return true return true
end end

View File

@ -31,6 +31,8 @@ AddCSLuaFile( "sh_holdtypes.lua" )
include ( "sh_holdtypes.lua" ) include ( "sh_holdtypes.lua" )
AddCSLuaFile( "sh_reload.lua" ) AddCSLuaFile( "sh_reload.lua" )
include ( "sh_reload.lua" ) include ( "sh_reload.lua" )
AddCSLuaFile( "sh_drop.lua" )
include ( "sh_drop.lua" )
AddCSLuaFile( "cl_wm.lua" ) AddCSLuaFile( "cl_wm.lua" )
if CLIENT then if CLIENT then
@ -50,6 +52,7 @@ function SWEP:SetupDataTables()
self:NetworkVar( "Float", 9, "Wep2_Holstering" ) self:NetworkVar( "Float", 9, "Wep2_Holstering" )
self:NetworkVar( "Float", 10, "Wep1_Reloading" ) self:NetworkVar( "Float", 10, "Wep1_Reloading" )
self:NetworkVar( "Float", 11, "Wep2_Reloading" ) self:NetworkVar( "Float", 11, "Wep2_Reloading" )
self:NetworkVar( "Float", 12, "JustThrew" )
self:NetworkVar( "String", 0, "Wep1" ) self:NetworkVar( "String", 0, "Wep1" )
self:NetworkVar( "String", 1, "Wep2" ) self:NetworkVar( "String", 1, "Wep2" )
self:NetworkVar( "String", 2, "Wep1_Clip" ) self:NetworkVar( "String", 2, "Wep1_Clip" )
@ -62,6 +65,7 @@ function SWEP:SetupDataTables()
self:NetworkVar( "Int", 5, "Wep2_ReloadType" ) self:NetworkVar( "Int", 5, "Wep2_ReloadType" )
self:NetworkVar( "Bool", 0, "UserAim" ) self:NetworkVar( "Bool", 0, "UserAim" )
self:NetworkVar( "Bool", 1, "GrenadeDown" ) self:NetworkVar( "Bool", 1, "GrenadeDown" )
self:NetworkVar( "Bool", 2, "JustThrewHand" )
self:SetWep1_Firemode( 1 ) self:SetWep1_Firemode( 1 )
self:SetWep2_Firemode( 1 ) self:SetWep2_Firemode( 1 )
@ -114,6 +118,14 @@ hook.Add( "PlayerButtonDown", "Benny_PlayerButtonDown_TempForAim", function( ply
if button == ply:GetInfoNum("benny_bind_reloada", KEY_T) then if button == ply:GetInfoNum("benny_bind_reloada", KEY_T) then
wep:Reload( wep:hFlipHand( true ) ) wep:Reload( wep:hFlipHand( true ) )
end end
if button == ply:GetInfoNum("benny_bind_drop", KEY_G) then
wep:Drop( wep:hFlipHand( false ) )
end
if button == ply:GetInfoNum("benny_bind_dropa", KEY_H) then
wep:Drop( wep:hFlipHand( true ) )
end
end end
end) end)
@ -184,6 +196,8 @@ function SWEP:Think()
-- Just know, this feels bad. -- Just know, this feels bad.
if self:bGetReloadTime( hand ) > 0 then if self:bGetReloadTime( hand ) > 0 then
-- hold -- hold
elseif self:GetJustThrew() > CurTime() then
-- hold
elseif self:bWepClass( hand ) and self:bGetShotTime( hand ) + self:GetStat( hand, "ShootHolsterTime" ) > CurTime() then elseif self:bWepClass( hand ) and self:bGetShotTime( hand ) + self:GetStat( hand, "ShootHolsterTime" ) > CurTime() then
-- hold -- hold
else else
@ -207,6 +221,13 @@ function SWEP:Think()
self:BThinkHolster( hand ) self:BThinkHolster( hand )
if self:GetJustThrew() != 0 and self:GetJustThrew() <= CurTime() then
if SERVER then
InvDiscard( p, self:bGetInvID( self:GetJustThrewHand() ) )
end
self:SetJustThrew( 0 )
end
do -- Reload logic do -- Reload logic
if self:bGetReloadTime( hand ) != -1 then if self:bGetReloadTime( hand ) != -1 then
local rlt = self:bGetReloadType( hand ) local rlt = self:bGetReloadType( hand )
@ -250,7 +271,9 @@ function SWEP:Think()
if self:bWepClass( false ) and self:bGetHolsterTime( false ) < 0 then if self:bWepClass( false ) and self:bGetHolsterTime( false ) < 0 then
ht = "passive" ht = "passive"
if self:GetUserAim() then if self:GetUserAim() then
if self:bWepClass( true ) then if self:GetJustThrew() != 0 then
ht = "melee"
elseif self:bWepClass( true ) then
ht = "duel" ht = "duel"
else else
ht = self:GetStat( false, "HoldType" ) ht = self:GetStat( false, "HoldType" )

View File

@ -524,6 +524,11 @@ hook.Add( "HUDPaint", "Benny_HUDPaint", function()
draw.SimpleText( wep:B_FiremodeName( hand ), "Benny_12", p_x + pb + ss(14.5), p_y + pb + t_h + ss(8), scheme["bg"], TEXT_ALIGN_CENTER, TEXT_ALIGN_CENTER ) draw.SimpleText( wep:B_FiremodeName( hand ), "Benny_12", p_x + pb + ss(14.5), p_y + pb + t_h + ss(8), scheme["bg"], TEXT_ALIGN_CENTER, TEXT_ALIGN_CENTER )
-- draw.SimpleText( "[AMMO TYPE]", "Benny_10", p_x + pb + ss(30+4), p_y + pb + t_h + ss(8), scheme["fg"], TEXT_ALIGN_LEFT, TEXT_ALIGN_CENTER ) -- draw.SimpleText( "[AMMO TYPE]", "Benny_10", p_x + pb + ss(30+4), p_y + pb + t_h + ss(8), scheme["fg"], TEXT_ALIGN_LEFT, TEXT_ALIGN_CENTER )
end end
if wep_table.Thrown then
draw.SimpleText( "X", "Benny_48", p_x+p_w/2, p_y+p_h/2 + ss(8), scheme["fg"], TEXT_ALIGN_CENTER, TEXT_ALIGN_CENTER )
end
if wep:bMagClass( hand ) then -- Ammo if wep:bMagClass( hand ) then -- Ammo
local b_w, b_h = ss(3), ss(10) local b_w, b_h = ss(3), ss(10)
local lw, lh = ss(2), ss(2) local lw, lh = ss(2), ss(2)

View File

@ -59,42 +59,46 @@ if CLIENT then
end) end)
end end
concommand.Add("benny_inv_discard", function( ply, cmd, args ) function InvDiscard( ply, ID )
local inv = ply:INV_Get() local inv = ply:INV_Get()
local wep = ply:GetActiveWeapon() local wep = ply:GetActiveWeapon()
local item = inv[args[1]] local item = inv[ID]
-- PROTO: Check that this is the correct 'benny' weapon. -- PROTO: Check that this is the correct 'benny' weapon.
assert( item, "That item doesn't exist. " .. tostring(item) ) assert( item, "That item doesn't exist. " .. tostring(item) )
inv[args[1]] = nil inv[ID] = nil
net.Start( "benny_discardinvitem" ) net.Start( "benny_discardinvitem" )
net.WriteString( args[1] ) net.WriteString( ID )
net.Send( ply ) net.Send( ply )
if wep:bGetInvID( false ) == args[1] then if wep:bGetInvID( false ) == ID then
print( "Disequipped " .. args[1] .. " for " .. tostring(wep) ) print( "Disequipped " .. ID .. " for " .. tostring(wep) )
wep:SetWep1( "" ) wep:SetWep1( "" )
wep:SetWep1_Clip( "" ) wep:SetWep1_Clip( "" )
wep:SetClip1( 0 ) wep:SetClip1( 0 )
end end
if wep:bGetInvID( true ) == args[1] then if wep:bGetInvID( true ) == ID then
print( "Disequipped " .. args[1] .. " for " .. tostring(wep) ) print( "Disequipped " .. ID .. " for " .. tostring(wep) )
wep:SetWep2( "" ) wep:SetWep2( "" )
wep:SetWep2_Clip( "" ) wep:SetWep2_Clip( "" )
wep:SetClip2( 0 ) wep:SetClip2( 0 )
end end
if wep:bGetMagInvID( false ) == args[1] then if wep:bGetMagInvID( false ) == ID then
print( "Unloaded " .. args[1] .. " for " .. tostring(wep) ) print( "Unloaded " .. ID .. " for " .. tostring(wep) )
inv[wep:bGetInvID( false )].Loaded = "" inv[wep:bGetInvID( false )].Loaded = ""
wep:SetWep1_Clip( "" ) wep:SetWep1_Clip( "" )
wep:SetClip1( 0 ) wep:SetClip1( 0 )
end end
if wep:bGetMagInvID( true ) == args[1] then if wep:bGetMagInvID( true ) == ID then
print( "Unloaded " .. args[1] .. " for " .. tostring(wep) ) print( "Unloaded " .. ID .. " for " .. tostring(wep) )
inv[wep:bGetInvID( true )].Loaded = "" inv[wep:bGetInvID( true )].Loaded = ""
wep:SetWep2_Clip( "" ) wep:SetWep2_Clip( "" )
wep:SetClip2( 0 ) wep:SetClip2( 0 )
end end
end
concommand.Add("benny_inv_discard", function( ply, cmd, args )
InvDiscard( ply, args[1] )
end) end)
hook.Add( "PlayerDeathSound", "Benny_PlayerDeathSound", function( ply ) hook.Add( "PlayerDeathSound", "Benny_PlayerDeathSound", function( ply )

View File

@ -543,7 +543,7 @@ do -- Toolgun
end, end,
["summon_human"] = function( self, p, tr ) ["summon_human"] = function( self, p, tr )
if SERVER then if SERVER then
local summon = ents.Create( "benny_npc_human" ) local summon = ents.Create( "b-npc_human" )
summon:SetPos( tr.HitPos + tr.HitNormal ) summon:SetPos( tr.HitPos + tr.HitNormal )
local ang = Angle( 0, p:EyeAngles().y+0, 0 ) local ang = Angle( 0, p:EyeAngles().y+0, 0 )
summon:SetAngles( ang ) summon:SetAngles( ang )