diff --git a/code/DemoPlayer.cs b/code/DemoPlayer.cs index 73e148e..2fbc69a 100644 --- a/code/DemoPlayer.cs +++ b/code/DemoPlayer.cs @@ -98,7 +98,7 @@ protected override void OnUpdate() if ( localPly is null || !localPly.IsAlive ) return; var activeWep = localPly.Inventory.Active.GetComponent(); - if ( !activeWep.IsScoping && !activeWep.IsAiming ) + if ( activeWep == null || (!activeWep.IsScoping && !activeWep.IsAiming) ) { ConsoleSystem.Run( "thirdperson" ); timeSincePerspectiveSwitch = 0; diff --git a/code/swb_editor/Commands.cs b/code/swb_editor/Commands.cs index af1f8ae..84aac5e 100644 --- a/code/swb_editor/Commands.cs +++ b/code/swb_editor/Commands.cs @@ -11,6 +11,13 @@ internal class Commands public static void OpenOffsetsEditor() { var player = PlayerBase.Local; + + if (player.Inventory.Active == null ) + { + Log.Warning("No weapon equipped. Equip one to use the editor."); + return; + } + var weaponGO = player.Inventory.Active; var weapon = weaponGO.Components.Get(); diff --git a/code/swb_hud/InventoryDisplay.cs b/code/swb_hud/InventoryDisplay.cs index c2194e3..ba070c3 100644 --- a/code/swb_hud/InventoryDisplay.cs +++ b/code/swb_hud/InventoryDisplay.cs @@ -43,12 +43,9 @@ public override void Tick() activeItem = player.Inventory.Active?.Components.Get(); - if ( activeItem is not null ) + foreach ( var entry in itemPanels ) { - foreach ( var entry in itemPanels ) - { - entry.Value.SetClass( "active", entry.Key == activeItem.Slot ); - } + entry.Value.SetClass( "active", entry.Key == activeItem?.Slot ); } CheckInput(); @@ -88,7 +85,7 @@ void GetInventoryItems() void CheckInput() { - if ( activeItem is null || !activeItem.CanCarryStop() ) return; + if ( activeItem != null && !activeItem.CanCarryStop() ) return; if ( Input.Pressed( InputButtonHelper.Slot0 ) ) SwitchItem( 0 ); else if ( Input.Pressed( InputButtonHelper.Slot1 ) ) SwitchItem( 1 ); else if ( Input.Pressed( InputButtonHelper.Slot2 ) ) SwitchItem( 2 ); diff --git a/code/swb_player/Inventory.cs b/code/swb_player/Inventory.cs index 9bba76d..7149c8d 100644 --- a/code/swb_player/Inventory.cs +++ b/code/swb_player/Inventory.cs @@ -48,7 +48,7 @@ public bool Has( GameObject gameObject ) public void SetActive( GameObject gameObject ) { - if ( !Has( gameObject ) || Active == gameObject ) return; + if ( gameObject != null && !Has( gameObject ) ) return; if ( Active is not null && Active.Components.TryGet( out var oldActive ) ) { @@ -56,13 +56,21 @@ public void SetActive( GameObject gameObject ) oldActive.OnCarryStop(); } - if ( gameObject.Components.TryGet( out var newActive, FindMode.EverythingInSelf ) ) + if( gameObject == null || Active == gameObject ) { - newActive.OnCarryStart(); + Active = null; + ActiveItem = null; } + else + { + if ( gameObject.Components.TryGet( out var newActive, FindMode.EverythingInSelf ) ) + { + newActive.OnCarryStart(); + } - Active = gameObject; - ActiveItem = newActive; + Active = gameObject; + ActiveItem = newActive; + } } public void SetActive( string name )