C#:
// Все права принадлежат дискорд сообществу https://discord.gg/VgNHPpNrz6
/*
TODO:
- Fix players being kicked by Rust's anti-hack
- Prevent players from being slapped through walls
*/
using System;
using System.Collections.Generic;
using UnityEngine;
using Random = System.Random;
namespace Oxide.Plugins
{
[Info("Slap", "Wulf/lukespragg", "0.2.1", ResourceId = 1458)]
[Description("Allows players with permission to slap other players around.")]
class Slap : RustPlugin
{
// Do NOT edit this file, instead edit Slap.json in server/<identity>/oxide/config
#region Configuration
int DamageAmount => GetConfig("DamageAmount", 5);
int SlapsPerUse => GetConfig("SlapsPerUse", 3);
protected override void LoadDefaultConfig()
{
Config["DamageAmount"] = DamageAmount;
Config["SlapsPerUse"] = SlapsPerUse;
SaveConfig();
}
#endregion
#region Localization
readonly Dictionary<string, string> messages = new Dictionary<string, string>();
void LoadDefaultMessages()
{
messages.Add("ChatCommand", "slap");
messages.Add("CommandUsage", "Usage:\n /slap name (replace 'name' with a player's name)");
messages.Add("PlayerNotFound", "Player '{player}' not found!");
messages.Add("PlayerSlapped", "{player} got slapped!");
messages.Add("NoPermission", "Sorry, you can't use 'slap' right now");
lang.RegisterMessages(messages, this);
}
#endregion
#region Initialization
void Loaded()
{
#if !RUST
throw new NotSupportedException("This plugin does not support this game");
#endif
LoadDefaultConfig();
LoadDefaultMessages();
permission.RegisterPermission("slap.allowed", this);
cmd.AddChatCommand(GetMessage("ChatCommand"), this, "SlapChatCmd");
}
#endregion
#region Chat Command
#if RUST
void SlapChatCmd(BasePlayer player, string command, string[] args)
{
if (!HasPermission(player.UserIDString, "slap.allowed"))
{
PrintToChat(player, GetMessage("NoPermission", player.UserIDString));
return;
}
if (args.Length != 1)
{
PrintToChat(player, GetMessage("CommandUsage", player.UserIDString));
return;
}
var target = BasePlayer.Find(args[0]);
if (target == null)
{
PrintToChat(player, GetMessage("PlayerNotFound", player.UserIDString).Replace("{player}", args[0]));
return;
}
timer.Repeat(0.3f, SlapsPerUse, () =>
{
if (DamageAmount > 0f) target.Hurt(DamageAmount);
SlapPlayer(target);
});
PrintToChat(player, GetMessage("PlayerSlapped", player.UserIDString).Replace("{player}", target.displayName));
}
#endif
#endregion
#region Player Slapping
#if RUST
void SlapPlayer(BasePlayer player)
{
var position = player.transform.position;
var destination = new Vector3();
var random = new Random();
destination.x = position.x + random.Next(-3, 3);
destination.y = position.y + random.Next(1, 3);
destination.z = position.z + random.Next(-3, 3);
// Slap them around
var flinches = new[]
{
BaseEntity.Signal.Flinch_Chest,
BaseEntity.Signal.Flinch_Head,
BaseEntity.Signal.Flinch_Stomach
};
var flinch = flinches[random.Next(flinches.Length)];
player.SignalBroadcast(flinch, string.Empty, null);
// Make some sound
var effects = new[]
{
"headshot",
"headshot_2d",
"impacts/slash/clothflesh/clothflesh1",
"impacts/stab/clothflesh/clothflesh1"
};
var effect = effects[random.Next(effects.Length)];
Effect.server.Run($"assets/bundled/prefabs/fx/{effect}.prefab", player.transform.position, Vector3.zero);
// Make them fly
player.MovePosition(destination);
player.ClientRPCPlayer(null, player, "ForcePositionTo", destination);
player.TransformChanged();
}
#endif
#endregion
#region Helper Methods
T GetConfig<T>(string name, T defaultValue)
{
if (Config[name] == null) return defaultValue;
return (T) Convert.ChangeType(Config[name], typeof(T));
}
string GetMessage(string key, string steamId = null) => lang.GetMessage(key, this, steamId);
bool HasPermission(string steamId, string perm) => permission.UserHasPermission(steamId, perm);
#endregion
}
}