private void OnCreateSpeedZone([FromSource] Player player, byte[] data) { if (!IsConfigurationEnabled("use_speed_zones")) { return; } if (!IsPlayerAllowed(player)) { return; } SpeedZone.Create(data); }
private void AddSpeedZoneMenu() { UIMenu submenu = menuPool.AddSubMenu(mainMenu, "Speed Zones"); speedZoneMenu = submenu; // Used in ForceLoad, serves no other purpose. 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); string speedType = GetResourceMetadata(GetCurrentResourceName(), "speed_type", 0) ?? "MPH"; List <dynamic> speedList = new List <dynamic>() { 0, 5, 10, 15, 20, 25, 30, 40, 50, 60, 70 }; UIMenuListItem speed = new UIMenuListItem($"Speed ({speedType.ToUpper()})", speedList, 0); submenu.AddItem(speed); 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) { float speedDiv = speedType.ToLower() == "mph" ? 2.237f : 3.59f; SpeedZone.Create(radiusList[radius.Index], speedList[speed.Index] / speedDiv); } else if (item == remove) { Vector3 myPos = GetEntityCoords(PlayerPedId(), true); SpeedZone closest = null; float closestDistance = 100f; foreach (SpeedZone zone in SpeedZone.List) { float distance = Vector3.Distance(myPos, zone.Position); if (distance < closestDistance) { closest = zone; closestDistance = distance; } } if (closest != null) { BaseScript.TriggerServerEvent("TrafficManager:RemoveSpeedZone", closest.Id); } } }; }