Esempio n. 1
0
        public void VehicleFixStreamIn(Client player, Vehicle veh)
        {
            try
            {
                if (veh != null && NAPI.Entity.DoesEntityExist(veh))
                {
                    VehicleSyncData data = GetVehicleSyncData(veh);
                    if (data == default(VehicleSyncData))
                    {
                        data = new VehicleSyncData();
                    }
                    UpdateVehicleSyncData(veh, data);

                    List <object> vData = new List <object>()
                    {
                        veh.NumberPlate,
                        veh.PrimaryColor,
                        veh.SecondaryColor,
                    };
                    if (veh.HasData("ACCESS") && veh.GetData("ACCESS") == "PERSONAL")
                    {
                        vData.Add(VehicleManager.Vehicles[veh.NumberPlate].Components);
                    }
                    Trigger.ClientEvent(player, "VehStream_FixStreamIn", veh.Handle, JsonConvert.SerializeObject(vData));
                }
                return;
            }
            catch (Exception e) { Log.Write("VehStream_RequestFixStreamIn: " + e.Message, nLog.Type.Error); return; }
        }
Esempio n. 2
0
 //Used internally only but publicly available in case any of you need it
 public static bool UpdateVehicleSyncData(Vehicle veh, VehicleSyncData data)
 {
     try
     {
         if (veh != null)
         {
             if (NAPI.Entity.DoesEntityExist(veh))
             {
                 if (data != null)
                 {
                     if (VehiclesSyncDatas.ContainsKey(veh))
                     {
                         VehiclesSyncDatas[veh] = data;
                     }
                     else
                     {
                         VehiclesSyncDatas.Add(veh, data);
                     }
                     NAPI.Data.SetEntitySharedData(veh, "VehicleSyncData", JsonConvert.SerializeObject(data));
                     return(true);
                 }
             }
         }
         return(false);
     }
     catch (Exception e) { Log.Write("UpdateVehicleSyncData: " + e.Message, nLog.Type.Error); return(false); }
 }
        public static WindowState GetVehicleWindowState(Vehicle veh, WindowID window)
        {
            VehicleSyncData data = GetVehicleSyncData(veh);

            if (data == default(VehicleSyncData))
            {
                data = new VehicleSyncData();
                UpdateVehicleSyncData(veh, data);
            }
            return((WindowState)data.Window[(int)window]);
        }
        public static DoorState GetDoorState(Vehicle veh, DoorID door)
        {
            VehicleSyncData data = GetVehicleSyncData(veh);

            if (data == default(VehicleSyncData))
            {
                data = new VehicleSyncData();
                UpdateVehicleSyncData(veh, data);
            }
            return((DoorState)data.Door[(int)door]);
        }
        public static WheelState GetVehicleWheelState(Vehicle veh, WheelID wheel)
        {
            VehicleSyncData data = GetVehicleSyncData(veh);

            if (data == default(VehicleSyncData))
            {
                data = new VehicleSyncData();
                UpdateVehicleSyncData(veh, data);
            }
            return((WheelState)data.Wheel[(int)wheel]);
        }
        public static float GetVehicleDirt(Vehicle veh)
        {
            VehicleSyncData data = GetVehicleSyncData(veh);

            if (data == default(VehicleSyncData))
            {
                data = new VehicleSyncData();
                UpdateVehicleSyncData(veh, data);
            }
            return(data.Dirt);
        }
Esempio n. 7
0
        public void VehStreamEnter(Client player, Vehicle veh, sbyte seat)
        {
            VehicleSyncData data = GetVehicleSyncData(veh);

            if (data == default(VehicleSyncData))
            {
                data = new VehicleSyncData();
            }
            UpdateVehicleSyncData(veh, data);
            Trigger.ClientEvent(player, "VehStream_PlayerEnterVehicle", veh, seat, data.Engine);
        }
Esempio n. 8
0
        public void VehStreamExitAttempt(Client player, Vehicle veh)
        {
            VehicleSyncData data = GetVehicleSyncData(veh);

            if (data == default(VehicleSyncData))
            {
                data = new VehicleSyncData();
            }
            UpdateVehicleSyncData(veh, data);
            Trigger.ClientEvent(player, "VehStream_PlayerExitVehicleAttempt", veh, data.Engine);
        }
        public static bool GetLockState(Vehicle veh)
        {
            VehicleSyncData data = GetVehicleSyncData(veh);

            if (data == default(VehicleSyncData))
            {
                data = new VehicleSyncData();
                UpdateVehicleSyncData(veh, data);
            }
            return(data.Locked);
        }
        public void VehStreamEnterAttempt(Client player, Vehicle veh, sbyte seat)
        {
            VehicleSyncData data = GetVehicleSyncData(veh);

            if (data == default(VehicleSyncData))
            {
                data = new VehicleSyncData();
            }

            UpdateVehicleSyncData(veh, data);
            NAPI.ClientEvent.TriggerClientEvent(player, "VehStream_PlayerEnterVehicleAttempt", veh, seat);
        }
        //API functions for people to use
        public static void SetVehicleWindowState(Vehicle veh, WindowID window, WindowState state)
        {
            VehicleSyncData data = GetVehicleSyncData(veh);

            if (data == default(VehicleSyncData)) //If data doesn't exist create a new one. This is the process for all API functions
            {
                data = new VehicleSyncData();
            }

            data.Window[(int)window] = (int)state;
            UpdateVehicleSyncData(veh, data);
            NAPI.ClientEvent.TriggerClientEventInDimension(veh.Dimension, "VehStream_SetVehicleWindowStatus_Single", veh.Handle, (int)window, (int)state);
        }
Esempio n. 12
0
        public static void SetDoorState(Vehicle veh, DoorID door, DoorState state)
        {
            VehicleSyncData data = GetVehicleSyncData(veh);

            if (data == default(VehicleSyncData))
            {
                data = new VehicleSyncData();
            }

            data.Door[(int)door] = (int)state;
            UpdateVehicleSyncData(veh, data);
            Trigger.ClientEventInRange(veh.Position, 250, "VehStream_SetVehicleDoorStatus_Single", veh, (int)door, (int)state);
        }
        public static void SetVehicleWheelState(Vehicle veh, WheelID wheel, WheelState state)
        {
            VehicleSyncData data = GetVehicleSyncData(veh);

            if (data == default(VehicleSyncData))
            {
                data = new VehicleSyncData();
            }

            data.Wheel[(int)wheel] = (int)state;
            UpdateVehicleSyncData(veh, data);
            NAPI.ClientEvent.TriggerClientEventInDimension(veh.Dimension, "VehStream_SetVehicleWheelStatus_Single", veh.Handle, (int)wheel, (int)state);
        }
        public static void SetDoorState(Vehicle veh, DoorID door, DoorState state)
        {
            VehicleSyncData data = GetVehicleSyncData(veh);

            if (data == default(VehicleSyncData))
            {
                data = new VehicleSyncData();
            }

            data.Door[(int)door] = (int)state;
            UpdateVehicleSyncData(veh, data);
            NAPI.ClientEvent.TriggerClientEventInDimension(veh.Dimension, "VehStream_SetVehicleDoorStatus_Single", veh, (int)door, (int)state);
        }
        public static void SetVehicleDirt(Vehicle veh, float dirt)
        {
            VehicleSyncData data = GetVehicleSyncData(veh);

            if (data == default(VehicleSyncData))
            {
                data = new VehicleSyncData();
            }

            data.Dirt = dirt;
            UpdateVehicleSyncData(veh, data);
            NAPI.ClientEvent.TriggerClientEventInDimension(veh.Dimension, "VehStream_SetVehicleDirtLevel", veh.Handle, dirt);
        }
        public static void SetLockStatus(Vehicle veh, bool status)
        {
            VehicleSyncData data = GetVehicleSyncData(veh);

            if (data == default(VehicleSyncData))
            {
                data = new VehicleSyncData();
            }

            data.Locked = status;
            UpdateVehicleSyncData(veh, data);
            NAPI.ClientEvent.TriggerClientEventInDimension(veh.Dimension, "VehStream_SetLockStatus", veh, status);
        }
Esempio n. 17
0
        public static void SetEngineState(Vehicle veh, bool status)
        {
            NAPI.Vehicle.SetVehicleEngineStatus(veh, status);
            VehicleSyncData data = GetVehicleSyncData(veh);

            if (data == default(VehicleSyncData))
            {
                data = new VehicleSyncData();
            }

            data.Engine = status;
            UpdateVehicleSyncData(veh, data);
            Trigger.ClientEventInRange(veh.Position, 250, "VehStream_SetEngineStatus", veh, status);
        }
Esempio n. 18
0
        public static void SetLockStatus(Vehicle veh, bool status)
        {
            VehicleSyncData data = GetVehicleSyncData(veh);

            if (data == default(VehicleSyncData))
            {
                data = new VehicleSyncData();
            }

            veh.SetSharedData("LOCKED", status);
            data.Locked = status;
            UpdateVehicleSyncData(veh, data);
            Trigger.ClientEventInRange(veh.Position, 250, "VehStream_SetLockStatus", veh, status);
        }
        public void VehDoorBreak(Vehicle veh, int index)
        {
            VehicleSyncData data = GetVehicleSyncData(veh);

            if (data == default(VehicleSyncData))
            {
                data = new VehicleSyncData();
            }

            data.Door[index] = 2;

            UpdateVehicleSyncData(veh, data);

            NAPI.ClientEvent.TriggerClientEventInDimension(veh.Dimension, "VehStream_SetVehicleDoorStatus", veh.Handle, data.Door[0], data.Door[1], data.Door[2], data.Door[3], data.Door[4], data.Door[5], data.Door[6], data.Door[7]);
        }
        public void VehStreamExit(Client player, Vehicle veh)
        {
            VehicleSyncData data = GetVehicleSyncData(veh);

            if (data == default(VehicleSyncData))
            {
                data = new VehicleSyncData();
            }

            data.Position = veh.Position;
            data.Rotation = veh.Rotation;

            UpdateVehicleSyncData(veh, data);
            NAPI.ClientEvent.TriggerClientEvent(player, "VehStream_PlayerExitVehicle", veh);
        }
        public void VehStreamSetDirtLevel(Client player, Vehicle veh, float dirt)
        {
            VehicleSyncData data = GetVehicleSyncData(veh);

            if (data == default(VehicleSyncData))
            {
                data = new VehicleSyncData();
            }

            data.Dirt = dirt;

            UpdateVehicleSyncData(veh, data);

            //Re-distribute the goods
            NAPI.ClientEvent.TriggerClientEventInDimension(veh.Dimension, "VehStream_SetVehicleDirtLevel", veh.Handle, dirt);
        }
 //Used internally only but publicly available in case any of you need it
 public static bool UpdateVehicleSyncData(Vehicle veh, VehicleSyncData data)
 {
     if (veh != null)
     {
         if (NAPI.Entity.DoesEntityExist(veh))
         {
             if (data != null)
             {
                 data.Position = veh.Position;
                 data.Rotation = veh.Rotation;
                 NAPI.Data.SetEntitySharedData(veh, "VehicleSyncData", data);
                 return(true);
             }
         }
     }
     return(false);
 }
Esempio n. 23
0
        public void VehStreamSetIndicatorLightsData(Client player, Vehicle veh, bool leftstate, bool rightstate)
        {
            VehicleSyncData data = GetVehicleSyncData(veh);

            if (data == default(VehicleSyncData))
            {
                data = new VehicleSyncData();
            }
            if (data.Engine)
            {
                data.RightIL = rightstate;
                data.LeftIL  = leftstate;
                veh.SetSharedData("rightlight", rightstate);
                veh.SetSharedData("leftlight", leftstate);
                UpdateVehicleSyncData(veh, data);
                Trigger.ClientEventInRange(veh.Position, 250, "VehStream_SetVehicleIndicatorLights", veh.Handle, leftstate, rightstate);
            }
        }
Esempio n. 24
0
        public static bool GetVehicleIndicatorLights(Vehicle veh, bool light)
        {
            VehicleSyncData data = GetVehicleSyncData(veh);

            if (data == default(VehicleSyncData))
            {
                data = new VehicleSyncData();
                UpdateVehicleSyncData(veh, data);
            }
            if (!light)
            {
                return(data.RightIL);
            }
            else
            {
                return(data.LeftIL);
            }
        }
Esempio n. 25
0
        public static void SetEngineState(Vehicle veh, bool status)
        {
            NAPI.Vehicle.SetVehicleEngineStatus(veh, status);
            VehicleSyncData data = GetVehicleSyncData(veh);

            if (data == default(VehicleSyncData))
            {
                data = new VehicleSyncData();
            }

            data.Engine  = status;
            data.RightIL = false;
            data.LeftIL  = false;
            veh.SetSharedData("rightlight", false);
            veh.SetSharedData("leftlight", false);
            UpdateVehicleSyncData(veh, data);
            NAPI.Vehicle.SetVehicleEngineStatus(veh, status);
            Trigger.ClientEventInRange(veh.Position, 250, "VehStream_SetEngineStatus", veh, status, true, data.LeftIL, data.RightIL);
        }
        public void VehDamage(Vehicle veh, float bodyHealthLoss, float engineHealthLoss)
        {
            VehicleSyncData data = GetVehicleSyncData(veh);

            if (data == default(VehicleSyncData))
            {
                data = new VehicleSyncData();
            }

            data.BodyHealth   -= bodyHealthLoss;
            data.EngineHealth -= engineHealthLoss;

            UpdateVehicleSyncData(veh, data);

            if (NAPI.Vehicle.GetVehicleDriver(veh) != default(Client)) //Doesn't work?
            {
                NAPI.ClientEvent.TriggerClientEvent(NAPI.Vehicle.GetVehicleDriver(veh), "VehStream_PlayerExitVehicleAttempt", veh);
            }
        }
        public void VehStreamSetWindowData(Client player, Vehicle veh, int window1state, int window2state, int window3state, int window4state)
        {
            VehicleSyncData data = GetVehicleSyncData(veh);

            if (data == default(VehicleSyncData))
            {
                data = new VehicleSyncData();
            }

            data.Window[0] = window1state;
            data.Window[1] = window2state;
            data.Window[2] = window3state;
            data.Window[3] = window4state;

            UpdateVehicleSyncData(veh, data);

            //Re-distribute the goods
            NAPI.ClientEvent.TriggerClientEventInDimension(veh.Dimension, "VehStream_SetVehicleWindowStatus", veh.Handle, window1state, window2state, window3state, window4state);
        }
        public void VehStreamSetDoorData(Client player, Vehicle veh, int door1state, int door2state, int door3state, int door4state, int door5state, int door6state, int door7state, int door8state)
        {
            VehicleSyncData data = GetVehicleSyncData(veh);

            if (data == default(VehicleSyncData))
            {
                data = new VehicleSyncData();
            }

            data.Door[0] = door1state;
            data.Door[1] = door2state;
            data.Door[2] = door3state;
            data.Door[3] = door4state;
            data.Door[4] = door5state;
            data.Door[5] = door6state;
            data.Door[6] = door7state;
            data.Door[7] = door8state;

            UpdateVehicleSyncData(veh, data);

            //Re-distribute the goods
            NAPI.ClientEvent.TriggerClientEventInDimension(veh.Dimension, "VehStream_SetVehicleDoorStatus", veh.Handle, door1state, door2state, door3state, door4state, door5state, door6state, door7state, door8state);
        }
Esempio n. 29
0
        public static void SetVehicleDirt(Vehicle veh, float dirt)
        {
            VehicleSyncData data = GetVehicleSyncData(veh);

            if (data == default(VehicleSyncData))
            {
                data = new VehicleSyncData();
            }
            data.Dirt = dirt;
            UpdateVehicleSyncData(veh, data);

            if (veh.HasData("ACCESS") && veh.GetData("ACCESS") == "PERSONAL")
            {
                if (!VehicleManager.Vehicles.ContainsKey(veh.NumberPlate))
                {
                    return;
                }

                VehicleManager.Vehicles[veh.NumberPlate].Dirt = dirt;
            }

            Trigger.ClientEventInDimension(veh.Dimension, "VehStream_SetVehicleDirtLevel", veh.Handle, dirt);
        }
        public void VehStreamSetWheelData(Client player, Vehicle veh, int wheel1state, int wheel2state, int wheel3state, int wheel4state, int wheel5state, int wheel6state, int wheel7state, int wheel8state, int wheel9state, int wheel10state)
        {
            VehicleSyncData data = GetVehicleSyncData(veh);

            if (data == default(VehicleSyncData))
            {
                data = new VehicleSyncData();
            }

            data.Wheel[0] = wheel1state;
            data.Wheel[1] = wheel2state;
            data.Wheel[2] = wheel3state;
            data.Wheel[3] = wheel4state;
            data.Wheel[4] = wheel5state;
            data.Wheel[5] = wheel6state;
            data.Wheel[6] = wheel7state;
            data.Wheel[7] = wheel8state;
            data.Wheel[8] = wheel9state;
            data.Wheel[9] = wheel10state;
            UpdateVehicleSyncData(veh, data);

            //Re-distribute the goods
            NAPI.ClientEvent.TriggerClientEventInDimension(veh.Dimension, "VehStream_SetVehicleWheelStatus", veh.Handle, wheel1state, wheel2state, wheel3state, wheel4state, wheel5state, wheel6state, wheel7state, wheel8state, wheel9state, wheel10state);
        }