From 6fe7725ebd3a1a9e1694025fa66920a9dbb9ea9a Mon Sep 17 00:00:00 2001 From: Fesiug Date: Wed, 13 Sep 2023 22:15:43 -0400 Subject: [PATCH] Camera kissy --- gamemodes/benny/entities/weapons/benny.lua | 33 ++++ .../gamemode/modules/player/cl_camera.lua | 148 +++++++----------- .../benny/gamemode/modules/player/cl_hud.lua | 23 +++ .../gamemode/modules/player/sh_basic.lua | 8 + .../gamemode/modules/player/sh_movement.lua | 44 ++++++ .../gamemode/modules/player/sh_shared.lua | 100 ------------ 6 files changed, 163 insertions(+), 193 deletions(-) create mode 100644 gamemodes/benny/entities/weapons/benny.lua create mode 100644 gamemodes/benny/gamemode/modules/player/cl_hud.lua create mode 100644 gamemodes/benny/gamemode/modules/player/sh_basic.lua create mode 100644 gamemodes/benny/gamemode/modules/player/sh_movement.lua delete mode 100644 gamemodes/benny/gamemode/modules/player/sh_shared.lua diff --git a/gamemodes/benny/entities/weapons/benny.lua b/gamemodes/benny/entities/weapons/benny.lua new file mode 100644 index 0000000..1505658 --- /dev/null +++ b/gamemodes/benny/entities/weapons/benny.lua @@ -0,0 +1,33 @@ + +SWEP.Base = "weapon_base" + +SWEP.PrintName = "Benny Weapon Handler" + +SWEP.ViewModel = "models/weapons/c_pistol.mdl" +SWEP.WorldModel = "models/weapons/w_pistol.mdl" + +function SWEP:PrimaryAttack() + return true +end + +function SWEP:SecondaryAttack() + return true +end + +function SWEP:Reload() + return true +end + +function SWEP:Think() + self:SetWeaponHoldType("normal") + self:SetHoldType("normal") + return true +end + +function SWEP:Deploy() + return true +end + +function SWEP:Holster() + return true +end \ No newline at end of file diff --git a/gamemodes/benny/gamemode/modules/player/cl_camera.lua b/gamemodes/benny/gamemode/modules/player/cl_camera.lua index a4d0947..fe89d6c 100644 --- a/gamemodes/benny/gamemode/modules/player/cl_camera.lua +++ b/gamemodes/benny/gamemode/modules/player/cl_camera.lua @@ -3,9 +3,11 @@ local debugcolor = Color( 255, 0, 255, 1 ) -BENNY.Cameras = {} +tempmapcameras = {} -BENNY.Cameras["main"] = { +tempmapcameras["benny_test"] = {} + +tempmapcameras["benny_test"]["main"] = { Type = "Standard", Pos = Vector( -692, 0, 268 ), Ang = Angle( 55, 0, 0 ), @@ -41,7 +43,7 @@ BENNY.Cameras["main"] = { end } -BENNY.Cameras["grass"] = { +tempmapcameras["benny_test"]["grass"] = { Pos = Vector( -1622, -214, 284 ), Ang = Angle( 70, 0, 0 ), FOV = 90, @@ -94,7 +96,7 @@ BENNY.Cameras["grass"] = { end } -BENNY.Cameras["barber"] = { +tempmapcameras["benny_test"]["barber"] = { Pos = Vector( -64, -126, 54 ), Ang = Angle( 15, 45, 0 ), FOV = 90, @@ -121,109 +123,69 @@ BENNY.Cameras["barber"] = { end } ---[[ BENNY.Cameras["hall"] = { - Type = "Fixed", - Pos = Vector( 794, -40, 84 ), - Ang = Angle( 29, 180, 0 ), - Checks = { - { - Vector( 273, -111, 0 ), - Vector( 751, 99, -130 ), - }, - }, - v1 = Vector( 400, 0, -128 ), - v2 = Vector( 630, 0, -128 ), - FOV = 67, - Special = function( self, ply ) - local pos = Vector() - pos:Set( self.Pos ) - local ang = Angle() - ang:Set( self.Ang ) - - debugoverlay.Cross( self.v1, 8, 0, color_white, true ) - debugoverlay.Cross( self.v2, 8, 0, color_white, true ) - - local amt = math.TimeFraction( self.v1.x, self.v2.x, ply:GetPos().x ) - amt = math.Clamp( amt, 0, 1 ) - ang.p = ang.p + ( 32 * amt ) - pos.x = pos.x - ( 50 * (1-amt) ) - return pos, ang, self.FOV - end -} ]] - ---[[ BENNY.Cameras["racks"] = { - Type = "Standard", - Pos = Vector( 120, 0, 280 ), - Ang = Angle( 60, 180, 0 ), - Checks = { - { - Vector( 890, 135, 0 ), - Vector( -253, 765, -130 ) - }, - }, - v1 = Vector( 870, 135, -130 ), - v2 = Vector( 760, 135, -130 ), - v3 = Vector( 890, 135, -130 ), - v4 = Vector( -253, 135, -130 ), - FOV = 75, - Special = function( self, ply ) - local pos = Vector() - pos:Set( ply:GetPos() ) - pos:Add( self.Pos ) - local ang = Angle() - ang:Set( self.Ang ) - - debugoverlay.Cross( self.v1, 8, 0, color_white, true ) - debugoverlay.Cross( self.v2, 8, 0, color_white, true ) - - pos.x = math.Clamp( pos.x, -200, 890 ) - pos.y = math.Clamp( pos.y, 300, 600 ) - - do -- close to back wall - local amt = math.TimeFraction( self.v1.x, self.v2.x, ply:GetPos().x ) - amt = math.Clamp( amt, 0, 1 ) - -- pos.x = pos.x - ( (150) * (1-amt) ) - ang.p = ang.p + ( 10 * (1-amt) ) - end - - do -- stretch - local amt = math.TimeFraction( self.v3.x, self.v4.x, ply:GetPos().x ) - amt = math.Clamp( amt, 0, 1 ) - -- pos.x = pos.x - ( (1143) * (amt) ) - end - - - return pos, ang, self.FOV - end -} ]] - -BENNY_ACTIVECAMERA = BENNY_ACTIVECAMERA or nil +BENNY_ACTIVECAMERA = nil local c_over = CreateConVar( "benny_cam_override", "" ) local c_unlock = CreateConVar( "benny_cam_unlock", 0 ) +local si = 4 +local ctrace = { + start = nil, + endpos = nil, + mins = Vector( -si, -si, -si ), + maxs = Vector( si, si, si ), + mask = MASK_SHOT_HULL, + filter = nil, +} +local tempcam = { + FOV = 90, + + Special = function( self, ply ) + local pos = Vector() + local ang = Angle() + local fov = self.FOV + local ppos = ply:GetPos() + local pang = ply:EyeAngles() + + pos:Set( ppos ) + ang:Add( pang ) + + pos.z = pos.z + 68 + ctrace.start = pos + ctrace.endpos = pos + ( ang:Forward() * -60 ) + ( ang:Right() * 20 ) + ctrace.filter = ply + local tr = util.TraceHull( ctrace ) + + pos = tr.HitPos + + return pos, ang, fov + end +} + local function decide_active() - print( LocalPlayer():GetPos() ) - for name, camera in pairs( BENNY.Cameras ) do - if camera.Checks then - for i, v in ipairs(camera.Checks) do - if LocalPlayer():GetPos():WithinAABox( v[1], v[2] ) then - debugoverlay.Box( vector_origin, v[1], v[2], 0, debugcolor ) - return name + -- print( LocalPlayer():GetPos() ) + -- BENNY_ACTIVECAMERA = tempcam + if tempmapcameras[ game.GetMap() ] then + for name, camera in pairs( tempmapcameras[ game.GetMap() ] ) do + if camera.Checks then + for i, v in ipairs(camera.Checks) do + if LocalPlayer():GetPos():WithinAABox( v[1], v[2] ) then + debugoverlay.Box( vector_origin, v[1], v[2], 0, debugcolor ) + BENNY_ACTIVECAMERA = camera + return true + end end end end end + return false end hook.Add( "CalcView", "MyCalcView", function( ply, pos, ang, fov ) if c_unlock:GetBool() then return end if ply:GetMoveType() == MOVETYPE_NOCLIP then return end - local da = decide_active() - if da then - BENNY_ACTIVECAMERA = da - end - local camera = BENNY.Cameras[BENNY_ACTIVECAMERA] + decide_active() + local camera = BENNY_ACTIVECAMERA if camera then local view = { origin = camera.Pos, diff --git a/gamemodes/benny/gamemode/modules/player/cl_hud.lua b/gamemodes/benny/gamemode/modules/player/cl_hud.lua new file mode 100644 index 0000000..8267e35 --- /dev/null +++ b/gamemodes/benny/gamemode/modules/player/cl_hud.lua @@ -0,0 +1,23 @@ + +-- HUD + +local hide = { + ["CHudHealth"] = true, + ["CHudBattery"] = true, + ["CHudAmmo"] = true, + ["CHudSecondaryAmmo"] = true, + ["CHudPoisonDamageIndicator"] = true, +} + +hook.Add( "HUDShouldDraw", "HideHUD", function( name ) + if ( hide[ name ] ) then return false end +end ) + +function ss( scale ) + return scale * ( ScrH() / 480 ) +end + +hook.Add( "HUDPaint", "Benny_HUDPaint", function() + surface.SetDrawColor( 0, 0, 0, 0 ) + surface.DrawRect( 0, 0, 256, 256 ) +end ) \ No newline at end of file diff --git a/gamemodes/benny/gamemode/modules/player/sh_basic.lua b/gamemodes/benny/gamemode/modules/player/sh_basic.lua new file mode 100644 index 0000000..52eb58b --- /dev/null +++ b/gamemodes/benny/gamemode/modules/player/sh_basic.lua @@ -0,0 +1,8 @@ + +function GM:PlayerSetModel( ply ) + ply:SetModel( "models/player/group01/male_07.mdl" ) +end + +function GM:PlayerLoadout( ply ) + ply:Give( "benny" ) +end \ No newline at end of file diff --git a/gamemodes/benny/gamemode/modules/player/sh_movement.lua b/gamemodes/benny/gamemode/modules/player/sh_movement.lua new file mode 100644 index 0000000..eca5bc9 --- /dev/null +++ b/gamemodes/benny/gamemode/modules/player/sh_movement.lua @@ -0,0 +1,44 @@ + +-- Movement + +local wa, wb = 0, 0 + +local blop = Angle() + +hook.Add( "CreateMove", "CamFuck", function( cmd ) + if LocalPlayer():GetMoveType() != MOVETYPE_NOCLIP then + local x, y = cmd:GetForwardMove(), cmd:GetSideMove() + wa, wb = x, y + + local ad = Vector( x, y, 0 ) + + local an = Angle() + an:Set( RenderAngles() ) + an.p = 0 + + local am = Angle() + am:Set( cmd:GetViewAngles() ) + am.p = 0 + + ad:Rotate( am ) + ad:Rotate( -an ) + + ad:Normalize() + ad:Mul(320) + + cmd:SetForwardMove( ad.x ) + cmd:SetSideMove( ad.y ) + + if x != 0 or y != 0 then + local thing = Vector( x, -y, 0 ):Angle() + thing.y = thing.y + an.y + blop.y = math.ApproachAngle( blop.y, thing.y, FrameTime() * 360 ) + end + cmd:SetViewAngles( blop ) + + end +end) + +function GM:PlayerNoClip() + return true +end \ No newline at end of file diff --git a/gamemodes/benny/gamemode/modules/player/sh_shared.lua b/gamemodes/benny/gamemode/modules/player/sh_shared.lua deleted file mode 100644 index 111de02..0000000 --- a/gamemodes/benny/gamemode/modules/player/sh_shared.lua +++ /dev/null @@ -1,100 +0,0 @@ - -local wa, wb = 0, 0 - -hook.Add( "CreateMove", "CamFuck", function( cmd ) - if LocalPlayer():GetMoveType() != MOVETYPE_NOCLIP then - local x, y = cmd:GetForwardMove(), cmd:GetSideMove() - wa, wb = x, y - - local ad = Vector( x, y, 0 ) - - local an = Angle() - an:Set( RenderAngles() ) - an.p = 0 - - local am = Angle() - am:Set( cmd:GetViewAngles() ) - am.p = 0 - - ad:Rotate( am ) - ad:Rotate( -an ) - - ad:Normalize() - ad:Mul(320) - - --print(ad.x, ad.y) - - cmd:SetForwardMove( ad.x ) - cmd:SetSideMove( ad.y ) - end -end) - -function GM:PlayerNoClip() - return true -end - -if CLIENT then - local function ss( scale ) - return scale * ( ScrH() / 480 ) - end - - local w25, w50, w75, w100 = Color( 255, 255, 255, 0.25*255 ), Color( 255, 255, 255, 0.50*255 ), Color( 255, 255, 255, 0.75*255 ), Color( 255, 255, 255, 1.00*255 ) - local g25, g50, g75, g100 = Color( 0, 0, 0, 0.25*255 ), Color( 0, 0, 0, 0.50*255 ), Color( 0, 0, 0, 0.75*255 ), Color( 0, 0, 0, 1.00*255 ) - - hook.Add( "HUDPaint", "HUDFuck", function() - local bo = ss( 20 ) - local cr, cd = ss( 50 ), ss( 100 ) - - surface.SetDrawColor( g100 ) - surface.DrawRect( bo, ScrH() - bo + cr, cd, cd ) - - surface.SetDrawColor( w25 ) - surface.DrawLine( bo + cr, ScrH() - bo - cd, bo + cr, ScrH() - bo ) - surface.DrawLine( bo, ScrH() - bo - cr, bo + cd, ScrH() - bo - cr ) - - surface.SetDrawColor( w100 ) - surface.DrawCircle( bo + cr, ScrH() - bo - cr, cr ) - - local ox, oy = 0, 0 - local msp = 300 - - ox = wb/msp - oy = -wa/msp - - ox = math.Clamp( ox, -1, 1 ) * cr - oy = math.Clamp( oy, -1, 1 ) * cr - - surface.DrawCircle( bo + cr + ox, ScrH() - bo - cr + oy, ss( 2 ) ) - - -- local x, y, w, h = 0, 0, 360, 240 - -- local ow, oh = 512, 512 - - -- local camera = BENNY.Cameras[BENNY_ACTIVECAMERA] - -- local view = { - -- origin = camera.Pos, - -- angles = camera.Ang, - -- fov = camera.FOV or 60, - -- drawviewer = true - -- } - -- if camera.Special then - -- view.origin, view.angles, view.fov = camera.Special( camera, LocalPlayer() ) - -- end - -- view.angles.p = 0 - -- view.angles.r = 0 - - -- local aratio = w/h - - -- render.RenderView( { - -- origin = view.origin + Vector( 0, 0, 64 ), - -- angles = Angle( 90, view.angles.y, 0 ), - -- aspect = 1, - -- fov = 90, - -- x = x, y = y, - -- w = w, h = h, - -- ortho = { - -- left = -ow, right = ow, - -- top = -oh / aratio, bottom = oh / aratio, - -- }, - -- } ) - end) -end \ No newline at end of file