Limit repeated AI driver honking; record Workshop 0.0.129
continuous-integration/drone/push Build is passing
continuous-integration/drone/push Build is passing
This commit is contained in:
@@ -0,0 +1,43 @@
|
||||
// Bound native AI horn requests without changing steering, braking or player input.
|
||||
class ERR_AIDriverHornLimit
|
||||
{
|
||||
protected int m_End = -1;
|
||||
protected int m_Next = 0;
|
||||
protected int m_Last = -1;
|
||||
bool Allow(bool requested, int now)
|
||||
{
|
||||
if (m_Last >= 0 && now < m_Last) { m_End = -1; m_Next = now + 30000; }
|
||||
m_Last = now;
|
||||
if (!requested) { m_End = -1; return false; }
|
||||
if (m_End >= 0)
|
||||
{
|
||||
if (now < m_End) return true;
|
||||
m_End = -1;
|
||||
}
|
||||
if (now < m_Next) return false;
|
||||
m_End = now + 500;
|
||||
m_Next = now + 30000;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
modded class SCR_CharacterControllerComponent
|
||||
{
|
||||
protected ref ERR_AIDriverHornLimit m_ERRHornLimit;
|
||||
protected override void OnApplyControls(IEntity owner, float timeSlice)
|
||||
{
|
||||
super.OnApplyControls(owner, timeSlice);
|
||||
if (!Replication.IsServer() || !owner || ERR_Actors.Player(owner)) return;
|
||||
ERR_GameMode mode = ERR_GameMode.Get();
|
||||
if (!mode) return;
|
||||
IEntity vehicle = CompartmentAccessComponent.GetVehicleIn(owner);
|
||||
if (!vehicle || !vehicle.FindComponent(AICarMovementComponent)) return;
|
||||
BaseVehicleControllerComponent controls = BaseVehicleControllerComponent.Cast(vehicle.FindComponent(BaseVehicleControllerComponent));
|
||||
if (!controls || !controls.GetPilotCompartmentSlot() || controls.GetPilotCompartmentSlot().GetOccupant() != owner) return;
|
||||
CharacterInputContext input = GetInputContext();
|
||||
if (!input) return;
|
||||
if (!m_ERRHornLimit) m_ERRHornLimit = new ERR_AIDriverHornLimit();
|
||||
bool permitted = m_ERRHornLimit.Allow(mode.Active() && input.GetVehicleHorn() != 0, System.GetTickCount());
|
||||
if (!permitted) input.SetVehicleHorn(0);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user