Hello!
In the process of studying the creation of plugins for the game Unturned, I was faced with the task of determining the pose of the character. In particular, I need to determine when a player assumes a prone or sitting position in order to respond appropriately to this in a game chat.
I will be grateful for any help or code examples that will help me solve this problem.
#Plugins
1 messages · Page 1 of 1 (latest)
Hey, what problem you have?
I need my plugin to check the player's pose only when he changes it, in order to minimize the load on the server.
I also wanted to know if there is any dictionary in which it would be possible to quickly and conveniently search for functions like this?
I see you have event, you have it in OnLoad too?
Yes
So what the issue then? Its not logging when stance is updated?
Here is the entire plugin code, it almost works as needed, but for some reason it does not respond to changes in the player's pose, except for CROUCH, it is only displayed in the logs.
using System;
using Rocket.API;
using Rocket.Core.Logging;
using Rocket.Core.Plugins;
using Rocket.Unturned.Chat;
using Rocket.Unturned.Player;
using SDG.Unturned;
using UnityEngine;
using Logger = Rocket.Core.Logging.Logger;
namespace Test
{
public class Main : RocketPlugin<PluginConfig>
{
private const string PluginName = "LieDownNotifier";
protected override void Load()
{
Logger.Log($"[{PluginName}] Инициализация плагина...");
try
{
PlayerStance.OnStanceChanged_Global += OnStanceChanged;
Logger.Log($"[{PluginName}] Подписка на глобальное событие выполнена.");
}
catch (Exception ex)
{
Logger.LogError($"[{PluginName}] Ошибка при подписке на глобальное событие: {ex.Message}");
}
Logger.Log($"[{PluginName}] Плагин загружен успешно!");
Logger.Log($"[{PluginName}] Конфигурация: ChatNotifications={Configuration.Instance.EnableChatNotifications}, " +
$"NotificationMessage='{Configuration.Instance.NotificationMessage}', MessageColor='{Configuration.Instance.MessageColor}'");
}
protected override void Unload()
{
try
{
PlayerStance.OnStanceChanged_Global -= OnStanceChanged;
Logger.Log($"[{PluginName}] Плагин выгружен.");
}
catch (Exception ex)
{
Logger.LogError($"[{PluginName}] Ошибка при отписке от глобального события: {ex.Message}");
}
}
private void OnStanceChanged(PlayerStance stance)
{
try
{
UnturnedPlayer player = UnturnedPlayer.FromPlayer(stance.player);
if (player == null)
{
Logger.Log($"[{PluginName}] Не удалось получить игрока из события изменения позы.");
return;
}
EPlayerStance newStance = stance.stance;
Logger.Log($"[{PluginName}] {player.DisplayName} изменил позу на: {newStance}");
if (newStance == EPlayerStance.PRONE)
{
if (Configuration.Instance.EnableChatNotifications)
{
Color chatColor = UnturnedChat.GetColorFromName(Configuration.Instance.MessageColor, Color.yellow);
UnturnedChat.Say(player, Configuration.Instance.NotificationMessage, chatColor);
}
if (player.Player.equipment.asset is ItemGunAsset)
{
player.Player.equipment.dequip();
Logger.Log($"[{PluginName}] Оружие автоматически снято у игрока: {player.DisplayName}");
}
else
{
Logger.Log($"[{PluginName}] Для игрока {player.DisplayName} оружие не обнаружено или тип отличается.");
}
}
else
{
Logger.Log($"[{PluginName}] Дополнительных действий для состояния {newStance} не предусмотрено.");
}
}
catch (Exception ex)
{
Rocket.Core.Logging.Logger.LogError($"[{PluginName}] Ошибка в обработчике OnStanceChanged: {ex.Message}");
}
}
}
}
I've completely run out of ideas what the problem might be.
the problem is that, that event is not working at all; sub to the player instance event instead, lol.