The spawning utilities provide methods to create custom items either as world pickups or directly in a player’s inventory.Documentation Index
Fetch the complete documentation index at: https://mintlify.com/Bill3621/CustomItems/llms.txt
Use this file to discover all available pages before exploring further.
TrySpawn
Spawns a custom item as a pickup at a specific world position.Parameters
The unique identifier of the custom item to spawn
The world position where the pickup should be spawned
When this method returns, contains the spawned Pickup object if successful, or null if the spawn failed
Returns
true if the item was successfully spawned; otherwise, false.
Behavior
- Validates that a custom item with the specified ID exists in the registry
- Creates a pickup at the specified position using the item’s base type
- Sets the pickup’s weight to match the custom item’s weight
- Registers the pickup in the CurrentItems dictionary with a new instance of the custom item
- Spawns the pickup on the network using NetworkServer
- Logs the spawn event with the item name, ID, position, and serial number
Example
TryGive
Gives a custom item directly to a player’s inventory.Parameters
The unique identifier of the custom item to give
The player who will receive the item
When this method returns, contains the Item object that was added to the player’s inventory if successful, or null if the operation failed
The reason for adding the item, used for tracking and event handling
Returns
true if the item was successfully given to the player; otherwise, false.
Behavior
- Validates that a custom item with the specified ID exists in the registry
- Adds the item to the player’s inventory using the item’s base type
- Registers the item in the CurrentItems dictionary with a new instance of the custom item
- Logs the give event with the item name, ID, player nickname, and serial number
Example
Notes
- Both methods create a new instance of the custom item class using
Activator.CreateInstance - The spawned/given items are automatically tracked in the
CurrentItemsdictionary by their serial number - If the custom item ID is not registered, the methods return
falseimmediately - For
TryGive, if the player’s inventory is full or the item cannot be added for any reason, the method returnsfalse