2023-09-23 22:51:35 -04:00
|
|
|
|
2023-11-15 19:01:38 -05:00
|
|
|
function GM:PlayerSpawn( ply )
|
|
|
|
player_manager.SetPlayerClass( ply, "player_benny" )
|
|
|
|
ply:SetModel( "models/player/police.mdl" )
|
|
|
|
ply:SetViewOffset( Vector( 0, 0, 64 ) )
|
|
|
|
ply:SetViewOffsetDucked( Vector( 0, 0, 50 ) )
|
|
|
|
ply:SetPlayerColor( Vector( 0.275, 0.2, 0.145 ) )
|
|
|
|
ply:Give( "benny" )
|
|
|
|
|
2023-11-28 23:11:10 -05:00
|
|
|
ply:SetStamina( 1 )
|
|
|
|
|
2023-11-15 19:01:38 -05:00
|
|
|
ply:SetCrouchedWalkSpeed( 0.3 )
|
|
|
|
ply:SetDuckSpeed( 0.1 )
|
|
|
|
ply:SetUnDuckSpeed( 0.1 )
|
|
|
|
ply:SetSlowWalkSpeed( 100 )
|
|
|
|
ply:SetWalkSpeed( 160 )
|
|
|
|
ply:SetRunSpeed( 220 )
|
|
|
|
ply:SetStepSize( 16 )
|
|
|
|
ply:SetCanZoom( false )
|
|
|
|
end
|
|
|
|
|
2023-09-23 22:51:35 -04:00
|
|
|
local PT = FindMetaTable( "Player" )
|
|
|
|
|
2023-11-06 14:03:14 -05:00
|
|
|
function PT:BennyCheck()
|
2023-11-15 19:01:38 -05:00
|
|
|
local wep = self:GetActiveWeapon()
|
2023-11-16 01:54:54 -05:00
|
|
|
return ( wep:IsValid() and wep:GetClass() == "benny" and wep.GetUserAim ) and wep or false
|
2023-11-06 14:03:14 -05:00
|
|
|
end
|
|
|
|
|
2023-10-22 00:38:30 -04:00
|
|
|
function PT:CamSpot( ang )
|
|
|
|
local w = self:GetActiveWeapon()
|
|
|
|
if !IsValid( w ) then w = false end
|
|
|
|
|
|
|
|
local aim = w and w:GetAim() or 0
|
2023-11-06 14:03:14 -05:00
|
|
|
if w then aim = w:GetUserAim() and math.ease.OutCubic( aim ) or math.ease.InCubic( aim ) end
|
2023-10-22 00:38:30 -04:00
|
|
|
|
|
|
|
local pos = self:GetPos()
|
|
|
|
|
|
|
|
local perc = math.TimeFraction( self:GetViewOffset().z, self:GetViewOffsetDucked().z, self:GetCurrentViewOffset().z )
|
|
|
|
pos.z = pos.z + Lerp( perc, 64, 52 )
|
|
|
|
|
|
|
|
pos:Add( Lerp( aim, 16, 16 ) * ang:Right() )
|
|
|
|
pos:Add( Lerp( aim, -64, -32 ) * ang:Forward() )
|
|
|
|
pos:Add( 0 * ang:Up() )
|
|
|
|
|
|
|
|
pos:Add( Lerp( aim, 16, 16 ) * ang:Up() * (ang.p/90) )
|
|
|
|
|
|
|
|
local tr = util.TraceHull( {
|
|
|
|
start = self:GetPos() + Vector( 0, 0, Lerp( perc, 64, 52 ) ),
|
|
|
|
endpos = pos,
|
|
|
|
mins = -Vector( 4, 4, 4 ),
|
|
|
|
maxs = Vector( 4, 4, 4 ),
|
|
|
|
filter = self
|
|
|
|
})
|
|
|
|
|
|
|
|
return tr.HitPos, ang, 90
|
|
|
|
end
|
|
|
|
|
2023-11-14 02:45:34 -05:00
|
|
|
function PT:NoclippingAndNotVaulting()
|
|
|
|
return (self:GetMoveType() == MOVETYPE_NOCLIP and self:GetVaultTransition() == 0)
|
|
|
|
end
|
|
|
|
|
2023-09-23 22:51:35 -04:00
|
|
|
function PT:INV_Get()
|
|
|
|
if !self.INV then
|
|
|
|
print( "Inventory created")
|
|
|
|
self.INV = {}
|
|
|
|
end
|
|
|
|
return self.INV
|
2023-10-09 15:05:58 -04:00
|
|
|
end
|
|
|
|
|
2023-11-14 01:12:55 -05:00
|
|
|
function PT:INV_Discard( id )
|
|
|
|
if self:INV_Get()[ id ] then
|
|
|
|
self:INV_Get()[ id ] = nil
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2023-11-14 22:35:14 -05:00
|
|
|
SORTS = {
|
|
|
|
["Acquisition"] = function( a, b ) return inv[b]["Acquisition"] > inv[a]["Acquisition"] end,
|
|
|
|
}
|
|
|
|
|
2023-11-16 22:00:11 -05:00
|
|
|
function PT:INV_Find( class, exclude )
|
2023-11-14 01:32:08 -05:00
|
|
|
local inv = self:INV_Get()
|
|
|
|
local results = {}
|
|
|
|
for i, v in pairs( inv ) do
|
2023-11-16 22:00:11 -05:00
|
|
|
if v.Class == class and i != (exclude or "") then
|
2023-11-14 01:32:08 -05:00
|
|
|
table.insert( results, i )
|
|
|
|
end
|
|
|
|
end
|
2023-11-16 22:00:11 -05:00
|
|
|
-- PROTO: HOLY SHIT THIS SUCKS, MAKES A FUNCTION AND MIGHT RUN EVERY FRAME!!!
|
2023-11-15 18:01:51 -05:00
|
|
|
table.sort( results, function( a, b ) return inv[b]["Acquisition"] > inv[a]["Acquisition"] end )
|
|
|
|
-- table.sort( results, SORTS["Acquisition"] )
|
2023-11-14 01:32:08 -05:00
|
|
|
return results
|
|
|
|
end
|
|
|
|
|
2023-12-03 23:24:42 -05:00
|
|
|
local T_WEIGHT = {
|
|
|
|
["machinegun"] = 40,
|
|
|
|
["rifle"] = 35,
|
|
|
|
["shotgun"] = 30,
|
|
|
|
["smg"] = 25,
|
|
|
|
["pistol"] = 20,
|
|
|
|
["melee"] = 15,
|
|
|
|
["special"] = 10,
|
|
|
|
["utility"] = 05,
|
|
|
|
["equipment"] = 00,
|
|
|
|
["grenade"] = -10,
|
|
|
|
["magazine"] = -100,
|
|
|
|
}
|
|
|
|
|
|
|
|
function PT:INV_Weight()
|
|
|
|
local inv = self:INV_Get()
|
|
|
|
local results = {}
|
|
|
|
for i, v in pairs( inv ) do
|
|
|
|
if WeaponGet(v.Class).Features != "magazine" then
|
|
|
|
table.insert( results, { inv[i], WeaponGet(v.Class) } )
|
|
|
|
end
|
|
|
|
end
|
|
|
|
-- PROTO: HOLY SHIT THIS SUCKS, MAKES A FUNCTION AND MIGHT RUN EVERY FRAME!!!
|
|
|
|
table.sort( results, function( a, b )
|
|
|
|
return (T_WEIGHT[b[2]["Type"]] + b[1]["Acquisition"]*(1e-5))
|
|
|
|
< (T_WEIGHT[a[2]["Type"]] + a[1]["Acquisition"]*(1e-5))
|
|
|
|
end )
|
|
|
|
local finale = {}
|
|
|
|
for i, v in ipairs( results ) do
|
|
|
|
table.insert( finale, v[1] )
|
|
|
|
end
|
|
|
|
return finale
|
|
|
|
end
|
|
|
|
|
2023-11-16 22:00:11 -05:00
|
|
|
function PT:INV_FindMag( class, exclude )
|
|
|
|
local inv = self:INV_Get()
|
|
|
|
local results = {}
|
|
|
|
for i, v in pairs( inv ) do
|
2023-11-17 22:56:41 -05:00
|
|
|
if v.Class == class and (exclude and !exclude[i] or !exclude and true) then
|
2023-11-16 22:00:11 -05:00
|
|
|
table.insert( results, i )
|
|
|
|
end
|
|
|
|
end
|
|
|
|
-- PROTO: HOLY SHIT THIS SUCKS, MAKES A FUNCTION AND MIGHT RUN EVERY FRAME!!!
|
2023-12-03 23:24:42 -05:00
|
|
|
table.sort( results, function( a, b ) return (inv[b]["Ammo"] - (inv[b]["Acquisition"]*(1e-5))) < (inv[a]["Ammo"] - (inv[a]["Acquisition"]*(1e-5))) end )
|
2023-11-16 22:00:11 -05:00
|
|
|
return results
|
|
|
|
end
|
|
|
|
|
2023-10-09 15:05:58 -04:00
|
|
|
do
|
|
|
|
local translat = {
|
2023-11-12 19:59:12 -05:00
|
|
|
["melee"] = { 1, 1 },
|
|
|
|
["special"] = { 1, 2 },
|
|
|
|
["pistol"] = { 2, 1 },
|
|
|
|
["smg"] = { 3, 1 },
|
|
|
|
["shotgun"] = { 4, 1 },
|
|
|
|
["rifle"] = { 5, 1 },
|
2023-11-03 13:20:39 -04:00
|
|
|
["machinegun"] = { 5, 2 },
|
2023-11-12 19:59:12 -05:00
|
|
|
["grenade"] = { 6, 1 },
|
|
|
|
["utility"] = { 6, 2 },
|
2023-11-11 21:08:34 -05:00
|
|
|
["equipment"] = { 7, 1 },
|
2023-11-16 22:00:11 -05:00
|
|
|
["magazine"] = { 8, 1 },
|
2023-10-09 15:05:58 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
-- PROTO: Cache this!
|
|
|
|
function PT:INV_Buckets()
|
|
|
|
local inventorylist = {
|
|
|
|
[1] = {},
|
|
|
|
[2] = {},
|
|
|
|
[3] = {},
|
|
|
|
[4] = {},
|
2023-11-03 13:20:39 -04:00
|
|
|
[5] = {},
|
|
|
|
[6] = {},
|
2023-11-11 21:08:34 -05:00
|
|
|
[7] = {},
|
2023-11-16 22:00:11 -05:00
|
|
|
[8] = {},
|
2023-10-09 15:05:58 -04:00
|
|
|
}
|
2023-11-15 18:01:51 -05:00
|
|
|
-- PROTO: HOLY SHIT THIS SUCKS, MAKES A FUNCTION EVERY FRAME, AND RUNS EVERY FRAME!!!
|
2023-11-12 19:59:12 -05:00
|
|
|
local inv = self:INV_Get()
|
2023-11-14 22:35:14 -05:00
|
|
|
local function BucketSorter(a, b)
|
|
|
|
return (inv[b[1]]["Acquisition"] + (b[2]*10000)) > (inv[a[1]]["Acquisition"] + (a[2]*10000))
|
|
|
|
end
|
2023-10-09 15:05:58 -04:00
|
|
|
for i, bucket in ipairs( inventorylist ) do
|
|
|
|
local temp = {}
|
2023-11-12 19:59:12 -05:00
|
|
|
for id, data in pairs( inv ) do
|
2023-11-29 18:40:45 -05:00
|
|
|
local idata = WeaponGet(data.Class)
|
2023-10-09 15:05:58 -04:00
|
|
|
local translated = translat[idata.Type]
|
|
|
|
|
|
|
|
if i == translated[1] then
|
|
|
|
table.insert( temp, { id, translated[2] } )
|
|
|
|
end
|
|
|
|
end
|
2023-11-14 22:35:14 -05:00
|
|
|
table.sort( temp, BucketSorter )
|
2023-10-09 15:05:58 -04:00
|
|
|
for i, v in ipairs( temp ) do
|
|
|
|
table.insert( bucket, v[1] )
|
|
|
|
end
|
|
|
|
end
|
|
|
|
return inventorylist
|
|
|
|
end
|
2023-11-16 01:54:54 -05:00
|
|
|
-- 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
|
|
|
|
|
|
|
|
-- weapon select
|
|
|
|
|
|
|
|
hook.Add("StartCommand", "Benny_INV_StartCommand", function( ply, cmd )
|
2023-11-17 21:12:25 -05:00
|
|
|
-- 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
|
2023-11-16 01:54:54 -05:00
|
|
|
end)
|
|
|
|
|
|
|
|
|
|
|
|
-- cmd:KeyDown( IN_WEAPON1 )
|
|
|
|
-- cmd:KeyDown( IN_WEAPON2 )
|
|
|
|
-- cmd:KeyDown( IN_BULLRUSH )
|
|
|
|
-- cmd:KeyDown( IN_GRENADE1 )
|
|
|
|
-- cmd:KeyDown( IN_GRENADE2 )
|