public override void Process(ConstructorBeginCrafting packet, NitroxServer.Player player)
        {
            VehicleModel vehicleModel = VehicleModelFactory.BuildFrom(packet);

            vehicleManager.AddVehicle(vehicleModel);
            playerManager.SendPacketToOtherPlayers(packet, player);
        }
示例#2
0
 public override void Process(VehicleCreated packet, Player player)
 {
     Log.Debug(packet);
     vehicleManager.AddVehicle(packet.CreatedVehicle);
     playerManager.SendPacketToOtherPlayers(packet, player);
 }
 public override void Process(ConstructorBeginCrafting packet, NitroxServer.Player player)
 {
     vehicleManager.AddVehicle(packet.VehicleModel);
     playerManager.SendPacketToOtherPlayers(packet, player);
 }
示例#4
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<dynamic>((a) =>
            //{
            //    //dynamic data = a;
            //    _vehicleManager.SyncAllVehiclesOnFirstSpawn(a);
            //});

            EventHandlers["ELS:serverNetworkId"] += new Action <int, int, int, int>((servernetid, serverentityid, sententid, sentnetid) =>
            {
                Utils.DebugWrite($"Got Server net id of {servernetid} for server entity {serverentityid} for client entity {sententid} with net id of {sentnetid}");
            });

            EventHandlers["ELS:FullSync:Unicast"] += new Action <int, dynamic>((vehid, data) =>
            {
                Utils.DebugWriteLine($"Got single vehicle of {vehid} adding vehicle");
                _vehicleManager.AddVehicle(vehid, data);
            });

            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(2000);
                try
                {
                    if (vehicle.Exists() && vehicle.IsEls())
                    {
                        if (!API.DecorExistOn(vehicle.Handle, "elsplus_id"))
                        {
                            Delay(Global.RegistrationDelay);
                        }
                        int vehid = vehicle.GetElsId();

                        int currVehId = LocalPlayer.Character.CurrentVehicle.GetElsId();
                        if (vehid == currVehId)
                        {
                            Utils.DebugWriteLine("Vehicle is in list moving on");
                            Utils.DebugWriteLine("ELS Vehicle entered syncing UI");
                            lastVehicle = vehid;
                            if (userSettings.uiSettings.enabled)
                            {
                                ElsUiPanel.ShowUI();
                            }
                            VehicleManager.SyncUI(vehid);

                            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[vehid].SetSaveSettings(usrVeh);
                            }
                            VehicleManager.vehicleList[vehid].SetInofVeh();
                        }
                        Utils.DebugWriteLine($"Vehicle {vehid}({currVehId}) entered");
                    }
                }
                catch (Exception e)
                {
                    Utils.ReleaseWriteLine($"Exception {e.Message} caught via vehicle entered");
                }
            });
            EventHandlers["ELS:VehicleExited"] += new Action <int>((veh) =>
            {
                Vehicle vehicle = new Vehicle(veh);
                try
                {
                    if (vehicle.Exists() && vehicle.IsEls())
                    {
                        int vehid   = vehicle.GetElsId();
                        lastVehicle = vehid;
                        //int currVehId = LocalPlayer.Character.CurrentVehicle?.GetElsId();
                        if (VehicleManager.vehicleList.ContainsKey(vehid) && (vehid == lastVehicle))
                        {
                            if (Global.DisableSirenOnExit)
                            {
                                VehicleManager.vehicleList[vehid].DisableSiren();
                            }
                            Utils.DebugWriteLine("save settings for vehicle it");
                            VehicleManager.vehicleList[vehid].GetSaveSettings();
                            VehicleManager.vehicleList[vehid].SetOutofVeh();
                        }
                        Utils.DebugWriteLine($"Vehicle {vehid}({lastVehicle}) exited");
                    }
                }
                catch (Exception e)
                {
                    Utils.ReleaseWriteLine($"Exception {e.Message} caught via vehicle exited");
                }
            });
            //Take in data and apply it
            EventHandlers["ELS:NewFullSyncData"] += new Action <string, int>(_vehicleManager.SetVehicleSyncData);

            EventHandlers["ELS:removeStaleFromList"] += new Action <int>((id) =>
            {
                VehicleManager.vehicleList.Remove(id);
            });

            EventHandlers["ELS:clearVehicleList"] += new Action(() =>
            {
                VehicleManager.vehicleList.Clear();
            });


            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 += $"{Path.GetFileNameWithoutExtension(entry.filename)}\n";
                    }
                }
                Utils.DebugWriteLine(listString);
            }), false);
        }