public ELSVehicle(int handle, IDictionary <string, object> data) : base(handle) { _vehicle = new Vehicle(handle); ModelLoaded(); if (_vehicle.DisplayName == "CARNOTFOUND" || _vehicle.GetNetworkId() == 0) { throw new Exception("Vehicle creation failure."); } else if (VCF.ELSVehicle.Exists(item => item.Item2.FileName == _vehicle.DisplayName)) { _vcf = VCF.ELSVehicle.Find(item => item.Item2.FileName == _vehicle.DisplayName).Item2; } if (data.ContainsKey("Siren")) { _siren = new Siren.Siren(_vehicle, _vcf, (IDictionary <string, object>)data["Siren"]); } else { //_vehicle.SetExistOnAllMachines(true); #if DEBUG CitizenFX.Core.Debug.WriteLine(CitizenFX.Core.Native.API.IsEntityAMissionEntity(_vehicle.Handle).ToString()); CitizenFX.Core.Debug.WriteLine($"registering netid:{_vehicle.GetNetworkId()}\n" + $"Does entity belong to this script:{CitizenFX.Core.Native.API.DoesEntityBelongToThisScript(_vehicle.Handle, false)}"); #endif _siren = new Siren.Siren(_vehicle, _vcf); } #if DEBUG CitizenFX.Core.Debug.WriteLine($"created vehicle"); #endif }
public ELSVehicle(int handle, [Optional] IDictionary <string, object> data) : base(handle) { _vehicle = new Vehicle(handle); ModelLoaded(); lastdrivetime = Game.GameTime; API.SetVehRadioStation(_vehicle.Handle, "OFF"); API.SetVehicleRadioEnabled(_vehicle.Handle, false); if (_vehicle.DisplayName == "CARNOTFOUND") { throw new Exception("ELSVehicle.cs:Vehicle not found"); } else if (_vehicle.GetNetworkId() == 0) { throw new Exception("ELSVehicle.cs:NetworkId is 0"); } else if (VCF.ELSVehicle.ContainsKey(_vehicle.Model)) { _vcf = VCF.ELSVehicle[_vehicle.Model].root; } try { Function.Call((Hash)0x5f3a3574, _vehicle.Handle, true); } catch (Exception e) { Utils.ReleaseWriteLine("ELSVehicle.cs:Repair Fix is not enabled on this client"); } _light = new Light.Lights(_vehicle, _vcf, (IDictionary <string, object>)data?["light"]); _siren = new Siren.Siren(_vehicle, _vcf, (IDictionary <string, object>)data?["siren"], _light); _light.SetGTASirens(false); //_vehicle.SetExistOnAllMachines(true); cachedNetId = _vehicle.GetNetworkId(); #if DEBUG CitizenFX.Core.Debug.WriteLine(CitizenFX.Core.Native.API.IsEntityAMissionEntity(_vehicle.Handle).ToString()); CitizenFX.Core.Debug.WriteLine($"ELSVehicle.cs:registering netid:{_vehicle.GetNetworkId()}\n" + $"Does entity belong to this script:{CitizenFX.Core.Native.API.DoesEntityBelongToThisScript(_vehicle.Handle, false)}"); CitizenFX.Core.Debug.WriteLine($"ELSVehicle.cs:created vehicle"); #endif }
internal void Runtick() { var localPlayer = Game.Player; if (localPlayer.Character.IsInVehicle() && localPlayer.Character.IsSittingInVehicle() && localPlayer.Character.CurrentVehicle.IsEls() && ( localPlayer.Character.CurrentVehicle.GetPedOnSeat(VehicleSeat.Driver) == localPlayer.Character || localPlayer.Character.CurrentVehicle.GetPedOnSeat(VehicleSeat.Passenger) == localPlayer.Character ) ) { if (_currentSiren == null || _currentSiren._vehicle != Game.Player.Character.CurrentVehicle) { var vehicle = Game.Player.Character.CurrentVehicle; AddVehicleIfNotRegistered(vehicle); _currentSiren = _sirens.Find(siren => siren._vehicle.Handle == vehicle.Handle); } _currentSiren.ticker(); } }
public void SetCurrentSiren(Vehicle vehicle) { if (!vehicleIsRegisteredLocaly(vehicle)) { AddSiren(vehicle); #if DEBUG Debug.WriteLine("added new siren"); #endif SetCurrentSiren(vehicle); } else { foreach (Siren.Siren siren in _sirens) { if (siren._vehicle.Handle == vehicle.Handle) { #if DEBUG Debug.WriteLine("added existing siren"); #endif currentSiren = siren; } } } }
public ELSVehicle(int handle, [Optional] ELSVehicleFSData data) : base(handle) { _vehicle = new Vehicle(handle); if (!_vehicle.Exists()) { return; } ModelLoaded(); lastdrivetime = Game.GameTime; API.SetVehRadioStation(_vehicle.Handle, "OFF"); API.SetVehicleRadioEnabled(_vehicle.Handle, false); if (_vehicle.DisplayName == "CARNOTFOUND") { throw new Exception("ELSVehicle.cs: Vehicle not found"); } else if (VCF.ELSVehicle.ContainsKey(_vehicle.Model)) { _vcf = VCF.ELSVehicle[_vehicle.Model].root; } if (API.DecorExistOn(_vehicle.Handle, "elsplus_id")) { cachedElsID = _vehicle.GetElsId(); } else { Utils.ReleaseWriteLine("ELSVehicle.cs: Vehicle is being created without a els id attempting to set now"); if (data.Id > 0) { cachedElsID = data.Id; API.DecorSetInt(_vehicle.Handle, "elsplus_id", cachedElsID); } } try { Function.Call((Hash)0x5f3a3574, _vehicle.Handle, true); } catch (Exception e) { Utils.ReleaseWriteLine("ELSVehicle.cs: Repair Fix is not enabled on this client"); } Utils.DebugWriteLine($"ELS Vehicle Data: {JsonConvert.SerializeObject(data)}"); if (data.Id.Equals(null)) { _light = new Light.Lights(_vehicle, _vcf); _siren = new Siren.Siren(_vehicle, _vcf, _light); } else { _light = new Light.Lights(_vehicle, _vcf, data.Light); _siren = new Siren.Siren(_vehicle, _vcf, _light, data.Siren); } _light.SetGTASirens(false); Utils.DebugWriteLine(API.IsEntityAMissionEntity(_vehicle.Handle).ToString()); Utils.DebugWriteLine($"ELSVehicle.cs:registering \n" + $"Does entity belong to this script:{API.DoesEntityBelongToThisScript(_vehicle.Handle, false)}"); Utils.DebugWriteLine($"ELSVehicle.cs:created vehicle"); FullSync.FullSyncManager.SendDataBroadcast(JsonConvert.SerializeObject(GetData()), Game.Player.ServerId); }