Skip to content

Commit

Permalink
Ignoring local player's pointers option
Browse files Browse the repository at this point in the history
Settings hide
  • Loading branch information
SDraw committed Apr 15, 2023
1 parent fa5a033 commit f983f29
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 2 deletions.
1 change: 1 addition & 0 deletions ml_prm/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ Optional mod's settings with [BTKUILib](https://github.com/BTK-Development/BTKUI
* **Use gravity:** enables/disables gravity for ragdoll; `true` by default.
* Note: Forcibly enabled in worlds that don't allow flight.
* **Pointers reaction:** enables ragdoll state when player collides with trigger colliders with CVRPointer component of `ragdoll` type (avatars, props and world included); `true` by default.
* **Ignore local pointers:** enables/disables ignoring of CVRPointer components of `ragdoll` type on local player's avatar; `true` by default.
* **Combat reaction:** enables ragdoll state upon death in worlds with combat system; `true` by default.
* **Auto recover:** enables automatic recovering after specific time delay; `false` by default.
* **Velocity multiplier:** velocity force multiplier based on player's movement direction; `2.0` by default.
Expand Down
8 changes: 7 additions & 1 deletion ml_prm/RagdollTrigger.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using ABI.CCK.Components;
using ABI_RC.Core.Player;
using UnityEngine;

namespace ml_prm
Expand Down Expand Up @@ -32,7 +33,7 @@ void Update()
void OnTriggerEnter(Collider p_other)
{
CVRPointer l_pointer = p_other.GetComponent<CVRPointer>();
if((l_pointer != null) && (l_pointer.type == "ragdoll") && (m_lastTrigger != p_other))
if((l_pointer != null) && (l_pointer.type == "ragdoll") && !IsIgnored(l_pointer.transform) && (m_lastTrigger != p_other))
{
m_lastTrigger = p_other;
m_triggered = true;
Expand All @@ -51,5 +52,10 @@ public bool GetStateWithReset()
m_triggered = false;
return l_state;
}

static bool IsIgnored(Transform p_transform)
{
return (Settings.IgnoreLocal && (p_transform.root == PlayerSetup.Instance.transform));
}
}
}
21 changes: 20 additions & 1 deletion ml_prm/Settings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ enum ModSetting
AngularDrag,
Gravity,
PointersReaction,
IgnoreLocal,
CombatReaction,
AutoRecover,
RecoverDelay
Expand All @@ -27,6 +28,7 @@ enum UiElementIndex
RestorePosition,
Gravity,
PointersReaction,
IgnoreLocal,
CombatReaction,
AutoRecover,
VelocityMultiplier,
Expand All @@ -42,6 +44,7 @@ enum UiElementIndex
public static float AngularDrag { get; private set; } = 2f;
public static bool Gravity { get; private set; } = true;
public static bool PointersReaction { get; private set; } = true;
public static bool IgnoreLocal { get; private set; } = true;
public static bool CombatReaction { get; private set; } = true;
public static bool AutoRecover { get; private set; } = false;
public static float RecoverDelay { get; private set; } = 3f;
Expand All @@ -54,6 +57,7 @@ enum UiElementIndex
static public event Action<float> AngularDragChange;
static public event Action<bool> GravityChange;
static public event Action<bool> PointersReactionChange;
static public event Action<bool> IgnoreLocalChange;
static public event Action<bool> CombatReactionChange;
static public event Action<bool> AutoRecoverChange;
static public event Action<float> RecoverDelayChange;
Expand All @@ -65,7 +69,7 @@ enum UiElementIndex

internal static void Init()
{
ms_category = MelonLoader.MelonPreferences.CreateCategory("PRM");
ms_category = MelonLoader.MelonPreferences.CreateCategory("PRM", null, true);
ms_entries = new List<MelonLoader.MelonPreferences_Entry>()
{
ms_category.CreateEntry(ModSetting.Hotkey.ToString(), Hotkey),
Expand All @@ -75,6 +79,7 @@ internal static void Init()
ms_category.CreateEntry(ModSetting.AngularDrag.ToString(), AngularDrag),
ms_category.CreateEntry(ModSetting.Gravity.ToString(), Gravity),
ms_category.CreateEntry(ModSetting.PointersReaction.ToString(), PointersReaction),
ms_category.CreateEntry(ModSetting.IgnoreLocal.ToString(), IgnoreLocal),
ms_category.CreateEntry(ModSetting.CombatReaction.ToString(), CombatReaction),
ms_category.CreateEntry(ModSetting.AutoRecover.ToString(), AutoRecover),
ms_category.CreateEntry(ModSetting.RecoverDelay.ToString(), RecoverDelay)
Expand All @@ -87,6 +92,7 @@ internal static void Init()
AngularDrag = Mathf.Clamp((float)ms_entries[(int)ModSetting.MovementDrag].BoxedValue, 0f, 50f);
Gravity = (bool)ms_entries[(int)ModSetting.Gravity].BoxedValue;
PointersReaction = (bool)ms_entries[(int)ModSetting.PointersReaction].BoxedValue;
IgnoreLocal = (bool)ms_entries[(int)ModSetting.IgnoreLocal].BoxedValue;
CombatReaction = (bool)ms_entries[(int)ModSetting.CombatReaction].BoxedValue;
AutoRecover = (bool)ms_entries[(int)ModSetting.AutoRecover].BoxedValue;
RecoverDelay = Mathf.Clamp((float)ms_entries[(int)ModSetting.RecoverDelay].BoxedValue, 1f, 10f);
Expand Down Expand Up @@ -141,6 +147,14 @@ static void CreateBtkUi()
PointersReactionChange?.Invoke(state);
};

ms_uiElements.Add(l_categoryMod.AddToggle("Ignore local pointers", "Ignore local avatar's CVRPointer components of 'ragdoll' type", IgnoreLocal));
(ms_uiElements[(int)UiElementIndex.IgnoreLocal] as BTKUILib.UIObjects.Components.ToggleButton).OnValueUpdated += (state) =>
{
IgnoreLocal = state;
ms_entries[(int)ModSetting.IgnoreLocal].BoxedValue = state;
IgnoreLocalChange?.Invoke(state);
};

ms_uiElements.Add(l_categoryMod.AddToggle("Combat reaction", "Ragdoll upon combat system death", CombatReaction));
(ms_uiElements[(int)UiElementIndex.CombatReaction] as BTKUILib.UIObjects.Components.ToggleButton).OnValueUpdated += (state) =>
{
Expand Down Expand Up @@ -211,6 +225,11 @@ static void CreateBtkUi()
(ms_uiElements[(int)UiElementIndex.PointersReaction] as BTKUILib.UIObjects.Components.ToggleButton).ToggleValue = true;
PointersReactionChange?.Invoke(true);

IgnoreLocal = true;
ms_entries[(int)ModSetting.IgnoreLocal].BoxedValue = true;
(ms_uiElements[(int)UiElementIndex.IgnoreLocal] as BTKUILib.UIObjects.Components.ToggleButton).ToggleValue = true;
IgnoreLocalChange?.Invoke(true);

CombatReaction = true;
ms_entries[(int)ModSetting.CombatReaction].BoxedValue = true;
(ms_uiElements[(int)UiElementIndex.CombatReaction] as BTKUILib.UIObjects.Components.ToggleButton).ToggleValue = true;
Expand Down

0 comments on commit f983f29

Please sign in to comment.