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