Can anyone help fix this old plugin?
getting error: "Error while compiling: HitInformer.cs(209,151): error CS0234: The type or namespace name `ObjectList' does not exist in the namespace `Facepunch'. Are you missing an assembly reference?"
// Reference: Newtonsoft.Json
using UnityEngine;
using Rust;
using System;
using System.Reflection;
using System.Collections;
using System.Collections.Generic;
using Oxide.Core;
using Oxide.Core.Plugins;
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;
namespace Oxide.Plugins
{
[Info("HitInformer", "Wolfs Darker", "1.0.0")]
class HitInformer : RustPlugin
{
static String[] BODY_PARTS = { "SPINE", "LIP", "JAW", "NECK", "TAIL", "HIP", "FOOT", "PELVIS",
"LEG", "HEAD", "ARM", "JOINT", "PENIS", "WING", "EYE",
"EAR", "STOMACH", "MANE", "CLAVICLE", "FINGERS", "THIGH", "GROUP", "SHOULDER",
"CALF", "TOE", "HAND", "KNEE", "FOREARM", "UPPERARM", "TONGUE", "SHIN", "ULNA", "ROOTBONE",
"BROW" };
static String[] BODY_NAMES = { "Spine", "Lips", "Jaw", "Neck",
"Tail", "Hip", "Feet", "Pelvis", "Leg", "Head",
"Arm", "Joint", "Penis", "Wing", "Eye", "Ear", "Stomach", "Mane", "Clavicle",
"Fingers", "Thigh", "Group", "Shoulder", "Calf", "Toe",
"Hand", "Knee", "Forearm", "Upperarm", "Tongue", "Shin",
"Elbow", "Rootbone", "Brow" };
static string ATTACK_GUI_DATA = @"[
{
""name"": ""AttackHit"",
""parent"": ""Overlay"",
""components"":
[
{
""type"":""UnityEngine.UI.Image"",
""color"":""0.1 0.1 0.1 0.7"",
},
{
""type"":""RectTransform"",
""anchormin"": ""0.280 0.920"",
""anchormax"": ""0.720 0.990""
}
]
},
{
""parent"": ""AttackHit"",
""components"":
[
{
""type"":""UnityEngine.UI.Text"",
""text"":""{message}"",
""fontSize"":15,
""align"": ""MiddleCenter"",
},
{
""type"":""RectTransform"",
""anchormin"": ""0 0.350"",
""anchormax"": ""1 0.730""
}
]
}
]
";
static string TARGET_GUI_DATA = @"[
{
""name"": ""TargetHit"",
""parent"": ""Overlay"",
""components"":
[
{
""type"":""UnityEngine.UI.Image"",
""color"":""0.1 0.1 0.1 0.7"",
},
{
""type"":""RectTransform"",
""anchormin"": ""0.280 0.840"",
""anchormax"": ""0.720 0.910""
}
]
},
{
""parent"": ""TargetHit"",
""components"":
[
{
""type"":""UnityEngine.UI.Text"",
""text"":""{message}"",
""fontSize"":15,
""align"": ""MiddleCenter"",
},
{
""type"":""RectTransform"",
""anchormin"": ""0 0.35"",
""anchormax"": ""1 0.73""
}
]
}
]
";
Configuration config = new Configuration();
public class Configuration
{
public int message_delay;
public List<String> players_list = new List<String>();
}
protected override void LoadDefaultConfig()
{
config.message_delay = 1;
Config["configuration"] = config;
SaveConfig();
}
void Loaded()
{
if(!permission.PermissionExists("hitinformer.use")) permission.RegisterPermission("hitinformer.use", this);
Puts("HitInformer Loaded!");
}
[HookMethod("OnServerInitialized")]
void OnServerInitialized()
{
try
{
if(!permission.PermissionExists("hitinformer.use")) permission.RegisterPermission("hitinformer.use", this);
LoadConfig();
config = JsonConvert.DeserializeObject<Configuration>(JsonConvert.SerializeObject(Config["configuration"]).ToString());
}
catch (Exception ex)
{
Puts("OnServerInitialized failed: " + ex.Message);
}
}
void OnPlayerAttack(BasePlayer attacker, HitInfo hitInfo)
{
if (attacker == null || hitInfo == null || hitInfo.HitEntity == null || !(hitInfo.HitEntity is BasePlayer))
return;
//----------------------------> removed by isuelt
// if (!config.players_list.Contains(attacker.userID.ToString()))
// return;
String bone = StringPool.Get(hitInfo.HitBone).ToUpper();
BasePlayer target = hitInfo.HitEntity as BasePlayer;
if (target == null ) { return; }
bone = bone.Replace("R_", "").Replace("L_", "");
if (bone.Contains("SPINE"))
bone = "SPINE";
for (int i = 0; i < BODY_PARTS.Length; i++)
{
if (BODY_PARTS[i].Equals(bone))
{
bone = ", Body Part: " + BODY_NAMES[i];
break;
}
}
if (!bone.Contains("Body Part"))
{
bone = "";
}
sendGui(attacker, "You attacked <color=yellow>" + target.displayName + "</color>!(Distance: " + (int)attacker.Distance(target) + "m" + bone + ")", ATTACK_GUI_DATA);
if (config.players_list.Contains(target.userID.ToString()))
sendGui(target, "<color=yellow>" + attacker.displayName + "</color> attacked you!(Distance: " + (int)attacker.Distance(target) + "m)", TARGET_GUI_DATA);
ConVar.Server.Log("oxide/logs/attack-log.txt", "|" + attacker.displayName +"|" + (int)attacker.Distance(target) +"m|"+ bone + "|" );
}
void sendGui(BasePlayer player, String message, String data)
{
// Changed by isuelt
// CommunityEntity.ServerInstance.ClientRPCEx(new Network.SendInfo() { connection = player.net.connection }, null, "DestroyUI", data.Equals(TARGET_GUI_DATA) ? "TargetHit" : "AttackHit");
CommunityEntity.ServerInstance.ClientRPCEx(new Network.SendInfo() { connection = player.net.connection }, null, "DestroyUI", new Facepunch.ObjectList(data.Equals(TARGET_GUI_DATA) ? "TargetHit" : "AttackHit", null, null, null, null));
// Puts($"hitinformer AddGUI = " + data.Equals(TARGET_GUI_DATA) ? "TargetHit" : "AttackHit");
// CommunityEntity.ServerInstance.ClientRPCEx(new Network.SendInfo() { connection = player.net.connection }, null, "AddUI", data.Replace("{message}", message));
CommunityEntity.ServerInstance.ClientRPCEx(new Network.SendInfo() { connection = player.net.connection }, null, "AddUI", new Facepunch.ObjectList(data.Replace("{message}", message), null, null, null, null));
// Puts($"hitinformer DestroyGUI = " + data.Replace("{message}", message));
timer.Once(config.message_delay, () =>
{
// changed by isuelt
// CommunityEntity.ServerInstance.ClientRPCEx(new Network.SendInfo() { connection = player.net.connection }, null, "DestroyUI", data.Equals(TARGET_GUI_DATA) ? "TargetHit" : "AttackHit");
// Puts($"hitinformer delay ended - " + config.message_delay);
CommunityEntity.ServerInstance.ClientRPCEx(new Network.SendInfo() { connection = player.net.connection }, null, "DestroyUI", new Facepunch.ObjectList(data.Equals(TARGET_GUI_DATA) ? "TargetHit" : "AttackHit", null, null, null, null));
CommunityEntity.ServerInstance.ClientRPCEx(new Network.SendInfo() { connection = player.net.connection }, null, "DestroyUI", new Facepunch.ObjectList(data.Replace("{message}", message), null, null, null, null));
});
}
[ChatCommand("hitdelay")]
void cmdHitDelay(BasePlayer player, string command, string[] args)
{
if (player.net.connection.authLevel < 2 && !permission.UserHasPermission(player.userID.ToString(), "hit_delay"))
{
SendReply(player, "You don't have access to this command.");
return;
}
if (args.Length == 0)
{
SendReply(player, "Wrong command usage! Try again! (/hitdelay time (in seconds)");
return;
}
try
{
config.message_delay = int.Parse(args[0]);
Config["configuration"] = config;
SaveConfig();
}
catch (Exception e)
{
SendReply(player, "Invalid time value! Try again! (/hitdelay time (in seconds)");
Puts("Message delay error: " + e.Message);
}
}
[ChatCommand("togglehit")]
void cmdToggleHit(BasePlayer player, string command, string[] args)
{
if (player.net.connection.authLevel < 2 && !permission.UserHasPermission(player.userID.ToString(), "hitinformer.use"))
{
SendReply(player, "You don't have access to this command.");
return;
}
if (config.players_list.Contains(player.userID.ToString()))
{
config.players_list.Remove(player.userID.ToString());
SendReply(player, "Hit detector is Off!");
}
else
{
config.players_list.Add(player.userID.ToString());
SendReply(player, "Hit detector is On!");
}
Config["configuration"] = config;
SaveConfig();
}
}
}