Weapon mechanics, sound & caption system
This commit is contained in:
parent
89e037fcf5
commit
e1b2c35fb7
|
@ -30,14 +30,28 @@ function SWEP:SetupDataTables()
|
|||
self:NetworkVarNotify( "Wep2", self.OnVarChanged )
|
||||
end
|
||||
|
||||
function SWEP:OnReloaded()
|
||||
self.B_WepT1 = self:GetOwner():INV_Get()[self:GetWep1()]
|
||||
if self.B_WepT1 then
|
||||
self.B_ClassT1 = WEAPONS[self.B_WepT1.Class]
|
||||
end
|
||||
self.B_WepT2 = self:GetOwner():INV_Get()[self:GetWep2()]
|
||||
if self.B_WepT2 then
|
||||
self.B_ClassT2 = WEAPONS[self.B_WepT2.Class]
|
||||
end
|
||||
end
|
||||
|
||||
function SWEP:OnVarChanged( name, old, new )
|
||||
print( name, old, new )
|
||||
if name == "Wep1" then
|
||||
self.B_WepT1 = self:GetOwner():INV_Get()[new]
|
||||
self.B_ClassT1 = WEAPONS[self.B_WepT1.Class]
|
||||
if self.B_WepT1 then
|
||||
self.B_ClassT1 = WEAPONS[self.B_WepT1.Class]
|
||||
end
|
||||
elseif name == "Wep2" then
|
||||
self.B_WepT2 = self:GetOwner():INV_Get()[new]
|
||||
self.B_ClassT2 = WEAPONS[self.B_WepT1.Class]
|
||||
if self.B_WepT2 then
|
||||
self.B_ClassT2 = WEAPONS[self.B_WepT2.Class]
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -54,11 +68,12 @@ function SWEP:PrimaryAttack()
|
|||
return
|
||||
end
|
||||
|
||||
if CLIENT then
|
||||
AddCaption( "PISTOL", Color( 61, 61, 61 ), "[Pistol shot]", 0.1, 0.5 )
|
||||
end
|
||||
-- if CLIENT then
|
||||
-- AddCaption( "PISTOL", Color( 61, 61, 61 ), "[Pistol shot]", 0.1, 0.5 )
|
||||
-- end
|
||||
|
||||
self:EmitSound( "benny/weapons/1911/0".. math.random(1,3) ..".ogg", 110, 100, 1, CHAN_STATIC )
|
||||
B_Sound( self, self.B_ClassT1.Sound_Fire )
|
||||
-- self:EmitSound( "benny/weapons/1911/0".. math.random(1,3) ..".ogg", 110, 100, 1, CHAN_STATIC )
|
||||
|
||||
self:B_Ammo1( self:Clip1() - 1 )
|
||||
self:SetDelay1( CurTime() + 0.2 )
|
||||
|
@ -98,7 +113,8 @@ function SWEP:SecondaryAttack()
|
|||
end
|
||||
|
||||
function SWEP:Reload()
|
||||
if self:B_Wep1() then
|
||||
if self:B_Wep1() and self:Clip1() < self:B_Class1().Ammo then
|
||||
B_Sound( self, self.B_ClassT1.Sound_Reload )
|
||||
self:B_Ammo1( self:B_Class1().Ammo )
|
||||
end
|
||||
return true
|
||||
|
|
|
@ -130,7 +130,14 @@ captions = {
|
|||
function AddCaption( name, color, text, time_to_type, lifetime )
|
||||
if captions[#captions] and captions[#captions].name == name then
|
||||
local weh = captions[#captions]
|
||||
table.insert( weh.lines, { text = text, time_to_type=time_to_type, starttime=CurTime() } )
|
||||
local wehlast = weh.lines[#weh.lines]
|
||||
local patty = string.gsub(wehlast.text, " %((x%d+)%)", "")
|
||||
if patty == text then
|
||||
wehlast.repeated = (wehlast.repeated or 1) + 1
|
||||
wehlast.text = patty .. " (x" .. wehlast.repeated .. ")"
|
||||
else
|
||||
table.insert( weh.lines, { text = text, time_to_type=time_to_type, starttime=CurTime() } )
|
||||
end
|
||||
weh.lifetime = math.max( CurTime() + lifetime, weh.lifetime )
|
||||
else
|
||||
table.insert( captions, { name = name, color=color, lifetime=CurTime()+lifetime, lines = { { text=text, time_to_type=time_to_type, starttime=CurTime() } } })
|
||||
|
@ -140,11 +147,6 @@ end
|
|||
local color_caption = Color( 0, 0, 0, 127 )
|
||||
local mat_grad = Material( "benny/hud/grad.png", "mips smooth" )
|
||||
|
||||
local wep1 = {
|
||||
Name = "COBRA .45",
|
||||
Firemode = "SEMI",
|
||||
}
|
||||
|
||||
hook.Add( "HUDPaint", "Benny_HUDPaint", function()
|
||||
local sw, sh = ScrW(), ScrH()
|
||||
local b = ss(20)
|
||||
|
@ -196,9 +198,8 @@ hook.Add( "HUDPaint", "Benny_HUDPaint", function()
|
|||
local wep2 = wep.B_WepT2
|
||||
local wep2c = wep.B_ClassT2
|
||||
|
||||
do
|
||||
if false then -- Debug
|
||||
local ox, oy = 170, 24
|
||||
-- Debug
|
||||
surface.SetFont( "Benny_12" )
|
||||
surface.SetTextColor( scheme["fg"] )
|
||||
|
||||
|
@ -208,7 +209,7 @@ hook.Add( "HUDPaint", "Benny_HUDPaint", function()
|
|||
local num = 1
|
||||
if wep1 then for i, v in pairs( wep1 ) do
|
||||
surface.SetTextPos( ss(ox+16), ss(oy+10*num) )
|
||||
surface.DrawText( i .. ": " .. (v or "[no " .. i .. "]") )
|
||||
surface.DrawText( i .. ": " .. v )
|
||||
num = num + 1
|
||||
end end
|
||||
|
||||
|
@ -217,7 +218,7 @@ hook.Add( "HUDPaint", "Benny_HUDPaint", function()
|
|||
|
||||
if wep2 then for i, v in pairs( wep2 ) do
|
||||
surface.SetTextPos( ss(ox+128+16), ss(oy+10*num) )
|
||||
surface.DrawText( i .. ": " .. (v or "[no " .. i .. "]") )
|
||||
surface.DrawText( i .. ": " .. v )
|
||||
num = num + 1
|
||||
end end
|
||||
end
|
||||
|
@ -311,13 +312,14 @@ hook.Add( "HUDPaint", "Benny_HUDPaint", function()
|
|||
do -- Inventory
|
||||
local gap = 0
|
||||
for ID, Data in pairs( p:INV_Get() ) do
|
||||
local active = (wep:GetWep2() == ID) and "Wep2" or (wep:GetWep1() == ID) and "Wep1" or ""
|
||||
surface.SetDrawColor( scheme["bg"] )
|
||||
surface.DrawRect( b + ss(4), b + ss(4) + gap, ss(140), ss(30) )
|
||||
surface.DrawRect( b + ss(4), b + ss(4) + gap, ss(240), ss(30) )
|
||||
|
||||
surface.SetFont( "Benny_12" )
|
||||
surface.SetTextColor( scheme["fg"] )
|
||||
surface.SetTextPos( b + ss(4 + 4), b + ss(4 + 3) + gap )
|
||||
surface.DrawText( ID )
|
||||
surface.DrawText( ID .. " " .. active )
|
||||
|
||||
local str = ""
|
||||
for i, v in pairs( Data ) do
|
||||
|
@ -328,6 +330,11 @@ hook.Add( "HUDPaint", "Benny_HUDPaint", function()
|
|||
surface.SetTextColor( scheme["fg"] )
|
||||
surface.SetTextPos( b + ss(4 + 4), b + ss(4 + 3 + 8) + gap )
|
||||
surface.DrawText( str )
|
||||
|
||||
surface.SetFont( "Benny_12" )
|
||||
surface.SetTextColor( scheme["fg"] )
|
||||
surface.SetTextPos( b + ss(4 + 4), b + ss(4 + 3 + 8 + 8) + gap )
|
||||
-- surface.DrawText( active )
|
||||
gap = gap + ss(30+4)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -53,4 +53,56 @@ if CLIENT then
|
|||
assert(IsValid( ply ), "ply is invalid?")
|
||||
ply:INV_Get()[net.ReadString()] = net.ReadTable()
|
||||
end)
|
||||
end
|
||||
|
||||
CAPTIONS = {
|
||||
["1911.Fire"] = {
|
||||
Name = "Cobra .45",
|
||||
Color = color_white,
|
||||
Text = "[Cobra .45 fire]",
|
||||
TypeTime = 0.1,
|
||||
LifeTime = 0.5,
|
||||
},
|
||||
["1911.Reload"] = {
|
||||
Name = "Cobra .45",
|
||||
Color = color_white,
|
||||
Text = "[Cobra .45 reload]",
|
||||
TypeTime = 0.1,
|
||||
LifeTime = 0.5,
|
||||
},
|
||||
}
|
||||
|
||||
-- CAPTIONS["en-us"] = {}
|
||||
-- CAPTIONS = CAPTIONS["en-us"]
|
||||
|
||||
SOUNDS = {}
|
||||
|
||||
function AddSound( name, path, sndlevel, pitch, volume, channel )
|
||||
SOUNDS[name] = {
|
||||
path = path,
|
||||
sndlevel = sndlevel or 70,
|
||||
pitch = pitch or 100,
|
||||
volume = volume or 1,
|
||||
channel = channel or CHAN_STATIC,
|
||||
}
|
||||
end
|
||||
|
||||
local screwup = SERVER and Color(150, 255, 255) or Color(255, 200, 150)
|
||||
|
||||
function B_Sound( ent, tag )
|
||||
local tagt = SOUNDS[tag]
|
||||
if !tagt then MsgC( screwup, "Invalid sound " .. tag .. "\n" ) return end
|
||||
local path, sndlevel, pitch, volume, channel = tagt.path, tagt.sndlevel, tagt.pitch, tagt.volume, tagt.channel
|
||||
if istable( path ) then
|
||||
path = path[math.Round(util.SharedRandom( "B_Sound", 1, #path ))]
|
||||
end
|
||||
ent:EmitSound( path, sndlevel, pitch, volume, channel )
|
||||
if CLIENT then
|
||||
if CAPTIONS[tag] then
|
||||
local capt = CAPTIONS[tag]
|
||||
AddCaption( capt.Name, capt.Color, capt.Text, capt.TypeTime, capt.LifeTime )
|
||||
else
|
||||
MsgC( screwup, "No caption defined for " .. tag .. "\n" )
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,12 +1,22 @@
|
|||
|
||||
WEAPONS = {}
|
||||
|
||||
AddSound( "1911.Fire", {
|
||||
"benny/weapons/1911/01.ogg",
|
||||
"benny/weapons/1911/02.ogg",
|
||||
"benny/weapons/1911/03.ogg",
|
||||
}, 140, 100, 0.5, CHAN_STATIC )
|
||||
|
||||
AddSound( "1911.Reload", "benny/weapons/1911/slidedrop.ogg", 140, 100, 0.5, CHAN_STATIC )
|
||||
|
||||
local wep = {}
|
||||
WEAPONS["1911"] = wep
|
||||
wep.Name = "COBRA .45"
|
||||
wep.Description = "Hits hard. They don't make them like they used to! Low capacity."
|
||||
|
||||
wep.WModel = "models/weapons/w_pist_usp.mdl"
|
||||
wep.Sound_Fire = "1911.Fire"
|
||||
wep.Sound_Reload = "1911.Reload" -- placeholder
|
||||
|
||||
wep.Delay = (60/300)
|
||||
wep.Ammo = 8
|
||||
|
|
Loading…
Reference in New Issue