83 lines
2.6 KiB
C
83 lines
2.6 KiB
C
[ComponentEditorProps(category: "GameScripted/Character", description: "Erlaubt automatisches Laufen/Rennen")]
|
|
class SCR_AutorunComponentClass: ScriptComponentClass
|
|
{
|
|
}
|
|
|
|
class SCR_AutorunComponent: ScriptComponent
|
|
{
|
|
protected bool m_bIsAutorunEnabled = false;
|
|
protected bool m_bWaitForKeyRelease = false; // Neu: Die Sicherung
|
|
|
|
protected SCR_CharacterControllerComponent m_CharacterController;
|
|
protected InputManager m_InputManager;
|
|
|
|
protected void OnAutorunPressed()
|
|
{
|
|
m_bIsAutorunEnabled = !m_bIsAutorunEnabled;
|
|
|
|
// Wenn Autorun AN geht und der Spieler hält W bereits gedrückt...
|
|
if (m_bIsAutorunEnabled && m_InputManager.GetActionValue("CharacterForward") > 0.5)
|
|
{
|
|
m_bWaitForKeyRelease = true; // ...Sicherung aktivieren!
|
|
}
|
|
else
|
|
{
|
|
m_bWaitForKeyRelease = false;
|
|
}
|
|
}
|
|
|
|
protected void OnLifeStateChangedCallback()
|
|
{
|
|
m_bIsAutorunEnabled = false;
|
|
}
|
|
|
|
protected void OnControlledByPlayerCallback(IEntity owner, bool controlled)
|
|
{
|
|
m_bIsAutorunEnabled = false;
|
|
}
|
|
|
|
protected void OnPrepareControlsCallback(IEntity owner, ActionManager am, float dt, bool player)
|
|
{
|
|
if (!m_bIsAutorunEnabled)
|
|
return;
|
|
|
|
float forwardInput = m_InputManager.GetActionValue("CharacterForward");
|
|
float rightInput = m_InputManager.GetActionValue("CharacterRight");
|
|
|
|
// Wenn die Sicherung an ist und der Spieler W loslässt (Wert unter 0.5) -> Sicherung raus
|
|
if (m_bWaitForKeyRelease && forwardInput < 0.5)
|
|
{
|
|
m_bWaitForKeyRelease = false;
|
|
}
|
|
|
|
// Autorun abbrechen, wenn: Kontext inaktiv, Karte offen, A/D gedrückt,
|
|
// oder W/S gedrückt (ABER W bricht nur ab, wenn die Sicherung draußen ist!)
|
|
if (!m_InputManager.IsContextActive("CharacterMovementContext") ||
|
|
am.GetActionTriggered("GadgetMap") ||
|
|
Math.AbsFloat(rightInput) >= 0.75 ||
|
|
(!m_bWaitForKeyRelease && Math.AbsFloat(forwardInput) >= 0.75))
|
|
{
|
|
m_bIsAutorunEnabled = false;
|
|
return;
|
|
}
|
|
|
|
// Bewegungswerte zwingen (Laufen + Rennen)
|
|
m_InputManager.SetActionValue("CharacterForward", 1.0);
|
|
m_InputManager.SetActionValue("CharacterSprint", 1.0);
|
|
}
|
|
|
|
override void OnPostInit(IEntity owner)
|
|
{
|
|
m_CharacterController = SCR_CharacterControllerComponent.Cast(owner.FindComponent(SCR_CharacterControllerComponent));
|
|
if (!m_CharacterController)
|
|
{
|
|
Print("[SCR_Autorun] Kein SCR_CharacterControllerComponent gefunden! Mod funktioniert nicht.", LogLevel.WARNING);
|
|
return;
|
|
}
|
|
|
|
m_InputManager = GetGame().GetInputManager();
|
|
|
|
m_CharacterController.m_OnPrepareControls.Insert(OnPrepareControlsCallback);
|
|
m_InputManager.AddActionListener("SCR_Autorun", EActionTrigger.DOWN, OnAutorunPressed);
|
|
}
|
|
} |