Benny/gamemodes/benny/gamemode/modules/player/sh_basic.lua

131 lines
3.1 KiB
Lua
Raw Normal View History

2023-09-13 22:15:43 -04:00
2023-09-24 01:19:23 -04:00
if SERVER then
2023-09-25 17:26:52 -04:00
util.AddNetworkString( "benny_sendinvitem" )
util.AddNetworkString( "benny_discardinvitem" )
2023-09-24 01:19:23 -04:00
end
function BENNY.CreateItem( classname )
2024-01-15 01:43:44 -05:00
local class = ItemDef(classname)
2023-09-24 01:19:23 -04:00
assert( class, "Invalid Class " .. tostring(classname) )
2023-09-24 01:19:23 -04:00
local item = {
Class = classname,
2023-11-12 19:59:12 -05:00
Acquisition = CurTime(),
2023-09-24 01:19:23 -04:00
}
2024-01-15 01:43:44 -05:00
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
concommand.Add("benny_debug_give", function(ply, cmd, args)
assert(SERVER, "not server")
local inv = ply:INV_Get()
local str = UUID_generate()
local newitem = BENNY.CreateItem( args[1] )
inv[str] = newitem
2023-09-24 01:19:23 -04:00
-- PROTO: WriteTable.
2023-09-25 17:26:52 -04:00
net.Start( "benny_sendinvitem" )
2023-09-24 01:19:23 -04:00
net.WriteString( str )
net.WriteTable( newitem )
2023-09-24 01:19:23 -04:00
net.Send( ply )
2023-11-16 02:11:42 -05:00
end,
function(cmd, args)
args = string.Trim(args:lower())
local meow = {}
for i, v in SortedPairs( WEAPONS ) do
if string.lower(i):find(args) then
table.insert( meow, cmd .. " " .. i )
end
2023-09-24 01:19:23 -04:00
end
2023-11-16 02:11:42 -05:00
return meow
end, "arg 1: classname")
if CLIENT then
net.Receive( "benny_sendinvitem", function()
LocalPlayer():INV_Get()[net.ReadString()] = net.ReadTable()
end)
net.Receive( "benny_discardinvitem", function()
LocalPlayer():INV_Get()[net.ReadString()] = nil
end)
end
2023-09-24 01:19:23 -04:00
function InvDiscard( ply, ID )
2023-09-25 17:26:52 -04:00
local inv = ply:INV_Get()
local wep = ply:GetActiveWeapon()
local item = inv[ID]
2023-09-25 17:26:52 -04:00
-- PROTO: Check that this is the correct 'benny' weapon.
2023-10-09 17:05:55 -04:00
assert( item, "That item doesn't exist. " .. tostring(item) )
2023-09-25 17:26:52 -04:00
inv[ID] = nil
2023-09-25 17:26:52 -04:00
net.Start( "benny_discardinvitem" )
net.WriteString( ID )
2023-09-25 17:26:52 -04:00
net.Send( ply )
if wep:bGetInvID( false ) == ID then
print( "Disequipped " .. ID .. " for " .. tostring(wep) )
2023-09-25 17:26:52 -04:00
wep:SetWep1( "" )
wep:SetWep1_Clip( "" )
2023-09-25 17:26:52 -04:00
wep:SetClip1( 0 )
end
if wep:bGetInvID( true ) == ID then
print( "Disequipped " .. ID .. " for " .. tostring(wep) )
2023-09-25 17:26:52 -04:00
wep:SetWep2( "" )
wep:SetWep2_Clip( "" )
2023-09-25 17:26:52 -04:00
wep:SetClip2( 0 )
end
if wep:bGetMagInvID( false ) == ID then
print( "Unloaded " .. ID .. " for " .. tostring(wep) )
2024-01-01 16:12:35 -05:00
inv[wep:bGetInvID( false )].Loaded = ""
wep:SetWep1_Clip( "" )
wep:SetClip1( 0 )
end
if wep:bGetMagInvID( true ) == ID then
print( "Unloaded " .. ID .. " for " .. tostring(wep) )
2024-01-01 16:12:35 -05:00
inv[wep:bGetInvID( true )].Loaded = ""
wep:SetWep2_Clip( "" )
wep:SetClip2( 0 )
end
end
concommand.Add("benny_inv_discard", function( ply, cmd, args )
InvDiscard( ply, args[1] )
2023-09-25 17:26:52 -04:00
end)
2023-11-06 14:03:24 -05:00
hook.Add( "PlayerDeathSound", "Benny_PlayerDeathSound", function( ply )
return true -- we don't want the default sound!
end )
2023-12-04 18:20:18 -05:00
if CLIENT then
hook.Add( "PlayerButtonDown", "Benny_PlayerButtonDown_Dev", function( ply, button )
local wep = ply:BennyCheck()
2023-11-29 18:00:08 -05:00
2023-12-10 03:00:05 -05:00
if IsFirstTimePredicted() then
if button == KEY_F1 then
OpenSettingsMenu()
elseif button == KEY_F2 then
OpenDebugInv()
elseif button == KEY_F3 then
OpenSMenu()
elseif button == KEY_F4 then
2023-12-30 20:55:08 -05:00
-- OpenDeadeye()
2023-12-10 03:00:05 -05:00
elseif button == KEY_F5 then
elseif button == KEY_F6 then
elseif button == KEY_F7 then
elseif button == KEY_F8 then
elseif button == KEY_F9 then
elseif button == KEY_F11 then
elseif button == KEY_F12 then
end
end
2023-12-04 18:20:18 -05:00
end)
2023-09-13 22:15:43 -04:00
end