-
Notifications
You must be signed in to change notification settings - Fork 172
Expand file tree
/
Copy pathRust.cs
More file actions
180 lines (157 loc) · 6.06 KB
/
Rust.cs
File metadata and controls
180 lines (157 loc) · 6.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
using System;
using System.Linq;
using System.Reflection;
using Network;
using Oxide.Core;
using Oxide.Core.Libraries;
namespace Oxide.Game.Rust.Libraries
{
/// <summary>
/// A library containing utility shortcut functions for Rust
/// </summary>
public class Rust : Library
{
internal readonly Player Player = new Player();
internal readonly Server Server = new Server();
/// <summary>
/// Returns if this library should be loaded into the global namespace
/// </summary>
/// <returns></returns>
public override bool IsGlobal => false;
#region Utility
/// <summary>
/// Gets private bindingflag for accessing private methods, fields, and properties
/// </summary>
[LibraryFunction("PrivateBindingFlag")]
public BindingFlags PrivateBindingFlag() => BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Static | BindingFlags.Instance;
/// <summary>
/// Converts a string into a quote safe string
/// </summary>
/// <param name="str"></param>
[LibraryFunction("QuoteSafe")]
public string QuoteSafe(string str) => str.Quote();
#endregion Utility
#region Chat
/// <summary>
/// Broadcasts the specified chat message to all players
/// </summary>
/// <param name="name"></param>
/// <param name="message"></param>
/// <param name="userId"></param>
[LibraryFunction("BroadcastChat")]
public void BroadcastChat(string name, string message = null, string userId = "0")
{
Server.Broadcast(message, name, Convert.ToUInt64(userId));
}
/// <summary>
/// Sends a chat message to the player
/// </summary>
/// <param name="player"></param>
/// <param name="name"></param>
/// <param name="message"></param>
/// <param name="userId"></param>
[LibraryFunction("SendChatMessage")]
public void SendChatMessage(BasePlayer player, string name, string message = null, string userId = "0")
{
Player.Message(player, message, name, Convert.ToUInt64(userId));
}
#endregion Chat
#region Commands
/// <summary>
/// Runs a client command
/// </summary>
/// <param name="player"></param>
/// <param name="command"></param>
/// <param name="args"></param>
[LibraryFunction("RunClientCommand")]
public void RunClientCommand(BasePlayer player, string command, params object[] args)
{
Player.Command(player, command, args);
}
/// <summary>
/// Runs a server command
/// </summary>
/// <param name="command"></param>
/// <param name="args"></param>
[LibraryFunction("RunServerCommand")]
public void RunServerCommand(string command, params object[] args)
{
Server.Command(command, args);
}
#endregion Commands
/// <summary>
/// Returns the Steam ID for the specified connection as a string
/// </summary>
/// <param name="connection"></param>
/// <returns></returns>
[LibraryFunction("UserIDFromConnection")]
public string UserIDFromConnection(Connection connection)
{
return connection.userid.ToString();
}
/// <summary>
/// Returns the Steam ID for the specified building privilege as an array
/// </summary>
/// <param name="priv"></param>
/// <returns></returns>
[LibraryFunction("UserIDsFromBuildingPrivilege")]
public Array UserIDsFromBuildingPrivlidge(BuildingPrivlidge priv)
{
return priv.authorizedPlayers.Select(playerId => playerId.ToString()).ToArray();
}
/// <summary>
/// Returns the Steam ID for the specified player as a string
/// </summary>
/// <param name="player"></param>
/// <returns></returns>
[LibraryFunction("UserIDFromPlayer")]
public string UserIDFromPlayer(BasePlayer player) => player.UserIDString;
/// <summary>
/// Returns the Steam ID for the specified entity as a string
/// </summary>
/// <param name="entity"></param>
/// <returns></returns>
[LibraryFunction("OwnerIDFromEntity")]
public string OwnerIDFromEntity(BaseEntity entity) => entity.OwnerID.ToString();
/// <summary>
/// Returns the player for the specified name, id or ip
/// </summary>
/// <param name="nameOrIdOrIp"></param>
/// <returns></returns>
[LibraryFunction("FindPlayer")]
public BasePlayer FindPlayer(string nameOrIdOrIp) => Player.Find(nameOrIdOrIp);
/// <summary>
/// Returns the player for the specified name
/// </summary>
/// <param name="name"></param>
/// <returns></returns>
[LibraryFunction("FindPlayerByName")]
public BasePlayer FindPlayerByName(string name) => Player.Find(name);
/// <summary>
/// Returns the player for the specified id
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
[LibraryFunction("FindPlayerById")]
public BasePlayer FindPlayerById(ulong id) => Player.FindById(id);
/// <summary>
/// Returns the player for the specified id
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
[LibraryFunction("FindPlayerByIdString")]
public BasePlayer FindPlayerByIdString(string id) => Player.FindById(id);
/// <summary>
/// Forces player position (teleportation)
/// </summary>
/// <param name="player"></param>
/// <param name="x"></param>
/// <param name="y"></param>
/// <param name="z"></param>
[LibraryFunction("ForcePlayerPosition")]
public void ForcePlayerPosition(BasePlayer player, float x, float y, float z)
{
Player.Teleport(player, x, y, z);
}
}
}