New way to holster & deploy weapons
This commit is contained in:
parent
a88beacc2d
commit
6253014a01
|
@ -197,6 +197,22 @@ end)
|
|||
function SWEP:Think()
|
||||
local p = self:GetOwner()
|
||||
|
||||
if p:GetReqID1() != self:D_GetID( false ) then
|
||||
if p:GetReqID1() != "" then
|
||||
self:BDeploy( false, p:GetReqID1() )
|
||||
else
|
||||
self:BHolster( false )
|
||||
end
|
||||
end
|
||||
|
||||
if p:GetReqID2() != self:D_GetID( true ) then
|
||||
if p:GetReqID2() != "" then
|
||||
self:BDeploy( true, p:GetReqID2() )
|
||||
else
|
||||
self:BHolster( true )
|
||||
end
|
||||
end
|
||||
|
||||
local wep1 = self:BTable( false )
|
||||
local wep1c = self:BClass( false )
|
||||
local wep2 = self:BTable( true )
|
||||
|
|
|
@ -1097,50 +1097,4 @@ do
|
|||
return true
|
||||
end
|
||||
end)
|
||||
end
|
||||
|
||||
local dads = {
|
||||
[KEY_1] = 1,
|
||||
[KEY_2] = 2,
|
||||
[KEY_3] = 3,
|
||||
[KEY_4] = 4,
|
||||
[KEY_5] = 5,
|
||||
[KEY_6] = 6,
|
||||
[KEY_7] = 7,
|
||||
[KEY_8] = 8,
|
||||
[KEY_9] = 9,
|
||||
[KEY_0] = 0,
|
||||
}
|
||||
|
||||
local function beatup( ply, num )
|
||||
local weighted = ply:INV_Weight()
|
||||
local inv = ply:INV_Get()
|
||||
local iflip = table.Flip( inv )
|
||||
|
||||
local invid = 0
|
||||
for _, item in pairs( weighted ) do
|
||||
local class = WeaponGet(item.Class)
|
||||
if class.Features == "firearm" or class.Features == "grenade" then
|
||||
invid = invid + 1
|
||||
if num == invid then
|
||||
RunConsoleCommand( "benny_inv_equip", iflip[item], "false", "false" )
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
hook.Add( "PlayerButtonDown", "Benny_PlayerButtonDown_Inv", function( ply, button )
|
||||
local wep = ply:BennyCheck()
|
||||
|
||||
if button == KEY_F then
|
||||
if tobool(ply:GetInfoNum("benny_wep_toggleaim", 1)) then
|
||||
wep:SetUserAim( !wep:GetUserAim() )
|
||||
else
|
||||
wep:SetUserAim( true )
|
||||
end
|
||||
end
|
||||
|
||||
if dads[button] then
|
||||
beatup( ply, dads[button] )
|
||||
end
|
||||
end)
|
||||
end
|
|
@ -44,81 +44,6 @@ function(cmd, args)
|
|||
return meow
|
||||
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 )
|
||||
local wep = ply:BennyCheck()
|
||||
if wep then
|
||||
local hand = args[2]!=nil and tobool(args[2])
|
||||
local id = args[1]
|
||||
local swap_or_replace = tobool(args[3])
|
||||
|
||||
local L, R = true, false
|
||||
local curr_r = wep:D_GetID( false )
|
||||
local curr_l = wep:D_GetID( true )
|
||||
|
||||
if hand == R then
|
||||
if curr_r == id then
|
||||
-- We already have this equipped
|
||||
return
|
||||
elseif swap_or_replace and curr_r != "" then
|
||||
-- We already have something equipped here, move it to the offhand
|
||||
wep:BDeploy( L, curr_r )
|
||||
elseif curr_l == id then
|
||||
-- You have the gun we want, snatched
|
||||
wep:BHolster( L )
|
||||
end
|
||||
wep:BDeploy( R, id )
|
||||
elseif hand == L then
|
||||
if curr_l == id then
|
||||
-- We already have this equipped
|
||||
return
|
||||
elseif swap_or_replace and curr_l != "" then
|
||||
-- We already have something equipped here, move it to the offhand
|
||||
wep:BDeploy( R, curr_l )
|
||||
elseif curr_r == id then
|
||||
-- You have the gun we want, snatched
|
||||
wep:BHolster( R )
|
||||
end
|
||||
wep:BDeploy( L, id )
|
||||
end
|
||||
end
|
||||
end,
|
||||
function(cmd, args)
|
||||
args = string.Trim(args:lower())
|
||||
local meow = {}
|
||||
for i, v in SortedPairs( Entity(1):INV_Get() ) do
|
||||
if string.lower(i):find(args) then
|
||||
table.insert( meow, cmd .. " " .. i )
|
||||
end
|
||||
end
|
||||
return meow
|
||||
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 )
|
||||
local wep = ply:BennyCheck()
|
||||
if wep then
|
||||
if wep:D_GetID( false ) == args[1] then
|
||||
wep:BHolster( false )
|
||||
elseif wep:D_GetID( true ) == args[1] then
|
||||
wep:BHolster( true )
|
||||
end
|
||||
end
|
||||
end)
|
||||
|
||||
concommand.Add("benny_inv_sync", function( ply, cmd, args )
|
||||
local inv = ply:INV_Get()
|
||||
|
||||
-- PROTO: WriteTable.
|
||||
net.Start("benny_syncinv")
|
||||
net.WriteUInt( table.Count( inv ), 4 )
|
||||
for ID, Data in pairs( inv ) do
|
||||
net.WriteString( ID )
|
||||
net.WriteTable( Data )
|
||||
end
|
||||
net.Send( ply )
|
||||
end)
|
||||
|
||||
concommand.Add("benny_inv_discard", function( ply, cmd, args )
|
||||
local inv = ply:INV_Get()
|
||||
local wep = ply:GetActiveWeapon()
|
||||
|
@ -143,27 +68,6 @@ concommand.Add("benny_inv_discard", function( ply, cmd, args )
|
|||
end
|
||||
end)
|
||||
|
||||
-- Network to client
|
||||
if CLIENT then
|
||||
net.Receive( "benny_syncinv", function( len, ply )
|
||||
local ply = LocalPlayer()
|
||||
local inv = ply:INV_Get()
|
||||
|
||||
table.Empty( inv )
|
||||
for i=1, net.ReadUInt( 4 ) do
|
||||
inv[net.ReadString()] = net.ReadTable()
|
||||
end
|
||||
end)
|
||||
net.Receive( "benny_sendinvitem", function( len, ply )
|
||||
local ply = LocalPlayer()
|
||||
ply:INV_Get()[net.ReadString()] = net.ReadTable()
|
||||
end)
|
||||
net.Receive( "benny_discardinvitem", function( len, ply )
|
||||
local ply = LocalPlayer()
|
||||
ply:INV_Get()[net.ReadString()] = nil
|
||||
end)
|
||||
end
|
||||
|
||||
hook.Add( "PlayerDeathSound", "Benny_PlayerDeathSound", function( ply )
|
||||
return true -- we don't want the default sound!
|
||||
end )
|
||||
|
|
|
@ -0,0 +1,45 @@
|
|||
|
||||
-- Predicted weapon switching
|
||||
|
||||
local dads = {
|
||||
[KEY_1] = 1,
|
||||
[KEY_2] = 2,
|
||||
[KEY_3] = 3,
|
||||
[KEY_4] = 4,
|
||||
[KEY_5] = 5,
|
||||
[KEY_6] = 6,
|
||||
[KEY_7] = 7,
|
||||
[KEY_8] = 8,
|
||||
[KEY_9] = 9,
|
||||
[KEY_0] = 0,
|
||||
}
|
||||
|
||||
local function beatup( ply, num )
|
||||
local weighted = ply:INV_Weight()
|
||||
local inv = ply:INV_Get()
|
||||
local iflip = table.Flip( inv )
|
||||
|
||||
local invid = 0
|
||||
for _, item in pairs( weighted ) do
|
||||
local class = WeaponGet(item.Class)
|
||||
if class.Features == "firearm" or class.Features == "grenade" then
|
||||
invid = invid + 1
|
||||
if num == invid then
|
||||
--RunConsoleCommand( "benny_inv_equip", iflip[item], "false", "false" )
|
||||
if ply:KeyDown(IN_ZOOM) then
|
||||
ply:SetReqID2(iflip[item])
|
||||
else
|
||||
ply:SetReqID1(iflip[item])
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
hook.Add( "PlayerButtonDown", "Benny_PlayerButtonDown_Inv", function( ply, button )
|
||||
local wep = ply:BennyCheck()
|
||||
|
||||
if dads[button] then
|
||||
beatup( ply, dads[button] )
|
||||
end
|
||||
end)
|
|
@ -31,6 +31,9 @@ function PLAYER:SetupDataTables()
|
|||
self.Player:NetworkVar( "Vector", 1, "VaultPos2")
|
||||
|
||||
self.Player:NetworkVar( "Float", 2, "Stamina" )
|
||||
|
||||
self.Player:NetworkVar( "String", 0, "ReqID1")
|
||||
self.Player:NetworkVar( "String", 1, "ReqID2")
|
||||
end
|
||||
|
||||
player_manager.RegisterClass( "player_benny", PLAYER, "player_default" )
|
||||
|
|
Loading…
Reference in New Issue