forked from chickenlord01/johnsspeedlimitdisplay
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclient.lua
96 lines (83 loc) · 3.86 KB
/
client.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
local showlimit = true
--Trigger this event in another script to toggle seeing the text on the screen or not.
RegisterNetEvent("ToggleSpeedLimit")
AddEventHandler("ToggleSpeedLimit", function(toggle)
showlimit = toggle
end)
--Handles client interaction with the world (draws text to screen when inside a car and on a road)
Citizen.CreateThread(function()
while true do
Wait(0)
local display = Config.DisplaySettings.text
local speed = GetEntitySpeed(GetVehiclePedIsIn(PlayerPedId()))
local limit = GetSpeedLimit()
if Config.DisplaySettings.speedType == "MPH" then
--speed type is MPH
speed = speed * 2.236936
display = display:gsub("{SPEED_TYPE}", "MPH")
elseif Config.DisplaySettings.speedType == "KPH" then
--speed type is KPH
speed = speed * 3.6
display = display:gsub("{SPEED_TYPE}", "KPH")
elseif (Config.DisplaySettings.speedType ~= "MPH") and (Config.DisplaySettings.speedType ~= "KPH") then
--speed type is not configured correctly. Assumes MPH speed wise.
speed = speed * 2.236936
display = display:gsub("{SPEED_TYPE}", "~r~~h~Contact Development!")
end
if Config.DisplaySettings.ColorOptions.enableColorChange and type(limit) == "number" and IsPedInAnyVehicle(PlayerPedId()) then
--setting the differnce
local diff = speed - limit
if diff < Config.DisplaySettings.ColorOptions.color2Speed and diff > Config.DisplaySettings.ColorOptions.color1Speed then
--player is going faster than speed 1
display = display:gsub("{LIMIT}", Config.DisplaySettings.ColorOptions.color1 .. limit)
elseif diff > Config.DisplaySettings.ColorOptions.color2Speed then
--player is going faster than speed 2
display = display:gsub("{LIMIT}", Config.DisplaySettings.ColorOptions.color2 .. limit)
else
--Player is going below speed 1
display = display:gsub("{LIMIT}", limit)
end
else
display = display:gsub("{LIMIT}", limit)
end
if Config.enableBadssentialsIntegration then
--Is Badssentials enabled and hud is not toggled and if player is in a vehicle
if showlimit and (not Config.showOnFoot) and IsPedInAnyVehicle(PlayerPedId()) and (not exports.Badssentials:IsDisplaysHidden()) then
DrawTxt(Config.DisplaySettings.x, Config.DisplaySettings.y, Config.DisplaySettings.width, Config.DisplaySettings.height, Config.DisplaySettings.scale, display, 255, 255, 255, 255)
elseif Config.showOnFoot and (not exports.Badssentials:IsDisplaysHidden()) then
DrawTxt(Config.DisplaySettings.x, Config.DisplaySettings.y, Config.DisplaySettings.width, Config.DisplaySettings.height, Config.DisplaySettings.scale, display, 255, 255, 255, 255)
end
else
--Badssentials is not enabled
if showlimit and IsPedInAnyVehicle(PlayerPedId()) and (not Config.showOnFoot) then
DrawTxt(Config.DisplaySettings.x, Config.DisplaySettings.y, Config.DisplaySettings.width, Config.DisplaySettings.height, Config.DisplaySettings.scale, display, 255, 255, 255, 255)
elseif showlimit and Config.showOnFoot then
DrawTxt(Config.DisplaySettings.x, Config.DisplaySettings.y, Config.DisplaySettings.width, Config.DisplaySettings.height, Config.DisplaySettings.scale, display, 255, 255, 255, 255)
end
end
end
end)
--Returns current road speed limit
function GetSpeedLimit()
local coords = GetEntityCoords(PlayerPedId())
local location = GetStreetNameFromHashKey(GetStreetNameAtCoord(coords.x, coords.y, coords.z))
local limit = Config.Limits[location]
if limit then
return limit
else
return "~r~~h~Contact Development!"
end
end
--Draws text to the screen
function DrawTxt(x, y, width, height, scale, text, r, g, b, a)
SetTextFont(6)
SetTextProportional(0)
SetTextScale(scale, scale)
SetTextColour(r, g, b, a)
SetTextDropShadow(0, 0, 0, 0,255)
SetTextEdge(1, 0, 0, 0, 255)
SetTextOutline()
SetTextEntry("STRING")
AddTextComponentString(text)
DrawText(x - width/2, y - height/2 + 0.005)
end