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
  • Checks if the game is running on a dedicated server.
  • Checks if the current active scene is the main menu.
  • Checks if the current active scene is the main game scene.
  • Gets the username associated with a SteamID.
  • Toggle the mouse cursor with high priority (mostly used by the mod loader).
  • Toggle the mouse cursor.
  • Gets the local player object from the network.
  • Broadcasts a chat message to all players.
  • Gives a specified amount of items to the local player.
  • Allows an item to be placed on a specific block quad type.
  • Disallows an item from being placed on a specific block quad type.
  • Registers a new item.
  • Unregisters an item, removing it from inventories and world.
  • Sets the in-hand prefab object for a specific item.
  • Sends a network message to all players.
  • Listens for network messages on a specific network channel.

Was this helpful?

  1. Modding API

RAPI

The RAPI class provides convenient methods for various actions, including adding new items and showing the cursor, making modding tasks easier and more accessible.

Checks if the game is running on a dedicated server.

Returns true if the game is running on a dedicated server, false otherwise.

// RAPI.IsDedicatedServer()
public static bool IsDedicatedServer()

Checks if the current active scene is the main menu.

Returns true if the current active scene is the main menu, false otherwise.

// RAPI.IsCurrentSceneMainMenu()
public static bool IsCurrentSceneMainMenu()

Checks if the current active scene is the main game scene.

Returns true if the current active scene is the main game scene, false otherwise.

// RAPI.IsCurrentSceneGame()
public static bool IsCurrentSceneGame()

Gets the username associated with a SteamID.

Returns the player's username.

// RAPI.GetUsernameFromSteamID(Steamworks.CSteamID)
public static string GetUsernameFromSteamID(CSteamID steamid)
string username = RAPI.GetUsernameFromSteamID(playerSteamID);
Debug.Log("Player username: " + username);

Toggle the mouse cursor with high priority (mostly used by the mod loader).

// RAPI.TogglePriorityCursor(System.Boolean)
public static void TogglePriorityCursor(bool status)
RAPI.ToggleCursor(true); // This will show the cursor.
RAPI.ToggleCursor(false); // This will hide the cursor.

Toggle the mouse cursor.

// RAPI.ToggleCursor(System.Boolean)
public static void ToggleCursor(bool status)
RAPI.ToggleCursor(true); // This will show the cursor.
RAPI.ToggleCursor(false); // This will hide the cursor.

Gets the local player object from the network.

Returns the local player object.

// RAPI.GetLocalPlayer()
public static Network_Player GetLocalPlayer()
Network_Player player = RAPI.GetLocalPlayer();
// The player variable will contain the local player script.

Broadcasts a chat message to all players.

// RAPI.BroadcastChatMessage(System.String)
public static void BroadcastChatMessage(string message)
RAPI.BroadcastChatMessage("I'm a message");
// Will send "I'm a message" to every player.

Gives a specified amount of items to the local player.

// RAPI.GiveItem(Item_Base,System.Int32)
public static void GiveItem(Item_Base item, int amount)
RAPI.GiveItem(ItemManager.GetItemByName("item_name"), 5);
// Gives 5 items of "item_name" to the local player.

Allows an item to be placed on a specific block quad type.

// RAPI.AddItemToBlockQuadType(Item_Base,RBlockQuadType)
public static void AddItemToBlockQuadType(Item_Base item, RBlockQuadType quadtype)
RAPI.AddItemToBlockQuadType(YourNewItem, RBlockQuadType.quad_foundation);
// Allow "YourNewItem" to be placed on foundations.

Disallows an item from being placed on a specific block quad type.

// RAPI.RemoveItemFromBlockQuadType(System.String,RBlockQuadType)
public static void RemoveItemFromBlockQuadType(string itemUniqueName, RBlockQuadType quadtype)
RAPI.RemoveItemFromBlockQuadType("YourItemUniqueName", RBlockQuadType.quad_foundation);
// Disallow the item with the uniquename "YourItemUniqueName" to be placed on foundations.

Registers a new item.

// RAPI.RegisterItem(Item_Base,System.Boolean)
public static void RegisterItem(Item_Base item, bool ignoreMaxValues = false)
RAPI.RegisterItem(yourItem); // Replace with actual item initialization

Unregisters an item, removing it from inventories and world.

// RAPI.UnregisterItem(Item_Base)
public static void UnregisterItem(Item_Base item)
RAPI.UnregisterItem(ItemManager.GetItemByName("item_name"));

Sets the in-hand prefab object for a specific item.

// RAPI.SetItemObject(Item_Base,UnityEngine.GameObject,RItemHand)
public static void SetItemObject(Item_Base item, GameObject prefab, RItemHand parent = RItemHand.rightHand)
Item_Base newItem = new Item_Base(); // Replace with actual item initialization
GameObject itemPrefab = new GameObject(); // Replace with actual prefab initialization
RAPI.RegisterItem(newItem);
RAPI.SetItemObject(newItem, itemPrefab);

Sends a network message to all players.

// RAPI.SendNetworkMessage(Message,System.Int32,Steamworks.EP2PSend,Target,Steamworks.CSteamID)
public static void SendNetworkMessage(Message message, int channel = 0, EP2PSend ep2psend = EP2PSend.k_EP2PSendReliable, Target target = Target.Other, CSteamID fallbackSteamID = new CSteamID())
public enum CustomMessages
{
    MyCustomMessage = 8000
}
// This will send your network message to all players.
RAPI.SendNetworkMessage(new YourMessageClass((Messages)CustomMessages.MyCustomMessage)); // Replace with your own message class.

Listens for network messages on a specific network channel.

Returns the received network message.

// RAPI.ListenForNetworkMessagesOnChannel(System.Int32)
public static NetworkMessage ListenForNetworkMessagesOnChannel(int channel = 2)
public enum CustomMessages
{
    MyCustomMessage = 8000
}
NetworkMessage netMessage = RAPI.ListenForNetworkMessagesOnChannel(15);
if (netMessage != null)
{
    CSteamID id = netMessage.steamid;
    Message message = netMessage.message;
    // Here we use 8000 because we can't modify an enum, you can use any values 
    // as long as its not in the Messages enum already. Bigger than 1000 is perfect.
    if(message.Type == (Messages)CustomMessages.MyCustomMessage){
        // Do your stuff with the message now that you know 
        // its yours and its the wanted type.
        YourMessageClass msg = message as YourMessageClass;
    }
}
PreviousGetting access to the modding repositoriesNextMod

Last updated 1 year ago

Was this helpful?

⚒️