Get the player username from a SteamID.
string GetUsernameFromSteamID(CSteamID steamid)
string username = RAPI.GetUsernameFromSteamID(playersteamid);RConsole.Log("The player name is " + username);
Toggle the mouse cursor.
void ToggleCursor(bool var)
RAPI.ToggleCursor(true); // This will show the cursor.RAPI.ToggleCursor(false); // This will hide the cursor.
Register a new item.
void RegisterItem(Item_Base item)
// Here we load the item from the assetbundleItem_Base yournewitem = asset.LoadAsset<Item_Base>("yournewitem");// Then we register it using RegisterItem()RAPI.RegisterItem(yournewitem);
Set an item prefab.
void SetItemObject(Item_Base item, GameObject prefab)// The default hand is right. RItemHand can be leftHand or rightHand.void SetItemObject(Item_Base item, GameObject prefab, RItemHand parent)
// Here we load the item from the assetbundleItem_Base yournewitem = asset.LoadAsset<Item_Base>("yournewitem");// Then we register it using RegisterItem()RAPI.RegisterItem(yournewitem);// Then we set his prefab by loading it from the assetbundleRAPI.SetItemObject(yournewitem, asset.LoadAsset<GameObject>("yournewitem"));
Gets the local Network_Player script.
Network_Player GetLocalPlayer()
Network_Player player = RAPI.GetLocalPlayer();// The player variable will contain the local player script.
Give an item to the local player.
void GiveItem(Item_Base item, int amount)
RAPI.GiveItem(ItemManager.GetItemByName("raw_potato"),10);// This will give 10 raw potatoes to the local player.
Broadcast a chat message.
void BroadcastChatMessage(string message)
RAPI.BroadcastChatMessage("I'm a message");// Will send "I'm a message" to every players.
Allow the placement of a block on the grid system.
void AddItemToBlockQuadType(Item_Base item, RBlockQuadType quadtype)
RAPI.AddItemToBlockQuadType(YourNewItem, RBlockQuadType.quad_foundation);// Allow "YourNewItem" to be placed on foundations.
Disallow the placement of a block on the grid system.
void RemoveItemFromBlockQuadType(string itemUniqueName, RBlockQuadType quadtype)
RAPI.RemoveItemFromBlockQuadType("YourItemUniqueName", RBlockQuadType.quad_foundation);// Disallow the item with the uniquename "YourItemUniqueName" to be placed on foundations.​
Listen for network messages on a specific network channel. (0 and 1 are locked for the game and can't be used)
NetworkMessage ListenForNetworkMessagesOnChannel(int channel = 0)
// Choose a unique ID for the channel id to not interfer with other mods.NetworkMessage netMessage = RAPI.ListenForNetworkMessagesOnChannel(30);if (netMessage != null){CSteamID id = netMessage.steamid;Message message = netMessage.message;// Here we use 5000 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)5000){// Do your stuff with the message now that you know// its yours and its the wanted type.YourMessageClass msg = message as YourMessageClass;}}
Send a network message to all players.
void SendNetworkMessage(Message message, int channel = 0, EP2PSend ep2psend = EP2PSend.k_EP2PSendReliable, Target target = Target.Other, CSteamID fallbackSteamID = new CSteamID())
// This will send your network message to all players.RAPI.SendNetworkMessage(new YourMessageClass((Messages)5000));