diff --git a/gamemodes/benny/entities/weapons/benny/sh_inv.lua b/gamemodes/benny/entities/weapons/benny/sh_inv.lua index ec28331..4409bd7 100644 --- a/gamemodes/benny/entities/weapons/benny/sh_inv.lua +++ b/gamemodes/benny/entities/weapons/benny/sh_inv.lua @@ -71,23 +71,14 @@ function SWEP:BDeploy( hand, id ) assert( item, "That item doesn't exist. " .. tostring(item) ) self:D_SetID( hand, id ) + self:D_SetMagID( hand, "" ) + self:D_SetClip( hand, 0 ) if item.Loaded then - local mid = inv[ item.Loaded ] - if mid then - self:D_SetMagID( hand, item.Loaded ) - self:D_SetClip( hand, mid.Ammo ) - end - end - - -- PROTO: Make grenade/melee/firearm logic way way better. - if class.Features == "firearm" then - -- if item.Loaded != "" then - -- assert( inv[ item.Loaded ], "That magazine doesn't exist." ) - -- end - - -- self:D_SetClip( hand, item.Loaded == "" and 0 or inv[ "Ammo" .. item.Loaded ] ) - else - self:D_SetClip( hand, 0 ) + local mid = item.Loaded + local midi = inv[ mid ] + assert( midi, "Deploy: Magazine doesn't exist in the inventory!! " .. tostring(item.Loaded) ) + self:D_SetMagID( hand, mid ) + self:D_SetClip( hand, midi.Ammo ) end end diff --git a/gamemodes/benny/entities/weapons/benny/shared.lua b/gamemodes/benny/entities/weapons/benny/shared.lua index b986c61..0d2c03a 100644 --- a/gamemodes/benny/entities/weapons/benny/shared.lua +++ b/gamemodes/benny/entities/weapons/benny/shared.lua @@ -77,7 +77,6 @@ function SWEP:B_Ammo( hand, value ) local p = self:GetOwner() local inv = p:INV_Get() self:D_SetClip( hand, value ) - print( hand, value ) assert( self:D_GetMagID( hand ) != "", "There is no magazine loaded!" ) inv[ self:D_GetMagID( hand ) ].Ammo = value end @@ -105,57 +104,45 @@ function SWEP:Reload() local p = self:GetOwner() local inv = p:INV_Get() if p:KeyPressed( IN_RELOAD ) then - -- for i=1, 2 do - local hand = self:GetTempHandedness()--true--i==2 - local wep_table = self:BTable( hand ) - local wep_class = self:BClass( hand ) - if wep_table then - print( "First Test: ", i, wep_table, WEAPONS[wep_table.Class].Name ) - if wep_class.Reload then - if wep_class.Reload( self, wep_table ) then return end - end - if self:D_GetDelay( hand ) > CurTime() then - return false - end + local hand = self:GetTempHandedness() + local wep_table = self:BTable( hand ) + local wep_class = self:BClass( hand ) + if wep_table then + if wep_class.Reload then + if wep_class.Reload( self, wep_table ) then return end + end + if self:D_GetDelay( hand ) > CurTime() then + return false + end - local mid = self:D_GetMagID( hand ) + local mid = self:D_GetMagID( hand ) + if SERVER or (CLIENT and IsFirstTimePredicted()) then if mid != "" then - B_Sound( self, wep_class.Sound_MagOut ) - if inv[mid].Ammo == 0 then if SERVER or (CLIENT and IsFirstTimePredicted()) then p:INV_Discard( mid ) end end - self:D_SetClip( hand, 0 ) self:D_SetMagID( hand, "" ) + self:D_SetClip( hand, 0 ) + B_Sound( self, wep_class.Sound_MagOut ) wep_table.Loaded = "" else local maglist = p:INV_FindMag( "mag_" .. wep_table.Class ) - PrintTable( maglist ) local mag = maglist[1] if mag then - if hand then - self:SetWep2_Clip( mag ) - self:SetClip2( inv[mag].Ammo ) - inv[self:GetWep2()].Loaded = mag - else - self:SetWep1_Clip( mag ) - self:SetClip1( inv[mag].Ammo ) - inv[self:GetWep1()].Loaded = mag - end - -- wep_table.Loaded = mag - -- self:D_SetMagID( hand, mag ) - -- self:D_SetClip( hand, inv[mag].Ammo ) + self:D_SetMagID( hand, mag ) + self:D_SetClip( hand, inv[mag].Ammo ) + wep_table.Loaded = mag B_Sound( self, wep_class.Sound_MagIn ) else B_Sound( self, "Common.NoAmmo" ) end end - self:TPReload( self:GetTempHandedness() ) end - -- end + self:TPReload( self:GetTempHandedness() ) + end end return true end diff --git a/gamemodes/benny/gamemode/modules/player/cl_hud.lua b/gamemodes/benny/gamemode/modules/player/cl_hud.lua index 6e5fea9..ffd2a78 100644 --- a/gamemodes/benny/gamemode/modules/player/cl_hud.lua +++ b/gamemodes/benny/gamemode/modules/player/cl_hud.lua @@ -240,9 +240,15 @@ hook.Add( "HUDPaint", "Benny_HUDPaint", function() local scheme = schemes[active] do -- Health + local b_w, b_h = ss(142), ss(32) + local b_bh = ss(14) + local b_bh2 = ss(8) + local b_s = ss(4) + local b_s2 = b_s*2 + local b_x, b_y = b, sh - b - b_h -- BG surface.SetDrawColor( scheme["bg"] ) - surface.DrawRect( b, sh - b - ss(22), ss(140), ss(14+8) ) + surface.DrawRect( b_x, b_y, b_w, b_h ) local hp = p:Health()/100 --CurTime()*0.5 % 1 local ti = (CurTime()*0.75 / (hp)) % 1 @@ -250,24 +256,41 @@ hook.Add( "HUDPaint", "Benny_HUDPaint", function() -- Text underneath surface.SetFont( "Benny_18" ) surface.SetTextColor( scheme["fg"] ) - surface.SetTextPos( b + ss(6), sh - b - ss(22) + ss(3) ) + surface.SetTextPos( b_x + ss(6), b_y + ss(3) ) surface.DrawText( scheme["name"] ) -- Bar surface.SetDrawColor( scheme["fg"] ) - surface.DrawRect( b + ss(4), sh - b - ss(22) + ss(4), ss((140*hp)-8), ss(14) ) + surface.DrawOutlinedRect( b_x + b_s, b_y + b_s, ss(142-8), b_bh, ss( 0.5 ) ) + surface.DrawRect( b_x + b_s + ss(1), b_y + b_s + ss(1), ss(142*hp-8-2), b_bh - ss(2) ) heartbeatcol.a = math.ease.OutQuint(1-ti)*255 surface.SetDrawColor( heartbeatcol ) surface.SetMaterial( mat_grad ) - surface.DrawTexturedRect( b + ss(4), sh - b - ss(22) + ss(4), ss((140*hp*ti)-8), ss(14) ) + surface.DrawTexturedRect( b_x + b_s + ss(1), b_y + b_s + ss(1), ss(142*hp*ti-8-2), b_bh - ss(2) ) -- Bar text surface.SetTextColor( scheme["bg"] ) - surface.SetTextPos( b + ss(6), sh - b - ss(22) + ss(3) ) - render.SetScissorRect( b + ss(4), sh - b - ss(22) + ss(4), b + ss(4) + ss((140*hp)-8), sh - b - ss(22) + ss(4) + ss(14), true ) -- Enable the rect + surface.SetTextPos( b_x + ss(6), b_y + ss(3) ) + render.SetScissorRect( b_x + b_s, b_y + b_s, b_x + b_s + ss(142*hp-8), b_y + b_s + b_bh, true ) -- Enable the rect surface.DrawText( scheme["name"] ) render.SetScissorRect( 0, 0, 0, 0, false ) -- Disable after you are done + + if true then -- Stamina + local perc = CurTime()*0.5 % 2 + if perc > 1 then perc = 2-perc end + for i=1, 4 do + local localperc = math.Clamp( math.Remap( perc, (0.25*(i-1)), (0.25*(i)), 0, 1 ), 0, 1 ) + surface.SetDrawColor( scheme["fg"] ) + surface.DrawOutlinedRect( b_x + b_s + ((i-1)*ss(32+2)), b_y + b_bh + ss(4+2), ss(32), b_bh2, ss(0.5) ) + surface.DrawRect( b_x + b_s + ((i-1)*ss(32+2)) + ss(1), b_y + b_bh + ss(4+2) + ss(1), ss(32*localperc) - ss(2), b_bh2 - ss(2) ) + end + end + if wep and wep:GetTempHandedness() then + surface.SetDrawColor( scheme["bg"] ) + surface.DrawRect( b_x, b_y - ss( 12+3 ), ss( 86 ), ss( 12 ) ) + draw.SimpleText( "LEFT-HANDED MODE", "Benny_12", b_x + ss( 2 ), b_y - ss( 12+2 ), scheme["fg"], TEXT_ALIGN_LEFT, TEXT_ALIGN_TOP ) + end end do -- Vaulting @@ -348,6 +371,12 @@ hook.Add( "HUDPaint", "Benny_HUDPaint", function() count = count + 1 end draw.SimpleText( wep:D_GetClip( hand ), "Benny_12", p_x + p_w - pb - ss(1), p_y + p_h - offset - ss(12+3), scheme["fg"], TEXT_ALIGN_RIGHT, TEXT_ALIGN_TOP ) + + if wep:D_GetMagID( hand ) != wep_table.Loaded then + surface.SetDrawColor( scheme["bg"] ) + surface.DrawRect( p_x, p_y - ss( 12+3 ), ss( 66 ), ss( 12 ) ) + draw.SimpleText( "!! Mag desync.", "Benny_12", p_x + ss( 2 ), p_y - ss( 12+2 ), scheme["fg"], TEXT_ALIGN_LEFT, TEXT_ALIGN_TOP ) + end end if wep_class.Ammo then -- Magazines local m_w, m_h = ss( 14 ), ss( 24 ) @@ -366,7 +395,7 @@ hook.Add( "HUDPaint", "Benny_HUDPaint", function() table.insert( newmaglist, v ) end for id, tag in ipairs( newmaglist ) do - assert( inv[tag], "That magazine doesn't exist." ) + --assert( inv[tag], "That magazine doesn't exist. " .. tag ) local chunk = ((ss(1)+m_w)*(id-1)) surface.SetDrawColor( scheme["bg"] ) surface.DrawRect( m_x - chunk, m_y, m_w, m_h ) @@ -727,7 +756,7 @@ hook.Add( "HUDPaint", "Benny_HUDPaint", function() end end - if false and p:BennyCheck() then + if true and p:BennyCheck() then local bx, by = sw/2, sh*(0.75) local mx = 50 @@ -737,7 +766,9 @@ hook.Add( "HUDPaint", "Benny_HUDPaint", function() draw.SimpleText( "Clip1: " .. wep:Clip1(), "Trebuchet24", bx-mx, by+24*0, color_white, TEXT_ALIGN_RIGHT, TEXT_ALIGN_TOP ) draw.SimpleText( "ID1: " .. wep:GetWep1(), "Trebuchet24", bx-mx, by+24*1, color_white, TEXT_ALIGN_RIGHT, TEXT_ALIGN_TOP ) draw.SimpleText( "MagID1: " .. wep:D_GetMagID( false ), "Trebuchet24", bx-mx, by+24*2, color_white, TEXT_ALIGN_RIGHT, TEXT_ALIGN_TOP ) - draw.SimpleText( "T_MagID1: " .. wep1_table.Loaded, "Trebuchet24", bx-mx, by+24*3, color_white, TEXT_ALIGN_RIGHT, TEXT_ALIGN_TOP ) + if wep1_table.Loaded then + draw.SimpleText( "T_MagID1: " .. wep1_table.Loaded, "Trebuchet24", bx-mx, by+24*3, color_white, TEXT_ALIGN_RIGHT, TEXT_ALIGN_TOP ) + end end local wep2_table, wep2_class = wep:BTable( true ), wep:BClass( true ) @@ -746,7 +777,9 @@ hook.Add( "HUDPaint", "Benny_HUDPaint", function() draw.SimpleText( "Clip2: " .. wep:Clip2(), "Trebuchet24", bx+mx, by+24*0, color_white, TEXT_ALIGN_LEFT, TEXT_ALIGN_TOP ) draw.SimpleText( "ID2: " .. wep:GetWep2(), "Trebuchet24", bx+mx, by+24*1, color_white, TEXT_ALIGN_LEFT, TEXT_ALIGN_TOP ) draw.SimpleText( "MagID2: " .. wep:D_GetMagID( true ), "Trebuchet24", bx+mx, by+24*2, color_white, TEXT_ALIGN_LEFT, TEXT_ALIGN_TOP ) - draw.SimpleText( "T_MagID2: " .. wep2_table.Loaded, "Trebuchet24", bx+mx, by+24*3, color_white, TEXT_ALIGN_LEFT, TEXT_ALIGN_TOP ) + if wep2_table.Loaded then + draw.SimpleText( "T_MagID2: " .. wep2_table.Loaded, "Trebuchet24", bx+mx, by+24*3, color_white, TEXT_ALIGN_LEFT, TEXT_ALIGN_TOP ) + end end end end ) @@ -756,9 +789,9 @@ do local ply = LocalPlayer() local buckets = ply:INV_Buckets() if buckets[bucket_selected] and buckets[bucket_selected][item_selected] then - ply.CLIENTDESIRE = buckets[bucket_selected][item_selected] + -- ply.CLIENTDESIRE = buckets[bucket_selected][item_selected] - --RunConsoleCommand( "benny_inv_equip", buckets[bucket_selected][item_selected] ) + RunConsoleCommand( "benny_inv_equip", buckets[bucket_selected][item_selected] ) end end local function Locate( ply, buckets, id ) diff --git a/gamemodes/benny/gamemode/modules/player/sh_basic.lua b/gamemodes/benny/gamemode/modules/player/sh_basic.lua index 863ff14..a6d23ba 100644 --- a/gamemodes/benny/gamemode/modules/player/sh_basic.lua +++ b/gamemodes/benny/gamemode/modules/player/sh_basic.lua @@ -46,7 +46,8 @@ end, "arg 1: player ent index, arg 2: classname") -- PROTO: Move this all into weapon code. concommand.Add("benny_inv_equip", function( ply, cmd, args ) - if ply:BennyCheck() then ply:GetActiveWeapon():BDeploy( args[2] and true or false, args[1] ) end + local wep = ply:BennyCheck() + if wep then wep:BDeploy( wep:GetTempHandedness(), args[1] ) end end, function(cmd, args) args = string.Trim(args:lower()) @@ -61,7 +62,8 @@ end, "arg 1: item id, arg 2 does offhand") -- PROTO: Move this all into weapon code. concommand.Add("benny_inv_holster", function( ply, cmd, args ) - if ply:BennyCheck() then ply:GetActiveWeapon():BHolster( ply:GetActiveWeapon():GetTempHandedness() ) end + local wep = ply:BennyCheck() + if wep then wep:BHolster( wep:GetTempHandedness() ) end end) concommand.Add("benny_inv_sync", function( ply, cmd, args ) @@ -91,12 +93,12 @@ concommand.Add("benny_inv_discard", function( ply, cmd, args ) if wep:GetWep1() == args[1] then wep:SetWep1( "" ) - wep:SetWep1Clip( 0 ) + wep:SetWep1_Clip( "" ) wep:SetClip1( 0 ) end if wep:GetWep2() == args[1] then wep:SetWep2( "" ) - wep:SetWep2Clip( 0 ) + wep:SetWep2_Clip( "" ) wep:SetClip2( 0 ) end end) diff --git a/gamemodes/benny/gamemode/modules/player/sh_checker.lua b/gamemodes/benny/gamemode/modules/player/sh_checker.lua index 3ec47f1..e75da48 100644 --- a/gamemodes/benny/gamemode/modules/player/sh_checker.lua +++ b/gamemodes/benny/gamemode/modules/player/sh_checker.lua @@ -10,7 +10,7 @@ if easyway then Player(data.userid).CheckerReady = true end ) - local checkerinterval = 12 + local checkerinterval = 1 util.AddNetworkString( "Benny_Checker" ) hook.Add( "PlayerTick", "Benny_Checker", function( ply ) @@ -23,7 +23,7 @@ if easyway then net.WriteString( i ) net.WriteTable( v ) end - print( net.BytesWritten() ) + print( ply, net.BytesWritten() ) net.Send( ply ) ply.CheckerLast = CurTime() end @@ -62,6 +62,9 @@ if SERVER then net.WriteUInt( table.Count(inv), UINTBITS ) for i, v in pairs( inv ) do net.WriteString( i ) + + net.WriteBool( v.Loaded ) + if v.Loaded then net.WriteString( v.Loaded ) end end net.Send( ply ) ply.CheckerLast = CurTime() @@ -108,7 +111,13 @@ else local amt = net.ReadUInt( UINTBITS ) local evallist = {} for i=1, amt do - evallist[net.ReadString()] = true + local id = net.ReadString() + local loaded_exists = net.ReadBool() + local loaded = nil + if loaded_exists then + loaded = net.ReadString() + end + evallist[id] = loaded or true end local inv = ply:INV_Get() @@ -118,6 +127,9 @@ else for i, v in pairs( evallist ) do if inv[i] then -- Success + if isstring(v) then + inv[i].Loaded = v + end else missinglist[i] = true end diff --git a/gamemodes/benny/gamemode/modules/player/sh_player.lua b/gamemodes/benny/gamemode/modules/player/sh_player.lua index f1c9873..837a1c6 100644 --- a/gamemodes/benny/gamemode/modules/player/sh_player.lua +++ b/gamemodes/benny/gamemode/modules/player/sh_player.lua @@ -178,25 +178,24 @@ end -- weapon select hook.Add("StartCommand", "Benny_INV_StartCommand", function( ply, cmd ) - local wep = ply:BennyCheck() - if wep then - local inv = ply:INV_Get() - local inv_bucketlist = ply:INV_ListFromBuckets() - local inv_bucketlist_flipped = table.Flip( inv_bucketlist ) - if CLIENT and ply.CLIENTDESIRE and inv[ply.CLIENTDESIRE ] and inv_bucketlist_flipped[ ply.CLIENTDESIRE ] then - cmd:SetUpMove( inv_bucketlist_flipped[ ply.CLIENTDESIRE ] ) - end - local id = cmd:GetUpMove() - local hand = wep:GetTempHandedness() - if id > 0 and inv_bucketlist[id] and inv[inv_bucketlist[id]] then - wep:BDeploy( hand, inv_bucketlist[ id ] ) - if CLIENT and (wep:D_GetID( hand ) == ply.CLIENTDESIRE) then - ply.CLIENTDESIRE = 0 - print("Fixed") - end - end - - end + -- local wep = ply:BennyCheck() + -- if wep then + -- local hand = wep:GetTempHandedness() + -- local inv = ply:INV_Get() + -- local inv_bucketlist = ply:INV_ListFromBuckets() + -- local inv_bucketlist_flipped = table.Flip( inv_bucketlist ) + -- if CLIENT and ply.CLIENTDESIRE and inv[ply.CLIENTDESIRE ] and inv_bucketlist_flipped[ ply.CLIENTDESIRE ] then + -- cmd:SetUpMove( inv_bucketlist_flipped[ ply.CLIENTDESIRE ] ) + -- end + -- if CLIENT and (wep:D_GetID( hand ) == ply.CLIENTDESIRE) then + -- ply.CLIENTDESIRE = 0 + -- print("Fixed") + -- end + -- local id = cmd:GetUpMove() + -- if id > 0 and inv_bucketlist[id] and inv[inv_bucketlist[id]] then + -- wep:BDeploy( hand, inv_bucketlist[ id ] ) + -- end + -- end end)