ToolGun, Init_Item, .Equipable

This commit is contained in:
Fesiug 2024-01-15 01:43:44 -05:00
parent 93d3bb4b7a
commit af48ebde81
7 changed files with 196 additions and 130 deletions

View File

@ -16,7 +16,17 @@ end
-- ItemDef metatable
ItemDef = {}
ItemDefHelpers = {
Get = function( self, key )
return self.key
end,
GetRaw = function( self, key )
return rawget( self, key )
end,
}
function ItemDef.__index( self, key )
if ItemDefHelpers[key] then return ItemDefHelpers[key] end
if rawget(self, "BaseClass") then
return rawget(self, "BaseClass")[key]
end
@ -28,9 +38,8 @@ function ItemDef:new( classname, classtable )
newdef.ClassName = classname
newdef.BaseClass = WEAPONS[newdef.Base]
WEAPONS[classname] = newdef
setmetatable( newdef, ItemDef )
WEAPONS[classname] = newdef
return newdef
else
return WEAPONS[classname]

View File

@ -748,7 +748,7 @@ hook.Add( "HUDPaint", "Benny_HUDPaint", function()
draw.SimpleText( "L", "Benny_10", b_x + bump + ss(2), b_y + ss(b_h) - ss(9), scheme["bg"], TEXT_ALIGN_LEFT, TEXT_ALIGN_TOP )
end
end
if class.Features == "firearm" or class.Features == "grenade" or class.Features == "melee" then
if class.Equipable or class.Features == "firearm" or class.Features == "grenade" or class.Features == "melee" then
invid = invid + 1
surface.SetDrawColor( scheme[active and "bg" or "fg"] )
surface.DrawOutlinedRect( b_x + bump + ss(1), b_y + ss(1), boxsize-ss(2), ss(b_h-2), ss(0.5) )

View File

@ -5,7 +5,7 @@ if SERVER then
end
function BENNY.CreateItem( classname )
local class = WeaponGet(classname)
local class = ItemDef(classname)
assert( class, "Invalid Class " .. tostring(classname) )
@ -14,12 +14,14 @@ function BENNY.CreateItem( classname )
Acquisition = CurTime(),
}
if class.Features == "firearm" then
item.Loaded = ""
elseif class.Features == "magazine" then
item.Ammo = class.Ammo
end
class.Init_Item( class, item )
--if class.Features == "firearm" then
-- item.Loaded = ""
--elseif class.Features == "magazine" then
-- item.Ammo = class.Ammo
--end
--
return item
end

View File

@ -26,7 +26,7 @@ local function beatup( ply, num )
for _, item in pairs( weighted ) do
local class = WeaponGet(item.Class)
local id = iflip[item]
if class.Features == "firearm" or class.Features == "grenade" or class.Features == "melee" then
if class.Equipable or class.Features == "firearm" or class.Features == "grenade" or class.Features == "melee" then
invid = invid + 1
if num == 0 then num = 10 end
if num == invid then

View File

@ -1,106 +1,6 @@
do -- Toolgun
local ToolGunTools = {
["ammocrate"] = function( self, p, tr )
if SERVER then
local summon = ents.Create( "benny_equipment_ammo" )
summon:SetPos( tr.HitPos + tr.HitNormal )
summon:Spawn()
end
end,
["summon_human"] = function( self, p, tr )
if SERVER then
local summon = ents.Create( "benny_npc_human" )
summon:SetPos( tr.HitPos + tr.HitNormal )
local ang = Angle( 0, p:EyeAngles().y+0, 0 )
summon:SetAngles( ang )
summon:Spawn()
end
end,
["remover"] = function( self, p, tr )
if SERVER then
local ent = tr.Entity
if IsValid( ent ) then
ent:Remove()
return
end
end
end,
}
local function CreateSelect()
local Frame = vgui.Create( "DFrame" )
Frame:SetSize( 300, 85 )
Frame:SetTitle( "Toolgun Select" )
Frame:Center()
Frame:MakePopup()
local Text = Frame:Add( "DLabel" )
Text:Dock( TOP )
Text:DockMargin( 10, 0, 10, 0 )
Text:SetText( "Select a tool." )
local List = Frame:Add( "DComboBox" )
List:Dock( TOP )
List:SetValue(GetConVar("benny_wep_toolgun"):GetString())
List:DockMargin( 10, 0, 10, 0 )
for i, v in SortedPairs( ToolGunTools ) do
List:AddChoice( i )
end
List.OnSelect = function( self, index, value )
RunConsoleCommand( "benny_wep_toolgun", value )
Frame:Remove()
end
end
WEAPONS["toolgun"] = {
Name = "TOOL GUN",
Description = "Developer development device. Hold ALT for Remover",
Type = "special",
WModel = "models/weapons/w_toolgun.mdl",
HoldType = "revolver",
GestureDraw = { ACT_HL2MP_GESTURE_RELOAD_REVOLVER, 0.8 },
Delay = (60/300),
Firemodes = FIREMODE_SEMI,
Custom_Fire = function( self, data )
if self:GetDelay1() > CurTime() then
return true
end
self:SetDelay1( CurTime() + 0.2 )
local p = self:GetOwner()
local tr = p:GetEyeTrace()
local tool = p:KeyDown( IN_WALK ) and "remover" or p:GetInfo( "benny_wep_toolgun" )
if ToolGunTools[tool] then ToolGunTools[tool]( self, p, tr ) else return true end
if CLIENT and IsFirstTimePredicted() then
local vStart = self:GetAttachment( 1 ).Pos
local vPoint = tr.HitPos
local effectdata = EffectData()
effectdata:SetStart( vStart )
effectdata:SetOrigin( vPoint )
util.Effect( "ToolTracer", effectdata )
end
-- Return true to skip weapon logic
return true
end,
Custom_Reload = function( self, data )
if CLIENT then
CreateSelect()
end
-- Return true to skip weapon logic
return true
end,
Features = "firearm",
}
WEAPONS["camera"] = {
Name = "CAMERA",
@ -658,7 +558,7 @@ do -- Grenades, nothing here is guaranteed.
Custom_Reload = GrenadeReload,
Custom_Think = GrenadeThink,
Custom_Holster = GrenadeHolster,
GrenadeEnt = "benny_grenade_frag",
GrenadeEnt = "b-gr_frag",
GrenadeFuse = 4,
GrenadeCharge = true,
@ -678,7 +578,7 @@ do -- Grenades, nothing here is guaranteed.
Custom_Reload = GrenadeReload,
Custom_Think = GrenadeThink,
Custom_Holster = GrenadeHolster,
GrenadeEnt = "benny_grenade_semtex",
GrenadeEnt = "b-gr_semtex",
GrenadeFuse = 4,
GrenadeCharge = true,
@ -698,7 +598,7 @@ do -- Grenades, nothing here is guaranteed.
Custom_Reload = GrenadeReload,
Custom_Think = GrenadeThink,
Custom_Holster = GrenadeHolster,
GrenadeEnt = "benny_grenade_molotov",
GrenadeEnt = "b-gr_molotov",
GrenadeFuse = 4,
GrenadeCharge = true,
@ -718,7 +618,7 @@ do -- Grenades, nothing here is guaranteed.
Custom_Reload = GrenadeReload,
Custom_Think = GrenadeThink,
Custom_Holster = GrenadeHolster,
GrenadeEnt = "benny_grenade_tknife",
GrenadeEnt = "b-gr_tknife",
GrenadeFuse = 4,
GrenadeCharge = true,
@ -738,7 +638,7 @@ do -- Grenades, nothing here is guaranteed.
Custom_Reload = GrenadeReload,
Custom_Think = GrenadeThink,
Custom_Holster = GrenadeHolster,
GrenadeEnt = "benny_grenade_smoke",
GrenadeEnt = "b-gr_smoke",
GrenadeFuse = 4,
GrenadeCharge = true,
@ -758,7 +658,7 @@ do -- Grenades, nothing here is guaranteed.
Custom_Reload = GrenadeReload,
Custom_Think = GrenadeThink,
Custom_Holster = GrenadeHolster,
GrenadeEnt = "benny_grenade_flashbang",
GrenadeEnt = "b-gr_flashbang",
GrenadeFuse = 2,
GrenadeCharge = false,
@ -778,7 +678,7 @@ do -- Grenades, nothing here is guaranteed.
Custom_Reload = GrenadeReload,
Custom_Think = GrenadeThink,
Custom_Holster = GrenadeHolster,
GrenadeEnt = "benny_grenade_prox",
GrenadeEnt = "b-gr_prox",
GrenadeFuse = 4,
GrenadeCharge = true,

View File

@ -110,7 +110,7 @@ WEAPONS["g_gas"] = {
Custom_Reload = GrenadeReload,
Custom_Think = GrenadeThink,
Custom_Holster = GrenadeHolster,
GrenadeEnt = "benny_grenade_gas",
GrenadeEnt = "b-gr_gas",
GrenadeFuse = 4,
GrenadeCharge = true,
@ -130,7 +130,7 @@ WEAPONS["g_claymore"] = {
Custom_Reload = GrenadeReload,
Custom_Think = GrenadeThink,
Custom_Holster = GrenadeHolster,
GrenadeEnt = "benny_grenade_claymore",
GrenadeEnt = "b-gr_claymore",
GrenadeFuse = 4,
GrenadeCharge = true,
@ -150,7 +150,7 @@ WEAPONS["g_scrambler"] = {
Custom_Reload = GrenadeReload,
Custom_Think = GrenadeThink,
Custom_Holster = GrenadeHolster,
GrenadeEnt = "benny_grenade_scrambler",
GrenadeEnt = "b-gr_scrambler",
GrenadeFuse = 4,
GrenadeCharge = true,
@ -170,7 +170,7 @@ WEAPONS["g_emp"] = {
Custom_Reload = GrenadeReload,
Custom_Think = GrenadeThink,
Custom_Holster = GrenadeHolster,
GrenadeEnt = "benny_grenade_emp",
GrenadeEnt = "b-gr_emp",
GrenadeFuse = 4,
GrenadeCharge = true,
@ -190,7 +190,7 @@ WEAPONS["g_shockcharge"] = {
Custom_Reload = GrenadeReload,
Custom_Think = GrenadeThink,
Custom_Holster = GrenadeHolster,
GrenadeEnt = "benny_grenade_shockcharge",
GrenadeEnt = "b-gr_shockcharge",
GrenadeFuse = 4,
GrenadeCharge = true,
@ -210,7 +210,7 @@ WEAPONS["g_thermobaric"] = {
Custom_Reload = GrenadeReload,
Custom_Think = GrenadeThink,
Custom_Holster = GrenadeHolster,
GrenadeEnt = "benny_grenade_thermobaric",
GrenadeEnt = "b-gr_thermobaric",
GrenadeFuse = 4,
GrenadeCharge = true,

View File

@ -93,6 +93,8 @@ do -- Sound definitions
AddSound( "P226.MagIn", "benny/weapons/p226/magin.ogg", 70, 100, 0.5, CHAN_STATIC )
-- CZ-75A
AddSound( "CZ75A.MagOut", "benny/weapons/cz75a/magout.ogg", 70, 100, 0.5, CHAN_STATIC )
AddSound( "CZ75A.MagIn", "benny/weapons/cz75a/magin.ogg", 70, 100, 0.5, CHAN_STATIC )
-- SMGs
@ -233,6 +235,10 @@ do -- Bases
Speed_FiringTime = 0.2,
ShootHolsterTime = 0,
Init_Item = function( class, item, class_for )
print( class, ": Base says hi")
end,
Func_Attack = function( self, hand )
end,
@ -288,6 +294,14 @@ do -- Bases
Reload_MagIn_Bonus1 = 0.56,
Reload_MagIn_Bonus2 = 0.56+0.1,
Init_Item = function( class, item )
if class.BaseClass:GetRaw( "Init_Item" ) then
class.BaseClass:GetRaw( "Init_Item" )( class.BaseClass, item )
end
print( class, ": Firearm init" )
item.Loaded = ""
end,
Func_Attack = function( self, hand )
if self:GetAim() == 1 then
local p = self:GetOwner()
@ -404,6 +418,13 @@ do -- Bases
Range = 64,
HullSize = 2,
Init_Item = function( class, item )
if class.BaseClass:GetRaw( "Init_Item" ) then
class.BaseClass:GetRaw( "Init_Item" )( class.BaseClass, item )
end
print( class, ": Melee init" )
end,
Func_Attack = function( self, hand )
if self:bGetIntDelay( hand ) > CurTime() then
return
@ -473,6 +494,13 @@ do -- Bases
Features = "grenade",
Hide = true,
Init_Item = function( class, item )
if class.BaseClass:GetRaw( "Init_Item" ) then
class.BaseClass:GetRaw( "Init_Item" )( class.BaseClass, item )
end
print( class, ": Grenade init" )
end,
WModel = "models/weapons/w_grenade.mdl",
HoldType = "slam",
})
@ -485,12 +513,139 @@ do -- Bases
Features = "magazine",
Hide = true,
--
AmmoStd = 0,
AutoGenMag = false,
Init_Item = function( class, item )
if class.BaseClass:GetRaw( "Init_Item" ) then
class.BaseClass:GetRaw( "Init_Item" )( class.BaseClass, item )
end
print( class, ": Clip init" )
item.Ammo = class.Ammo
end,
WModel = "models/weapons/w_slam.mdl",
HoldType = "slam",
})
end
do -- Toolgun
local ToolGunTools = {
["ammocrate"] = function( self, p, tr )
if SERVER then
local summon = ents.Create( "b-eq_ammo" )
summon:SetPos( tr.HitPos + tr.HitNormal )
summon:Spawn()
end
end,
["summon_human"] = function( self, p, tr )
if SERVER then
local summon = ents.Create( "benny_npc_human" )
summon:SetPos( tr.HitPos + tr.HitNormal )
local ang = Angle( 0, p:EyeAngles().y+0, 0 )
summon:SetAngles( ang )
summon:Spawn()
end
end,
["remover"] = function( self, p, tr )
if SERVER then
local ent = tr.Entity
if IsValid( ent ) then
ent:Remove()
return
end
end
end,
}
local function CreateSelect()
local Frame = vgui.Create( "DFrame" )
Frame:SetSize( 300, 85 )
Frame:SetTitle( "Toolgun Select" )
Frame:Center()
Frame:MakePopup()
local Text = Frame:Add( "DLabel" )
Text:Dock( TOP )
Text:DockMargin( 10, 0, 10, 0 )
Text:SetText( "Select a tool." )
local List = Frame:Add( "DComboBox" )
List:Dock( TOP )
List:SetValue(GetConVar("benny_wep_toolgun"):GetString())
List:DockMargin( 10, 0, 10, 0 )
for i, v in SortedPairs( ToolGunTools ) do
List:AddChoice( i )
end
List.OnSelect = function( self, index, value )
RunConsoleCommand( "benny_wep_toolgun", value )
Frame:Remove()
end
end
WEAPONS["toolgun"] = {
Name = "TOOL GUN",
Description = "Developer development device. Hold ALT for Remover",
Base = "base",
Category = "special",
Equipable = true,
WModel = "models/weapons/w_toolgun.mdl",
HoldType = "revolver",
GestureDraw = { ACT_HL2MP_GESTURE_RELOAD_REVOLVER, 0.8 },
Delay = (60/300),
Firemodes = FIREMODE_SEMI,
-- These for some reason aren't taken by the base correctly
Init_Item = function()
end,
Speed_Move = 1,
Speed_Aiming = 1,
Speed_Reloading = 1,
Speed_Firing = 1,
Speed_FiringTime = 0.2,
ShootHolsterTime = 0,
--
Func_Attack = function( self, data )
if self:GetDelay1() > CurTime() then
return true
end
self:SetDelay1( CurTime() + 0.2 )
local p = self:GetOwner()
local tr = p:GetEyeTrace()
local tool = p:KeyDown( IN_WALK ) and "remover" or p:GetInfo( "benny_wep_toolgun" )
if ToolGunTools[tool] then ToolGunTools[tool]( self, p, tr ) else return true end
if CLIENT and IsFirstTimePredicted() then
local vStart = self:GetAttachment( 1 ).Pos
local vPoint = tr.HitPos
local effectdata = EffectData()
effectdata:SetStart( vStart )
effectdata:SetOrigin( vPoint )
util.Effect( "ToolTracer", effectdata )
end
-- Return true to skip weapon logic
return true
end,
Func_Reload = function( self, data )
if CLIENT then
CreateSelect()
end
-- Return true to skip weapon logic
return true
end,
}
end
do -- Melee
ItemDef("bat", {