Exemplo n.º 1
0
        private void AddSecureZoneMenu()
        {
            UIMenu submenu = menuPool.AddSubMenu(mainMenu, "Secure Zones");

            submenu.MouseControlsEnabled = false;

            List <dynamic> radiusList = new List <dynamic>()
            {
                5, 10, 15, 20, 25, 30, 40, 50, 75, 100
            };
            UIMenuListItem radius = new UIMenuListItem("Radius", radiusList, 0);

            submenu.AddItem(radius);

            UIMenuItem create = new UIMenuItem("~b~Create");

            submenu.AddItem(create);

            UIMenuItem remove = new UIMenuItem("~r~Remove Closest");

            submenu.AddItem(remove);

            submenu.OnItemSelect += (sender, item, index) =>
            {
                if (item == create)
                {
                    SecureZone.Create(radiusList[radius.Index]);
                }
                else if (item == remove)
                {
                    Vector3 myPos = GetEntityCoords(PlayerPedId(), true);

                    SecureZone closest         = null;
                    float      closestDistance = 100f;
                    foreach (SecureZone zone in SecureZone.List)
                    {
                        float distance = Vector3.Distance(myPos, zone.Position);
                        if (distance < closestDistance)
                        {
                            closest         = zone;
                            closestDistance = distance;
                        }
                    }

                    if (closest != null)
                    {
                        BaseScript.TriggerServerEvent("TrafficManager:RemoveSecureZone", closest.Id);
                    }
                }
            };
        }
Exemplo n.º 2
0
        private void OnCreateSecureZone([FromSource] Player player, byte[] data)
        {
            if (!IsConfigurationEnabled("use_secure_zones"))
            {
                return;
            }

            if (!IsPlayerAllowed(player))
            {
                return;
            }

            SecureZone.Create(data);
        }
Exemplo n.º 3
0
        public static void Create(int radius)
        {
            SecureZone zone = new SecureZone()
            {
                Position = GetEntityCoords(PlayerPedId(), true),
                Radius   = radius
            };

            using MemoryStream stream = new MemoryStream();
            using BinaryWriter writer = new BinaryWriter(stream);
            writer.Write(zone);

            BaseScript.TriggerServerEvent("TrafficManager:CreateSecureZone", stream.ToArray());
        }
Exemplo n.º 4
0
        public static void Create(byte[] data)
        {
            using MemoryStream stream = new MemoryStream(data);
            using BinaryReader reader = new BinaryReader(stream);

            SecureZone zone = reader.Read <SecureZone>();

            zone.Id = Utility.GetNextIdentifier();
            List.Add(zone);

            stream.Position           = 0;
            using BinaryWriter writer = new BinaryWriter(stream);
            writer.Write(zone);

            BaseScript.TriggerClientEvent("TrafficManager:CreateSecureZone", stream.ToArray());
        }
Exemplo n.º 5
0
        private void OnRemoveSecureZone([FromSource] Player player, int id)
        {
            if (!IsConfigurationEnabled("use_secure_zones"))
            {
                return;
            }

            if (!IsPlayerAllowed(player))
            {
                return;
            }

            SecureZone zone = SecureZone.List.FirstOrDefault(z => z.Id == id);

            if (zone == null)
            {
                return;
            }

            SecureZone.List.Remove(zone);
            TriggerClientEvent("TrafficManager:RemoveSecureZone", id);
        }
Exemplo n.º 6
0
        public Main()
        {
            EventHandlers["TrafficManager:CreateSpeedZone"] += new Action <byte[]>((data) =>
            {
                using MemoryStream stream = new MemoryStream(data);
                using BinaryReader reader = new BinaryReader(stream);

                SpeedZone zone = reader.Read <SpeedZone>();
                zone.Enable();
                SpeedZone.List.Add(zone);
            });

            EventHandlers["TrafficManager:RemoveSpeedZone"] += new Action <int>((id) =>
            {
                SpeedZone zone = SpeedZone.List.FirstOrDefault(z => z.Id == id);
                if (zone == null)
                {
                    return;
                }

                zone.Disable();
                SpeedZone.List.Remove(zone);
            });

            EventHandlers["TrafficManager:CreateSecureZone"] += new Action <byte[]>((data) =>
            {
                using MemoryStream stream = new MemoryStream(data);
                using BinaryReader reader = new BinaryReader(stream);

                SecureZone zone = reader.Read <SecureZone>();
                zone.Enable();
                SecureZone.List.Add(zone);

                Tick += SecureZoneThread;
            });

            EventHandlers["TrafficManager:RemoveSecureZone"] += new Action <int>((id) =>
            {
                SecureZone zone = SecureZone.List.FirstOrDefault(z => z.Id == id);
                if (zone == null)
                {
                    return;
                }

                zone.Disable();
                SecureZone.List.Remove(zone);

                if (SecureZone.List.Count == 0)
                {
                    Tick -= SecureZoneThread;
                }
            });

            EventHandlers["TrafficManager:EditNode"] += new Action <byte[]>((data) =>
            {
                using MemoryStream stream = new MemoryStream(data);
                using BinaryReader reader = new BinaryReader(stream);

                Node node = reader.Read <Node>();
                node.Enable();
                Node.List.Add(node);
            });

            EventHandlers["TrafficManager:RemoveNode"] += new Action <int>((id) =>
            {
                Node node = Node.List.FirstOrDefault(n => n.Id == id);
                if (node == null)
                {
                    return;
                }

                node.Disable();
                Node.List.Remove(node);
            });

            EventHandlers["TrafficManager:FullSync"] += new Action <byte[]>((data) =>
            {
                using MemoryStream stream = new MemoryStream(data);
                using BinaryReader reader = new BinaryReader(stream);

                List <SpeedZone> speedZones = reader.ReadList <SpeedZone>();
                speedZones.ForEach(s => s.Enable());
                SpeedZone.List.AddRange(speedZones);

                List <SecureZone> secureZones = reader.ReadList <SecureZone>();
                secureZones.ForEach(s => s.Enable());
                SecureZone.List.AddRange(secureZones);

                if (SecureZone.List.Count > 0)
                {
                    Tick += SecureZoneThread;
                }

                List <Node> nodes = reader.ReadList <Node>();
                nodes.ForEach(n => n.Enable());
                Node.List.AddRange(nodes);
            });

            EventHandlers["TrafficManager:ToggleMenu"] += new Action(() =>
            {
                Menu.Instance.Toggle();
            });

            // This would be registered on the server, but for some unbewnost reason RegisterKeyMapping fails to work with it on the server.
            // This method is just as safe.
            RegisterCommand("trafficmenu", new Action <int, List <object>, string>((source, args, raw) =>
            {
                TriggerServerEvent("TrafficManager:ToggleMenu");
            }), false);

            string defaultKey = GetResourceMetadata(GetCurrentResourceName(), "default_menu_button", 0) ?? "F5";

            RegisterKeyMapping("trafficmenu", "Traffic", "keyboard", defaultKey);

            Menu.ForceLoad();

            TriggerServerEvent("TrafficManager:PlayerConnected");
        }