Holy SHIT. Predicted Inventory selection.
This commit is contained in:
parent
2fefc88b86
commit
6b6438e05f
|
@ -48,7 +48,8 @@ function SWEP:BDeploy( hand, id )
|
||||||
assert( isbool(hand), "You forgot the hand." )
|
assert( isbool(hand), "You forgot the hand." )
|
||||||
assert( isstring(id), "You forgot the ID." )
|
assert( isstring(id), "You forgot the ID." )
|
||||||
if self:D_GetID( hand ) == id then
|
if self:D_GetID( hand ) == id then
|
||||||
return -- PROTO: If you're in the middle of holstering, cancel it
|
-- This breaks prediction somewhat!!
|
||||||
|
-- return -- PROTO: If you're in the middle of holstering, cancel it
|
||||||
elseif self:D_GetID( hand ) != "" then
|
elseif self:D_GetID( hand ) != "" then
|
||||||
self:BHolster( hand )
|
self:BHolster( hand )
|
||||||
end
|
end
|
||||||
|
@ -88,5 +89,6 @@ function SWEP:BHolster( hand )
|
||||||
end
|
end
|
||||||
|
|
||||||
self:D_SetID( hand, "" )
|
self:D_SetID( hand, "" )
|
||||||
|
self:D_SetMagID( hand, 0 )
|
||||||
self:D_SetClip( hand, 0 )
|
self:D_SetClip( hand, 0 )
|
||||||
end
|
end
|
|
@ -234,7 +234,7 @@ hook.Add( "HUDPaint", "Benny_HUDPaint", function()
|
||||||
local b = ss(20)
|
local b = ss(20)
|
||||||
local p = LocalPlayer()
|
local p = LocalPlayer()
|
||||||
-- PROTO: Make sure this is the 'benny' weapon.
|
-- PROTO: Make sure this is the 'benny' weapon.
|
||||||
local wep = p:GetActiveWeapon()
|
local wep = p:BennyCheck()
|
||||||
|
|
||||||
local active = GetConVar("benny_hud_tempactive"):GetString()
|
local active = GetConVar("benny_hud_tempactive"):GetString()
|
||||||
local scheme = schemes[active]
|
local scheme = schemes[active]
|
||||||
|
@ -287,7 +287,7 @@ hook.Add( "HUDPaint", "Benny_HUDPaint", function()
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
if p:BennyCheck() then -- Weapon
|
if wep then -- Weapon
|
||||||
local inv = p:INV_Get()
|
local inv = p:INV_Get()
|
||||||
local wep1 = wep:BTable( false )
|
local wep1 = wep:BTable( false )
|
||||||
local wep1c = wep:BClass( false )
|
local wep1c = wep:BClass( false )
|
||||||
|
@ -309,7 +309,9 @@ hook.Add( "HUDPaint", "Benny_HUDPaint", function()
|
||||||
surface.SetDrawColor( scheme["fg"] )
|
surface.SetDrawColor( scheme["fg"] )
|
||||||
surface.DrawRect( p_x+pb, p_y+pb, p_w-pb2, t_h )
|
surface.DrawRect( p_x+pb, p_y+pb, p_w-pb2, t_h )
|
||||||
|
|
||||||
draw.SimpleText( wep1c.Name, "Benny_16", p_x+ss(6), p_y+ss(5), scheme["bg"], TEXT_ALIGN_TOP, TEXT_ALIGN_LEFT )
|
draw.SimpleText( wep1c.Name, "Benny_16", p_x+ss(6), p_y+ss(5), scheme["bg"], TEXT_ALIGN_LEFT, TEXT_ALIGN_TOP )
|
||||||
|
|
||||||
|
draw.SimpleText( wep:D_GetID( false ), "Benny_10", p_x+p_w-pb2, p_y+ss(7), scheme["bg"], TEXT_ALIGN_RIGHT, TEXT_ALIGN_TOP )
|
||||||
|
|
||||||
if wep:BClass( false ).Firemodes then -- Firemode
|
if wep:BClass( false ).Firemodes then -- Firemode
|
||||||
surface.SetDrawColor( scheme["fg"] )
|
surface.SetDrawColor( scheme["fg"] )
|
||||||
|
@ -444,7 +446,19 @@ hook.Add( "HUDPaint", "Benny_HUDPaint", function()
|
||||||
local bump = 0
|
local bump = 0
|
||||||
|
|
||||||
-- PROTO: Maybe check this every 10hz instead
|
-- PROTO: Maybe check this every 10hz instead
|
||||||
|
do
|
||||||
|
-- local flipped = table.Flip( Entity(1):INV_ListFromBuckets() )
|
||||||
|
-- local id = flipped[ Entity(1):GetActiveWeapon():D_GetID( false ) ]
|
||||||
|
|
||||||
|
for n, bucket in ipairs( inventorylist ) do
|
||||||
|
for i, v in ipairs( bucket ) do
|
||||||
|
if v == wep:D_GetID( false ) then
|
||||||
|
bucket_selected = n
|
||||||
|
item_selected = i
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
for i, bucket in ipairs( inventorylist ) do
|
for i, bucket in ipairs( inventorylist ) do
|
||||||
surface.SetDrawColor( scheme["bg"] )
|
surface.SetDrawColor( scheme["bg"] )
|
||||||
|
@ -476,7 +490,7 @@ hook.Add( "HUDPaint", "Benny_HUDPaint", function()
|
||||||
else
|
else
|
||||||
for d, item in ipairs( bucket ) do
|
for d, item in ipairs( bucket ) do
|
||||||
local idata = WEAPONS[inv[item].Class]
|
local idata = WEAPONS[inv[item].Class]
|
||||||
local sel = d==item_selected
|
local sel = item==wep:D_GetID( false )--d==item_selected
|
||||||
surface.SetDrawColor( scheme["bg"] )
|
surface.SetDrawColor( scheme["bg"] )
|
||||||
surface.DrawRect( bump + b, (item_start+ybump) + b, size_textx, (sel and size_texty_sel or size_texty) )
|
surface.DrawRect( bump + b, (item_start+ybump) + b, size_textx, (sel and size_texty_sel or size_texty) )
|
||||||
if sel then
|
if sel then
|
||||||
|
@ -678,7 +692,9 @@ do
|
||||||
local ply = LocalPlayer()
|
local ply = LocalPlayer()
|
||||||
local buckets = ply:INV_Buckets()
|
local buckets = ply:INV_Buckets()
|
||||||
if buckets[bucket_selected] and buckets[bucket_selected][item_selected] then
|
if buckets[bucket_selected] and buckets[bucket_selected][item_selected] then
|
||||||
RunConsoleCommand( "benny_inv_equip", buckets[bucket_selected][item_selected] )
|
ply.CLIENTDESIRE = buckets[bucket_selected][item_selected]
|
||||||
|
|
||||||
|
--RunConsoleCommand( "benny_inv_equip", buckets[bucket_selected][item_selected] )
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
local function Locate( ply, buckets, id )
|
local function Locate( ply, buckets, id )
|
||||||
|
|
|
@ -83,9 +83,9 @@ if SERVER then
|
||||||
table.insert( regenlist, id )
|
table.insert( regenlist, id )
|
||||||
else
|
else
|
||||||
-- Punish
|
-- Punish
|
||||||
print( "The item the client requested didn't exist. Malicious? Not supporting for 30 seconds." )
|
print( ply, "The item the client requested, '" .. tostring(id) .."' didn't exist. Malicious?") -- Matters in public servers!! -- Not supporting for 5 seconds." )
|
||||||
ply.CheckerRequestBan = CurTime() + 30
|
-- ply.CheckerRequestBan = CurTime() + 5
|
||||||
return
|
-- return
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -61,7 +61,7 @@ hook.Add( "CreateMove", "Benny_CreateMove", function( cmd )
|
||||||
-- ad:Normalize()
|
-- ad:Normalize()
|
||||||
-- ad:Mul(320)
|
-- ad:Mul(320)
|
||||||
|
|
||||||
cmd:ClearMovement()
|
--cmd:ClearMovement()
|
||||||
cmd:SetForwardMove( ad.x )
|
cmd:SetForwardMove( ad.x )
|
||||||
cmd:SetSideMove( ad.y )
|
cmd:SetSideMove( ad.y )
|
||||||
|
|
||||||
|
@ -132,7 +132,7 @@ hook.Add( "CreateMove", "Benny_CreateMove", function( cmd )
|
||||||
moveintent:Rotate( fixang )
|
moveintent:Rotate( fixang )
|
||||||
|
|
||||||
|
|
||||||
cmd:ClearMovement()
|
-- cmd:ClearMovement()
|
||||||
cmd:SetForwardMove( moveintent.x )
|
cmd:SetForwardMove( moveintent.x )
|
||||||
cmd:SetSideMove( moveintent.y )
|
cmd:SetSideMove( moveintent.y )
|
||||||
end
|
end
|
||||||
|
|
|
@ -21,7 +21,7 @@ local PT = FindMetaTable( "Player" )
|
||||||
|
|
||||||
function PT:BennyCheck()
|
function PT:BennyCheck()
|
||||||
local wep = self:GetActiveWeapon()
|
local wep = self:GetActiveWeapon()
|
||||||
return ( wep:IsValid() and wep:GetClass() == "benny" and wep.GetUserAim )
|
return ( wep:IsValid() and wep:GetClass() == "benny" and wep.GetUserAim ) and wep or false
|
||||||
end
|
end
|
||||||
|
|
||||||
function PT:CamSpot( ang )
|
function PT:CamSpot( ang )
|
||||||
|
@ -136,4 +136,56 @@ do
|
||||||
end
|
end
|
||||||
return inventorylist
|
return inventorylist
|
||||||
end
|
end
|
||||||
|
-- PROTO: I am on an outdated version of GMod.
|
||||||
|
function table.Flip( tab )
|
||||||
|
local res = {}
|
||||||
|
|
||||||
|
for k, v in pairs( tab ) do
|
||||||
|
res[ v ] = k
|
||||||
|
end
|
||||||
|
|
||||||
|
return res
|
||||||
|
end
|
||||||
|
function PT:INV_ListFromBuckets()
|
||||||
|
local buckets = self:INV_Buckets()
|
||||||
|
|
||||||
|
local complete = {}
|
||||||
|
for n, bucket in ipairs( buckets ) do
|
||||||
|
for i, v in ipairs( bucket ) do
|
||||||
|
table.insert( complete, v )
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
return complete
|
||||||
|
end
|
||||||
end
|
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()
|
||||||
|
|
||||||
|
if id > 0 and inv_bucketlist[id] and inv[inv_bucketlist[id]] then
|
||||||
|
wep:BDeploy( false, inv_bucketlist[ id ] )
|
||||||
|
if CLIENT and IsFirstTimePredicted() and wep:D_GetID( false ) == inv_bucketlist[ply.CLIENTDESIRE] then
|
||||||
|
ply.CLIENTDESIRE = 0
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
end)
|
||||||
|
|
||||||
|
|
||||||
|
-- cmd:KeyDown( IN_WEAPON1 )
|
||||||
|
-- cmd:KeyDown( IN_WEAPON2 )
|
||||||
|
-- cmd:KeyDown( IN_BULLRUSH )
|
||||||
|
-- cmd:KeyDown( IN_GRENADE1 )
|
||||||
|
-- cmd:KeyDown( IN_GRENADE2 )
|
|
@ -929,7 +929,10 @@ do -- Grenades, nothing here is guaranteed.
|
||||||
if SERVER then GrenadeCreate( self, data ) end
|
if SERVER then GrenadeCreate( self, data ) end
|
||||||
local id = self:D_GetID( false )
|
local id = self:D_GetID( false )
|
||||||
self:BHolster( false )
|
self:BHolster( false )
|
||||||
|
|
||||||
|
if SERVER or (CLIENT and IsFirstTimePredicted()) then
|
||||||
p:INV_Discard( id )
|
p:INV_Discard( id )
|
||||||
|
end
|
||||||
|
|
||||||
local subsequent = p:INV_Find( data.Class )[1]
|
local subsequent = p:INV_Find( data.Class )[1]
|
||||||
if subsequent then
|
if subsequent then
|
||||||
|
|
Loading…
Reference in New Issue