WorldItemHandler - jimdroberts/FishMMO GitHub Wiki

Description

WorldItemHandler handles interactions with world item objects on the server in FishMMO. It allows players to pick up items from the world, adds them to inventory, and despawns the item if picked up.


API Access

Methods

  • public void HandleInteraction(IInteractable interactable, IPlayerCharacter character, ISceneObject sceneObject, InteractableSystem serverInstance)

    Handles the interaction between a player character and a world item. Validates the item, attempts to add it to the player's inventory, and despawns the item if picked up. Parameters: - IInteractable interactable: The interactable object (should be a WorldItem). - IPlayerCharacter character: The player character interacting with the item. - ISceneObject sceneObject: The scene object associated with the interaction. - InteractableSystem serverInstance: The server instance managing interactables.


Basic Usage

Setup

  1. Register WorldItemHandler as the handler for world item interactables on the server.
  2. The handler will automatically process player interactions, add items to inventory, and despawn items as needed.

Example

// Example 1: Handling a world item interaction
worldItemHandler.HandleInteraction(interactable, character, sceneObject, serverInstance);

Best Practices

  • Ensure the handler is registered for the correct interactable types.
  • Validate item data and inventory state before adding items.
  • Despawn items promptly after pickup to prevent duplication or exploits.
⚠️ **GitHub.com Fallback** ⚠️