C#:
using System.Collections.Generic;
using Oxide.Core.Configuration;
using Newtonsoft.Json;
using Oxide.Core.Plugins;
using UnityEngine;
using System.Linq;
using Oxide.Core;
using System;
using Oxide.Game.Rust.Cui;
using System.Text.RegularExpressions;
using Color = UnityEngine.Color;
using VLB;
using Rust;
namespace Oxide.Plugins {
[Info("FreezeBurn", "Ts3Hosting", "1.0.0")]
[Description("Freeze & Burn players in place")]
public class FreezeBurn : RustPlugin {
public static FreezeBurn plugin;
public readonly Dictionary<ulong, Vector3> Freeze = new Dictionary<ulong, Vector3>();
private new void LoadDefaultMessages() {
lang.RegisterMessages(new Dictionary<string, string> {
["Blocked"]
= "<color=#ce422b>You can not use this command</color>", ["usage"] = "Freeze Burn Usage:\n\n" + "<color=#ce422b>/freeze <player name></color> - Freeze the player in place.\n" + "<color=#ce422b>/unfreeze <player name></color> - UnFreeze/StopBurning the player.\n" + "<color=#ce422b>/setonfire <player name></color> - Freeze player and set on fire.\n", ["NoPlayer"] = "<color=#ce422b>No player found.</color>", ["ToManyPlayers"] = "<color=#ce422b>To many players found starting with {0}.</color>", ["FrozenAlready"] = "<color=#ce422b>{0} is frozen already.</color>", ["NotFrozen"] = "<color=#ce422b>{0} is not frozen.</color>", ["UnFrozen"] = "<color=#ce422b>{0} is now unfrozen.</color>", ["Frozen"] = "<color=#ce422b>{0} is now frozen.</color>", ["SetOnFire"] = "<color=#ce422b>{0} is now frozen and on fire.</color>", ["OnFireAlready"] = "<color=#ce422b>{0} is already frozen and on fire.</color>",
}
, this);
}
#region Config
private ConfigData configData;
class ConfigData {
[JsonProperty(PropertyName = "Settings")]
public Settings settings {
get;
set;
}
public class Settings {
public string PermissionUse {
get;
set;
}
}
public Oxide.Core.VersionNumber Version {
get;
set;
}
}
protected override void LoadConfig() {
plugin = this;
base.LoadConfig();
configData = Config.ReadObject<ConfigData>();
if (configData.Version < Version) UpdateConfigValues();
Config.WriteObject(configData, true);
}
protected override void LoadDefaultConfig() => configData = GetBaseConfig();
private ConfigData GetBaseConfig() {
return new ConfigData {
settings = new ConfigData.Settings {
PermissionUse = "freeze.use",
}
, Version = Version
}
;
}
protected override void SaveConfig() => Config.WriteObject(configData, true);
private void UpdateConfigValues() {
PrintWarning("Config update detected! Updating config values...");
ConfigData baseConfig = GetBaseConfig();
if (configData.Version < new VersionNumber(1, 0, 1)) configData = baseConfig;
configData.Version = Version;
PrintWarning("Config update completed!");
}
#endregion
void Unload() {
var Controller = UnityEngine.Object.FindObjectsOfType<PlayerFreeze>();
foreach (var insp in Controller) {
insp.Remove();
}
}
[ChatCommand("freeze")]
private void FreezePlayer(BasePlayer player, string cmd, string[] args) {
int count = 0;
BasePlayer victim = null;
if (args.Length == 0) {
SendReply(player, lang.GetMessage("usage", this, player.UserIDString));
return;
}
foreach (BasePlayer current in BasePlayer.activePlayerList.ToList()) {
if (current.displayName.Contains(args[0])) {
count++;
victim = current;
}
else if (current.displayName.ToLower().Contains(args[0].ToLower())) {
count++;
victim = current;
}
}
if (victim == null) {
SendReply(player, lang.GetMessage("NoPlayer", this, player.UserIDString));
return;
}
else if (count > 1) {
SendReply(player, lang.GetMessage("ToManyPlayers", this, player.UserIDString), args[0].ToLower());
return;
}
else {
PlayerFreeze Controller = player.GetComponent<PlayerFreeze>();
if (Controller == null) player.gameObject.AddComponent<PlayerFreeze>();
else {
SendReply(player, lang.GetMessage("FrozenAlready", this, player.UserIDString), victim.displayName);
return;
}
SendReply(player, lang.GetMessage("Frozen", this, player.UserIDString), victim.displayName);
if (!Freeze.ContainsKey(player.userID)) Freeze.Add(player.userID, player.transform.position);
else Freeze[player.userID] = player.transform.position;
}
}
[ChatCommand("unfreeze")]
private void UnFreezePlayer(BasePlayer player, string cmd, string[] args) {
int count = 0;
BasePlayer victim = null;
if (args.Length == 0) {
SendReply(player, lang.GetMessage("usage", this, player.UserIDString));
return;
}
foreach (BasePlayer current in BasePlayer.activePlayerList.ToList()) {
if (current.displayName.Contains(args[0])) {
count++;
victim = current;
}
else if (current.displayName.ToLower().Contains(args[0].ToLower())) {
count++;
victim = current;
}
}
if (victim == null) {
SendReply(player, lang.GetMessage("NoPlayer", this, player.UserIDString));
return;
}
else if (count > 1) {
SendReply(player, lang.GetMessage("ToManyPlayers", this, player.UserIDString), args[0].ToLower());
return;
}
else {
PlayerFreeze Controller = player.GetComponent<PlayerFreeze>();
if (Controller != null) Controller.Remove();
else if (Controller == null && !Freeze.ContainsKey(player.userID)) {
SendReply(player, lang.GetMessage("NotFrozen", this, player.UserIDString), victim.displayName);
return;
}
SendReply(player, lang.GetMessage("UnFrozen", this, player.UserIDString), victim.displayName);
if (Freeze.ContainsKey(player.userID)) Freeze.Remove(player.userID);
}
}
[ChatCommand("setonfire")]
private void SetOnFirePlayer(BasePlayer player, string cmd, string[] args) {
int count = 0;
BasePlayer victim = null;
if (args.Length == 0) {
SendReply(player, lang.GetMessage("usage", this, player.UserIDString));
return;
}
foreach (BasePlayer current in BasePlayer.activePlayerList.ToList()) {
if (current.displayName.Contains(args[0])) {
count++;
victim = current;
}
else if (current.displayName.ToLower().Contains(args[0].ToLower())) {
count++;
victim = current;
}
}
if (victim == null) {
SendReply(player, lang.GetMessage("NoPlayer", this, player.UserIDString));
return;
}
else if (count > 1) {
SendReply(player, lang.GetMessage("ToManyPlayers", this, player.UserIDString), args[0].ToLower());
return;
}
else {
PlayerFreeze Controller = player.GetComponent<PlayerFreeze>();
if (Controller == null) Controller = player.gameObject.AddComponent<PlayerFreeze>();
if(!Controller.PlayerOnFire) {
Controller.StartFire();
SendReply(player, lang.GetMessage("SetOnFire", this, player.UserIDString), victim.displayName);
if (!Freeze.ContainsKey(player.userID)) Freeze.Add(player.userID, player.transform.position);
else Freeze[player.userID] = player.transform.position;
}
else SendReply(player, lang.GetMessage("OnFireAlready", this, player.UserIDString), victim.displayName);
}
}
private class PlayerFreeze : MonoBehaviour {
public BasePlayer player;
public BaseMountable InvisMount;
public BaseEntity FireBurn;
public bool PlayerOnFire;
private void Awake() {
player = GetComponent<BasePlayer>();
FreezeThePlayer();
}
public void Remove(bool forced = false) {
if (InvisMount != null) {
InvisMount?.DismountPlayer(player, true);
InvisMount?.Kill();
}
if (FireBurn != null) {
CancelInvoke("applyBlastDamage");
FireBurn.Kill();
}
CancelInvoke("ColdEffects");
if (player != null) {
player.metabolism.temperature.Reset();
player.metabolism.SendChangesToClient();
}
Destroy(this);
}
public void FreezeThePlayer() {
if (player == null || player.IsSleeping() || !player.IsConnected) {
return;
}
if (player.IsWounded()) {
player.StopWounded();
player.SetHealth(14f);
player.metabolism.bleeding.value = 0f;
}
Vector3 Cuffedpos = player.transform.position;
Quaternion playerloc = player.transform.rotation;
if (InvisMount == null) {
InvisMount = GameManager.server.CreateEntity("assets/prefabs/vehicle/seats/arcadeuser.prefab", Cuffedpos, playerloc) as BaseMountable;
if (InvisMount == null) return;
InvisMount.enableSaving = false;
InvisMount.Spawn();
player.EnsureDismounted();
InvisMount.MountPlayer(player);
UnityEngine.Object.Destroy(InvisMount.GetComponent<Collider>());
Transform[] dismount = InvisMount.dismountPositions;
dismount = new Transform[1 ];
dismount[0] = player.transform;
InvisMount.transform.hasChanged = true;
InvisMount.UpdateNetworkGroup();
InvisMount.SendNetworkUpdateImmediate();
InvokeRepeating("ColdEffects", 4.0f, 4.1f);
}
else if (InvisMount != null) {
player.EnsureDismounted();
InvisMount.MountPlayer(player);
InvokeRepeating("ColdEffects", 4.0f, 4.1f);
}
}
public void UnFreezeThePlayer() {
Remove(true);
}
private void ColdEffects() {
if (player == null || player.IsDead()) {
CancelInvoke("ColdEffects");
return;
}
player.metabolism.temperature.SetValue(-50f);
player.metabolism.SendChangesToClient();
Vector3 breathPosition = player.eyes.position + Quaternion.Euler(player.serverInput.current.aimAngles) * new Vector3(0, 0, 0.2f);
Effect.server.Run("assets/bundled/prefabs/fx/player/frosty_breath.prefab", breathPosition);
}
public void StartFire() {
if (PlayerOnFire == true || player == null || player.IsDead()) return;
PlayerOnFire = true;
var playerPos = player.transform.position;
var playerRot = player.transform.rotation;
FireBurn = GameManager.server.CreateEntity("assets/bundled/prefabs/oilfireballsmall.prefab", playerPos, playerRot);
FireBurn.Spawn();
FireBurn.SetParent(player);
FireBurn.transform.localPosition = new Vector3(0f, 0f, 0f);
InvokeRepeating("applyBlastDamage", 1.0f, 1.1f);
((Rigidbody)FireBurn.gameObject.GetComponent(typeof(Rigidbody))).isKinematic = true;
CancelInvoke("ColdEffects");
return;
}
void applyBlastDamage() {
if (player == null || player.IsDead()) {
CancelInvoke("applyBlastDamage");
if (FireBurn != null) FireBurn?.Kill();
PlayerOnFire = false;
return;
}
player.Hurt(1.5f);
}
}
private void OnPlayerDeath(BasePlayer player, HitInfo info) {
PlayerFreeze Controller = player.GetComponent<PlayerFreeze>();
if (Controller != null) Controller.Remove();
}
private void OnPlayerSleepEnded(BasePlayer player) {
if (Freeze.ContainsKey(player.userID)) {
PlayerFreeze Controller = player.GetComponent<PlayerFreeze>();
if (Controller != null) {
Controller.FreezeThePlayer();
}
else {
player.transform.position = Freeze[player.userID];
NextTick(() => {
player.gameObject.AddComponent<PlayerFreeze>();
}
);
}
}
}
private void OnPlayerDisconnected(BasePlayer player) {
PlayerFreeze Controller = player.GetComponent<PlayerFreeze>();
if (Controller != null) if (Controller.InvisMount != null) Controller.Remove();
}
private void OnEntityTakeDamage(BasePlayer player, HitInfo hitInfo) {
if (hitInfo?.damageTypes?.GetMajorityDamageType() == Rust.DamageType.Cold || hitInfo?.damageTypes?.GetMajorityDamageType() == Rust.DamageType.ColdExposure) {
if (player != null) {
PlayerFreeze Controller = player.GetComponent<PlayerFreeze>();
if (Controller == null) return;
hitInfo.damageTypes = new Rust.DamageTypeList();
hitInfo.HitMaterial = 0;
hitInfo.PointStart = Vector3.zero;
}
}
}
private object CanDismountEntity(BasePlayer player, BaseMountable entity) {
PlayerFreeze Controller = player.GetComponent<PlayerFreeze>();
if (Controller == null) return null;
if (Controller.InvisMount != null) return true;
return null;
}
private object OnServerCommand(ConsoleSystem.Arg arg) {
if (arg.cmd?.Name != "kill") return null;
if (arg.Player() == null) return null;
var player = arg.Player();
if (player == null) return null;
PlayerFreeze Controller = player.GetComponent<PlayerFreeze>();
if (Controller == null) return null;
if (Controller.InvisMount != null) return true;
return null;
}
}
}