Jump to content

1 Screenshot

  • 56
  • 2
  • 65.16 kB
  • Update details
    v1.0.0
    Released
    Download size65.16 kB
    Total versions1
    Freshness Updated today

About ServerPrefabs

Need a robust foundation for creating custom Rust entities and prefabs from your own plugins? ServerPrefabs is a powerful library plugin for Oxide/uMod and Carbon that lets plugin developers register custom server-side prefabs and entities, with support for custom networking, persistent save/load, built-in inventories, and runtime scaling.

 

🧩 What Is ServerPrefabs?

ServerPrefabs is not a standalone gameplay plugin — it’s a developer library.

It does nothing on its own. Instead, other plugins use its API to define, register, and manage their own custom prefabs and entities on the server. If you’re building advanced Rust systems with custom deployables, persistent world objects, or specialized networked entities, ServerPrefabs provides the core framework you need.

 

🛠️ Core Features

  • Custom Server-Side Prefab Registration:
    Create and register fully custom prefabs directly from your plugin. Once registered, they become usable and spawnable by the game.
  • Custom Entity Component Support:
    Attach your own BaseEntity-derived component to a prefab and define custom entity logic exactly how your plugin needs it.
  • Persistent Save / Load System:
    Custom entity save data is written to:
    oxide/data/ServerPrefabs/<prefab>.sav
  • Custom Network Serialization:
    Provide your own network save behavior so clients receive the exact entity state they need.
  • Arbitrary Per-Entity Data Storage:
    Implement stream-based save/load methods for custom entity state and plugin-specific data.
  • Built-In Inventory Component:
    Use EntityInventory for a built-in, network-replicated item container with configurable capacity and optional handler callbacks.
  • Runtime Scaling Support:
    Use Scaler to persist and replicate transform scale for custom entities.
  • Lightweight Stub Entities:
    Use StubEntity for lightweight, non-saving entities with RPC and save event hooks, plus a helper factory for cloning visuals and bounds from a base prefab.
  • Per-Entity Behavior Flags:
    Opt into special behaviors such as disabling disk saving or excluding entities from spawn command lists via CustomFlags.

 

🔌 Public API

The main entry point is:

ServerPrefabs.For(plugin)

This returns a per-plugin context you can use to create and register prefabs.

Example usage:

var prefab = ServerPrefabs.For(this)
    .CreatePrefab("my_thing")
    .AddEntityComponent<MyEntity>(clientPrefabId)
    .Register();

This workflow allows a consumer plugin to:

  • Create a custom prefab
  • Attach a custom BaseEntity component
  • Register it with the game
  • Make it available for spawning and runtime use

 

🧠 Extension Interfaces

  • ICustomPrefab
    Calls OnCustomPrefabRegistered() once the prefab is registered.
  • ICustomEntity
    Calls OnCustomEntityRegistered() when the custom entity is registered.
  • ICustomEntity.SaveForNetwork
    Lets you customize the network proto sent to clients.
  • ICustomEntity.SaveData
    Adds Save(Stream) and Load(Stream) support for arbitrary per-entity data.

 

🚩 Entity Flags

Optional behaviors are controlled through the EntityFlags CustomFlags property on ICustomEntity.

By default, the value is EntityFlags.None, so you only override it when special behavior is needed. The property is named CustomFlags specifically to avoid colliding with BaseEntity.Flags.

Example:

class MyEntity : BaseEntity, ServerPrefabs.ICustomEntity
{
    public void OnCustomEntityRegistered() { }

    public ServerPrefabs.EntityFlags CustomFlags =>
        ServerPrefabs.EntityFlags.DisableSaving | ServerPrefabs.EntityFlags.NoSpawnCommand;
}

Available flags:

  • EntityFlags.None
    No special behavior.
  • EntityFlags.DisableSaving
    Excludes the entity from disk saving by setting enableSaving = false.
  • EntityFlags.NoSpawnCommand
    Prevents the entity from being added to the spawnable-entity command list.

 

🧰 Included Components

  • EntityInventory
    A built-in, network-replicated item container. Set Capacity and optionally assign an EntityInventory.IHandler with callbacks such as:
    • OnCreated
    • OnInventoryDirty
    • OnItemAddedOrRemoved
    • ItemFilter
  • Scaler
    Persists and replicates entity transform scale.
  • StubEntity
    A lightweight, non-saving entity with onRpcMessage and onSave events, plus a StubEntity.Create<T>(...) factory for cloning visuals and bounds from a base prefab.

 

👉 Installation

  1. Drop ServerPrefabs.cs into:
    • oxide/plugins/
    • or carbon/plugins/
  2. The server will compile and load it automatically.
  3. On first load, a config file is generated.
  4. Dependent plugins can reference it via:
    • [PluginReference] Plugin ServerPrefabs;
    • or the static API

 

⚙️ Configuration

Configuration file:

oxide/config/ServerPrefabs.json

  • Allow outdated saves
    Default: false
    Allows loading .sav files written by a different Rust save protocol version.
  • Enable debug logging
    Default: false
    Enables verbose [ServerPrefabs] [DEBUG] log output for troubleshooting.

Safe Config Recovery:
If the config becomes invalid or unreadable, it is automatically backed up as ServerPrefabs.json.bak. A new default config is then generated, so a broken manual edit won’t silently destroy your settings.

 

🚦 Compatibility Notes

ServerPrefabs uses Harmony IL transpilers against Rust internals, specifically:

  • SaveRestore.Load
  • SaveRestore.WriteEntities

Because these patches rely on specific internal instruction patterns, a Rust update can break compatibility.

After a force wipe or game update, check the server console during load for errors like:

  • Phase 1 failed!
  • Phase 2 failed!
  • Phase 3 failed!
  • or other patch-related errors

If those appear, the plugin likely needs to be updated to match the current Rust version.

 

💡 Why Use ServerPrefabs?

  • Create advanced custom entities directly from your plugin
  • Add server-side prefabs with persistent save/load support
  • Customize network behavior for non-standard entities
  • Use built-in inventory and scaling systems instead of building your own
  • Control save and spawn-list behavior with simple entity flags
  • Perfect for framework plugins, deployables, machines, automation systems, and persistent world objects

 

ServerPrefabs is a core utility library for Rust plugin developers who want deeper control over custom entities and prefab-based systems.

 

One library. Custom prefabs. Persistent entities. A powerful base for advanced Rust modding.


User Feedback

About Us

Codefling is the largest marketplace for plugins, maps, tools, and more, making it easy for customers to discover new content and for creators to monetize their work.

Downloads
2.5m
Total downloads
Customers
11.3k
Customers served
Files Sold
161.5k
Total sales
Payments
3.5m
Processed total
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.