private void OnEntitySpawned(BaseVehicle aVehicle) { SirenController theController = aVehicle.GetComponent <SirenController>(); if (!theController) { float theProbability; if (config.SirenSpawnProbability.TryGetValue(aVehicle is ModularCar ? KEY_MODULAR_CAR : aVehicle.PrefabName, out theProbability) && Core.Random.Range(0f, 1f) < theProbability) { AttachSirens(aVehicle, SirenDictionary.Values.First(), config.DefaultState); } } }
/// <summary> /// Creates or replaces the SirenController of the given vehicle. /// </summary> /// <param name="aVehicle">The vehicle.</param> /// <param name="aSiren">The Siren.</param> /// <param name="someNetIDs">Already existing siren entities.</param> /// <returns>The newly created SirenController.</returns> private SirenController CreateSirenController(BaseVehicle aVehicle, Siren aSiren, IEnumerable <uint> someNetIDs = null) { SirenController theController = aVehicle.GetComponent <SirenController>(); if (theController) { UnityEngine.Object.DestroyImmediate(theController); } theController = aVehicle.gameObject.AddComponent <SirenController>(); theController.Config = config; theController.Siren = aSiren; if (someNetIDs != null) { theController.NetIDs.UnionWith(someNetIDs); } return(theController); }
/// <summary> /// Detaches the siren from a vehicle and removes all corresponding entities. /// </summary> /// <param name="aVehicle"> The vehicle.</param> /// <returns>True, if a siren was removed.</returns> private bool DetachSirens(BaseVehicle aVehicle) { SirenController theController = aVehicle.GetComponent <SirenController>(); if (theController) { foreach (BaseEntity eachEntity in aVehicle.GetComponentsInChildren <BaseEntity>()) { if (theController.NetIDs.Contains(eachEntity.net.ID)) { Destroy(eachEntity); } } UnityEngine.Object.DestroyImmediate(theController); return(true); } return(false); }
private object OnButtonPress(PressButton aButton, BasePlayer aPlayer) { BaseVehicle theVehicle = aButton.GetComponentInParent <BaseVehicle>()?.VehicleParent(); theVehicle = theVehicle ? theVehicle : aButton.GetComponentInParent <BaseVehicle>(); if (theVehicle) { SirenController theController = theVehicle.GetComponent <SirenController>(); if (theController) { if ((config.MountNeeded && aPlayer.GetMountedVehicle() != theVehicle) || !theController.NetIDs.Contains(aButton.net.ID)) { return(false); } theController.ChangeState(); } } return(null); }
private void ToggleSirens(IPlayer aPlayer, string aCommand, string[] someArgs) { if (aPlayer.IsServer) { Message(aPlayer, I18N_PLAYERS_ONLY, aCommand); return; } BasePlayer thePlayer = aPlayer.Object as BasePlayer; BaseVehicle theVehicle = thePlayer?.GetMountedVehicle(); if (theVehicle) { theVehicle.GetComponent <SirenController>()?.ChangeState(); } else if (!config.MountNeeded) { RaycastVehicle(aPlayer)?.GetComponent <SirenController>()?.ChangeState();; } }