From 7cc6031dc112f72698d60e4e42453cb9bef09351 Mon Sep 17 00:00:00 2001 From: Leonardo Bishop Date: Mon, 31 Jul 2023 02:59:08 +0100 Subject: Add looking at info --- code/pawn/Player.cs | 25 +++++++++++++++ code/ui/Hud.razor | 1 + code/ui/character/LookingAtInfo.razor | 57 +++++++++++++++++++++++++++++++++++ 3 files changed, 83 insertions(+) create mode 100644 code/ui/character/LookingAtInfo.razor diff --git a/code/pawn/Player.cs b/code/pawn/Player.cs index 1d87d94..7073bb1 100644 --- a/code/pawn/Player.cs +++ b/code/pawn/Player.cs @@ -60,6 +60,8 @@ public partial class Player : AnimatedEntity [Net, Predicted] public TimeSince TimeSinceDeath { get; set; } = 0; + public Player LookingAt { get; set; } + public override void Spawn() { SetModel( "models/citizen/citizen.vmdl" ); @@ -189,6 +191,29 @@ public partial class Player : AnimatedEntity Components.Create(); } + if ( Game.IsClient ) + { + var start = AimRay.Position; + var end = AimRay.Position + AimRay.Forward * 5000; + + var trace = Trace.Ray( start, end ) + .UseHitboxes() + .WithAnyTags( "solid", "livingplayer" ) + .Ignore( this ) + .Size( 1f ); + + var tr = trace.Run(); + if ( tr.Hit && tr.Entity.IsValid() && tr.Entity is Player player ) + { + LookingAt = player; + } + else + { + LookingAt = null; + } + } + + } public override void BuildInput() diff --git a/code/ui/Hud.razor b/code/ui/Hud.razor index 9fcdfdc..d6fe5b6 100644 --- a/code/ui/Hud.razor +++ b/code/ui/Hud.razor @@ -14,6 +14,7 @@ + diff --git a/code/ui/character/LookingAtInfo.razor b/code/ui/character/LookingAtInfo.razor new file mode 100644 index 0000000..4a54b81 --- /dev/null +++ b/code/ui/character/LookingAtInfo.razor @@ -0,0 +1,57 @@ +@using Sandbox; +@using Sandbox.UI; +@using System; + +@namespace MurderGame +@inherits Panel + + + +
+ @GetLookingAtName() +
+ +@code +{ + public string GetLookingAtName() + { + if (Game.LocalPawn is not Player player) return ""; + return player.LookingAt is not { } lookingAt ? "" : lookingAt.CharacterName; + } + + public string GetLookingAtColour() + { + if (Game.LocalPawn is not Player player) return "white"; + return player.LookingAt is not { } lookingAt ? "white" : lookingAt.HexColor; + } + + protected override int BuildHash() + { + return GetLookingAtName().GetHashCode(); + } +} -- cgit v1.2.3-70-g09d2