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)
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.
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;
}
}