Advertisement
Guest User

Untitled

a guest
Sep 14th, 2020
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 9.33 KB | None | 0 0
  1. CLIENT.LUA
  2.  
  3. --AddSpeedZoneForCoord(float x, float y, float z, float radius, float speed, BOOL p5);
  4.  
  5. local speedZoneActive = false
  6. local blip
  7. local speedZone
  8. local speedzones = {}
  9. local PlayerData              = {}
  10.  
  11. ESX                           = nil
  12.  
  13. Citizen.CreateThread(function()
  14.     while ESX == nil do
  15.         TriggerEvent('esx:getSharedObject', function(obj) ESX = obj end)
  16.         Citizen.Wait(0)
  17.     end
  18.  
  19.     while ESX.GetPlayerData().job == nil do
  20.         Citizen.Wait(10)
  21.     end
  22.  
  23.     PlayerData = ESX.GetPlayerData()
  24. end)
  25.  
  26.  
  27. _menuPool = NativeUI.CreatePool()
  28. trafficmenu = NativeUI.CreateMenu("Five Brothers RP", "~b~Scene Menu")
  29. _menuPool:Add(trafficmenu)
  30. _menuPool:MouseControlsEnabled(false)
  31. _menuPool:ControlDisablingEnabled(false)
  32.  
  33. function ShowNotification(text)
  34.   SetNotificationTextEntry("STRING")
  35.   AddTextComponentString(text)
  36.   DrawNotification(false, false)
  37. end
  38.  
  39. function ObjectsSubMenu(menu)
  40.   local submenu = _menuPool:AddSubMenu(menu, "Objects Menu")
  41.   local objects = {
  42.     "Slow sign",
  43.     "Grootte pion",
  44.     "Kleine pion",
  45.     "Scene Light",
  46.     "Tent",
  47. }
  48.   local objectlist = NativeUI.CreateListItem("Object Spawnen", objects, 1, "Choose an object to spawn.")
  49.   local deletebutton = NativeUI.CreateItem("Remove", "Delete nearest item.")
  50.  
  51.  
  52.   submenu:AddItem(deletebutton)
  53.   deletebutton.Activated = function(sender, item, index)
  54.     local theobject1 = 'prop_barrier_work05'
  55.     local object1 = GetHashKey(theobject1)
  56.     local x, y, z = table.unpack(GetEntityCoords(PlayerPedId(), true))
  57.     if DoesObjectOfTypeExistAtCoords(x, y, z, 0.9, object1, true) then
  58.         local obj1 = GetClosestObjectOfType(x, y, z, 0.9, object1, false, false, false)
  59.         DeleteObject(obj1)
  60.     end
  61.  
  62.     local theobject2 = 'prop_roadcone01a'
  63.     local object2 = GetHashKey(theobject2)
  64.     if DoesObjectOfTypeExistAtCoords(x, y, z, 0.9, object2, true) then
  65.         local obj2 = GetClosestObjectOfType(x, y, z, 0.9, object2, false, false, false)
  66.         DeleteObject(obj2)
  67.     end
  68.  
  69.     local theobject4 = 'prop_gazebo_02'
  70.     local object4 = GetHashKey(theobject4)
  71.     if DoesObjectOfTypeExistAtCoords(x, y, z, 0.9, object4, true) then
  72.         local obj4 = GetClosestObjectOfType(x, y, z, 0.9, object4, false, false, false)
  73.         DeleteObject(obj4)
  74.     end
  75.  
  76.     local theobject5 = 'prop_roadcone02b'
  77.     local object5 = GetHashKey(theobject5)
  78.     if DoesObjectOfTypeExistAtCoords(x, y, z, 0.9, object5, true) then
  79.         local obj5 = GetClosestObjectOfType(x, y, z, 0.9, object5, false, false, false)
  80.         DeleteObject(obj5)
  81.     end
  82.  
  83.     local theobject3 = 'prop_worklight_03b'
  84.     local object3 = GetHashKey(theobject3)
  85.     if DoesObjectOfTypeExistAtCoords(x, y, z, 0.9, object3, true) then
  86.         local obj3 = GetClosestObjectOfType(x, y, z, 0.9, object3, false, false, false)
  87.         DeleteObject(obj3)
  88.     end
  89.   end
  90.  
  91.   submenu:AddItem(objectlist)
  92.   objectlist.OnListSelected = function(sender, item, index)
  93.     local Player = GetPlayerPed(-1)
  94.     local heading = GetEntityHeading(Player)
  95.     local x, y, z = table.unpack(GetEntityCoords(Player, true))
  96.      local object = item:IndexToItem(index)
  97.         if object == objects[1] then
  98.         local objectname = 'prop_barrier_work05'
  99.           RequestModel(objectname)
  100.           while not HasModelLoaded(objectname) do
  101.             Citizen.Wait(1)
  102.           end
  103.             local obj = CreateObject(GetHashKey(objectname), x, y, z, true, false);
  104.             PlaceObjectOnGroundProperly(obj)
  105.             SetEntityHeading(obj, heading)
  106.             FreezeEntityPosition(obj, true)
  107.         elseif object == objects[2] then
  108.             local objectname = 'prop_roadcone01a'
  109.             RequestModel(objectname)
  110.             while not HasModelLoaded(objectname) do
  111.               Citizen.Wait(1)
  112.             end
  113.               local obj = CreateObject(GetHashKey(objectname), x, y, z, true, false);
  114.               PlaceObjectOnGroundProperly(obj)
  115.               SetEntityHeading(obj, heading)
  116.               FreezeEntityPosition(obj, true)
  117.         elseif object == objects[4] then
  118.           local objectname = 'prop_worklight_03b'
  119.           RequestModel(objectname)
  120.           while not HasModelLoaded(objectname) do
  121.             Citizen.Wait(1)
  122.           end
  123.             local obj = CreateObject(GetHashKey(objectname), x, y, z, true, false);
  124.             PlaceObjectOnGroundProperly(obj)
  125.             SetEntityHeading(obj, heading)
  126.             FreezeEntityPosition(obj, true)
  127.         elseif object == objects[3] then
  128.             local objectname = 'prop_roadcone02b'
  129.             RequestModel(objectname)
  130.             while not HasModelLoaded(objectname) do
  131.               Citizen.Wait(1)
  132.             end
  133.               local obj = CreateObject(GetHashKey(objectname), x, y, z, true, false);
  134.               PlaceObjectOnGroundProperly(obj)
  135.               SetEntityHeading(obj, heading)
  136.               FreezeEntityPosition(obj, true)
  137.         elseif object == objects[5] then
  138.               local objectname = 'prop_gazebo_02'
  139.               RequestModel(objectname)
  140.               while not HasModelLoaded(objectname) do
  141.                 Citizen.Wait(1)
  142.               end
  143.                 local obj = CreateObject(GetHashKey(objectname), x, y, z, true, false);
  144.                 PlaceObjectOnGroundProperly(obj)
  145.                 SetEntityHeading(obj, heading)
  146.                 FreezeEntityPosition(obj, true)
  147.         end
  148. end
  149.  
  150. end
  151.  
  152. function SpeedZoneSubMenu(menu)
  153.   local submenu = _menuPool:AddSubMenu(menu, "Speed Zone")
  154.   local radiusnum = {
  155.     "25",
  156.     "50",
  157.     "75",
  158.     "100",
  159.     "125",
  160.     "150",
  161.     "175",
  162.     "200",
  163.   }
  164.  
  165.   local speednum = {
  166.     "0",
  167.     "5",
  168.     "10",
  169.     "15",
  170.     "20",
  171.     "25",
  172.     "30",
  173.     "35",
  174.     "40",
  175.     "45",
  176.     "50",
  177.   }
  178.  
  179.   local zonecreate = NativeUI.CreateItem("Create Zone", "Creat a speed zone.")
  180.   local zoneradius = NativeUI.CreateSliderItem("Radius", radiusnum, 1, false)
  181.   local zonespeed = NativeUI.CreateListItem("Speed", speednum, 1)
  182.   local zonedelete = NativeUI.CreateItem("Delete Zone", "Remove the zone you are in.")
  183.  
  184.   submenu:AddItem(zoneradius)
  185.   submenu:AddItem(zonespeed)
  186.   submenu:AddItem(zonecreate)
  187.   submenu:AddItem(zonedelete)
  188.  
  189.   zonecreate:SetRightBadge(BadgeStyle.Tick)
  190.  
  191.   submenu.OnSliderChange = function(sender, item, index)
  192.         radius = item:IndexToItem(index)
  193.         ShowNotification("Change radius to ~r~" .. radius)
  194.   end
  195.  
  196.   submenu.OnListChange = function(sender, item, index)
  197.     speed = item:IndexToItem(index)
  198.     ShowNotification("Change speed to ~r~" .. speed)
  199.   end
  200.  
  201.   zonedelete.Activated = function(sender, item, index)
  202.       TriggerServerEvent('Disable')
  203.       ShowNotification("Zone removed.")
  204.   end
  205.  
  206.   zonecreate.Activated = function(sender, item, index)
  207.  
  208.       if not speed then
  209.         speed = 0
  210.       end
  211.  
  212.       if not radius then
  213.         ShowNotification("~r~Please change the radius!")
  214.         return
  215.       end
  216.  
  217.           speedZoneActive = true
  218.           ShowNotification("Speed zone created.")
  219.           local x, y, z = table.unpack(GetEntityCoords(GetPlayerPed(-1)))
  220.           radius = radius + 0.0
  221.           speed = speed + 0.0
  222.      
  223.           local streetName, crossing = GetStreetNameAtCoord(x, y, z)
  224.           streetName = GetStreetNameFromHashKey(streetName)
  225.      
  226.           local message = "^* ^1Traffic Warning: ^r^*^7The street has been cordoned off at^2" .. streetName .. " ^7like to drive at a speed of:^2" .. speed .. "km/h ^7by accident!."
  227.      
  228.           TriggerServerEvent('ZoneActivated', message, speed, radius, x, y, z)
  229.      
  230.  
  231.   end
  232.  
  233. end
  234.  
  235. ObjectsSubMenu(trafficmenu)
  236. SpeedZoneSubMenu(trafficmenu)
  237.  
  238. Citizen.CreateThread(function()
  239.   while true do
  240.       Citizen.Wait(0)
  241.       _menuPool:ProcessMenus()
  242.       if IsControlJustPressed(0, 166) and GetLastInputMethod( 0 ) and PlayerData.job ~= nil and PlayerData.job.name == 'police' then
  243.           trafficmenu:Visible(not trafficmenu:Visible())
  244.       end
  245.   end
  246. end)
  247.  
  248.  
  249. RegisterNetEvent('Zone')
  250. AddEventHandler('Zone', function(speed, radius, x, y, z)
  251.  
  252.   blip = AddBlipForRadius(x, y, z, radius)
  253.       SetBlipColour(blip,idcolor)
  254.       SetBlipAlpha(blip,80)
  255.       SetBlipSprite(blip,9)
  256.   speedZone = AddSpeedZoneForCoord(x, y, z, radius, speed, true)
  257.  
  258.   table.insert(speedzones, {x, y, z, speedZone, blip})
  259.  
  260. end)
  261.  
  262. RegisterNetEvent('RemoveBlip')
  263. AddEventHandler('RemoveBlip', function()
  264.  
  265.     if speedzones == nil then
  266.       return
  267.     end
  268.     local playerPed = GetPlayerPed(-1)
  269.     local x, y, z = table.unpack(GetEntityCoords(playerPed, true))
  270.     local closestSpeedZone = 0
  271.     local closestDistance = 1000
  272.     for i = 1, #speedzones, 1 do
  273.         local distance = Vdist(speedzones[i][1], speedzones[i][2], speedzones[i][3], x, y, z)
  274.         if distance < closestDistance then
  275.             closestDistance = distance
  276.             closestSpeedZone = i
  277.         end
  278.     end
  279.     RemoveSpeedZone(speedzones[closestSpeedZone][4])
  280.     RemoveBlip(speedzones[closestSpeedZone][5])
  281.     table.remove(speedzones, closestSpeedZone)
  282.  
  283. end)
  284.  
  285. SERVER.LUA
  286.  
  287. RegisterServerEvent('ZoneActivated')
  288. AddEventHandler('ZoneActivated', function(message, speed, radius, x, y, z)
  289.     TriggerClientEvent('chatMessage', -1, message)
  290.     TriggerClientEvent('Zone', -1, speed, radius, x, y, z)
  291. end)
  292.  
  293. RegisterServerEvent('Disable')
  294. AddEventHandler('Disable', function(blip)
  295.     TriggerClientEvent('RemoveBlip', -1)
  296. end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement