Exemplo n.º 1
0
        private void SetupConnections()
        {
            EventHandlers["onClientResourceStop"] += new Action <string>(async(string obj) =>
            {
                if (obj == Function.Call <string>(Hash.GET_CURRENT_RESOURCE_NAME))
                {
                    _vehicleManager.CleanUP();
                    _FileLoader.UnLoadFilesFromScript(obj);
                }
            });
            //command that siren state has changed.
            //recieves a command
            //EventHandlers["ELS:SirenUpdated"] += new Action<string, int, int, bool>(_vehicleManager.UpdateRemoteSirens);
            EventHandlers["ELS:SpawnCar"] += new Action <string>((veh) =>
            {
                SpawnCar(veh);
            });
            EventHandlers["ELS:VcfSync:Client"] += new Action <List <dynamic> >((vcfs) =>
            {
                VCF.ParseVcfs(vcfs);
            });
            EventHandlers.Add("ELS:PatternSync:Client", new Action <List <dynamic> >((patterns) =>
            {
                VCF.ParsePatterns(patterns);
            }));
            EventHandlers["ELS:FullSync:NewSpawnWithData"] += new Action <System.Dynamic.ExpandoObject>((a) =>
            {
                _vehicleManager.SyncAllVehiclesOnFirstSpawn(a);
                Tick -= Class1_Tick;
                Tick += Class1_Tick;
            });
            EventHandlers["ELS:FullSync:NewSpawn"] += new Action(() =>
            {
                Tick -= Class1_Tick;
                Tick += Class1_Tick;
            });

            EventHandlers["ELS:VehicleEntered"] += new Action <int>((veh) =>
            {
                Utils.DebugWriteLine("Vehicle entered");
                Vehicle vehicle = new Vehicle(veh);
                if (vehicle.IsEls() && VehicleManager.vehicleList.ContainsKey(vehicle.GetNetworkId()))
                {
                    Utils.DebugWriteLine("ELS Vehicle entered syncing UI");
                    VehicleManager.SyncUI(vehicle.GetNetworkId());
                }
            });
            //Take in data and apply it
            EventHandlers["ELS:NewFullSyncData"] += new Action <IDictionary <string, object>, int>(_vehicleManager.SetVehicleSyncData);


            API.RegisterCommand("vcfsync", new Action <int, List <object>, string>((source, arguments, raw) =>
            {
                TriggerServerEvent("ELS:VcfSync:Server", Game.Player.ServerId);
            }), false);

            API.RegisterCommand("elsui", new Action <int, List <object>, string>((source, arguments, raw) =>
            {
                if (arguments.Count != 1)
                {
                    return;
                }
                if (arguments[0].Equals("enable"))
                {
                    ElsUiPanel.EnableUI();
                }
                else if (arguments[0].Equals("disable"))
                {
                    ElsUiPanel.DisableUI();
                }
                else if (arguments[0].Equals("show"))
                {
                    ElsUiPanel.ShowUI();
                }
            }), false);

            API.RegisterCommand("elslist", new Action <int, List <object>, string>((source, args, raw) =>
            {
                var listString = "";
                listString    += $"Available ELS Vehicles\n" +
                                 $"----------------------\n";
                foreach (var entry in VCF.ELSVehicle.Values)
                {
                    if (entry.modelHash.IsValid)
                    {
                        listString += $"{System.IO.Path.GetFileNameWithoutExtension(entry.filename)}\n";
                    }
                }
                CitizenFX.Core.Debug.WriteLine(listString);
            }), false);
        }
Exemplo n.º 2
0
        private void SetupConnections()
        {
            EventHandlers["onClientResourceStop"] += new Action <string>(async(string obj) =>
            {
                if (obj == Function.Call <string>(Hash.GET_CURRENT_RESOURCE_NAME))
                {
                    _vehicleManager.CleanUP();
                    _FileLoader.UnLoadFilesFromScript(obj);
                }
            });
            //command that siren state has changed.
            //recieves a command
            //EventHandlers["ELS:SirenUpdated"] += new Action<string, int, int, bool>(_vehicleManager.UpdateRemoteSirens);
            EventHandlers["ELS:SpawnCar"] += new Action <string>((veh) =>
            {
                SpawnCar(veh);
            });
            EventHandlers["ELS:VcfSync:Client"] += new Action <List <dynamic> >((vcfs) =>
            {
                VCF.ParseVcfs(vcfs);
            });
            EventHandlers.Add("ELS:PatternSync:Client", new Action <List <dynamic> >((patterns) =>
            {
                VCF.ParsePatterns(patterns);
            }));
            EventHandlers["ELS:FullSync:NewSpawnWithData"] += new Action <System.Dynamic.ExpandoObject>((a) =>
            {
                _vehicleManager.SyncAllVehiclesOnFirstSpawn(a);
            });
            EventHandlers["ELS:FullSync:NewSpawn"] += new Action(() =>
            {
                Tick -= Class1_Tick;
                Tick += Class1_Tick;
            });

            EventHandlers.Add("playerSpawned", new Action(() => { TriggerServerEvent("ELS:FullSync:Request:All", Game.Player.ServerId); }));
            EventHandlers["ELS:VehicleEntered"] += new Action <int>((veh) =>
            {
                Utils.DebugWriteLine("Vehicle entered checking list");
                Vehicle vehicle = new Vehicle(veh);
                Delay(1000);
                try
                {
                    if (vehicle.Exists() && vehicle.IsEls())
                    {
                        if ((vehicle.GetNetworkId() == LocalPlayer.Character.CurrentVehicle.GetNetworkId()))
                        {
                            Utils.DebugWriteLine("Vehicle is in list moving on");
                            Utils.DebugWriteLine("ELS Vehicle entered syncing UI");
                            lastVehicle = vehicle.GetNetworkId();
                            if (userSettings.uiSettings.enabled)
                            {
                                ElsUiPanel.ShowUI();
                            }
                            VehicleManager.SyncUI(vehicle.GetNetworkId());

                            UserSettings.ELSUserVehicle usrVeh = userSettings.savedVehicles.Find(uveh => uveh.Model == vehicle.Model.Hash && uveh.ServerId == ServerId);
                            Utils.DebugWriteLine($"got usrveh of {usrVeh.Model} on server {usrVeh.ServerId}m");
                            if (ServerId.Equals(usrVeh.ServerId))
                            {
                                Utils.DebugWrite("Got Saved Vehicle Settings applying");
                                VehicleManager.vehicleList[vehicle.GetNetworkId()].SetSaveSettings(usrVeh);
                            }
                            VehicleManager.vehicleList[vehicle.GetNetworkId()].SetInofVeh();
                        }
                        Utils.DebugWriteLine($"Vehicle {vehicle.GetNetworkId()}({Game.PlayerPed.CurrentVehicle.GetNetworkId()}) entered");
                    }
                }
                catch (Exception e)
                {
                    Utils.ReleaseWriteLine("Exception caught via vehicle entered");
                }
            });
            EventHandlers["ELS:VehicleExited"] += new Action <int>((veh) =>
            {
                Vehicle vehicle = new Vehicle(veh);
                try
                {
                    if (vehicle.Exists() && vehicle.IsEls())
                    {
                        if (VehicleManager.vehicleList.ContainsKey(vehicle.GetNetworkId()) && (vehicle.GetNetworkId() == lastVehicle))
                        {
                            if (Global.DisableSirenOnExit)
                            {
                                VehicleManager.vehicleList[vehicle.GetNetworkId()].DisableSiren();
                            }
                            Utils.DebugWriteLine("save settings for vehicle it");
                            VehicleManager.vehicleList[vehicle.GetNetworkId()].GetSaveSettings();
                            VehicleManager.vehicleList[vehicle.GetNetworkId()].SetOutofVeh();
                        }
                        Utils.DebugWriteLine($"Vehicle {vehicle.GetNetworkId()}({Game.PlayerPed.LastVehicle.GetNetworkId()}) exited");
                    }
                }
                catch (Exception e)
                {
                    Utils.ReleaseWriteLine("Exception caught via vehicle exited");
                }
            });
            //Take in data and apply it
            EventHandlers["ELS:NewFullSyncData"] += new Action <IDictionary <string, object>, int>(_vehicleManager.SetVehicleSyncData);


            API.RegisterCommand("vcfsync", new Action <int, List <object>, string>((source, arguments, raw) =>
            {
                TriggerServerEvent("ELS:VcfSync:Server", Game.Player.ServerId);
            }), false);

            API.RegisterCommand("elsui", new Action <int, List <object>, string>((source, arguments, raw) =>
            {
                Task task = new Task(() => userSettings.SaveUI(true));
                if (arguments.Count != 1)
                {
                    return;
                }
                switch (arguments[0].ToString().ToLower())
                {
                case "enable":
                    ElsUiPanel.EnableUI();
                    break;

                case "disable":
                    ElsUiPanel.DisableUI();
                    userSettings.uiSettings.enabled = false;
                    break;

                case "show":
                    ElsUiPanel.ShowUI();
                    userSettings.uiSettings.enabled = true;
                    break;

                case "whelen":
                    userSettings.uiSettings.currentUI = UserSettings.ElsUi.Whelen;
                    break;

                case "new":
                    userSettings.uiSettings.currentUI = UserSettings.ElsUi.NewHotness;
                    break;

                case "old":
                    userSettings.uiSettings.currentUI = UserSettings.ElsUi.OldandBusted;
                    break;
                }
                task.Start();
            }), false);

            API.RegisterCommand("elslist", new Action <int, List <object>, string>((source, args, raw) =>
            {
                var listString = "";
                listString    += $"Available ELS Vehicles\n" +
                                 $"----------------------\n";
                foreach (var entry in VCF.ELSVehicle.Values)
                {
                    if (entry.modelHash.IsValid)
                    {
                        listString += $"{System.IO.Path.GetFileNameWithoutExtension(entry.filename)}\n";
                    }
                }
                CitizenFX.Core.Debug.WriteLine(listString);
            }), false);
        }
Exemplo n.º 3
0
        public ELS()
        {
            if (API.GetConvar("dev_server", "false") == "true" || API.GetConvar("test_server", "false") == "true")
            {
                Utils.IsDeveloper = true;
                Utils.ReleaseWriteLine("Debug logging enabled!");
            }
            bool Loaded = false;

            _controlConfiguration = new ElsConfiguration();
            _FileLoader           = new FileLoader(this);
            EventHandlers["onClientResourceStart"] += new Action <string>(async(string obj) =>
            {
                if (obj == CurrentResourceName())
                {
                    Utils.Debug = bool.Parse(API.GetConvar("elsplus_debug", "false"));
                    try
                    {
                        await Delay(100);
                        ServerId     = API.GetConvar("ElsServerId", null);
                        userSettings = new UserSettings();
                        await Delay(0);
                        Task settingsTask = new Task(() => userSettings.LoadUserSettings());
                        await Delay(0);
                        Utils.ReleaseWriteLine($"Welcome to ELS Plus on {ServerId} using version {Assembly.GetExecutingAssembly().GetName().Version}");
                        settingsTask.Start();
                        await Delay(250);
                        _FileLoader.RunLoader(obj);
                        await Delay(250);
                        SetupConnections();
                        await Delay(250);
                        VcfSync.CheckResources();
                        VCF.ParseVcfs(VcfSync.VcfData);
                        CustomPatterns.CheckCustomPatterns();
                        VCF.ParsePatterns(CustomPatterns.Patterns);
                        await Delay(250);
                        Tick -= Class1_Tick;
                        Tick += Class1_Tick;
                        await Delay(1000);
                        if (float.TryParse(API.GetResourceKvpString("daybrightness"), out var dayValue))
                        {
                            Function.Call((Hash)3520272001, "car.defaultlight.day.emissive.on", dayValue);
                        }
                        else
                        {
                            Function.Call((Hash)3520272001, "car.defaultlight.day.emissive.on", Global.DayLtBrightness);
                        }
                        if (float.TryParse(API.GetResourceKvpString("nightbrightness"), out var nightValue))
                        {
                            Function.Call((Hash)3520272001, "car.defaultlight.night.emissive.on", nightValue);
                        }
                        else
                        {
                            Function.Call((Hash)3520272001, "car.defaultlight.night.emissive.on", Global.NightLtBrightness);
                        }

                        API.RequestScriptAudioBank("DLC_WMSIRENS\\SIRENPACK_ONE", false);
                    }
                    catch (Exception e)
                    {
                        Screen.ShowNotification($"ERROR:{e.Message}");
                        Screen.ShowNotification($"ERROR:{e.StackTrace}");
                        Tick -= Class1_Tick;
                        Utils.ReleaseWriteLine($"ERROR:{e.StackTrace}");
                        Utils.ReleaseWriteLine($"Error: {e.Message}");
                    }
                }
            });
        }