Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 57 additions & 0 deletions [gameplay]/speedometer/client.lua
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,37 @@ local function dxDrawRelativeImage(startX, startY, width, height, image, rot, ro
dxDrawImage(screenW * startX, screenH * startY, scaledW, scaledH, image, rot or 0, rotX or 0, rotY or 0, color or base_color, postGUI or false)
end

function dxDrawRelText(text, relX, relY, relWidth, relHeight, color, scaleXY, font, alignX, alignY, clip, wordBreak, postGUI, colorCoded, subPixelPositioning, fRotation, fRotationCenterX, fRotationCenterY, fLineSpacing)
local scale = math.min(screenW / baseW, screenH / baseH)
local absX = screenW * relX
local absY = screenH * relY
local absRight = screenW * (relX + relWidth)
local absBottom = screenH * (relY + relHeight)


local scaledScale = scaleXY * scale

dxDrawText(
text,
absX, absY,
absRight, absBottom,
color or tocolor(255, 255, 255, 255),
scaledScale, scaledScale, -- scaleX, scaleY
font or "default",
alignX or "left",
alignY or "top",
clip or false,
wordBreak or false,
postGUI or false,
colorCoded or false,
subPixelPositioning or false,
fRotation or 0,
fRotationCenterX or 0,
fRotationCenterY or 0,
fLineSpacing or 0
)
end

function drawSpeedo()
local veh = getPedOccupiedVehicle(localPlayer)
if not veh then return end
Expand All @@ -18,9 +49,35 @@ function drawSpeedo()
local speed = (velx ^ 2 + vely ^ 2 + velz ^ 2) ^ (0.5)

dxDrawRelativeImage(0.82, 0.65, 300, 300, "images/disc.png")
local kmh = math.floor( getElementSpeed(veh, 'km/h') ) --mph
dxDrawRelText(kmh, 0.65, 0.71, 0.5, 0.1, tocolor(255, 255, 255), 1.5, "default-bold", "center", "center")

if getVehicleOverrideLights( veh ) == 2 then
dxDrawRelativeImage(0.88, 0.85, 40, 40, "images/lights_1.png", 0, 0, 0, tocolor(255, 255, 255, 255))
elseif getVehicleOverrideLights( veh ) == 1 then
dxDrawRelativeImage(0.88, 0.85, 40, 40, "images/lights_0.png", 0, 0, 0, tocolor(255, 255, 255, 255))
else
local h,m = getTime()
if h >= 6 and h <= 21 then
dxDrawRelativeImage(0.88, 0.85, 40, 40, "images/lights_0.png", 0, 0, 0, tocolor(255, 255, 255, 255))
else
dxDrawRelativeImage(0.88, 0.85, 40, 40, "images/lights_1.png", 0, 0, 0, tocolor(255, 255, 255, 255))
end
end

dxDrawRelativeImage(0.82, 0.65, 300, 300, "images/needle.png", -145-(1.5-(speed/1.5) * 305))
end

function getElementSpeed(theElement, unit)
assert(isElement(theElement), "Bad argument 1 @ getElementSpeed (element expected, got " .. type(theElement) .. ")")
local elementType = getElementType(theElement)
assert(elementType == "player" or elementType == "ped" or elementType == "object" or elementType == "vehicle" or elementType == "projectile", "Invalid element type @ getElementSpeed (player/ped/object/vehicle/projectile expected, got " .. elementType .. ")")
assert((unit == nil or type(unit) == "string" or type(unit) == "number") and (unit == nil or (tonumber(unit) and (tonumber(unit) == 0 or tonumber(unit) == 1 or tonumber(unit) == 2)) or unit == "m/s" or unit == "km/h" or unit == "mph"), "Bad argument 2 @ getElementSpeed (invalid speed unit)")
unit = unit == nil and 0 or ((not tonumber(unit)) and unit or tonumber(unit))
local mult = (unit == 0 or unit == "m/s") and 50 or ((unit == 1 or unit == "km/h") and 180 or 111.84681456)
return (Vector3(getElementVelocity(theElement)) * mult).length
end

local isSpeedoShown = false
function toggleRender(bool)
if bool then
Expand Down
Binary file added [gameplay]/speedometer/images/lights_0.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added [gameplay]/speedometer/images/lights_1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions [gameplay]/speedometer/meta.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,9 @@
<min_mta_version client="1.5.6-9.16404"></min_mta_version>
<file src="images/disc.png" />
<file src="images/needle.png" />

<file src="images/lights_0.png"/>
<file src="images/lights_1.png"/>

<script src="client.lua" type="client" />
</meta>