Reimplement some things

This commit is contained in:
Fesiug 2024-03-07 21:19:30 -05:00
parent 40a6931f51
commit 8db88566ad
Signed by: Fesiug
GPG Key ID: 374BFF45E1EEF243
8 changed files with 546 additions and 5 deletions

View File

@ -82,7 +82,7 @@ function SWEP:PrimaryAttack()
local p = self:GetOwner()
if self:ItemR() then
self:ItemR("Attack")
else
elseif SERVER then
local trace = self:ItemCheckTrace()
self:EquipItem( trace.Entity )
end
@ -153,8 +153,8 @@ end
function SWEP:DropItem()
local p = self:GetOwner()
local ent = self:GetActiveR()
if CLIENT then print("FUCK OFF") debug.Trace() return end
if ent:IsValid() then
if CLIENT then print("DropItem called on CLIENT but certain things aren't finished yet.") return end
ent:SetParent( NULL )
ent:SetOwner( NULL )

View File

@ -3,12 +3,33 @@
-- Your Name is Benny
---------------------
local cam_f = CreateConVar( "b-cam_f", -40 )
local cam_r = CreateConVar( "b-cam_r", 12 )
local cam_u = CreateConVar( "b-cam_u", 0 )
local cam_fov = CreateConVar( "b-cam_fov", 75 )
local m = 2
local m2 = Vector( m, m, m )
local m1 = m2:GetNegated()
function GM:CalcView( ply, pos, ang, fov )
local f, r, u = ang:Forward(), ang:Right(), ang:Up()
local tr = {
start = pos,
endpos = pos + (f*cam_f:GetFloat()) + (r*cam_r:GetFloat()) + (u*cam_u:GetFloat()),
filter = ply,
mins = m1,
maxs = m2,
}
tr = util.TraceHull(tr)
local view = {
origin = pos + (ang:Forward() * -64),
origin = tr.HitPos,
angles = angles,
fov = fov,
fov = cam_fov:GetFloat(),
drawviewer = true
}
return view
end

View File

@ -0,0 +1,17 @@
---------------------
-- Your Name is Benny
---------------------
Convars = {}
Convars.List = {}
function Convars:Add( name, def, help, mins, max )
end
function Convars:GetVector()
local exploded = string.Explode( " ", "" )
return Vector()
end

View File

@ -0,0 +1,103 @@
---------------------
-- Your Name is Benny
---------------------
-- Stack related
local function xy( x, y )
return {x, y}
end
local function hXY( x, y )
local rx, ry = 0, 0
for key, value in ipairs(stack) do
rx = rx + value[1]
ry = ry + value[2]
end
if x then rx = rx + x end
if y then ry = ry + y end
return rx, ry
end
local function S_Push( x, y )
stack:Push( xy( x, y ) )
end
local function S_Pop( x, y )
stack:Pop()
end
local function hCol( r, g, b, a )
return surface.SetDrawColor( r, g, b, a )
end
local function hCoo( col )
return col
end
local function hRect( x, y, w, h )
gx, gy = hXY()
x = (x or 0) + gx
y = (y or 0) + gy
surface.DrawRect( x, y, w, h )
end
local function hORect( x, y, w, h, r )
gx, gy = hXY()
x = (x or 0) + gx
y = (y or 0) + gy
surface.DrawOutlinedRect( x, y, w, h, r )
end
local COLOR_DARK = Color( 40, 40, 80 )
local COLOR_BRIGHT = Color( 80, 80, 160 )
local COLOR_MAIN = Color( 160, 160, 240 )
-- Drawing
function GM:HUDPaint()
stack = util.Stack()
-- Centered
S_Push( ScrW()/2, ScrH()/2 )
-- Push Top, Centered Health
S_Push( -320/2, -440 )
hCol( COLOR_DARK )
hRect( 0, 0, 320, 30 )
hCol( COLOR_MAIN )
hRect( 2, 2, 320-2-2, 30-2-2 )
S_Pop()
S_Pop()
if stack:Size() != 0 then print("Stack unfinished.") end
return
end
-- Not drawing
local hide = {
["CHudHealth"] = true,
["CHudBattery"] = true,
["CHudAmmo"] = true,
["CHudSecondaryAmmo"] = true,
["CHudDamageIndicator"] = true,
["CHudCloseCaption"] = true,
["CHudCrosshair"] = true,
["CHudSuitPower"] = true,
["CHUDQuickInfo"] = true,
["CHudZoom"] = true,
}
function GM:HUDShouldDraw( name )
if hide[ name ] then
return false
else
return true
end
end

View File

@ -0,0 +1,216 @@
---------------------
-- Your Name is Benny
---------------------
local PT = FindMetaTable("Player")
function PT:GetItems()
return
end
function PT:HandlerCheck()
return self:GetActiveWeapon().AEItemHandler and self:GetActiveWeapon()
end
InventoryMeta = {}
function InventoryMeta:Destroy()
local p = self[0].Owner
p.Inventory = nil
p:GetInventory()
end
function InventoryMeta:BugCheck()
for i, v in pairs(self) do
if i != 0 and !i:IsValid() then
self[i] = nil
end
end
end
function InventoryMeta:GetWeighted()
local itemlist = {}
for i, v in pairs(self) do
if i == 0 then continue end
table.insert( itemlist, i )
end
table.sort( itemlist, function( a, b )
return a:GetAcquisition() < b:GetAcquisition()
end)
return itemlist
end
function InventoryMeta:Sync()
if SERVER then
net.Start("AEINV_InvSync")
local count = table.Count( self )-1 -- The header is included
net.WriteUInt( count, 8 )
for key, _ in pairs( self ) do
if key == 0 then continue end
net.WriteEntity( key )
end
net.Send( self[0].Owner )
end
end
InventoryMeta.__index = InventoryMeta
function PT:GetInventory()
if !self.Inventory then
print("Creating new inventory for", self)
self.Inventory = {}
self.Inventory[0] = { Owner = self }
setmetatable( self.Inventory, InventoryMeta )
if SERVER then
for i, v in pairs( self:GetChildren() ) do
if v.AEItem then
print( "Regen, adding", v, "to inventory")
self.Inventory[v] = true
end
end
self.Inventory:Sync()
end
end
self.Inventory:BugCheck()
return self.Inventory
end
gameevent.Listen( "OnRequestFullUpdate" )
hook.Add( "OnRequestFullUpdate", "OnRequestFullUpdate_example", function( data )
local name = data.name // Same as Player:Nick()
local steamid = data.networkid // Same as Player:SteamID()
local id = data.userid // Same as Player:UserID()
local index = data.index // Same as Entity:EntIndex() minus one
if SERVER then
Player(id):GetInventory():Sync()
end
end )
if SERVER then
util.AddNetworkString("AEINV_InvSync")
else
net.Receive("AEINV_InvSync", function()
print("Destroyed old inventory")
local p = LocalPlayer()
p.Inventory = nil
if p.GetInventory then
local inv = p:GetInventory()
local count = net.ReadUInt(8)
for i=1, count do
local key = net.ReadEntity()
print( "Added", key)
inv[key] = true
end
else
print("TOO EARLY!!!!!!!!!!!!!!!!")
end
end)
end
do
local qt = {
["slot1"] = true,
["slot2"] = true,
["slot3"] = true,
["slot4"] = true,
["slot5"] = true,
["slot6"] = true,
["slot7"] = true,
["slot8"] = true,
["slot9"] = true,
["slot0"] = true,
["invprev"] = true,
["invnext"] = true,
}
hook.Add( "PlayerBindPress", "Benny_PlayerBindPress_Original", function( ply, bind, pressed, code )
if qt[bind] and pressed then
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 mwheel = {
[MOUSE_WHEEL_DOWN] = 1,
[MOUSE_WHEEL_UP] = -1
}
local function beatup( ply, num )
local inv = ply:GetInventory():GetWeighted()
local wep = ply:HandlerCheck()
local ent = inv[num]
if ent then
if ent == wep:GetActiveR() then
wep:Deactive()
else
wep:SetActive(ent)
end
end
end
local function boba( ply, mwheel )
if mwheel != 0 then
print("Test", math.Round( CurTime()%60, 4 ), mwheel )
local inv = ply:GetInventory():GetWeighted()
local wep = ply:HandlerCheck()
local inf = table.Flip( inv )
local currpos = inf[wep:GetActiveR()]
if !currpos then
if mwheel > 0 then
currpos = 0
else
currpos = #inv+1
end
end
local want = currpos+mwheel
if want > #inv then
want = want - #inv
elseif want <= 0 then
want = want + #inv
end
local ent = inv[want]
if ent then
wep:SetActive(ent)
end
end
end
hook.Add( "PlayerButtonDown", "Benny_PlayerButtonDown_Inv", function( ply, button )
local wep = ply:HandlerCheck()
if dads[button] then
beatup( ply, dads[button] )
elseif mwheel[button] then
boba( ply, mwheel[button] )
end
end)

View File

@ -0,0 +1,128 @@
---------------------
-- Your Name is Benny
---------------------
function GM:PlayerSpawn( ply )
player_manager.SetPlayerClass( ply, "player_benny" )
ply:SetViewOffset( Vector( 0, 0, 64 ) )
ply:SetViewOffsetDucked( Vector( 0, 0, 50 ) )
ply:Give( "itemhandler" )
ply:SetStamina( 1 )
ply:SetCrouchedWalkSpeed( 0.3 )
ply:SetDuckSpeed( 0.1 )
ply:SetUnDuckSpeed( 0.1 )
ply:SetSlowWalkSpeed( 100 )
ply:SetWalkSpeed( 200 )
ply:SetRunSpeed( 200 )
ply:SetStepSize( 18 )
ply:SetCanZoom( false )
ply:MakeCharacter()
end
local PT = FindMetaTable( "Player" )
local bgl = {
["benny"] = {
[0] = Vector( 0.275, 0.7, 0.7 ),
[1] = 17,
[2] = 7,
[3] = 2,
[4] = 11,
[5] = 3,
[6] = 0,
[7] = 0,
[8] = 3,
[9] = 0,
[10] = 0,
[11] = 0,
[12] = 3,
[13] = 0,
},
["nikki"] = {
[0] = Vector( 0.9, 0.3, 0.9 ),
[1] = 17,
[2] = 7,
[3] = 2,
[4] = 11,
[5] = 3,
[6] = 0,
[7] = 0,
[8] = 2,
[9] = 1,
[10] = 5,
[11] = 0,
[12] = 3,
[13] = 0,
},
["igor"] = {
[0] = Vector( 0.776, 0.929, 0.89 ),
[1] = 4,
[2] = 6,
[3] = 2,
[4] = 3,
[5] = 1,
[6] = 0,
[7] = 2,
[8] = 3,
[9] = 3,
[10] = 6,
[11] = 2,
[12] = 1,
[13] = 0,
},
["yanghao"] = {
[0] = Vector( 0.627, 0.21, 0.186 ),
[1] = 13,
[2] = 2,
[3] = 0,
[4] = 3,
[5] = 0,
[6] = 1,
[7] = 3,
[8] = 0,
[9] = 3,
[10] = 4,
[11] = 0,
[12] = 0,
[13] = 0,
},
["mp_cia"] = {
[0] = Vector( 1, 1, 1 )
},
["mp_plasof"] = {
[0] = Vector( 1, 1, 1 )
},
["mp_militia"] = {
[0] = Vector( 1, 1, 1 )
},
["mp_natguard"] = {
[0] = Vector( 1, 1, 1 )
},
["mp_viper"] = {
[0] = Vector( 1, 1, 1 )
},
["mp_halo"] = {
[0] = Vector( 1, 1, 1 )
},
}
function PT:MakeCharacter()
local char = "benny"
self:SetModel( "models/player/infoplayerrealism.mdl" )
self:SetPlayerColor( bgl[char][0] )
self:SetBodygroup( 0, 0 )
self:SetSkin( 3 )
for i, v in ipairs( bgl[char] ) do
self:SetBodygroup( i, v )
end
end
function PT:BennyCheck()
local wep = self:GetActiveWeapon()
return ( wep:IsValid() and wep:GetClass() == "itemhandler" and wep.GetActiveR ) and wep or false
end

View File

@ -0,0 +1,45 @@
AddCSLuaFile()
local PLAYER = {}
PLAYER.DisplayName = "Benny Player Class"
PLAYER.SlowWalkSpeed = 200
PLAYER.WalkSpeed = 250
PLAYER.RunSpeed = 280
PLAYER.CrouchedWalkSpeed = 0.3
PLAYER.DuckSpeed = 0.3
PLAYER.UnDuckSpeed = 0.3
PLAYER.JumpPower = 200
PLAYER.CanUseFlashlight = false
PLAYER.MaxHealth = 100
PLAYER.MaxArmor = 100
PLAYER.StartHealth = 100
PLAYER.StartArmor = 0
PLAYER.DropWeaponOnDie = false
PLAYER.TeammateNoCollide = true
PLAYER.AvoidPlayers = true
PLAYER.UseVMHands = true
function PLAYER:Init()
self.Player:AddEFlags( EFL_NO_DAMAGE_FORCES )
end
function PLAYER:SetupDataTables()
self.Player:NetworkVar( "Bool", 0, "Shoulder" )
self.Player:NetworkVar( "Int", 0, "JumpBoost" )
self.Player:NetworkVar( "Float", 0, "VaultDebuff" )
self.Player:NetworkVar( "Float", 1, "VaultTransition" )
self.Player:NetworkVar( "Float", 2, "Stamina" )
self.Player:NetworkVar( "Vector", 0, "VaultPos1")
self.Player:NetworkVar( "Vector", 1, "VaultPos2")
self.Player:NetworkVar( "String", 0, "ReqID1")
self.Player:NetworkVar( "String", 1, "ReqID2")
end
player_manager.RegisterClass( "player_benny", PLAYER, "player_default" )

View File

@ -11,4 +11,15 @@ local AC, IN = AddCSLuaFile, include
AC("camera.lua")
IN("camera.lua")
AC("items.lua")
IN("items.lua")
IN("items.lua")
AC("player.lua")
IN("player.lua")
AC("player_class.lua")
IN("player_class.lua")
AC("inventory.lua")
IN("inventory.lua")
AC("hud.lua")
if CLIENT then
IN("hud.lua")
end