Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion code/DemoPlayer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ protected override void OnUpdate()
if ( localPly is null || !localPly.IsAlive ) return;

var activeWep = localPly.Inventory.Active.GetComponent<Weapon>();
if ( !activeWep.IsScoping && !activeWep.IsAiming )
if ( activeWep == null || (!activeWep.IsScoping && !activeWep.IsAiming) )
{
ConsoleSystem.Run( "thirdperson" );
timeSincePerspectiveSwitch = 0;
Expand Down
7 changes: 7 additions & 0 deletions code/swb_editor/Commands.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Weapon>();

Expand Down
9 changes: 3 additions & 6 deletions code/swb_hud/InventoryDisplay.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,9 @@ public override void Tick()

activeItem = player.Inventory.Active?.Components.Get<IInventoryItem>();

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();
Expand Down Expand Up @@ -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 );
Expand Down
18 changes: 13 additions & 5 deletions code/swb_player/Inventory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,21 +48,29 @@ 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<IInventoryItem>( out var oldActive ) )
{
if ( !oldActive.CanCarryStop() ) return;
oldActive.OnCarryStop();
}

if ( gameObject.Components.TryGet<IInventoryItem>( out var newActive, FindMode.EverythingInSelf ) )
if( gameObject == null || Active == gameObject )
{
newActive.OnCarryStart();
Active = null;
ActiveItem = null;
}
else
{
if ( gameObject.Components.TryGet<IInventoryItem>( out var newActive, FindMode.EverythingInSelf ) )
{
newActive.OnCarryStart();
}

Active = gameObject;
ActiveItem = newActive;
Active = gameObject;
ActiveItem = newActive;
}
}

public void SetActive( string name )
Expand Down