Skip to content

Utils functions Client ​

A library with util functions to create a script

JO Functions ​

jo.utils.loadGameData() ​

A function to load a game file

Syntax ​

lua
jo.utils.loadGameData(name, waiter)

Parameters ​

name : string|integer

The name of the file
Compatible with animation dictionaries, models (hashed or string), and texture dictionaries

waiter : boolean Optional

If the function has to wait after the loading to be completed

Example ​

lua
local model = "A_C_Horse_Morgan_Bay"
jo.utils.loadGameData(model, true)

jo.utils.releaseGameData() ​

A function to release a game file

Syntax ​

lua
jo.utils.releaseGameData(name)

Parameters ​

name : string|integer

The name of the file

Example ​

lua
local model = "A_C_Horse_Morgan_Bay"
jo.utils.releaseGameData(model)

jo.utils.screenToWorld() ​

Converts screen coordinates to world coordinates using camera raycasting
This function casts a ray from the camera through the specified screen position and returns information about what it hits in the 3D world

Syntax ​

lua
jo.utils.screenToWorld(distance, flags, toIgnore, mouseX, mouseY)

Parameters ​

distance : number Optional

Maximum raycast distance in game units
default:100

flags : integer Optional

Flags for the raycast
default:1|2|8|16

toIgnore : integer Optional

Entity to ignore in the raycast
default:PlayerPedId()

mouseX : number Optional

X screen coordinate normalized between 0-1
default:0.5 screen center

mouseY : number Optional

Y screen coordinate normalized between 0-1
default:0.5 screen center

Return Value ​

Type : boolean,vector3,vector3,integer

hit, endCoords, surfaceNormal, entityHit

Example ​

lua
CreateThread(function()
    local distance = 2.0
    local flags = 0     -- Intersect with nothing
    local toIgnore = jo.pl()
    local screenX = 0.5 -- Center of the screen
    local screenY = 0.5 -- Center of the screen
    while true do
        local hit, endCoords, surfaceNormal, entityHit = jo.utils.screenToWorld(distance, flags, toIgnore, screenX, screenY)
        Wait(0)
    end
end)

jo.utils.waiter() ​

A function to wait after a satisfying condition with a waiting duration

Syntax ​

lua
jo.utils.waiter(cb, maxDuration, loopTimer)

Parameters ​

cb : function

If the function returns true a new timer value is waited

maxDuration : integer Optional

The maximum duration the function will wait
default: 1000

loopTimer : integer Optional

The delay between tests of cb function in ms
default: 0

Return Value ​

Type : boolean

Returns true if the function is satisfied, false if the waiter was killed by the maxDuration value

Example ​

lua
local value = 0
local cb = function()
  value = math.random(1, 10)
  return value == 5
end
local maxDuration = 2000
local timer = 10

local startWait = GetGamerTimer()
print
killer = jo.utils.waiter(cb, maxDuration, timer)
print("Killer: ", killer, "Value: ", value, "Duration: ", GetGamerTimer() - startWait)
-- Expected output: Killer: true, Value : 5, Duration: (duration < 2000)
--OR
-- Expected output: Killer: false, Value : (<> 5), Duration: 2000

Last updated: