-
Notifications
You must be signed in to change notification settings - Fork 0
PlayerUtil
Kanisuko edited this page May 24, 2026
·
7 revisions
Namespace: ScavLib.util
Safe, null-protected wrappers around the player's inventory and basic state.
All methods return safe default values (0, false, null) when no world
is loaded — they will never throw a NullReferenceException.
| Method | Returns | Description |
|---|---|---|
GiveItem(string id) |
GameObject |
Spawn item at player feet and auto-pickup. Returns the spawned GameObject, or null on failure. |
TakeItem(string id) |
bool |
Drop the first inventory item matching the given ID. Returns true if found and dropped. |
HasItem(string id) |
bool |
Check if the player has at least one item with the given ID in their surface inventory (slots + wearables). |
GetAllItems() |
List<Item> |
Get all items currently in the player's slot inventory (not wearables). Returns an empty list if not in game. |
| Method | Returns | Condition |
|---|---|---|
IsAlive() |
bool |
brainHealth > 0 |
IsConscious() |
bool |
Alive AND consciousness > 30
|
IsDying() |
bool |
Any critical vital threshold breached |
| Method | Returns | Notes |
|---|---|---|
GetHunger() |
float |
Current hunger value. Returns 0 if not in game. |
GetThirst() |
float |
Current thirst value. Returns 0 if not in game. |
using ScavLib.util;
using ScavLib.event_bus;
using ScavLib.event_bus.events;
public class MyMod : BaseUnityPlugin
{
private void Awake()
{
EventBus.Register(this);
}
[Subscribe]
private void OnWorldLoaded(WorldLoadedEvent e)
{
if (PlayerUtil.IsAlive())
{
GameUtil.Log($"Hunger: {PlayerUtil.GetHunger()}");
GameUtil.Log($"Thirst: {PlayerUtil.GetThirst()}");
}
PlayerUtil.GiveItem("bandage");
if (PlayerUtil.HasItem("rifle"))
GameUtil.Log("Player has a rifle!");
}
}