12 Commits

Author SHA1 Message Date
github-actions
faa9dda57f chore: bump version to v3.31.4 2025-09-09 16:48:13 +00:00
Swellington Soares
619ecc9e55 feat(imports/dui): added mising dui methods (#47) 2025-09-09 18:47:01 +02:00
Maximus7474
56c0a91022 feat(imports/logger): add definable dataset for fivemanage logging (#45) 2025-09-04 18:48:50 +02:00
PotatoFarmer441
d6417b9a84 fix(zones): set zone distance on creation (#44)
* fix(zones): set zone distance on creation

Signed-off-by: PotatoFarmer441 <helioau@live.com.au>

* Update shared.lua

Signed-off-by: PotatoFarmer441 <helioau@live.com.au>

---------

Signed-off-by: PotatoFarmer441 <helioau@live.com.au>
2025-08-30 13:39:20 +02:00
github-actions
ac9625d33a chore: bump version to v3.31.3 2025-08-18 12:00:25 +00:00
Zoo
2ab9114d2f chore(package/index): export addKeybind function (#40) 2025-08-18 13:58:42 +02:00
github-actions
88c68c7068 chore: bump version to v3.31.2 2025-08-18 11:45:57 +00:00
PaPi
1e178180bb chore(locales): update fr.json (#38) 2025-08-18 13:45:14 +02:00
Zoo
fef441c456 feat(package/addKeybind): add keybind to ts package (#39) 2025-08-18 13:30:43 +02:00
github-actions
85a3879a03 chore: bump version to v3.31.1 2025-08-12 14:45:04 +00:00
mikigoalie
65813e75e6 feat(imports/table): add table.map (#35) 2025-08-12 16:42:57 +02:00
David Malchin
a9648fb45f fix(points): grid inconsistencies (#37) 2025-08-10 02:20:46 +02:00
10 changed files with 195 additions and 25 deletions

View File

@@ -6,7 +6,7 @@ rdr3_warning 'I acknowledge that this is a prerelease build of RedM, and I am aw
name 'ox_lib' name 'ox_lib'
author 'Overextended' author 'Overextended'
version '3.31.0' version '3.31.4'
license 'LGPL-3.0-or-later' license 'LGPL-3.0-or-later'
repository 'https://github.com/communityox/ox_lib' repository 'https://github.com/communityox/ox_lib'
description 'A library of shared functions to utilise in other resources.' description 'A library of shared functions to utilise in other resources.'

View File

@@ -84,6 +84,29 @@ function lib.dui:sendMessage(message)
end end
end end
---@param x number
---@param y number
function lib.dui:sendMouseMove(x, y)
SendDuiMouseMove(self.duiObject, x, y)
end
---@param button 'left' | 'middle' | 'right'
function lib.dui:sendMouseDown(button)
SendDuiMouseDown(self.duiObject, button)
end
---@param button 'left' | 'middle' | 'right'
function lib.dui:sendMouseUp(button)
SendDuiMouseUp(self.duiObject, button)
end
---@param deltaX number
---@param deltaY number
function lib.dui:sendMouseWheel(deltaX, deltaY)
SendDuiMouseWheel(self.duiObject, deltaY, deltaX)
end
AddEventHandler('onResourceStop', function(resourceName) AddEventHandler('onResourceStop', function(resourceName)
if cache.resource ~= resourceName then return end if cache.resource ~= resourceName then return end

View File

@@ -94,6 +94,7 @@ end
if service == 'fivemanage' then if service == 'fivemanage' then
local key = GetConvar('fivemanage:key', '') local key = GetConvar('fivemanage:key', '')
local dataset = GetConvar('fivemanage:dataset', '')
if key ~= '' then if key ~= '' then
local endpoint = 'https://api.fivemanage.com/api/logs/batch' local endpoint = 'https://api.fivemanage.com/api/logs/batch'
@@ -101,9 +102,13 @@ if service == 'fivemanage' then
local headers = { local headers = {
['Content-Type'] = 'application/json', ['Content-Type'] = 'application/json',
['Authorization'] = key, ['Authorization'] = key,
['User-Agent'] = 'ox_lib' ['User-Agent'] = 'ox_lib',
} }
if dataset ~= "" then
headers['X-Fivemanage-Dataset'] = dataset
end
function lib.logger(source, event, message, ...) function lib.logger(source, event, message, ...)
if not buffer then if not buffer then
buffer = {} buffer = {}

View File

@@ -39,10 +39,14 @@ local function removePoint(self)
points[self.id] = nil points[self.id] = nil
end end
local function hasRemovePoint(entry)
return entry.remove == removePoint
end
CreateThread(function() CreateThread(function()
while true do while true do
local coords = GetEntityCoords(cache.ped) local coords = GetEntityCoords(cache.ped)
local newPoints = lib.grid.getNearbyEntries(coords, function(entry) return entry.remove == removePoint end) --[[@as CPoint[] ]] local newPoints = lib.grid.getNearbyEntries(coords, hasRemovePoint) --[[@as CPoint[] ]]
local cellX, cellY = lib.grid.getCellPosition(coords) local cellX, cellY = lib.grid.getCellPosition(coords)
cache.coords = coords cache.coords = coords
closestPoint = nil closestPoint = nil
@@ -89,9 +93,11 @@ CreateThread(function()
nearbyCount += 1 nearbyCount += 1
nearbyPoints[nearbyCount] = point nearbyPoints[nearbyCount] = point
if point.onEnter and not point.inside then if not point.inside then
point.inside = true point.inside = true
point:onEnter() if point.onEnter then
point:onEnter()
end
end end
elseif point.currentDistance then elseif point.currentDistance then
if point.onExit then point:onExit() end if point.onExit then point:onExit() end

View File

@@ -123,11 +123,24 @@ local function shuffle(tbl)
return tbl return tbl
end end
---@param tbl table
---@param fn function(value: any, key: any): any
---@return table
local function map(tbl, fn)
local result = {}
for k, v in pairs(tbl) do
result[k] = fn(v, k)
end
return result
end
table.contains = contains table.contains = contains
table.matches = table_matches table.matches = table_matches
table.deepclone = table_deepclone table.deepclone = table_deepclone
table.merge = table_merge table.merge = table_merge
table.shuffle = shuffle table.shuffle = shuffle
table.map = map
local frozenNewIndex = function(self) error(('cannot set values on a frozen table (%s)'):format(self), 2) end local frozenNewIndex = function(self) error(('cannot set values on a frozen table (%s)'):format(self), 2) end
local _rawset = rawset local _rawset = rawset

View File

@@ -345,6 +345,8 @@ local function setZone(data)
data.contains = data.contains or contains data.contains = data.contains or contains
if lib.context == 'client' then if lib.context == 'client' then
local coords = cache.coords or GetEntityCoords(cache.ped)
data.distance = #(data.coords - coords)
data.setDebug = setDebug data.setDebug = setDebug
if data.debug then if data.debug then

View File

@@ -7,27 +7,27 @@
"confirm": "Confirmer", "confirm": "Confirmer",
"more": "Plus...", "more": "Plus...",
"settings": { "settings": {
"locale": "Change locale", "locale": "Changer la langue",
"locale_description": "Current language: ${language} (%s)", "locale_description": "Langue actuelle : ${language} (%s)",
"notification_audio": "Notification audio", "notification_audio": "Audio des notifications",
"notification_position": "Notification position" "notification_position": "Position des notifications"
}, },
"position": { "position": {
"bottom": "Bottom", "bottom": "Bas",
"bottom-left": "Bottom-left", "bottom-left": "Bas-gauche",
"bottom-right": "Bottom-right", "bottom-right": "Bas-droite",
"center-left": "Center-left", "center-left": "Centre-gauche",
"center-right": "Center-right", "center-right": "Centre-droite",
"top": "Top", "top": "Haut",
"top-left": "Top-left", "top-left": "Haut-gauche",
"top-right": "Top-right" "top-right": "Haut-droite"
} }
}, },
"open_radial_menu": "Open radial menu", "open_radial_menu": "Ouvrir le menu radial",
"cancel_progress": "Cancel current progress bar", "cancel_progress": "Annuler la barre de progression actuelle",
"txadmin_announcement": "Server announcement by %s", "txadmin_announcement": "Annonce serveur par %s",
"txadmin_dm": "Direct Message from %s", "txadmin_dm": "Message privé de %s",
"txadmin_warn": "You have been warned by %s", "txadmin_warn": "Vous avez été averti par %s",
"txadmin_warn_content": "%s \nAction ID: %s", "txadmin_warn_content": "%s\nID de l'action : %s",
"txadmin_scheduledrestart": "Scheduled Restart" "txadmin_scheduledrestart": "Redémarrage programmé"
} }

View File

@@ -0,0 +1,120 @@
interface CKeybind extends KeybindProps {
currentKey: string;
disabled: boolean;
isPressed: boolean;
hash: number;
getCurrentKey(): string;
isControlPressed(): boolean;
}
interface KeybindProps {
name: string;
description: string;
defaultMapper?: string;
defaultKey?: string;
disabled?: boolean;
disable?(this: CKeybind, toggle: boolean): void;
onPressed?(this: CKeybind): void;
onReleased?(this: CKeybind): void;
[key: string]: any;
}
const keybinds: Record<string, CKeybind> = {};
class Keybind implements CKeybind {
name: string;
description: string;
defaultMapper?: string;
defaultKey?: string;
onPressed?: (this: CKeybind) => void;
onReleased?: (this: CKeybind) => void;
secondaryKey?: string;
secondaryMapper?: string;
[key: string]: any;
disabled: boolean = false;
isPressed: boolean = false;
hash: number;
constructor(data: KeybindProps) {
this.name = data.name;
this.description = data.description;
this.defaultMapper = data.defaultMapper ?? "keyboard";
this.defaultKey = data.defaultKey ?? "";
this.secondaryKey = data.secondaryKey;
this.secondaryMapper = data.secondaryMapper;
if (typeof data.disabled === "boolean") this.disabled = data.disabled;
this.onPressed = data.onPressed;
this.onReleased = data.onReleased;
this.hash = GetHashKey("+" + this.name) | 0x80000000;
}
get currentKey(): string {
return this.getCurrentKey();
}
getCurrentKey(): string {
const label = GetControlInstructionalButton(0, this.hash, true);
return label.substring(2);
}
isControlPressed(): boolean {
return this.isPressed;
}
disable(toggle: boolean): void {
this.disabled = toggle;
}
}
export function addKeybind(data: KeybindProps): CKeybind {
const kb = new Keybind(data);
keybinds[kb.name] = kb;
RegisterCommand("+" + kb.name, () => {
if (kb.disabled || IsPauseMenuActive()) return;
kb.isPressed = true;
kb.onPressed?.call(kb);
}, false);
RegisterCommand("-" + kb.name, () => {
if (kb.disabled || IsPauseMenuActive()) return;
kb.isPressed = false;
kb.onReleased?.call(kb);
}, false);
RegisterKeyMapping(
"+" + kb.name,
kb.description,
kb.defaultMapper ?? "keyboard",
kb.defaultKey ?? ""
);
if (kb.secondaryKey) {
RegisterKeyMapping(
"~!+" + kb.name,
kb.description,
kb.secondaryMapper ?? kb.defaultMapper ?? "keyboard",
kb.secondaryKey
);
}
setTimeout(() => {
emit("chat:removeSuggestion", `/+${kb.name}`);
emit("chat:removeSuggestion", `/-${kb.name}`);
}, 500);
return kb;
}
export function getKeybind(name: string): CKeybind | undefined {
return keybinds[name];
}
export function getAllKeybinds(): Readonly<Record<string, CKeybind>> {
return keybinds;
}

View File

@@ -14,3 +14,4 @@ export * from './vehicleProperties';
export * from './callback'; export * from './callback';
export * from './points'; export * from './points';
export * from './dui'; export * from './dui';
export * from './addKeybind';

View File

@@ -1,7 +1,7 @@
{ {
"name": "@communityox/ox_lib", "name": "@communityox/ox_lib",
"author": "Overextended", "author": "Overextended",
"version": "3.31.0", "version": "3.31.4",
"description": "JS/TS wrapper for ox_lib exports", "description": "JS/TS wrapper for ox_lib exports",
"main": "./shared/index.js", "main": "./shared/index.js",
"types": "./shared/index.d.ts", "types": "./shared/index.d.ts",