示例#1
0
        internal static void makenetworked(Vehicle veh)
        {
            //////////
            ///
            ///  THANKS to Antivirus-chan in the FiveM community for supplying this code
            ///
            //////////
            //if (!veh.Model.IsLoaded) veh.Model.Request(-1);
            var net1     = API.VehToNet(veh.Handle);
            var attempts = 0;

            do
            {
                Utils.DebugWriteLine($"Attempt {attempts} of {veh.Handle} driven by {veh.GetPedOnSeat(VehicleSeat.Driver).Handle}");
                //BaseScript.Delay(500);
                var netid = API.NetworkGetNetworkIdFromEntity(veh.Handle);
                API.NetworkRegisterEntityAsNetworked(veh.Handle);
                API.SetEntityAsMissionEntity(veh.Handle, false, false);
                API.SetNetworkIdCanMigrate(netid, true);
                API.SetNetworkIdExistsOnAllMachines(netid, true);
                API.NetworkRequestControlOfEntity(veh.Handle);
                attempts++;
            }while (!API.NetworkDoesEntityExistWithNetworkId(veh.Handle) && attempts < 20);
            if (attempts == 20 && !notified)
            {
                CitizenFX.Core.Debug.WriteLine("Failed to register entity on net");
                notified = true;
            }
            else if (!notified)
            {
                CitizenFX.Core.Debug.WriteLine($"Registered {veh.Handle} on net as {net1}");
                ELS.TriggerEvent("ELS:VehicleEntered");
                notified = true;
            }
        }
示例#2
0
 internal async Task SoundCleanUpTick()
 {
     ELS.Delay(400);
     foreach (KeyValuePair <int, ELSVehicle> veh in vehicleList)
     {
         veh.Value.CleanUP();
     }
 }
示例#3
0
        internal async Task ElsIDSetTick()
        {
            await ELS.Delay(1000);

            List <Vehicle> vehicles = new List <Vehicle>(World.GetAllVehicles());

            for (int i = 0; i < vehicles.Count; i++)
            {
                if (vehicles[i].IsEls() && !API.DecorExistOn(vehicles[i].Handle, "elsplus_id") && vehicles[i].GetPedOnSeat(VehicleSeat.Driver) == Game.PlayerPed)
                {
                    Random rnd1 = new Random();
                    int    rnd  = rnd1.Next(Game.GameTime);
                    Utils.DebugWriteLine($"Registering Decor Int of {rnd} for vehicle elsplus id");
                    API.DecorSetInt(vehicles[i].Handle, "elsplus_id", rnd);
                }
            }
        }
示例#4
0
        internal static async void ReloadUI()
        {
            JObject message = new JObject();

            message["type"] = "reload";
            API.SendNuiMessage(message.ToString());
            await ELS.Delay(10000);

            Utils.ReleaseWriteLine("Reloaded UI");
            InitData();
            if (ELS.userSettings.uiSettings.enabled)
            {
                ShowUI();
            }
            else
            {
                DisableUI();
            }
        }
示例#5
0
 public StateControl(ELS els)
 {
     _els = els;
     els.EventHandlerDictionary["sirenStateChanged"] += new Action <int, string, string, bool>(delegate(int vehid, string netSoundid, string propertyName, bool state)
     {
         Debug.WriteLine(vehid.ToString());
         if (!Function.Call <bool>(Hash.NETWORK_DOES_NETWORK_ID_EXIST, vehid))
         {
             return;
         }
         var vehId = Function.Call <Entity>(Hash.NETWORK_GET_ENTITY_FROM_NETWORK_ID, vehid);
         if (Function.Call <bool>(Hash.DECOR_EXIST_ON, vehId, propertyName))
         {
         }
         else
         {
         }
         Screen.ShowNotification(netSoundid.ToString() + propertyName.ToString() + state.ToString());
     });
 }
示例#6
0
        static List <Ped> GetNearestVehicles(float range)
        {
            int        handle = 0;
            List <Ped> peds   = new List <Ped>();

            //API.isentityin
            ELS.Delay(10);
            if (handle == 0)
            {
                API.FindFirstPed(ref handle);
            }
            else
            {
                API.FindNextPed(handle, ref handle);
            }
            Ped ped = (Ped)Ped.FromHandle(handle);

            if (getDistanceBetweenEntities(Game.PlayerPed, ped) <= range && ped.IsInVehicle())
            {
                peds.Add(ped);
            }
            return(peds);
        }
示例#7
0
 internal static void SendDataUnicast(IDictionary dic, int PlayerID)
 {
     ELS.TriggerServerEvent("ELS:FullSync:Unicast", dic, PlayerID);
 }
示例#8
0
 internal static void SendDataBroadcast(IDictionary dic, int PlayerId)
 {
     ELS.TriggerServerEvent("ELS:FullSync:Broadcast", dic, PlayerId);
 }
示例#9
0
 internal static void RequestData(long NetworkID)
 {
     ELS.TriggerServerEvent("ELS:FullSync:Request", NetworkID);
 }
示例#10
0
        internal async Task RegistrationTick()
        {
            int count = 0;

            do
            {
                //Utils.DebugWriteLine($"Delay {count} at {Game.GameTime}");
                await ELS.Delay(1000);

                count++;
            } while (count < Global.RegistrationDelay);

            List <Vehicle> vehicles = new List <Vehicle>(World.GetAllVehicles());

            for (int i = 0; i < vehicles.Count; i++)
            {
                //if (vehicles[i].IsEls() && !API.DecorExistOn(vehicles[i].Handle, "elsplus_id") && vehicles[i].GetPedOnSeat(VehicleSeat.Driver) == Game.PlayerPed)
                //{
                //    Random rnd1 = new Random();
                //    int rnd = rnd1.Next(Game.GameTime);
                //    Utils.DebugWriteLine($"Registering Decor Int of {rnd} for vehicle elsplus id");
                //    API.DecorSetInt(vehicles[i].Handle, "elsplus_id", rnd);
                //    vehicleList.Add(vehicles[i].Handle);
                //}
                /*else*/
                if (vehicles[i].IsEls() && API.DecorExistOn(vehicles[i].Handle, "elsplus_id"))
                {
                    int id      = vehicles[i].GetElsId();
                    int currVeh = 0;
                    if (Game.PlayerPed.CurrentVehicle != null)
                    {
                        currVeh = Game.PlayerPed.CurrentVehicle.GetElsId();
                    }
                    Utils.DebugWriteLine($"Got ELS Id for this vehicle of {id}");
                    //if (!vehicleList.ContainsKey(id))
                    //{
                    //    Utils.DebugWriteLine($"ELS Vehicle found with id of {id} attempting to get data from server");
                    //    //ELS.TriggerServerEvent("ELS:FullSync:UniCast", Game.Player.ServerId, id);
                    //    //await ELS.Delay(5000);
                    //}
                    string json = API.GetConvar("elsplus_data", "");
                    //Utils.DebugWriteLine($"Got Registration Json of: {json}");
                    if (!String.IsNullOrEmpty(json))
                    {
                        Dictionary <int, string> vehlist = JsonConvert.DeserializeObject <Dictionary <int, string> >(json);
                        if (!vehicleList.ContainsKey(id) && vehlist.ContainsKey(id))
                        {
                            Utils.DebugWriteLine($"Veh not in client list registering new vehicle for id {id}");
                            vehicleList.Add(vehicles[i].Handle, JsonConvert.DeserializeObject <ELSVehicleFSData>(vehlist[id]));
                        }
                        else if (!vehicleList.ContainsKey(id) && !vehlist.ContainsKey(id))
                        {
                            Utils.DebugWriteLine($"Veh not in client list nor server list registering vehicle");
                            vehicleList.Add(vehicles[i].Handle);
                        }
                        else if (vehicleList.ContainsKey(id) && !vehlist.ContainsKey(id))
                        {
                            Utils.DebugWriteLine($"Veh not in client list nor server list registering vehicle");
                            vehicleList.Add(vehicles[i].Handle);
                        }
                        else if (vehicleList.ContainsKey(id) && currVeh > 0 && currVeh != id)
                        {
                            Utils.DebugWriteLine($"Vehicle in list but curr != id setting data from convar");
                            vehicleList[id].SetData(JsonConvert.DeserializeObject <ELSVehicleFSData>(vehlist[id]));
                            ;
                        }
                        else if (vehicleList.ContainsKey(id) && !vehlist.ContainsKey(id))
                        {
                            vehicleList.Remove(id);
                        }
                    }
                }
            }
        }
示例#11
0
 internal static void SendDataBroadcast(string dic, int PlayerId)
 {
     Utils.DebugWriteLine($"ELS FS Dic is {dic.GetType()}");
     ELS.TriggerServerEvent("ELS:FullSync:Broadcast", dic, PlayerId);
 }