mirror of
https://github.com/CommunityOx/ox_lib.git
synced 2026-08-17 15:06:02 +01:00
Compare commits
16 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
855e1e4a36 | ||
|
|
a2f6b9a9e9 | ||
|
|
13a24baee4 | ||
|
|
df7a6b9c21 | ||
|
|
faa9dda57f | ||
|
|
619ecc9e55 | ||
|
|
56c0a91022 | ||
|
|
d6417b9a84 | ||
|
|
ac9625d33a | ||
|
|
2ab9114d2f | ||
|
|
88c68c7068 | ||
|
|
1e178180bb | ||
|
|
fef441c456 | ||
|
|
85a3879a03 | ||
|
|
65813e75e6 | ||
|
|
a9648fb45f |
@@ -6,7 +6,7 @@ rdr3_warning 'I acknowledge that this is a prerelease build of RedM, and I am aw
|
||||
|
||||
name 'ox_lib'
|
||||
author 'Overextended'
|
||||
version '3.31.0'
|
||||
version '3.32.0'
|
||||
license 'LGPL-3.0-or-later'
|
||||
repository 'https://github.com/communityox/ox_lib'
|
||||
description 'A library of shared functions to utilise in other resources.'
|
||||
|
||||
@@ -84,6 +84,29 @@ function lib.dui:sendMessage(message)
|
||||
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)
|
||||
if cache.resource ~= resourceName then return end
|
||||
|
||||
|
||||
@@ -94,6 +94,7 @@ end
|
||||
|
||||
if service == 'fivemanage' then
|
||||
local key = GetConvar('fivemanage:key', '')
|
||||
local dataset = GetConvar('fivemanage:dataset', '')
|
||||
|
||||
if key ~= '' then
|
||||
local endpoint = 'https://api.fivemanage.com/api/logs/batch'
|
||||
@@ -101,9 +102,13 @@ if service == 'fivemanage' then
|
||||
local headers = {
|
||||
['Content-Type'] = 'application/json',
|
||||
['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, ...)
|
||||
if not buffer then
|
||||
buffer = {}
|
||||
|
||||
@@ -39,10 +39,14 @@ local function removePoint(self)
|
||||
points[self.id] = nil
|
||||
end
|
||||
|
||||
local function hasRemovePoint(entry)
|
||||
return entry.remove == removePoint
|
||||
end
|
||||
|
||||
CreateThread(function()
|
||||
while true do
|
||||
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)
|
||||
cache.coords = coords
|
||||
closestPoint = nil
|
||||
@@ -89,9 +93,11 @@ CreateThread(function()
|
||||
nearbyCount += 1
|
||||
nearbyPoints[nearbyCount] = point
|
||||
|
||||
if point.onEnter and not point.inside then
|
||||
if not point.inside then
|
||||
point.inside = true
|
||||
point:onEnter()
|
||||
if point.onEnter then
|
||||
point:onEnter()
|
||||
end
|
||||
end
|
||||
elseif point.currentDistance then
|
||||
if point.onExit then point:onExit() end
|
||||
|
||||
@@ -47,13 +47,10 @@ end
|
||||
---@return boolean
|
||||
---Compares if two values are equal, iterating over tables and matching both keys and values.
|
||||
local function table_matches(t1, t2)
|
||||
local tabletype1 = table.type(t1)
|
||||
local type1, type2 = type(t1), type(t2)
|
||||
|
||||
if not tabletype1 then return t1 == t2 end
|
||||
|
||||
if tabletype1 ~= table.type(t2) or (tabletype1 == 'array' and #t1 ~= #t2) then
|
||||
return false
|
||||
end
|
||||
if type1 ~= type2 then return false end
|
||||
if type1 ~= 'table' and type2 ~= 'table' then return t1 == t2 end
|
||||
|
||||
for k, v1 in pairs(t1) do
|
||||
local v2 = t2[k]
|
||||
@@ -123,11 +120,24 @@ local function shuffle(tbl)
|
||||
return tbl
|
||||
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.matches = table_matches
|
||||
table.deepclone = table_deepclone
|
||||
table.merge = table_merge
|
||||
table.shuffle = shuffle
|
||||
table.map = map
|
||||
|
||||
local frozenNewIndex = function(self) error(('cannot set values on a frozen table (%s)'):format(self), 2) end
|
||||
local _rawset = rawset
|
||||
|
||||
@@ -345,6 +345,8 @@ local function setZone(data)
|
||||
data.contains = data.contains or contains
|
||||
|
||||
if lib.context == 'client' then
|
||||
local coords = cache.coords or GetEntityCoords(cache.ped)
|
||||
data.distance = #(data.coords - coords)
|
||||
data.setDebug = setDebug
|
||||
|
||||
if data.debug then
|
||||
|
||||
@@ -7,27 +7,27 @@
|
||||
"confirm": "Confirmer",
|
||||
"more": "Plus...",
|
||||
"settings": {
|
||||
"locale": "Change locale",
|
||||
"locale_description": "Current language: ${language} (%s)",
|
||||
"notification_audio": "Notification audio",
|
||||
"notification_position": "Notification position"
|
||||
"locale": "Changer la langue",
|
||||
"locale_description": "Langue actuelle : ${language} (%s)",
|
||||
"notification_audio": "Audio des notifications",
|
||||
"notification_position": "Position des notifications"
|
||||
},
|
||||
"position": {
|
||||
"bottom": "Bottom",
|
||||
"bottom-left": "Bottom-left",
|
||||
"bottom-right": "Bottom-right",
|
||||
"center-left": "Center-left",
|
||||
"center-right": "Center-right",
|
||||
"top": "Top",
|
||||
"top-left": "Top-left",
|
||||
"top-right": "Top-right"
|
||||
"bottom": "Bas",
|
||||
"bottom-left": "Bas-gauche",
|
||||
"bottom-right": "Bas-droite",
|
||||
"center-left": "Centre-gauche",
|
||||
"center-right": "Centre-droite",
|
||||
"top": "Haut",
|
||||
"top-left": "Haut-gauche",
|
||||
"top-right": "Haut-droite"
|
||||
}
|
||||
},
|
||||
"open_radial_menu": "Open radial menu",
|
||||
"cancel_progress": "Cancel current progress bar",
|
||||
"txadmin_announcement": "Server announcement by %s",
|
||||
"txadmin_dm": "Direct Message from %s",
|
||||
"txadmin_warn": "You have been warned by %s",
|
||||
"txadmin_warn_content": "%s \nAction ID: %s",
|
||||
"txadmin_scheduledrestart": "Scheduled Restart"
|
||||
"open_radial_menu": "Ouvrir le menu radial",
|
||||
"cancel_progress": "Annuler la barre de progression actuelle",
|
||||
"txadmin_announcement": "Annonce serveur par %s",
|
||||
"txadmin_dm": "Message privé de %s",
|
||||
"txadmin_warn": "Vous avez été averti par %s",
|
||||
"txadmin_warn_content": "%s\nID de l'action : %s",
|
||||
"txadmin_scheduledrestart": "Redémarrage programmé"
|
||||
}
|
||||
|
||||
120
package/client/resource/addKeybind/index.ts
Normal file
120
package/client/resource/addKeybind/index.ts
Normal 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;
|
||||
}
|
||||
@@ -14,3 +14,4 @@ export * from './vehicleProperties';
|
||||
export * from './callback';
|
||||
export * from './points';
|
||||
export * from './dui';
|
||||
export * from './addKeybind';
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "@communityox/ox_lib",
|
||||
"author": "Overextended",
|
||||
"version": "3.31.0",
|
||||
"version": "3.32.0",
|
||||
"description": "JS/TS wrapper for ox_lib exports",
|
||||
"main": "./shared/index.js",
|
||||
"types": "./shared/index.d.ts",
|
||||
|
||||
@@ -11,6 +11,7 @@ local DisableControlAction = DisableControlAction
|
||||
local DisablePlayerFiring = DisablePlayerFiring
|
||||
local playerState = LocalPlayer.state
|
||||
local createdProps = {}
|
||||
local maxProps = GetConvarInt('ox:progressPropLimit', 2)
|
||||
|
||||
---@class ProgressPropProps
|
||||
---@field model string
|
||||
@@ -34,13 +35,16 @@ local createdProps = {}
|
||||
---@field disable? { move?: boolean, sprint?: boolean, car?: boolean, combat?: boolean, mouse?: boolean }
|
||||
|
||||
local function createProp(ped, prop)
|
||||
lib.requestModel(prop.model)
|
||||
local ok, result = pcall(lib.requestModel, prop.model)
|
||||
|
||||
if not ok then return lib.print.error(result) end
|
||||
|
||||
local coords = GetEntityCoords(ped)
|
||||
local object = CreateObject(prop.model, coords.x, coords.y, coords.z, false, false, false)
|
||||
local object = CreateObject(result, coords.x, coords.y, coords.z, false, false, false)
|
||||
|
||||
AttachEntityToEntity(object, ped, GetPedBoneIndex(ped, prop.bone or 60309), prop.pos.x, prop.pos.y, prop.pos.z, prop.rot.x, prop.rot.y, prop.rot.z, true,
|
||||
true, false, true, prop.rotOrder or 0, true)
|
||||
SetModelAsNoLongerNeeded(prop.model)
|
||||
SetModelAsNoLongerNeeded(result)
|
||||
|
||||
return object
|
||||
end
|
||||
@@ -90,7 +94,7 @@ local function startProgress(data)
|
||||
end
|
||||
|
||||
if data.prop then
|
||||
playerState:set('lib:progressProps', data.prop, true)
|
||||
TriggerServerEvent('ox_lib:progressProps', data.prop)
|
||||
end
|
||||
|
||||
local disable = data.disable
|
||||
@@ -137,7 +141,7 @@ local function startProgress(data)
|
||||
end
|
||||
|
||||
if data.prop then
|
||||
playerState:set('lib:progressProps', nil, true)
|
||||
TriggerServerEvent('ox_lib:progressProps', nil)
|
||||
end
|
||||
|
||||
if anim then
|
||||
@@ -225,14 +229,18 @@ end
|
||||
|
||||
local function deleteProgressProps(serverId)
|
||||
local playerProps = createdProps[serverId]
|
||||
|
||||
if not playerProps then return end
|
||||
|
||||
createdProps[serverId] = nil
|
||||
|
||||
for i = 1, #playerProps do
|
||||
local prop = playerProps[i]
|
||||
|
||||
if DoesEntityExist(prop) then
|
||||
DeleteEntity(prop)
|
||||
end
|
||||
end
|
||||
createdProps[serverId] = nil
|
||||
end
|
||||
|
||||
RegisterNetEvent('onPlayerDropped', function(serverId)
|
||||
@@ -248,22 +256,29 @@ AddStateBagChangeHandler('lib:progressProps', nil, function(bagName, key, value,
|
||||
local ped = GetPlayerPed(ply)
|
||||
local serverId = GetPlayerServerId(ply)
|
||||
|
||||
if not value then
|
||||
if not value or createdProps[serverId] then
|
||||
return deleteProgressProps(serverId)
|
||||
end
|
||||
|
||||
createdProps[serverId] = {}
|
||||
local playerProps = createdProps[serverId]
|
||||
local playerProps = {}
|
||||
|
||||
if value.model then
|
||||
playerProps[#playerProps + 1] = createProp(ped, value)
|
||||
local prop = createProp(ped, value)
|
||||
|
||||
if prop then
|
||||
playerProps[#playerProps + 1] = createProp(ped, value)
|
||||
end
|
||||
else
|
||||
for i = 1, #value do
|
||||
local prop = value[i]
|
||||
local propCount = math.min(maxProps, #value)
|
||||
|
||||
for i = 1, propCount do
|
||||
local prop = createProp(ped, value[i])
|
||||
|
||||
if prop then
|
||||
playerProps[#playerProps + 1] = createProp(ped, prop)
|
||||
playerProps[#playerProps + 1] = prop
|
||||
end
|
||||
end
|
||||
end
|
||||
end)
|
||||
|
||||
createdProps[serverId] = playerProps
|
||||
end)
|
||||
12
resource/interface/server/progress.lua
Normal file
12
resource/interface/server/progress.lua
Normal file
@@ -0,0 +1,12 @@
|
||||
local maxProps = GetConvarInt('ox:progressPropLimit', 2)
|
||||
|
||||
---@param props ProgressPropProps | ProgressPropProps[] | nil
|
||||
RegisterNetEvent('ox_lib:progressProps', function(props)
|
||||
if type(props) == 'table' then
|
||||
props = #props > maxProps and { table.unpack(props, 1, maxProps) } or props
|
||||
else
|
||||
props = nil
|
||||
end
|
||||
|
||||
Player(source).state:set('lib:progressProps', props, true)
|
||||
end)
|
||||
Reference in New Issue
Block a user