LogoLogo
Back to raftmodding.com
  • Welcome to the RaftModding docs!
  • ⬇️Getting started
    • Installing Raft Mod Loader
      • Troubleshooting
        • An error occured while fetching for updates
          • Disabling IPV6
          • Changing the DNS
        • The menu inside the game doesn't show up
        • The game crashes on startup
        • There are error notifications in-game
      • Linux or Steam Deck installation
        • Using Bottles
        • Using Wine
      • Configuring your antivirus
        • Windows Defender
        • Malwarebytes
        • Bitdefender
        • Avast
        • Norton
        • AVG
    • Installing a mod
      • Mods in multiplayer
    • How to run multiple raft instances
  • ⚙️MODDING TUTORIALS
    • How to create a mod project
      • The modinfo.json file
    • How to create an AssetBundle
    • How to create console commands
    • Harmony basics
    • Getting access to the modding repositories
  • ⚒️Modding API
    • RAPI
    • Mod
  • 📚Modding Examples
    • Accessing the player instance
    • Adding private variables
    • Spawning dropped items
    • Get selected hotbar item
    • Get the current SteamID
    • Get the current username
    • Giving items to a player
    • Modifying private variables
  • 🌏WEBSITE
    • Mod Slugs (Unique Identifier)
  • 🖥️RAFT DEDICATED SERVER
    • Raft Dedicated Server
Powered by GitBook
On this page
  • Allows mods to determine if they can be unloaded at the said moment.
  • Unloads the mod.
  • Gets the bytes of an embedded file in the mod.
  • Gets the mod information.
  • Logs a message with the mod name as a prefix.
  • The WorldEvent_WorldLoaded event triggers on world load complete.
  • The WorldEvent_WorldSaved event triggers on world save.
  • The LocalPlayerEvent_Hurt event triggers when the local player takes damage.
  • The LocalPlayerEvent_Death event triggers when the local player dies.
  • The LocalPlayerEvent_Respawn event triggers when the local player respawns.
  • The LocalPlayerEvent_ItemCrafted event triggers when the local player crafts an item.
  • The LocalPlayerEvent_PickupItem event triggers when the local player picks up a dropped item.
  • The LocalPlayerEvent_DropItem event triggers when the local player drops an item.
  • The WorldEvent_OnPlayerConnected event triggers when a player connects to the world.
  • The WorldEvent_OnPlayerDisconnected event triggers when a player disconnects from the world.
  • The WorldEvent_WorldUnloaded event triggers on world unload.
  • The ModEvent_OnModLoaded event triggers when a mod is loaded.
  • The ModEvent_OnModUnloaded event triggers when a mod is unloaded.

Was this helpful?

  1. Modding API

Mod

The Mod class serves as the base class for all mods, containing essential information about your mod, customizable events, and more. All mods inherit from this class.

Allows mods to determine if they can be unloaded at the said moment.

// Mod.CanUnload(System.String@)
public virtual bool CanUnload(ref string message)
bool stillLoading = true;
public override bool CanUnload(ref string message)
{
    if (stillLoading)
    {
        message = "The mod is still loading";
        return false;
    }
    return base.CanUnload(ref message);
}

Unloads the mod.

// Mod.UnloadMod()
public virtual void UnloadMod()

Gets the bytes of an embedded file in the mod.

Returns the bytes of the embedded file, or null if the file doesn't exist.

// Mod.GetEmbeddedFileBytes(System.String)
public virtual byte[] GetEmbeddedFileBytes(string path)
byte[] myBundleBytes = GetEmbeddedFileBytes("mybundle.assets");
AssetBundle bundle = AssetBundle.LoadFromMemory(myBundleBytes);

Gets the mod information.

Returns the mod information from the modinfo.json file.

// Mod.GetModInfo()
public JsonModInfo GetModInfo()
Debug.Log("Mod version: "+GetModInfo().version);

Logs a message with the mod name as a prefix.

// Mod.Log(System.Object)
public void Log(object message)
Log("This is a message"); // Outputs: "[ModName] This is a message".

The WorldEvent_WorldLoaded event triggers on world load complete.

// Mod.WorldEvent_WorldLoaded()
public virtual void WorldEvent_WorldLoaded()
public override void WorldEvent_WorldLoaded()
{
    Debug.Log("The world has loaded");
}

The WorldEvent_WorldSaved event triggers on world save.

// Mod.WorldEvent_WorldSaved()
public virtual void WorldEvent_WorldSaved()
public override void WorldEvent_WorldSaved()
{
    Debug.Log("The world has been saved");
}

The LocalPlayerEvent_Hurt event triggers when the local player takes damage.

// Mod.LocalPlayerEvent_Hurt(System.Single,UnityEngine.Vector3,UnityEngine.Vector3,EntityType)
public virtual void LocalPlayerEvent_Hurt(float damage, Vector3 hitPoint, Vector3 hitNormal, EntityType damageInflictorEntityType)
public override void LocalPlayerEvent_Hurt(float damage, Vector3 hitPoint, Vector3 hitNormal, EntityType damageInflictorEntityType)
{
    Debug.Log("Player hurt: " + damage + " damage taken");
}

The LocalPlayerEvent_Death event triggers when the local player dies.

// Mod.LocalPlayerEvent_Death(UnityEngine.Vector3)
public virtual void LocalPlayerEvent_Death(Vector3 deathPosition)
public override void LocalPlayerEvent_Death(Vector3 deathPosition)
{
    Debug.Log("Player died at: " + deathPosition);
}

The LocalPlayerEvent_Respawn event triggers when the local player respawns.

// Mod.LocalPlayerEvent_Respawn()
public virtual void LocalPlayerEvent_Respawn()
public override void LocalPlayerEvent_Respawn()
{
    Debug.Log("Player respawned");
}

The LocalPlayerEvent_ItemCrafted event triggers when the local player crafts an item.

// Mod.LocalPlayerEvent_ItemCrafted(Item_Base)
public virtual void LocalPlayerEvent_ItemCrafted(Item_Base item)
public override void LocalPlayerEvent_ItemCrafted(Item_Base item)
{
    Debug.Log("Item crafted: " + item.UniqueName);
}

The LocalPlayerEvent_PickupItem event triggers when the local player picks up a dropped item.

// Mod.LocalPlayerEvent_PickupItem(PickupItem)
public virtual void LocalPlayerEvent_PickupItem(PickupItem item)
public override void LocalPlayerEvent_PickupItem(PickupItem item)
{
    Debug.Log("Picked up item: " + item.itemInstance?.UniqueName);
}

The LocalPlayerEvent_DropItem event triggers when the local player drops an item.

// Mod.LocalPlayerEvent_DropItem(ItemInstance,UnityEngine.Vector3,UnityEngine.Vector3,System.Boolean)
public virtual void LocalPlayerEvent_DropItem(ItemInstance item, Vector3 position, Vector3 direction, bool parentedToRaft)
public override void LocalPlayerEvent_DropItem(ItemInstance item, Vector3 position, Vector3 direction, bool parentedToRaft)
{
    Debug.Log("Dropped item: " + item.UniqueName + " at position: " + position);
}

The WorldEvent_OnPlayerConnected event triggers when a player connects to the world.

// Mod.WorldEvent_OnPlayerConnected(Steamworks.CSteamID,RGD_Settings_Character)
public virtual void WorldEvent_OnPlayerConnected(CSteamID steamid, RGD_Settings_Character characterSettings)
public override void WorldEvent_OnPlayerConnected(CSteamID steamid, RGD_Settings_Character characterSettings)
{
    Debug.Log("Player connected: " + steamid);
}

The WorldEvent_OnPlayerDisconnected event triggers when a player disconnects from the world.

// Mod.WorldEvent_OnPlayerDisconnected(Steamworks.CSteamID,DisconnectReason)
public virtual void WorldEvent_OnPlayerDisconnected(CSteamID steamid, DisconnectReason disconnectReason)
public override void WorldEvent_OnPlayerDisconnected(CSteamID steamid, DisconnectReason disconnectReason)
{
    Debug.Log("Player disconnected: " + steamid + " Reason: " + disconnectReason);
}

The WorldEvent_WorldUnloaded event triggers on world unload.

// Mod.WorldEvent_WorldUnloaded()
public virtual void WorldEvent_WorldUnloaded()
public override void WorldEvent_WorldUnloaded()
{
    Debug.Log("World unloaded");
}

The ModEvent_OnModLoaded event triggers when a mod is loaded.

// Mod.ModEvent_OnModLoaded(HMLLibrary.Mod)
public virtual void ModEvent_OnModLoaded(Mod mod)
public override void ModEvent_OnModLoaded(Mod mod)
{
    Debug.Log("Mod loaded: " + mod.name);
}

The ModEvent_OnModUnloaded event triggers when a mod is unloaded.

// Mod.ModEvent_OnModUnloaded(HMLLibrary.Mod)
public virtual void ModEvent_OnModUnloaded(Mod mod)
public override void ModEvent_OnModUnloaded(Mod mod)
{
    Debug.Log("Mod unloaded: " + mod.name);
}
PreviousRAPINextAccessing the player instance

Last updated 1 year ago

Was this helpful?

⚒️