From 34a294da95284ea8d21ed430f8f9bd4c2cd0e34b Mon Sep 17 00:00:00 2001 From: Fesiug Date: Tue, 12 Mar 2024 18:43:31 -0400 Subject: [PATCH] Handler, weapon select, color --- .../benny/entities/weapons/itemhandler.lua | 13 +++- gamemodes/benny/gamemode/hud.lua | 30 +++++--- gamemodes/benny/gamemode/inventory.lua | 6 +- gamemodes/benny/gamemode/items.lua | 76 ++++++++++++++++++- gamemodes/benny/gamemode/languages/en-us.lua | 5 +- gamemodes/benny/gamemode/player.lua | 2 +- 6 files changed, 109 insertions(+), 23 deletions(-) diff --git a/gamemodes/benny/entities/weapons/itemhandler.lua b/gamemodes/benny/entities/weapons/itemhandler.lua index 80f217b..839ee4b 100644 --- a/gamemodes/benny/entities/weapons/itemhandler.lua +++ b/gamemodes/benny/entities/weapons/itemhandler.lua @@ -69,12 +69,19 @@ function SWEP:SetActive( ent ) if ent:GetOwner() != p then return false end if self:GetActiveR():IsValid() then self:Deactive() end self:SetActiveR( ent ) - self:ItemR( "Deploy" ) + if self:ItemR() then + self:ItemR( "Deploy" ) + self:ItemR():SetNoDraw( false ) + end return true end function SWEP:Deactive() local p = self:GetOwner() + if self:ItemR() then + self:ItemR( "Holster" ) + self:ItemR():SetNoDraw( true ) + end self:SetActiveR( NULL ) end @@ -131,6 +138,7 @@ function SWEP:EquipItem( ent ) ent:AddEFlags( EFL_KEEP_ON_RECREATE_ENTITIES ) ent:AddEffects( EF_BONEMERGE ) ent:SetMoveType( MOVETYPE_NONE ) + ent:SetNoDraw( true ) ent:SetParent( p ) ent:SetOwner( p ) ent:SetPos( vector_origin ) @@ -164,6 +172,7 @@ function SWEP:DropItem() ent:RemoveEFlags( EFL_KEEP_ON_RECREATE_ENTITIES ) ent:RemoveEffects( EF_BONEMERGE ) ent:SetMoveType( MOVETYPE_VPHYSICS ) + ent:SetNoDraw( false ) ent:SetPos( p:EyePos() + p:GetAimVector() * 0 ) ent:SetAngles( p:EyeAngles() + Angle( 0, 180, 0 ) ) @@ -192,7 +201,7 @@ function SWEP:Think() self:ItemR("Think") end - self:SetHoldType( self:ItemR() and "revolver" or "normal" ) + self:SetHoldType( self:ItemR() and (self:ItemR().Class.HoldType or "rpg") or "normal" ) else print( self, "Thinking without an owner." ) end diff --git a/gamemodes/benny/gamemode/hud.lua b/gamemodes/benny/gamemode/hud.lua index 85a98c5..c925f4c 100644 --- a/gamemodes/benny/gamemode/hud.lua +++ b/gamemodes/benny/gamemode/hud.lua @@ -79,15 +79,19 @@ local function regenfonts() end regenfonts() -local COLOR_DARK = Color( 40, 40, 80 ) -local COLOR_BRIGHT = Color( 80, 80, 160 ) -local COLOR_MAIN = Color( 160, 160, 240 ) +-- local COLOR_DARK = Color( 40, 40, 80 ) +-- local COLOR_BRIGHT = Color( 80, 80, 160 ) +-- local COLOR_MAIN = Color( 160, 160, 240 ) + +local COLOR_DARK = Color( 54, 44, 39 ) +local COLOR_BRIGHT = Color( 94, 84, 79 ) +local COLOR_MAIN = Color( 255, 238, 169 ) -- Drawing function GM:HUDPaint() local p = LocalPlayer() local w, h = ScrW(), ScrH() - local handler = p:BennyCheck() + local handler = p:HandlerCheck() stack = util.Stack() S_Push( 20, 20 ) @@ -106,14 +110,16 @@ function GM:HUDPaint() hScisoff() S_Pop() - S_Push( 20, h - 60 - 20 ) - for i, v in ipairs( p:GetInventory():GetWeighted() ) do - hCol( v == handler:GetActiveR() and COLOR_BRIGHT or COLOR_DARK ) - hRect( 0, 0, 120, 60 ) - local x, y = hXY( 0, 0 ) - draw.SimpleText( l8( v.Class.PrintName ) .. "(" .. v:GetClip() .. "/" .. v.Class.ClipSize .. ")", "HUD_24", x + 120/2, y + 60/2, COLOR_MAIN, TEXT_ALIGN_CENTER, TEXT_ALIGN_CENTER ) - end - S_Pop() + if handler then + S_Push( 20, h - 60 - 20 ) + for i, v in ipairs( p:GetInventory():GetWeighted() ) do + hCol( v == handler:GetActiveR() and COLOR_BRIGHT or COLOR_DARK ) + hRect( (i-1)*(120+10), 0, 120, 60 ) + local x, y = hXY( (i-1)*(120+10), 0 ) + draw.SimpleText( l8( v.Class.PrintName ) .. "(" .. v:GetClip() .. "/" .. v.Class.ClipSize .. ")", "HUD_24", x + 120/2, y + 60/2, COLOR_MAIN, TEXT_ALIGN_CENTER, TEXT_ALIGN_CENTER ) + end + S_Pop() + end if stack:Size() != 0 then print("Stack unfinished.") end return diff --git a/gamemodes/benny/gamemode/inventory.lua b/gamemodes/benny/gamemode/inventory.lua index a50c55c..4547cd2 100644 --- a/gamemodes/benny/gamemode/inventory.lua +++ b/gamemodes/benny/gamemode/inventory.lua @@ -9,10 +9,6 @@ function PT:GetItems() return end -function PT:HandlerCheck() - return self:GetActiveWeapon().AEItemHandler and self:GetActiveWeapon() -end - InventoryMeta = {} function InventoryMeta:Destroy() @@ -157,7 +153,7 @@ local dads = { local function beatup( ply, num ) local inv = ply:GetInventory():GetWeighted() - local wep = ply:BennyCheck() + local wep = ply:HandlerCheck() local ent = inv[num] if ent then diff --git a/gamemodes/benny/gamemode/items.lua b/gamemodes/benny/gamemode/items.lua index 6cee92c..3c694d9 100644 --- a/gamemodes/benny/gamemode/items.lua +++ b/gamemodes/benny/gamemode/items.lua @@ -48,6 +48,7 @@ AddItem( "base", { "Acquisition", }, }, + HoldType = "slam", ["Initialize"] = function( class, ent, handler ) print( class, "Initialized base initialization" ) @@ -89,6 +90,7 @@ AddItem( "base_firearm", { "DelayReload", }, }, + HoldType = "rpg", Delay = 0.1, Pellets = 1, @@ -106,17 +108,68 @@ AddItem( "base_firearm", { print( class, "Initialized a firearm" ) end, + ["Think"] = function( class, ent, handler ) + local InProcess = ent:GetBurstCount() > 0 + local Topped = ent:GetBurstCount() == class.BurstCount + local Runaway = class.BurstRunaway + local BAuto = class.BurstAuto + local Firedown = handler:GetOwner():KeyDown( IN_ATTACK ) + if Runaway and InProcess and !Topped then + class["Attack"]( class, ent, handler ) + else + if !Firedown then + if !Topped and InProcess then + ent:SetDelayBurst( CurTime() + class.BurstDelay ) + end + ent:SetBurstCount( 0 ) + end + if Topped and BAuto then + ent:SetBurstCount( 0 ) + ent:SetDelayBurst( CurTime() + class.BurstDelay ) + end + end + end, + ["Attack"] = function( class, ent, handler ) if ent:GetClip() <= 0 then return end if ent:GetDelay() > CurTime() then return end + if ent:GetBurstCount() >= class.BurstCount then return end + ent:SetBurstCount( ent:GetBurstCount() + 1 ) ent:SetClip( ent:GetClip() - 1 ) ent:SetDelay( CurTime() + class.Delay ) + handler:EmitSound( class.FireSound, 140, 100, 0.4, CHAN_STATIC ) + + local acc = 0 + local p = handler:GetOwner() + handler:FireBullets( { + Attacker = p, + Damage = 1, + Force = 1, + Num = class.Pellets, + Dir = p:GetAimVector(), + Src = p:GetShootPos(), + Spread = Vector( acc, acc, 0 ), + } ) end, ["Reload"] = function( class, ent, handler ) + if ent:GetClip() >= class.ClipSize then return end + if ent:GetDelay() > CurTime() then return end + handler:EmitSound( "weapons/m4a1/m4a1_boltpull.wav", 70, 125, 0.4, CHAN_STATIC ) + ent:SetDelay( CurTime() + 0.5 ) ent:SetClip( class.ClipSize ) end, + + ["Deploy"] = function( class, ent, handler ) + handler:EmitSound( "weapons/usp/usp_slideback.wav", 70, 125, 0.4, CHAN_STATIC ) + ent:SetDelay( CurTime() + 0.5 ) + end, + + ["Holster"] = function( class, ent, handler ) + handler:EmitSound( "weapons/m4a1/m4a1_deploy.wav", 70, 125, 0.4, CHAN_STATIC ) + ent:SetDelay( CurTime() + 0.5 ) + end, }) AddItem( "mk23", { @@ -125,10 +178,11 @@ AddItem( "mk23", { Category = "pistol", Base = "base_firearm", - Model = "models/weapons/w_pist_elite_single.mdl", + Model = "models/weapons/w_pist_usp.mdl", + HoldType = "revolver", ClipSize = 12, - Delay = (60/300), + Delay = (60/350), FireSound = "weapons/usp/usp_unsil-1.wav", Accuracy = 5/60, @@ -138,6 +192,24 @@ AddItem( "mk23", { Accuracy_Decay = 5, }) +AddItem( "fnc", { + PrintName = "#Item.fnc.Name", + Description = "#Item.fnc.Description", + Base = "base_firearm", + + Model = "models/weapons/w_rif_ar556.mdl", + HoldType = "rpg", + + ClipSize = 30, + Delay = (60/750), + FireSound = "weapons/m4a1/m4a1_unsil-1.wav", + + Accuracy = 1, + Accuracy_Add = 0.4, + Accuracy_Reset = 0.4, + Accuracy_Decay = 12, +}) + for ID, Data in pairs(ITEMS) do local tent = {} tent.Base = "b-itembase" diff --git a/gamemodes/benny/gamemode/languages/en-us.lua b/gamemodes/benny/gamemode/languages/en-us.lua index fac4d6b..e4e3c4c 100644 --- a/gamemodes/benny/gamemode/languages/en-us.lua +++ b/gamemodes/benny/gamemode/languages/en-us.lua @@ -4,4 +4,7 @@ Languages["en-us"] = L L["Name"] = "English (United States)" L["#Item.mk23.Name"] = "MK.23" -L["#Item.mk23.Description"] = "Special forces sidearm" \ No newline at end of file +L["#Item.mk23.Description"] = "Special forces sidearm" + +L["#Item.fnc.Name"] = "FNC Para" +L["#Item.fnc.Description"] = "Imported assault rifle" \ No newline at end of file diff --git a/gamemodes/benny/gamemode/player.lua b/gamemodes/benny/gamemode/player.lua index 94f0b50..d46248b 100644 --- a/gamemodes/benny/gamemode/player.lua +++ b/gamemodes/benny/gamemode/player.lua @@ -125,7 +125,7 @@ function PT:MakeCharacter() end end -function PT:BennyCheck() +function PT:HandlerCheck() local wep = self:GetActiveWeapon() return ( wep:IsValid() and wep:GetClass() == "itemhandler" and wep.GetActiveR ) and wep or false end