Skip to content

Commit

Permalink
Added Flashing Yellow Light Option
Browse files Browse the repository at this point in the history
Moved more strings to the config for easier locale editing
  • Loading branch information
92-Smallo committed Mar 29, 2020
1 parent 768dc32 commit 59f6faf
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 6 deletions.
42 changes: 36 additions & 6 deletions xnTrafficLights/client/client.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
local trafficLight = nil
local stopPointRadius = 4.5
local flashingLight = false
local lightObject = nil

Citizen.CreateThread(function()
JayMenu.CreateMenu('trafficLights', Config.Text.MenuTitle, function()
Expand All @@ -11,7 +13,7 @@ Citizen.CreateThread(function()
if JayMenu.IsMenuOpened('trafficLights') then
local playerPed = PlayerPedId()
local coords = GetEntityCoords(playerPed)
if JayMenu.Button("Place Traffic Light") then
if JayMenu.Button(Config.Text.PlaceTrafficLightButton) then
local heading = GetEntityHeading(playerPed)
if not DoesEntityExist(trafficLight) then
ReqModel(Config.TrafficLightProp)
Expand All @@ -29,12 +31,13 @@ Citizen.CreateThread(function()
SendTheFeedPost(Config.Text.TrafficLightExists)
end
end
if JayMenu.Button("Remove Traffic Light") then
if JayMenu.Button(Config.Text.RemoveTrafficLightButton) then
TriggerServerEvent('xnTrafficLights:UpdateTrafficLight', ObjToNet(trafficLight), 0, speedZonePoint, stopPointRadius) -- Green
DeleteEntity(trafficLight)
flashingLight = false
speedZonePoint = nil
end
if JayMenu.Button("Set Stopping Point") then
if JayMenu.Button(Config.Text.SetStoppingPointButton) then
if DoesEntityExist(trafficLight) then
TriggerServerEvent('xnTrafficLights:UpdateTrafficLight', ObjToNet(trafficLight), 0, speedZonePoint, stopPointRadius) -- Green
speedZonePoint = nil
Expand All @@ -43,14 +46,14 @@ Citizen.CreateThread(function()
SendTheFeedPost(Config.Text.PlaceLightFirst)
end
end
if JayMenu.Button("Set Light Green") then
if JayMenu.Button(Config.Text.SetLightGreenButton) then
if speedZonePoint ~= nil then
TriggerServerEvent('xnTrafficLights:UpdateTrafficLight', ObjToNet(trafficLight), 0, speedZonePoint, stopPointRadius) -- Green
else
SendTheFeedPost(Config.Text.PlaceStopPoint)
end
end
if JayMenu.Button("Set Light Red") then
if JayMenu.Button(Config.Text.SetLightRedButton) then
if speedZonePoint ~= nil then
Citizen.CreateThread(function()
TriggerServerEvent('xnTrafficLights:UpdateTrafficLight', ObjToNet(trafficLight), 2, speedZonePoint, stopPointRadius) -- Yellow
Expand All @@ -61,6 +64,13 @@ Citizen.CreateThread(function()
SendTheFeedPost(Config.Text.PlaceStopPoint)
end
end
if JayMenu.Button(Config.Text.SetLightFlashingYellowButton) then
if speedZonePoint ~= nil then
TriggerServerEvent('xnTrafficLights:UpdateTrafficLight', ObjToNet(trafficLight), 3, speedZonePoint, stopPointRadius) -- Flashing Yellow
else
SendTheFeedPost(Config.Text.PlaceStopPoint)
end
end
JayMenu.Display()
end
end
Expand Down Expand Up @@ -130,13 +140,33 @@ local playerLights = {}
RegisterNetEvent('xnTrafficLights:UpdateTrafficLightSetting')
AddEventHandler('xnTrafficLights:UpdateTrafficLightSetting', function(object, light, speedZoneCoords, playerName, radius)
if light == 0 then -- Green
flashingLight = false
RemoveSpeedZone(playerLights[playerName]) -- Make them go
SetEntityTrafficlightOverride(NetToObj(object), light)
elseif light == 1 then -- Red
flashingLight = false
playerLights[playerName] = AddSpeedZoneForCoord(speedZoneCoords, radius, 0.0, false) -- Make them stop
SetEntityTrafficlightOverride(NetToObj(object), light)
else -- Yellow
elseif light == 2 then -- Yellow
flashingLight = false
SetEntityTrafficlightOverride(NetToObj(object), light)
elseif light == 3 then -- Flashing Yellow
RemoveSpeedZone(playerLights[playerName]) -- Make them go
lightObject = NetToObj(object)
flashingLight = true
end
end)

Citizen.CreateThread(function()
while true do
if flashingLight then
local flashTime = Config.FlashInterval * 1000
SetEntityTrafficlightOverride(lightObject, 2)
Citizen.Wait(flashTime)
SetEntityTrafficlightOverride(lightObject, -1)
Citizen.Wait(flashTime)
end
Citizen.Wait(0)
end
end)

Expand Down
7 changes: 7 additions & 0 deletions xnTrafficLights/client/config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,17 @@ Config.ConfirmButton = 38 -- E
Config.CancelButton = 154 -- X
Config.StopPointSmaller = 174 -- Left Arrow
Config.StopPointBigger = 175 -- Right Arrow
Config.FlashInterval = 1.0 -- Seconds between flashes when set to flashing mode

Config.Text = {
["MenuTitle"] = "Traffic Control",
["MenuSubtitle"] = "Items",
["PlaceTrafficLightButton"] = "Place Traffic Light",
["RemoveTrafficLightButton"] = "Remove Traffic Light",
["SetStoppingPointButton"] = "Set Stopping Point",
["SetLightGreenButton"] = "Set Light Green",
["SetLightRedButton"] = "Set Light Red",
["SetLightFlashingYellowButton"] = "Set Light Flashing Yellow",
["TrafficLightExists"] = "You already have a ~y~traffic light~s~ created, you can only have ~r~1~s~ at a time.",
["PlaceLightFirst"] = "You need to place a ~y~traffic light~s~ first",
["PlaceStopPoint"] = "You need to place a ~y~stopping point~s~ first",
Expand Down

0 comments on commit 59f6faf

Please sign in to comment.