- 原地址
-
Simple Status
Overview Provides an API for adding custom status messages that fit in with those of vanilla Rust. This plugin requires another plugin to utilize it, it does not do anything on its own. Check out the "Works With" list above for some plugins that utilize this API. Commands /ts Toggles the visibili...codefling.com
介绍
该插件提供API来添加类似于原版Rust状态栏UI。该插件仅提供API功能,不提供实际的功能。您需要使用其它插件来创建UI。指令
- /ts - 显示/隐藏状态栏信息
- /simplestatus.clearcache - 强制清除缓存和状态数据,可通过控制台使用,适用于开发过程的调试。
Custom Status Framework
该插件是Custom Status Framework的重写版本,该版本性能更好。它们提供相同的功能,但彼此并不兼容!请不要在服务器上同时使用这两个插件。并且本插件不向后兼容,需要开发者重新适配兼容本插件。API
C#:
void CreateStatus(Plugin plugin, string statusId, string backgroundColor = "1 1 1 1", string title = "Text", string titleColor = "1 1 1 1", string text = null, string textColor = "1 1 1 1", string imageName = null, string imageColor = "1 1 1 1")
// 注册新状态,应该在插件初始化期间调用。
void SetStatus(ulong userId, string statusId, int duration = int.MaxValue, bool pauseOffline = true)
// 为玩家分配一个有持续时间的状态。将持续时间设置为int. MaxValue以获得无限状态。设置为0以清除状态。
void SetStatusColor(ulong userId, string statusId, string color = null)
// 设置玩家状态的背景颜色。分配为null以恢复原始状态颜色。
void SetStatusTitle(ulong userId, string statusId, string title = null)
// 使用指定的本地化消息ID更新title属性。
void SetStatusTitleColor(ulong userId, string statusId, string color = null)
// 为玩家状态设置标题的颜色。分配为null以恢复原始颜色。
void SetStatusText(ulong userId, string statusId, string text = null)
// 使用指定的本地化消息ID设置文本属性。
void SetStatusTextColor(ulong userId, string statusId, string color = null)
// 设置玩家状态的文本颜色。分配为null以恢复原始颜色。
void SetStatusIcon(ulong userId, string statusId, string imageLibraryNameOrAssetPath = null)
// 更新玩家状态的图标。接受注册的图像库名称、精灵资产路径或项目ID。请参阅下方查看如何支持不同的图像。
void SetStatusIconColor(ulong userId, string statusId, string color = null)
// 为玩家状态设置图标颜色的颜色。分配为null以恢复原始颜色。
void SetStatusProperty(ulong userId, string statusId, Dictionary<string, object> properties)
// 使用单个API调用为播放器状态设置多个属性。将最大限度地减少重画次数,因此比单独设置属性更好。有关有效属性值,请参阅OnStatusUpdate挂钩。
int GetDuration(ulong userId, string statusId)
// 返回玩家状态的持续时间(以秒为单位)。如果玩家没有该状态,则返回0.
Hook
C#:
void OnStatusSet(ulong userId, string statusId, int duration)
// 在最初为玩家设置状态时调用。
void OnStatusEnd(ulong userId, string statusId, int duration)
// 当玩家的状态被移除时调用。(当持续时间达到0时)。
void OnStatusUpdate(ulong userId, string statusId, string property, string value)
// 在状态属性更新时调用。
// 'property' 参数应为: 'title', 'titleColor', 'text', 'textColor', 'icon', 'iconColor', 'color'
图片类型
C#:
// 添加star图像到图像库的示例
ImageLibrary.Call<bool>("AddImage", "https://i.imgur.com/vnHTj1C.png", "star", 0UL);
// 设置图像库ID的图片
SimpleStatus.Call("SetStatusIcon", player.userID, "MyStatusID", "star");
// 使用star图标, 但使用 RawImageComponent.
SimpleStatus.Call("SetStatusIcon", player.userID, "MyStatusID", "raw:star");
// 使用物品ID为 1326180354 的物品图标.
SimpleStatus.Call("SetStatusIcon", player.userID, "MyStatusID", "itemid:1326180354");
// 使用游戏自带的enter图标.
SimpleStatus.Call("SetStatusIcon", player.userID, "MyStatusID", "assets/icons/enter.png");
代码示例
C#:
using Oxide.Core.Libraries.Covalence;
using Oxide.Core.Plugins;
using System.Collections.Generic;
namespace Oxide.Plugins
{
[Info("SimpleStatusDemo", "mr01sam", "1.1.0")]
[Description("Allows plugins to add custom status displays for the UI.")]
partial class SimpleStatusDemo : CovalencePlugin
{
[PluginReference]
private readonly Plugin ImageLibrary;
[PluginReference]
private readonly Plugin SimpleStatus;
public static SimpleStatusDemo PLUGIN;
private void OnServerInitialized()
{
PLUGIN = this;
ImageLibrary.Call<bool>("AddImage", "https://i.imgur.com/vnHTj1C.png", "star", 0UL);
// 示例: SimpleStatus.CallHook("CreateStatus", <plugin>, <statusId>, <backgroundColor>, <title>, <titleColor>, <text>, <textColor>, <imageLibraryNameOrAssetPath>, <iconColor>);
// 提示:该图标可以是资产精灵或图像库PNG。在这个例子中,我们对标题1和标题2使用精灵,而对标题3使用图像库PNG。
SimpleStatus.CallHook("CreateStatus", this, "status1", "0.77255 0.23922 0.15686 1", "title1", "0.91373 0.77647 0.75686 1", "text1", "0.91373 0.77647 0.75686 1", "assets/icons/home.png", "0.91373 0.77647 0.75686 1");
SimpleStatus.CallHook("CreateStatus", this, "status2", "0.35490 0.40980 0.24510 1", "title2", "0.69804 0.83137 0.46667 1", "text2", "0.69804 0.83137 0.46667 1", "assets/icons/info.png", "0.69804 0.83137 0.46667 1");
SimpleStatus.CallHook("CreateStatus", this, "status3", "0.08627 0.25490 0.38431 1", "title3", "0.25490 0.61176 0.86275 1", "text3", "0.25490 0.61176 0.86275 1", "star", "0.25490 0.61176 0.86275 1");
}
[Command("show")]
private void CmdShow(IPlayer player, string command, string[] args)
{
int duration = int.MaxValue;
if (args.Length > 0)
{
int.TryParse(args[0], out duration);
}
var basePlayer = player.Object as BasePlayer;
// EXAMPLE: SimpleStatus.CallHook("SetStatus", <userId>, <statusId>, <duration>, <pauseWhenOffline>);
// TIP: If you want the status to have no duration (be infinite) pass the duration as max value int otherwise,
// pass the number of seconds you want it to appear for.
SimpleStatus.CallHook("SetStatus", basePlayer.userID, "status3", duration);
SimpleStatus.CallHook("SetStatus", basePlayer.userID, "status2", duration);
SimpleStatus.CallHook("SetStatus", basePlayer.userID, "status1", duration);
}
[Command("change")]
private void CmdChange(IPlayer player, string command, string[] args)
{
var basePlayer = player.Object as BasePlayer;
// EXAMPLE: SimpleStatus.CallHook("SetStatusProperty", <userId>, <statusId>, <property dictionary>);
// TIP: You can set multiple properties at once with this method. See documentation for the keys for each
// property.
SimpleStatus.CallHook("SetStatusProperty", basePlayer.userID, "status3", new Dictionary<string, object>
{
["title"] = "changes",
["titleColor"] = GetRandomColor()
});
}
[Command("hide")]
private void CmdHide(IPlayer player, string command, string[] args)
{
var basePlayer = player.Object as BasePlayer;
// TIP: To remove a status from a player, set the duration to 0.
SimpleStatus.CallHook("SetStatus", basePlayer.userID, "status3", 0);
SimpleStatus.CallHook("SetStatus", basePlayer.userID, "status2", 0);
SimpleStatus.CallHook("SetStatus", basePlayer.userID, "status1", 0);
}
private string GetRandomColor() => $"{UnityEngine.Random.Range(0f, 1f)} {UnityEngine.Random.Range(0f, 1f)} {UnityEngine.Random.Range(0f, 1f)} 1";
protected override void LoadDefaultMessages()
{
lang.RegisterMessages(new Dictionary<string, string>
{
["title1"] = "Simple",
["title2"] = "Status",
["title3"] = "Rocks!",
["text1"] = "Make",
["text2"] = "Custom",
["text3"] = "Statuses",
["changes"] = "Changes!"
}, this);
}
}
}