34 lines
2.1 KiB
Lua
34 lines
2.1 KiB
Lua
local sx,sy = guiGetScreenSize()
|
|
local ss = dxCreateScreenSource(sx,sy)
|
|
function loop(ts)
|
|
if getPedOccupiedVehicle(localPlayer) then
|
|
dxUpdateScreenSource(ss)
|
|
local veh = getPedOccupiedVehicle(localPlayer)
|
|
local speed = getElementSpeed(veh)
|
|
local offsetX = math.round((math.random() - 1.5) * ((speed / 80) * (sx/1280)))
|
|
local offsetY = math.round((math.random() - 1.5) * ((speed / 80) * (sx/1280)))
|
|
dxDrawImage(offsetX,offsetY,sx,sy,ss)
|
|
end
|
|
end
|
|
addEventHandler("onClientPreRender",root,loop)
|
|
|
|
function getElementSpeed(theElement, unit)
|
|
-- Check arguments for errors
|
|
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)")
|
|
-- Default to m/s if no unit specified and 'ignore' argument type if the string contains a number
|
|
unit = unit == nil and 0 or ((not tonumber(unit)) and unit or tonumber(unit))
|
|
-- Setup our multiplier to convert the velocity to the specified unit
|
|
local mult = (unit == 0 or unit == "m/s") and 50 or ((unit == 1 or unit == "km/h") and 180 or 111.84681456)
|
|
-- Return the speed by calculating the length of the velocity vector, after converting the velocity to the specified unit
|
|
return (Vector3(getElementVelocity(theElement)) * mult).length
|
|
end
|
|
|
|
function math.round(num, decimals)
|
|
decimals = math.pow(10, decimals or 0)
|
|
num = num * decimals
|
|
if num >= 0 then num = math.floor(num + 0.5) else num = math.ceil(num - 0.5) end
|
|
return num / decimals
|
|
end |