Compare commits

..

37 Commits

Author SHA1 Message Date
Jim Shield
93b884de01 Bump to 2.0.01 2025-04-29 12:31:05 +01:00
Jim Shield
a308f82be9 version bump 2025-04-29 12:27:00 +01:00
Jim Shield
b3100a336c possible fix for lib error 2025-04-29 12:26:49 +01:00
Jim Shield
8f7f9bb009 force stash to a table when removing items 2025-04-29 02:37:47 +01:00
Jim Shield
25dadae446 Merge pull request #41 from jimathy/1.2 2025-04-28 18:19:38 +01:00
Jim Shield
1d588c4f41 Add a complete readme with documentation 2025-04-22 19:17:34 +01:00
Jim Shield
ac58fe4bb7 Fix and enhance update checker 2025-04-22 19:17:03 +01:00
Jim Shield
45c5af8e81 Fix duplicate functions and typos 2025-04-22 19:16:31 +01:00
Jim Shield
673d9e3a12 fix alt forcing nui focus 2025-04-20 23:44:09 +01:00
Jim Shield
738e11c8e3 Add support for built in nui menu 2025-04-20 19:17:40 +01:00
Jim Shield
842379e8f9 Add override convar checks 2025-04-20 19:17:16 +01:00
Jim Shield
d1bb796d5f implement inbuilt nui menu 2025-04-20 01:22:32 +01:00
Jim Shield
b7db98ffdc esx fixes 2025-04-18 19:45:56 +01:00
Jim Shield
6ce6770df4 add checks for if MySQL has loaded for ESX 2025-04-18 16:14:42 +01:00
Jim Shield
56ef3b75b2 Fix change dui functions 2025-04-14 21:58:38 +01:00
Jim Shield
bd1be5e953 add function to get animal anim table for that ped 2025-04-13 19:07:02 +01:00
Jim Shield
8f72968e76 Create FUNDING.yml 2025-04-13 13:26:09 +01:00
Jim Shield
b27f91ac87 fix playerdata check for isDead in server 2025-04-12 01:09:21 +01:00
Jim Shield
35357c07a3 add isDead and isDown to getPlayer() 2025-04-12 00:19:22 +01:00
Jim Shield
943436467e add ox checkbox option for input 2025-04-12 00:18:48 +01:00
Jim Shield
747fd272d4 fix bigmessage scaleform being local 2025-04-12 00:17:47 +01:00
Jim Shield
3ec00956df Enhance drawtext feature 2025-04-08 17:51:30 +01:00
Jim Shield
1248102635 Add more support for RedM RSGInv 2025-04-08 17:48:38 +01:00
Jim Shield
2be706a860 hopefully fix esx loading 2025-04-08 17:47:12 +01:00
Jim Shield
2da2c56705 add basic support for RedM (RSGCore) 2025-04-07 20:52:59 +01:00
Jim Shield
4d8305c844 changes for beta branch 2025-04-01 14:15:50 +01:00
Jim Shield
8611bc6d3c I am still alive 2025-03-26 21:43:48 +00:00
Jim Shield
2572f86030 input compat fixes 2025-03-11 22:41:13 +00:00
Jim Shield
83ba74bc12 fixes 2025-03-08 20:55:05 +00:00
Jim Shield
6bfb549fd0 refactor + attempt better support for other inventories 2025-03-08 13:44:05 +00:00
Jim Shield
31a7ac2951 general fixes and updates 2025-03-07 13:32:10 +00:00
Jim Shield
1cb2bdb525 fixes for jim-crafting changes 2025-03-07 13:30:17 +00:00
Jim Shield
daa9dca142 fix createCallback complaining on client side 2025-03-07 13:29:43 +00:00
Jim Shield
c947993e9e Add multiscript banking functions 2025-03-07 13:27:47 +00:00
Jim Shield
8dd2b7ae9a Beta: Fixes for existing scripts + feature for jim-crafting 2025-03-06 23:49:07 +00:00
Jim Shield
8eb98bff29 (Beta) Fixes for multiframework support 2025-03-01 12:58:43 +00:00
Jim Shield
f9812a689e Add files via upload 2025-02-22 13:21:54 +00:00
54 changed files with 12875 additions and 7797 deletions

12
.github/FUNDING.yml vendored Normal file
View File

@@ -0,0 +1,12 @@
# These are supported funding model platforms
github: # Replace with up to 4 GitHub Sponsors-enabled usernames e.g., [user1, user2]
patreon: # Replace with a single Patreon username
open_collective: # Replace with a single Open Collective username
ko_fi: jixelpatterns
tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel
community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry
liberapay: # Replace with a single Liberapay username
issuehunt: # Replace with a single IssueHunt username
otechie: # Replace with a single Otechie username
custom: ['https://jimathy666.tebex.io/']

1804
README.md Normal file

File diff suppressed because it is too large Load Diff

47
_versioncheck.lua Normal file
View File

@@ -0,0 +1,47 @@
function parseVersion(version)
local parts = {}
for num in version:gmatch("%d+") do
table.insert(parts, tonumber(num))
end
return parts
end
function compareVersions(current, newest)
local currentParts = parseVersion(current)
local newestParts = parseVersion(newest)
for i = 1, math.max(#currentParts, #newestParts) do
local c = currentParts[i] or 0
local n = newestParts[i] or 0
if c < n then return -1
elseif c > n then return 1 end
end
return 0 -- equal
end
function CheckBridgeVersion()
if IsDuplicityVersion() then
CreateThread(function()
Wait(4000)
local currentVersionRaw = GetResourceMetadata("jim_bridge", 'version')
PerformHttpRequest('https://raw.githubusercontent.com/jimathy/jim_bridge/master/version.txt', function(err, newestVersionRaw, headers)
if not newestVersionRaw then
print("^1Unable to run version check for ^7'^3jim_bridge^7' (^3"..currentVersionRaw.."^7)")
return
end
newestVersionRaw = newestVersionRaw:match("[^\r\n]+")
local compareResult = compareVersions(currentVersionRaw, newestVersionRaw)
if compareResult == 0 then
print("^7'^3jim_bridge^7' - ^2You are running the latest version^7. ^7(^3"..currentVersionRaw.."^7)")
elseif compareResult < 0 then
print("^7'^3jim_bridge^7' - ^1You are running an outdated version^7! ^7(^3"..currentVersionRaw.."^7 → ^3"..newestVersionRaw.."^7)")
else
print("^7'^3jim_bridge^7' - ^5You are running a newer version ^7(^3"..currentVersionRaw.."^7 ← ^3"..newestVersionRaw.."^7)")
end
end)
end)
end
end
CheckBridgeVersion()

View File

@@ -1,14 +1,24 @@
name "Jim_Bridge" name "Jim_Bridge"
author "Jimathy" author "Jimathy"
version "2.0" version "2.0.01"
description "Framework Bridge By Jimathy" description "Framework Bridge By Jimathy"
fx_version "cerulean" fx_version "cerulean"
game "gta5" rdr3_warning 'I acknowledge that this is a prerelease build of RedM, and I am aware my resources *will* become incompatible once RedM ships.'
games { 'gta5', 'rdr3' }
lua54 'yes' lua54 'yes'
files { files {
'starter.lua', 'starter.lua',
'shared/*.lua', 'shared/*.lua',
'shared/make/*.lua', 'shared/make/*.lua',
'shared/scaleforms/*.lua', 'shared/scaleforms/*.lua',
} }
-- Version checker
server_scripts { '_versioncheck.lua' }
-- NUI Menu Loading
client_scripts { 'nui/*.lua' }
ui_page 'nui/index.html'
files { 'nui/index.html', 'nui/script.js', 'nui/style.css' }

33
nui/index.html Normal file
View File

@@ -0,0 +1,33 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>QB Menu</title>
<script src="https://code.jquery.com/jquery-3.6.0.min.js" integrity="sha256-/xUj+3OJU5yExlq6GSYGSHk7tPXikynS7ogEvDej/m4=" crossorigin="anonymous"></script>
<!-- Font Awesome Icons Import -->
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.1.1/css/all.min.css">
<link rel="stylesheet" href="./style.css" />
<script src="./script.js" defer></script>
</head>
<body>
<div id="container">
<div id="buttons"></div>
</div>
<!--
<div id="input-popup" class="hidden">
<div class="input-box">
<div class="input-header">Enter Info</div>
<form id="input-form">
</form>
<div class="input-actions">
<button type="submit" form="input-form" class="input-submit">Submit</button>
<button type="button" class="input-cancel">Cancel</button>
</div>
</div>
</div>
-->
</body>
</html>

138
nui/main.lua Normal file
View File

@@ -0,0 +1,138 @@
Config = Config or { System = {} }
CreateThread(function()
local fileLoader = assert(load(LoadResourceFile('jim_bridge', ('starter.lua')), ('@@jim_bridge/starter.lua')))
fileLoader()
end)
local headerShown = false
local sendData = nil
local sendModifiers = nil
--Colours for progressbar
local colours = {
["dark.0"] = "#C1C2C5", ["dark.1"] = "#A6A7AB", ["dark.2"] = "#909296", ["dark.3"] = "#5C5F66", ["dark.4"] = "#373A40", ["dark.5"] = "#2C2E33", ["dark.6"] = "#25262B", ["dark.7"] = "#1A1B1E", ["dark.8"] = "#141517", ["dark.9"] = "#101113",
["gray.0"] = "#F8F9FA", ["gray.1"] = "#F1F3F5", ["gray.2"] = "#E9ECEF", ["gray.3"] = "#DEE2E6", ["gray.4"] = "#CED4DA", ["gray.5"] = "#ADB5BD", ["gray.6"] = "#868E96", ["gray.7"] = "#495057", ["gray.8"] = "#343A40", ["gray.9"] = "#212529",
["red.0"] = "#FFF5F5", ["red.1"] = "#FFE3E3", ["red.2"] = "#FFC9C9", ["red.3"] = "#FFA8A8", ["red.4"] = "#FF8787", ["red.5"] = "#FF6B6B", ["red.6"] = "#FA5252", ["red.7"] = "#F03E3E", ["red.8"] = "#E03131", ["red.9"] = "#C92A2A",
["pink.0"] = "#FFF0F6", ["pink.1"] = "#FFDEEB", ["pink.2"] = "#FCC2D7", ["pink.3"] = "#FAA2C1", ["pink.4"] = "#F783AC", ["pink.5"] = "#F06595", ["pink.6"] = "#E64980", ["pink.7"] = "#D6336C", ["pink.8"] = "#C2255C", ["pink.9"] = "#A61E4D",
["grape.0"] = "#F8F0FC", ["grape.1"] = "#F3D9FA", ["grape.2"] = "#EEBEFA", ["grape.3"] = "#E599F7", ["grape.4"] = "#DA77F2", ["grape.5"] = "#CC5DE8", ["grape.6"] = "#BE4BDB", ["grape.7"] = "#AE3EC9", ["grape.8"] = "#9C36B5", ["grape.9"] = "#862E9C",
["violet.0"] = "#F3F0FF", ["violet.1"] = "#E5DBFF", ["violet.2"] = "#D0BFFF", ["violet.3"] = "#B197FC", ["violet.4"] = "#9775FA", ["violet.5"] = "#845EF7", ["violet.6"] = "#7950F2", ["violet.7"] = "#7048E8", ["violet.8"] = "#6741D9", ["violet.9"] = "#5F3DC4",
["indigo.0"] = "#EDF2FF", ["indigo.1"] = "#DBE4FF", ["indigo.2"] = "#BAC8FF", ["indigo.3"] = "#91A7FF", ["indigo.4"] = "#748FFC", ["indigo.5"] = "#5C7CFA", ["indigo.6"] = "#4C6EF5", ["indigo.7"] = "#4263EB", ["indigo.8"] = "#3B5BDB", ["indigo.9"] = "#364FC7",
["blue.0"] = "#E7F5FF", ["blue.1"] = "#D0EBFF", ["blue.2"] = "#A5D8FF", ["blue.3"] = "#74C0FC", ["blue.4"] = "#4DABF7", ["blue.5"] = "#339AF0", ["blue.6"] = "#228BE6", ["blue.7"] = "#1C7ED6", ["blue.8"] = "#1971C2", ["blue.9"] = "#1864AB",
["cyan.0"] = "#E3FAFC", ["cyan.1"] = "#C5F6FA", ["cyan.2"] = "#99E9F2", ["cyan.3"] = "#66D9E8", ["cyan.4"] = "#3BC9DB", ["cyan.5"] = "#22B8CF", ["cyan.6"] = "#15AABF", ["cyan.7"] = "#1098AD", ["cyan.8"] = "#0C8599", ["cyan.9"] = "#0B7285",
["teal.0"] = "#E6FCF5", ["teal.1"] = "#C3FAE8", ["teal.2"] = "#96F2D7", ["teal.3"] = "#63E6BE", ["teal.4"] = "#38D9A9", ["teal.5"] = "#20C997", ["teal.6"] = "#12B886", ["teal.7"] = "#0CA678", ["teal.8"] = "#099268", ["teal.9"] = "#087F5B",
["green.0"] = "#EBFBEE", ["green.1"] = "#D3F9D8", ["green.2"] = "#B2F2BB", ["green.3"] = "#8CE99A", ["green.4"] = "#69DB7C", ["green.5"] = "#51CF66", ["green.6"] = "#40C057", ["green.7"] = "#37B24D", ["green.8"] = "#2F9E44", ["green.9"] = "#2B8A3E",
["lime.0"] = "#F4FCE3", ["lime.1"] = "#E9FAC8", ["lime.2"] = "#D8F5A2", ["lime.3"] = "#C0EB75", ["lime.4"] = "#A9E34B", ["lime.5"] = "#94D82D", ["lime.6"] = "#82C91E", ["lime.7"] = "#74B816", ["lime.8"] = "#66A80F", ["lime.9"] = "#5C940D",
["yellow.0"] = "#FFF9DB", ["yellow.1"] = "#FFF3BF", ["yellow.2"] = "#FFEC99", ["yellow.3"] = "#FFE066", ["yellow.4"] = "#FFD43B", ["yellow.5"] = "#FCC419", ["yellow.6"] = "#FAB005", ["yellow.7"] = "#F59F00", ["yellow.8"] = "#F08C00", ["yellow.9"] = "#E67700",
["orange.0"] = "#FFF4E6", ["orange.1"] = "#FFE8CC", ["orange.2"] = "#FFD8A8", ["orange.3"] = "#FFC078", ["orange.4"] = "#FFA94D", ["orange.5"] = "#FF922B", ["orange.6"] = "#FD7E14", ["orange.7"] = "#F76707",["orange.8"] = "#E8590C",["orange.9"] = "#D9480F"
}
-- Functions
function openNuiMenu(data, modifiers)
if not data or not next(data) then return end
for _, v in pairs(data) do
v["icon"] = v["arrow"] and "fas fa-angle-right" or v["icon"] or nil
v["colorScheme"] = v["colourScheme"] and colours[v["colourScheme"]] or (v["colorScheme"] and colours[v["colorScheme"]] or colours["green.7"])
if v["onSelect"] then
v.params = { isAction = true, event = v["onSelect"] }
end
end
SetNuiFocus(true, true)
headerShown = false
sendData = data
sendModifiers = modifiers or {}
SendNUIMessage({ action = 'OPEN_MENU', data = table.clone(data) })
end
local function closeMenu()
sendData = nil
sendModifiers = nil
headerShown = false
SetNuiFocus(false, false)
SendNUIMessage({ action = 'CLOSE_MENU' })
end
local function showHeader(data)
if not data or not next(data) then return end
headerShown = true
sendData = data
SendNUIMessage({ action = 'SHOW_HEADER', data = table.clone(data) })
end
-- Events
RegisterNetEvent("jim_bridge:client:openMenu", function(data) openNuiMenu(data) end)
RegisterNetEvent("jim_bridge:client:closeMenu", function() closeMenu() end)
-- NUI Callbacks
RegisterNUICallback('clickedButton', function(option)
if headerShown then headerShown = false end
PlaySound(-1, "CLICK_BACK", "WEB_NAVIGATION_SOUNDS_PHONE", 0, 0, 1)
SetNuiFocus(false, false)
if sendData then
local data = sendData[tonumber(option)]
sendData = nil
if data then
if data.params and data.params.event then
if data.params.isServer then
TriggerServerEvent(data.params.event, data.params.args)
elseif data.params.isCommand then
ExecuteCommand(data.params.event)
elseif data.params.isQBCommand then
TriggerServerEvent('QBCore:CallCommand', data.params.event, data.params.args)
elseif data.params.isAction then
data.params.event(data.params.args)
else
TriggerEvent(data.params.event, data.params.args)
end
end
end
end
end)
RegisterNUICallback('closeMenu', function()
if sendModifiers and sendModifiers.onExit then sendModifiers.onExit() end -- when close menu is triggered (with esc or using a button to close it) trigger onExit function
headerShown = false
sendModifiers = nil
sendData = nil
SetNuiFocus(false, false)
end)
-- Command and Keymapping
RegisterCommand('playerfocus', function() if headerShown then SetNuiFocus(true, true) end end)
RegisterKeyMapping('playerFocus', 'Give Menu Focus', 'keyboard', 'LMENU')
-- Exports
exports('openMenu', function(data) openNuiMenu(data) end)
exports('closeMenu', function() closeMenu() end)
exports('showHeader', function(data) showHeader(data) end)
-- Input Dialog
-- function inputDialog(title, config)
-- local p = promise.new()
-- local cbId = math.random(111111, 999999)
--
-- RegisterNUICallback("inputResult", function(data, cb)
-- if data.cbId == cbId then
-- cb({})
-- SetNuiFocus(false, false)
-- p:resolve(data.result)
-- end
-- end)
--
-- SendNUIMessage({
-- action = "SHOW_INPUT",
-- title = title,
-- data = config,
-- cbId = cbId
-- })
--
-- SetNuiFocus(true, true)
-- return Citizen.Await(p)
-- end
--
-- exports('inputDialog', inputDialog)

342
nui/script.js Normal file
View File

@@ -0,0 +1,342 @@
let buttonParams = [];
let menuItems = [];
const openMenu = (data = null) => {
let html = "<div id='buttons'>";
// Add search as a title-like fixed header
html += `
<div class="title search-container">
<input type="text" id="search-input" placeholder="Search..." autocomplete="off">
</div>
`;
data.forEach((item, index) => {
if (!item.hidden) {
let header = item.header || item.title;
let message = item.txt || item.text || item.description;
let isMenuHeader = item.isMenuHeader;
let isDisabled = item.disabled;
let icon = item.icon;
let progress = item.progress || item.progressbar;
let colour = item.colorScheme;
html += getButtonRender(header, message, index, isMenuHeader, isDisabled, icon, progress, colour);
if (item.params) buttonParams[index] = item.params;
}
});
html += "</div>";
$("#container").html(html);
$('.button').click(function() {
const target = $(this)
if (!target.hasClass('title') && !target.hasClass('disabled')) {
postData(target.attr('id'));
}
});
$("#search-input").on("input", function() {
const value = $(this).val().toLowerCase();
$("#buttons .button, #buttons .title").filter(function(index) {
if (index === 0) return; // Skip the search bar itself (first title)
$(this).toggle($(this).text().toLowerCase().indexOf(value) > -1);
});
});
};
const getButtonRender = (header, message = null, id, isMenuHeader, isDisabled, icon, progress, colour) => {
return `
<div class="${isMenuHeader ? "title" : "button"} ${isDisabled ? "disabled" : ""} " id="${id}">
${icon ? `
<div class="icon">
<img src=${icon} onerror="this.onerror=null; this.remove();">
<i class="${icon}" onerror="this.onerror=null; this.remove();"></i>
</div>
` : " " }
<div class="column">
<div class="header">${header ? `${header}` : " "}</div>
${message ? `<div class="text"> ${message}</div>` : ""}
</div>
</div>
${progress ? `
<div class="progress-container">
<div class="progress-bar" style="width: ${progress}%; background-color: ${colour};"></div>
</div>`
: ""}
`;
};
const closeMenu = () => {
$("#buttons").html(" ");
buttonParams = [];
$("#search-input").hide(); // hide search bar
};
const postData = (id) => {
$.post(`https://${GetParentResourceName()}/clickedButton`, JSON.stringify(parseInt(id) + 1));
return closeMenu();
};
const cancelMenu = () => {
$.post(`https://${GetParentResourceName()}/closeMenu`);
return closeMenu();
};
const filterButtons = (query) => {
const filteredItems = menuItems.filter(item => item.header.toLowerCase().includes(query.toLowerCase()));
openMenu(filteredItems);
};
$("#search-input").on('input', function() {
filterButtons($(this).val());
});
document.onkeyup = function (event) {
const charCode = event.key;
if (charCode == "Escape") {
cancelMenu();
}
};
let inputCallbackId = null;
window.addEventListener("message", (event) => {
const data = event.data;
const buttons = data.data;
const action = data.action;
debugLog("Opening Input Popup", data.data); // Log the input config specifically
switch (action) {
case "OPEN_MENU":
case "SHOW_HEADER":
return openMenu(buttons);
case "CLOSE_MENU":
return closeMenu();
case "SHOW_INPUT":
inputCallbackId = data.cbId;
debugLog("Opening Input Popup", data.data); // Log the input config specifically
return openInputPopup(data.data);
default:
return;
}
});
document.onkeyup = function (event) {
const charCode = event.key;
if (charCode == "Escape") {
cancelMenu();
}
};
const openInputPopup = (config) => {
if (!config || !Array.isArray(config)) {
console.error("Invalid input config: missing or malformed 'fields'", config);
return;
}
const container = document.getElementById("input-popup");
const form = document.getElementById("input-form");
form.innerHTML = ""; // clear form
config.forEach(field => {
let input;
switch (field.type) {
case "text":
case "number":
input = document.createElement("input");
input.type = field.type;
break;
case "radio":
input = document.createElement("input");
input.type = "radio";
break;
case "select":
input = document.createElement("select");
field.options.forEach(opt => {
const option = document.createElement("option");
option.value = opt;
option.textContent = opt;
input.appendChild(option);
});
break;
case "slider":
input = document.createElement("input");
input.type = "range";
input.min = field.min;
input.max = field.max;
input.step = field.step || 1;
break;
case "color":
input = document.createElement("input");
input.type = "color";
break;
}
if (!input) return;
input.name = field.name;
input.className = "input-field";
input.placeholder = field.label || field.placeholder || "";
if (field.required) input.required = true;
const wrapper = document.createElement("div");
wrapper.className = "input-wrapper";
if (field.type === "radio") {
if (field.label) {
const titleLabel = document.createElement("label");
titleLabel.className = "input-label";
titleLabel.textContent = field.label;
wrapper.appendChild(titleLabel);
}
if (Array.isArray(field.options)) {
field.options.forEach(opt => {
const radioWrapper = document.createElement("label");
radioWrapper.className = "radio-wrapper";
const radio = document.createElement("input");
radio.type = "radio";
radio.name = field.name;
radio.value = opt.value;
radio.className = "radio-input";
// Set default checked radio
if (field.default === opt.value) {
radio.checked = true;
}
const label = document.createElement("span");
label.className = "radio-label";
label.textContent = opt.label || opt.value;
radioWrapper.appendChild(radio);
radioWrapper.appendChild(label);
wrapper.appendChild(radioWrapper);
});
}
form.appendChild(wrapper);
return;
}
if (field.type === "color") {
if (field.label) {
const titleLabel = document.createElement("label");
titleLabel.className = "input-label";
titleLabel.textContent = field.label;
wrapper.appendChild(titleLabel);
}
const colorPreview = document.createElement("span");
colorPreview.className = "color-preview";
colorPreview.textContent = input.value;
input.addEventListener("input", () => {
const hex = input.value;
const rgb = hexToRgb(hex);
colorPreview.textContent = `${hex.toUpperCase()} (${rgb})`;
});
wrapper.classList.add("color-picker");
wrapper.appendChild(input);
wrapper.appendChild(colorPreview);
form.appendChild(wrapper);
return;
}
if (field.type === "slider") {
if (field.label) {
const titleLabel = document.createElement("label");
titleLabel.className = "input-label";
titleLabel.textContent = field.label;
wrapper.appendChild(titleLabel);
}
input.value = field.default || field.min;
const sliderValue = document.createElement("div");
sliderValue.className = "slider-values";
sliderValue.innerHTML = `
<span class="slider-min">${field.min}</span>
<span class="slider-current">${input.value}</span>
<span class="slider-max">${field.max}</span>
`;
input.addEventListener("input", () => {
sliderValue.querySelector(".slider-current").textContent = input.value;
});
wrapper.appendChild(sliderValue);
wrapper.appendChild(input);
form.appendChild(wrapper);
return;
}
// Common label
const label = document.createElement("label");
label.className = "input-label";
label.textContent = field.label || field.name || "Input";
wrapper.appendChild(label);
// Input
input.name = field.name;
input.className = "input-field";
if (field.required) input.required = true;
wrapper.appendChild(input);
form.appendChild(wrapper);
form.appendChild(wrapper);
});
form.onsubmit = function (e) {
e.preventDefault();
const data = {};
new FormData(form).forEach((val, key) => {
// checkboxes return "on" when checked
if (form[key].type === "checkbox") {
data[key] = form[key].checked;
} else if (form[key].type === "color") {
const hex = val;
const rgb = hexToRgb(hex);
data[key] = {
hex: hex.toUpperCase(),
rgb: rgb
};
} else {
data[key] = val;
}
});
returnInputData(data);
};
document.querySelector(".input-cancel").onclick = () => {
returnInputData(null);
};
container.classList.remove("hidden");
};
const closeInputPopup = () => {
document.getElementById("input-popup").classList.add("hidden");
};
const returnInputData = (result) => {
$.post(`https://${GetParentResourceName()}/inputResult`, JSON.stringify({
cbId: inputCallbackId,
result
}));
closeInputPopup();
};
const debugLog = (label, data) => {
//console.log(`^4[DEBUG] ${label}`);
//console.log(JSON.stringify(data, null, 2));
};
function hexToRgb(hex) {
const bigint = parseInt(hex.slice(1), 16);
const r = (bigint >> 16) & 255;
const g = (bigint >> 8) & 255;
const b = bigint & 255;
return `RGB(${r}, ${g}, ${b})`;
}

450
nui/style.css Normal file
View File

@@ -0,0 +1,450 @@
@import url("https://fonts.googleapis.com/css2?family=Poppins:wght@300;500&display=swap");
:root {
--font-family: "Poppins", sans-serif !important;
--width: 65%;
--text-colour: white;
--text-colour-hover: black;
--background-button: rgba(23, 23, 23, 85%);
--background-button-hover: rgba(200, 200, 200, 85%);
--background-title: rgba(23, 23, 23, 100%);
/*
--text-colour: black;
--text-colour-hover: white;
--background-button: rgba(200, 200, 200, 85%);
--background-button-hover: rgba(0, 0, 0, 85%);
--background-title: rgba(200, 200, 200);
*/
}
* {
padding: 0;
margin: 0;
font-family: var(--font-family);
font-weight: 300;
}
#container {
position: absolute;
height: auto;
top: 15%;
right: 20%;
z-index: 2;
}
.button {
cursor: pointer;
display: flex;
flex-direction: row !important;
gap: 10px;
}
.title {
cursor: default;
gap: 10px;
display: flex;
flex-direction: row !important;
}
#buttons {
max-height: 80vh;
width: 250%;
overflow-x: none;
overflow-y: auto;
padding: 10px;
}
html, body { background: transparent !important; }
#buttons::-webkit-scrollbar { display: none; }
body::-webkit-scrollbar { display: none; }
.button {
max-width: 56%;
height: 60%;
background-color: var(--background-button);
color: var(--text-colour);
margin: auto;
position: relative;
top: 10%;
overflow: hidden;
padding: 0.45rem;
display: flex;
flex-direction: column;
cursor: pointer;
z-index: 1;
transition-property: color;
transition-duration: 0.1s, 0.2s;
transition-timing-function: linear, ease-in;
}
.button::before {
content: "";
position: absolute;
top: 0;
left: 0;
width: 0%;
height: 100%;
background-color: var(--background-button-hover);
z-index: 0;
transition: width 0.2s ease;
}
.button:hover::before {
width: 100%;
}
.button > * {
position: relative;
z-index: 1;
}
.button:hover {
color: var(--text-colour-hover);
}
.icon > img {
width: 2.2vh !important;
}
.icon {
font-size: 1.2vh;
transition-property: all, filter;
transition-duration: 0.1s, 0.3s;
transition-timing-function: linear, ease-in;
display: inline-flex;
align-items: center;
position: static;
justify-content: left;
opacity: 0.5;
}
.button:hover > .icon {
opacity: 1.0;
animation: bounce 2s linear;
filter: drop-shadow(-1px -1px 15px white);
}
.bounce {
animation-name: bounce-4;
animation-timing-function: ease;
}
@keyframes bounce {
0% { transform: scale(1,1); }
10% { transform: scale(1.1); }
30% { transform: scale(1.5); }
50% { transform: scale(1.5); }
100% { transform: scale(1.5); }
}
.title {
font-family: var(--font-family);
width: auto;
max-width: 56%;
height: 60%;
background: var(--background-title);
color: var(--text-colour);
margin: auto;
margin-left: -0.5;
position: relative;
top: 10%;
overflow: hidden;
padding: 0.45rem;
flex-direction: column;
border-left: 0px;
}
.title > div.header {
font-family: var(--font-family);
text-decoration: underline !important;
}
.disabled {
cursor: default;
}
div > .text {
font-family: var(--font-family);
flex-direction: column;
font-size: 1.0vh;
overflow: hidden;
}
div > .header {
font-family: var(--font-family);
width: 100%;
max-width: 100%;
display: flex;
align-items: center;
position: relative;
justify-content: left;
overflow: wrap;
font-size: 1.3vh;
font-weight: 400;
overflow: hidden;
}
/* Search input */
.title.search-container {
background: var(--background-button);
color: var(--text-colour);
border-top-left-radius: 8px;
border-top-right-radius: 8px;
z-index: 3;
}
.title.search-container input[type="text"] {
color: var(--text-colour);
font-family: var(--font-family);
font-size: 1rem;
width: auto;
max-width: 56%;
border: none;
background-color: transparent;
transition: background-color 0.2s ease, color 0.2s ease;
outline: none;
}
.title.search-container input[type="text"]::placeholder {
color: var(--text-colour);
opacity: 0.5;
}
.progress-container {
z-index: 99999;
width: auto;
max-width: 56%;
background-color: var(--background-title);
height: 0.4vh;
padding-left: 0.45rem;
padding-right: 0.45rem;
margin: auto;
}
.progress-bar {
height: 90%;
max-width: auto;
transition: width 0.3s ease-in-out;
}
.hidden {
display: none !important;
}
#input-popup {
position: fixed;
top: 0;
left: 0;
height: 100vh;
width: 100vw;
display: flex;
align-items: center;
justify-content: center;
background: rgba(0, 0, 0, 0.5);
z-index: 999;
}
.input-box {
font-weight: 300;
background: var(--background-button);
color: var(--text-colour);
width: 25vw;
box-shadow: 0 0 15px var(--background-button-hover);
}
.input-header {
font-size: 1.4rem;
margin-bottom: 1rem;
margin-top: 0.5rem;
font-weight: 500;
text-align: center;
}
.input-actions {
display: flex;
justify-content: space-between;
margin-top: 1rem;
}
.input-actions button {
padding: 0.5rem 1rem;
border: none;
border-radius: 6px;
margin-bottom: 0.8rem;
margin-left: 0.6rem;
margin-right: 0.6rem;
cursor: pointer;
background: var(--background-button);
color: var(--text-colour);
transition: background 0.2s ease;
}
.input-actions button:hover {
color: var(--text-colour-hover);
background: var(--background-button-hover);
}
.input-wrapper {
position: relative;
width: 95%;
padding: 0.1rem;
margin-left: 0.6rem;
margin-bottom: 0.8rem;
background-color: var(--background-title);
overflow: hidden;
}
.input-wrapper::before {
content: "";
position: absolute;
top: 0;
left: 0;
width: 0%;
height: 100%;
background-color: var(--background-button-hover);
z-index: 0;
transition: width 0.2s ease;
}
.input-wrapper:focus-within::before {
width: 100%;
}
.input-wrapper:focus-within .input-field {
color: var(--text-colour-hover) !important;
}
.input-wrapper:focus-within .input-label {
color: var(--text-colour-hover) !important;
}
.checkbox-wrapper:has(.checkbox-input:focus) .checkbox-label {
color: var(--text-colour-hover) !important;
}
.input-wrapper:focus-within .color-preview {
color: var(--text-colour-hover) !important;
}
.input-wrapper:has(input[type="range"]:focus) .slider-values {
color: var(--text-colour-hover) !important;
}
.input-wrapper:focus-within .slider-current {
color: var(--text-colour-hover) !important;
}
.input-field {
width: 100%;
position: relative;
z-index: 1;
border: transparent;
background: transparent;
color: var(--text-colour);
font-size: 1rem;
transition: color 0.2s ease;
}
.input-wrapper:hover .input-field {
color: var(--text-colour-hover);
}
.input-label {
display: block;
font-size: 0.9rem;
font-weight: 500;
color: var(--text-colour);
margin-bottom: 0.25rem;
z-index: 1;
position: relative;
}
.radio-wrapper {
display: flex;
align-items: center;
gap: 0.5rem;
padding: 0.5rem;
background: var(--background-title);
border-radius: 4px;
z-index: 1;
}
.radio-input {
transform: scale(1.2);
accent-color: var(--background-button-hover);
z-index: 1;
}
.radio-label {
color: var(--text-colour);
font-size: 0.95rem;
z-index: 1;
}
/* Focus styling */
.radio-wrapper:has(.radio-input:focus) .radio-label {
color: var(--text-colour-hover) !important;
}
.input-wrapper:focus-within .radio-label {
color: var(--text-colour-hover) !important;
}
.input-wrapper.color-picker {
display: flex;
flex-direction: column; /* this is key */
align-items: flex-start;
justify-content: flex-start;
z-index: 1;
}
.input-field[type="color"] {
width: 100%; /* half width */
padding: 0.2rem;
cursor: pointer;
z-index: 1;
}
.color-preview {
display: inline-block;
margin-left: 0.5rem;
font-size: 0.9rem;
color: var(--text-colour);
z-index: 1;
position: relative;
}
.slider-values {
z-index: 2;
position: relative; /* <-- this is the key */
margin-left: 0.6rem;
margin-right: 0.6rem;
display: flex;
justify-content: space-between;
font-size: 0.85rem;
color: var(--text-colour);
margin-bottom: 0.3rem;
}
.slider-current {
font-weight: bold;
color: var(--text-colour);
z-index: 1;
}
.input-field select,
.input-field option {
background-color: var(--background-button);
color: var(--text-colour);
}
.input-field option:hover,
.input-field option:focus {
background-color: var(--background-button-hover);
color: var(--text-colour-hover);
}

View File

@@ -1,70 +1,105 @@
--- Executes a function when the player character is loaded into the game. --[[
--- Player & Resource Event Utility Functions
--- This function sets up event listeners for player loading based on the game framework detected (e.g., QB, ESX, OX). -------------------------------------------
--- This module provides functions to:
--- If `onStart` is `true`, it will also attempt to execute the function on resource start after ensuring the player is logged in. (Helpful for debugging) • Execute code when the player character is loaded or unloaded.
• Execute code on resource start and stop.
• Wait for the player to be logged in before proceeding.
]]
-------------------------------------------------------------
-- Player Loaded and Unloaded Events
-------------------------------------------------------------
--- Executes a function when the player character is loaded.
--- If onStart is true, the function will also run on resource start (after ensuring the player is logged in).
--- ---
--- @param func function The function to execute when the player is loaded. --- @param func function The function to execute when the player is loaded.
--- @param onStart boolean (optional) If `true`, the function will also execute on resource start. Default is `false`. --- @param onStart boolean (optional) If true, also execute on resource start. Default is false.
---
--- @usage --- @usage
--- ```lua --- ```lua
--- onPlayerLoaded(function() --- onPlayerLoaded(function()
--- -- Your code here --- print("Player logged in")
--- -- Your initialization code here.
--- end, true) --- end, true)
--- ``` --- ```
function onPlayerLoaded(func, onStart) function onPlayerLoaded(func, onStart)
local onPlayerName = "" local onPlayerFramework = ""
local loaded = false local loaded = false
if onStart then if onStart then
onResourceStart(function() onResourceStart(function()
if not LocalPlayer.state.isLoggedIn then if not waitForLogin() then return end
Wait(3000)
if not LocalPlayer.state.isLoggedIn then -- If the player is not logged in after waiting, skip execution loaded = true
return debugPrint("^6Bridge^7: ^3onResourceStart^7()^2 executed through ^3onPlayerLoaded^7()")
end
end
loaded = true -- Mark as already loaded
debugPrint("^6Bridge^7: ^2Loading ^3onResourceStart^7() ^2through ^3onPlayerLoaded^7()")
Wait(2000) Wait(2000)
func() func()
end, true) end, true)
end end
if not loaded then if not loaded then
local tempFunc = function() local tempFunc = function()
debugPrint("^6Bridge^7: ^2Executing ^3onPlayerLoaded^7()") debugPrint("^6Bridge^7: ^2Executing onPlayerLoaded")
func() func()
end end
if isStarted(QBExport) or isStarted(QBXExport) then onPlayerName = QBExport
if isStarted(QBExport) or isStarted(QBXExport) then
onPlayerFramework = QBExport
AddEventHandler('QBCore:Client:OnPlayerLoaded', tempFunc) AddEventHandler('QBCore:Client:OnPlayerLoaded', tempFunc)
elseif isStarted(ESXExport) then onPlayerName = ESXExport elseif isStarted(ESXExport) then
onPlayerFramework = ESXExport
AddEventHandler('esx:playerLoaded', tempFunc) AddEventHandler('esx:playerLoaded', tempFunc)
elseif isStarted(OXCoreExport) then onPlayerName = OXCoreExport elseif isStarted(OXCoreExport) then
onPlayerFramework = OXCoreExport
AddEventHandler('ox:playerLoaded', tempFunc) AddEventHandler('ox:playerLoaded', tempFunc)
elseif isStarted(RSGExport) then
onPlayerFramework = RSGExport
AddEventHandler('RSGCore:Client:OnPlayerLoaded', tempFunc)
end end
if onPlayerName ~= "" then
debugPrint("^6Bridge^7: ^2Registering ^3onPlayerLoaded^2 with ^7"..onPlayerName) if onPlayerFramework ~= "" then
debugPrint("^6Bridge^7: ^2Registering ^3onPlayerLoaded^7()^2 with ^3" .. onPlayerFramework.."^7")
else else
print("^4ERROR^7: ^2No Core detected for onPlayerLoaded ^7- ^2Check ^3exports^1.^2lua^7") print("^4ERROR^7: No supported core detected for onPlayerLoaded - Check starter.lua")
end end
end end
end end
--- Executes a function when the player character is unloaded.
--- @param func function The function to execute when the player unloads.
--- @usage
--- ```lua
--- onPlayerUnload(function()
--- print("Player has logged out of their character")
--- -- Your cleanup code here.
--- end)
--- ```
function onPlayerUnload(func)
AddEventHandler('QBCore:Client:OnPlayerUnload', function() func() end)
AddEventHandler('ox:playerLogout', function() func() end)
AddEventHandler('RSGCore:Client:OnPlayerUnload', function() func() end)
--AddEventHandler('esx:playerLogout', function() func() end)
-- ^ Only server side for now, need a way to send it to client if not already available
end
-------------------------------------------------------------
-- Resource Start and Stop Events
-------------------------------------------------------------
--- Executes a function when the resource starts. --- Executes a function when the resource starts.
--- --- @param func function The function to execute.
--- This function wraps the `onResourceStart` event, allowing you to execute code when the resource starts. --- @param thisScript boolean (optional) If true, only runs when this resource starts (default true).
---
--- @param func function The function to execute on resource start.
--- @param thisScript boolean (optional) If `true`, only runs the function when this resource starts. Default is `true`.
---
--- @usage --- @usage
--- ```lua --- ```lua
--- onResourceStart(function() --- onResourceStart(function()
--- -- Your code here --- print("Script ensured")
--- -- Initialization code on resource start.
--- end, true) --- end, true)
--- ``` --- ```
function onResourceStart(func, thisScript) function onResourceStart(func, thisScript)
debugPrint("^6Bridge^7: ^2Registering ^3onResourceStart^2") debugPrint("^6Bridge^7: Registering ^3onResourceStart^7()")
AddEventHandler('onResourceStart', function(resourceName) AddEventHandler('onResourceStart', function(resourceName)
if getScript() == resourceName and (thisScript or true) then if getScript() == resourceName and (thisScript or true) then
func() func()
@@ -73,20 +108,16 @@ function onResourceStart(func, thisScript)
end end
--- Executes a function when the resource stops. --- Executes a function when the resource stops.
--- --- @param func function The function to execute.
--- This function wraps the `onResourceStop` event, allowing you to execute code when the resource stops. --- @param thisScript boolean (optional) If true, only runs when this resource stops (default true).
---
--- @param func function The function to execute on resource stop.
--- @param thisScript boolean (optional) If `true`, only runs the function when this resource stops. Default is `true`.
---
--- @usage --- @usage
--- ```lua --- ```lua
--- onResourceStop(function() --- onResourceStop(function()
--- -- Cleanup code here --- -- Cleanup code here.
--- end, true) --- end, true)
--- ``` --- ```
function onResourceStop(func, thisScript) function onResourceStop(func, thisScript)
debugPrint("^6Bridge^7: ^2Registering ^3onResourceStop^2") debugPrint("^6Bridge^7: ^2Registering ^3onResourceStop^7()")
AddEventHandler('onResourceStop', function(resourceName) AddEventHandler('onResourceStop', function(resourceName)
if getScript() == resourceName and (thisScript or true) then if getScript() == resourceName and (thisScript or true) then
func() func()
@@ -94,17 +125,54 @@ function onResourceStop(func, thisScript)
end) end)
end end
--- Waits until the player is logged in before continuing execution. -------------------------------------------------------------
--- -- Wait for Login
--- This function blocks execution until `LocalPlayer.state.isLoggedIn` is `true`. -------------------------------------------------------------
---
---@usage --- Blocks execution until the player is logged in.
--- ```lua --- @usage
--- waitForLogin() --- waitForLogin()
--- ```
function waitForLogin() function waitForLogin()
while not LocalPlayer.state.isLoggedIn do local timeout = 10000 -- 10 seconds in milliseconds
debugPrint("Waiting") local startTime = GetGameTimer()
Wait(100) local loggedIn = false
if isStarted(ESXExport) then
debugPrint("^6Bridge^7: ^3ESX waitForLogin^7() ^2running^7")
while (GetGameTimer() - startTime) < timeout do
while not ESX do Wait(100) end
local playerData = ESX.GetPlayerData()
if playerData and playerData.job then
loggedIn = true
break
end
Wait(100)
end
elseif isStarted(OXCoreExport) then
if OxPlayer["stateId"] then
loggedIn = true
end
while not OxPlayer["stateId"] do
Wait(1000)
debugPrint("Waiting for stateId to class as logged in")
if OxPlayer.get["stateId"] then
loggedIn = true
break
end
end
else
-- For other frameworks, use LocalPlayer.state.isLoggedIn.
while not LocalPlayer.state.isLoggedIn and (GetGameTimer() - startTime) < timeout do
Wait(100)
end
loggedIn = LocalPlayer.state.isLoggedIn
end
if not loggedIn then
print("^4Error^7: ^2Timeout reached while waiting for player login^7.")
return false
else
debugPrint("^6Bridge^7: ^2Player Login Detected^7.")
return true
end end
end end

View File

@@ -0,0 +1,76 @@
function parseVersion(version)
local parts = {}
for num in version:gmatch("%d+") do
table.insert(parts, tonumber(num))
end
return parts
end
function compareVersions(current, newest)
local currentParts = parseVersion(current)
local newestParts = parseVersion(newest)
for i = 1, math.max(#currentParts, #newestParts) do
local c = currentParts[i] or 0
local n = newestParts[i] or 0
if c < n then return -1
elseif c > n then return 1 end
end
return 0 -- equal
end
function capitalize(str)
return (str:gsub("^%l", string.upper):gsub("%-%l", function(letter) return "-" .. string.upper(letter:sub(2)) end))
end
local scriptName = ("^2"..capitalize(getScript()):gsub("%-", "^7-^2"):gsub("%_", "^7_^2")) or ""
local scriptVersion = ("^5"..GetResourceMetadata(getScript(), 'version', nil):gsub("%.", "^7.^5")) or ""
local scriptDescription = ("^2"..GetResourceMetadata(getScript(), 'description', nil)) or ""
local scriptAuthor = ("^2by ^4"..GetResourceMetadata(getScript(), 'author', nil):gsub("%and", "^7and^4")) or ""
print(scriptName.." ^7v"..scriptVersion.."^7 - "..scriptDescription.." "..scriptAuthor.."^7")
function CheckVersion()
if isServer() then
CreateThread(function()
Wait(4000)
local script = getScript()
local currentVersionRaw = GetResourceMetadata(script, 'version')
PerformHttpRequest('https://raw.githubusercontent.com/jimathy/UpdateVersions/master/'..script..'.txt', function(err, newestVersionRaw, headers)
if not newestVersionRaw then
PerformHttpRequest('https://raw.githubusercontent.com/jimathy/'..script..'/master/version.txt', function(err, fallbackVersionRaw, headers)
if not fallbackVersionRaw then
print("^1Currently unable to run a version check for ^7'^3"..script.."^7' (^3"..currentVersionRaw.."^7)")
return
end
fallbackVersionRaw = fallbackVersionRaw:match("[^\r\n]+"):gsub("v", "")
local compareResult = compareVersions(currentVersionRaw, fallbackVersionRaw)
if compareResult == 0 then
print("^7'^3"..script.."^7' - ^2You are running the latest version^7. (^3"..currentVersionRaw.."^7)")
elseif compareResult < 0 then
print("^7'^3"..script.."^7' - ^1You are currently running an outdated version^7! (^3"..currentVersionRaw.."^7 → ^3"..fallbackVersionRaw.."^7)")
else
print("^7'^3"..script.."^7' - ^5You are running a newer version ^7(^3"..currentVersionRaw.."^7 ← ^3"..fallbackVersionRaw.."^7)")
end
end)
else
newestVersionRaw = newestVersionRaw:match("[^\r\n]+"):gsub("v", "")
local compareResult = compareVersions(currentVersionRaw, newestVersionRaw)
if compareResult == 0 then
print("^7'^3"..script.."^7' - ^2You are running the latest version^7. (^3"..currentVersionRaw.."^7)")
elseif compareResult < 0 then
print("^7'^3"..script.."^7' - ^1You are currently running an outdated version^7! (^3"..currentVersionRaw.."^7 → ^3"..newestVersionRaw.."^7)")
else
print("^7'^3"..script.."^7' - ^5You are running a newer version ^7(^3"..currentVersionRaw.."^7 ← ^3"..newestVersionRaw.."^7)")
end
end
end)
end)
end
end
CheckVersion()

View File

@@ -8,26 +8,39 @@
--- ---
---@usage ---@usage
--- ```lua --- ```lua
--- local table = { ["info"] = "HI" }
--- createCallback('myCallback', function(source, ...) --- createCallback('myCallback', function(source, ...)
--- -- Your callback code here --- return table
--- end)
---
--- createCallback("callback:checkVehicleOwned", function(source, plate)
--- local result = isVehicleOwned(plate)
--- if result then
--- return true
--- else
--- return false
--- end
--- end) --- end)
--- ``` --- ```
function createCallback(callbackName, funct) function createCallback(callbackName, funct)
if isStarted(OXLibExport) then if isServer() then
lib.callback.register(callbackName, funct) debugPrint("^6Bridge^7: ^3Registering callback^7:", callbackName)
else if isStarted(OXLibExport) then
local adaptedFunction = function(source, cb, ...) lib.callback.register(callbackName, funct)
local result = funct(source, ...)
cb(result)
end
if isStarted(QBExport) then
Core = Core or exports[QBExport]:GetCoreObject()
Core.Functions.CreateCallback(callbackName, adaptedFunction)
elseif isStarted(ESXExport) then
ESX.RegisterServerCallback(callbackName, adaptedFunction)
else else
print("^6Bridge^7: ^1ERROR^7: ^3Can't find any script to register callback with", callbackName) local adaptedFunction = function(source, cb, ...)
local result = funct(source, ...)
cb(result)
end
if isStarted(QBExport) then
Core = Core or exports[QBExport]:GetCoreObject()
Core.Functions.CreateCallback(callbackName, adaptedFunction)
elseif isStarted(ESXExport) then
ESX.RegisterServerCallback(callbackName, adaptedFunction)
else
print("^6Bridge^7: ^1ERROR^7: ^3Can't find any script to register callback with", callbackName)
end
end end
end end
end end
@@ -43,10 +56,15 @@ end
--- ---
---@usage ---@usage
--- ```lua --- ```lua
--- local result = triggerCallback('myCallback', arg1, arg2) --- local result = triggerCallback('myCallback')
--- jsonPrint(result)
---
--- local result = triggerCallback("callback:checkVehicleOwned", plate)
--- print(result)
--- ``` --- ```
function triggerCallback(callbackName, ...) function triggerCallback(callbackName, ...)
local result = nil local result = nil
debugPrint("^6Bridge^7: ^3Triggering callback^7:", callbackName)
if isStarted(OXLibExport) then if isStarted(OXLibExport) then
result = lib.callback.await(callbackName, false, ...) result = lib.callback.await(callbackName, false, ...)
elseif isStarted(QBExport) then elseif isStarted(QBExport) then
@@ -55,6 +73,7 @@ function triggerCallback(callbackName, ...)
p:resolve(cbResult) p:resolve(cbResult)
end, ...) end, ...)
result = Citizen.Await(p) result = Citizen.Await(p)
Wait(10)
elseif isStarted(ESXExport) then elseif isStarted(ESXExport) then
local p = promise.new() local p = promise.new()
ESX.TriggerServerCallback(callbackName, function(cbResult) ESX.TriggerServerCallback(callbackName, function(cbResult)

View File

@@ -1,25 +1,37 @@
--[[
Menu Opening Module
---------------------
This module provides a unified function to open menus using the configured menu system.
Supported systems include:
• jim_bridge (built-in nui menu that works on any framework)
• ox (or ox_context)
• qb (using QBMenuExport)
• gta (using WarMenu)
• esx (using ESX.UI.Menu)
]]
--- Opens a menu using the configured menu system. --- Opens a menu using the configured menu system.
--- ---
--- This function translates code and creates menus in several different menu scripts, depending on the configured menu system specified in `Config.System.Menu`. --- This function translates code and creates menus in several different menu scripts, depending on the configured menu system specified in `Config.System.Menu`.
--- ---
---@param Menu table A table containing the menu options to display. ---@param Menu table A table containing the menu options to display.
--- Each menu item can include: --- Each menu item can include:
--- - **header** (`string`): The text to display for the menu item. --- - header (`string`): The text to display for the menu item.
--- - **txt** (`string`, optional): Additional text or description. --- - txt (`string`, optional): Additional text or description.
--- - **icon** (`string`, optional): Icon to display with the menu item. --- - icon (`string`, optional): Icon to display with the menu item.
--- - **onSelect** (`function`, optional): Function to execute when the menu item is selected. --- - onSelect (`function`, optional): Function to execute when the menu item is selected.
--- - **arrow** (`boolean`, optional): Whether to display an arrow next to the item (for certain menus). --- - arrow (`boolean`, optional): Whether to display an arrow next to the item (for certain menus).
--- - **params** (`table`, optional): Additional parameters, such as events and arguments. --- - params (`table`, optional): Additional parameters, such as events and arguments.
--- - **isMenuHeader** (`boolean`, optional): Marks the item as a header. --- - isMenuHeader (`boolean`, optional): Marks the item as a header.
--- - **disabled** (`boolean`, optional): Disables the menu item if `true`. --- - disabled (`boolean`, optional): Disables the menu item if `true`.
--- ---
---@param data table A table containing configuration data for the menu. ---@param data table A table containing configuration data for the menu.
--- - **header** (`string`): The header/title of the menu. --- - header (`string`): The header/title of the menu.
--- - **headertxt** (`string`, optional): Additional header text. --- - headertxt (`string`, optional): Additional header text.
--- - **onBack** (`function`, optional): Function to call when the "Return" option is selected. --- - onBack (`function`, optional): Function to call when the "Return" option is selected.
--- - **onExit** (`function`, optional): Function to call when the menu is exited. --- - onExit (`function`, optional): Function to call when the menu is exited.
--- - **onSelected** (`function`, optional): Function to call when a menu item is selected (for certain menu systems). --- - onSelected (`function`, optional): Function to call when a menu item is selected (for certain menu systems).
--- - **canClose** (`boolean`, optional): Whether the menu can be closed by the user. --- - canClose (`boolean`, optional): Whether the menu can be closed by the user.
--- ---
---@usage ---@usage
--- ```lua --- ```lua
@@ -39,17 +51,42 @@ function openMenu(Menu, data)
if data.onBack then if data.onBack then
table.insert(Menu, 1, { table.insert(Menu, 1, {
icon = "fas fa-circle-arrow-left", icon = "fas fa-circle-arrow-left",
title = "Return", header = " ",
onSelect = data.onBack, txt = "Return",
params = {
isAction = true,
event = data.onBack,
},
})
elseif data.canClose then
table.insert(Menu, 1, {
icon = "fas fa-circle-xmark",
header = " ",
txt = "Close",
params = {
isAction = true,
event = data.onExit and data.onExit or (function() exports[QBMenuExport]:closeMenu() end),
},
}) })
end end
exports["jim-nui"]:openMenu({ if data.header ~= nil then
title = data.header..(data.headertxt and " -- "..data.headertxt or ""), local tempMenu = {}
canClose = data.canClose and data.canClose or nil, for k, v in pairs(Menu) do tempMenu[k + 1] = v end
onClose = (data.onBack and data.onBack) or (data.onExit and data.onExit) or nil, tempMenu[1] = { header = data.header, txt = data.headertxt or "", isMenuHeader = true }
onExit = data.onExit and data.onExit or nil, Menu = tempMenu
options = Menu, end
}) for k in pairs(Menu) do
if not Menu[k].params or not Menu[k].params.event then
Menu[k].params = {
isAction = true,
event = Menu[k].onSelect or function() end,
}
end
if not Menu[k].header then Menu[k].header = " " end
if Menu[k].arrow then Menu[k].icon = "fas fa-angle-right" end
Menu[k].isMenuHeader = Menu[k].isMenuHeader or Menu[k].disable
end
TriggerEvent("jim_bridge:client:openMenu", Menu)
elseif Config.System.Menu == "ox" then elseif Config.System.Menu == "ox" then
local index = nil local index = nil
@@ -65,6 +102,7 @@ function openMenu(Menu, data)
if data.onSelected and Menu[k].arrow then if data.onSelected and Menu[k].arrow then
Menu[k].icon = "fas fa-angle-right" Menu[k].icon = "fas fa-angle-right"
end end
-- If no title, use header or txt as title/label.
if not Menu[k].title then if not Menu[k].title then
if Menu[k].header ~= nil and Menu[k].header ~= "" then if Menu[k].header ~= nil and Menu[k].header ~= "" then
Menu[k].title = Menu[k].header Menu[k].title = Menu[k].header
@@ -75,12 +113,13 @@ function openMenu(Menu, data)
Menu[k].label = Menu[k].txt Menu[k].label = Menu[k].txt
end end
end end
-- Copy parameters from 'params' if available.
if Menu[k].params then if Menu[k].params then
Menu[k].event = Menu[k].params.event Menu[k].event = Menu[k].params.event
Menu[k].args = Menu[k].params.args or {} Menu[k].args = Menu[k].params.args or {}
end end
if Menu[k].isMenuHeader then if Menu[k].isMenuHeader then
Menu[k].disabled = true Menu[k].readOnly = true
end end
end end
local menuID = 'Menu' local menuID = 'Menu'
@@ -143,33 +182,24 @@ function openMenu(Menu, data)
end end
for k in pairs(Menu) do for k in pairs(Menu) do
if not Menu[k].params or not Menu[k].params.event then if not Menu[k].params or not Menu[k].params.event then
if Menu[k].onSelect then Menu[k].params = {
Menu[k].params = { isAction = true,
isAction = true, event = Menu[k].onSelect or function() end,
event = Menu[k].onSelect, }
}
else
Menu[k].params = {
isAction = true,
event = function() end,
}
end
end end
if not Menu[k].header then Menu[k].header = " " end if not Menu[k].header then Menu[k].header = " " end
if Menu[k].arrow then Menu[k].icon = "fas fa-angle-right" end if Menu[k].arrow then Menu[k].icon = "fas fa-angle-right" end
Menu[k].isMenuHeader = Menu[k].isMenuHeader or Menu[k].disable
end end
exports[QBMenuExport]:openMenu(Menu) exports[QBMenuExport]:openMenu(Menu)
elseif Config.System.Menu == "gta" then elseif Config.System.Menu == "gta" then
WarMenu.CreateMenu(tostring(Menu), WarMenu.CreateMenu(tostring(Menu), data.header, data.headertxt or " ", {
data.header, titleColor = { 222, 255, 255 },
data.headertxt or " ", maxOptionCountOnScreen = 15,
{ width = 0.25,
titleColor = { 222, 255, 255 }, x = 0.7,
maxOptionCountOnScreen = 15, })
width = 0.25,
x = 0.7,
})
if WarMenu.IsAnyMenuOpened() then return end if WarMenu.IsAnyMenuOpened() then return end
WarMenu.OpenMenu(tostring(Menu)) WarMenu.OpenMenu(tostring(Menu))
CreateThread(function() CreateThread(function()
@@ -238,7 +268,6 @@ function openMenu(Menu, data)
onSelect = data.onBack, onSelect = data.onBack,
}) })
end end
ESX.UI.Menu.Open("default", getScript(), "Example_Menu", { ESX.UI.Menu.Open("default", getScript(), "Example_Menu", {
title = data.header, title = data.header,
align = 'top-right', align = 'top-right',
@@ -259,15 +288,11 @@ function openMenu(Menu, data)
end end
end end
--- A line break constant used for formatting menu headers. --- A line break constant used for menu header formatting.
br = (Config.System.Menu == "ox" or Config.System.Menu == "gta") and "\n" or "<br>" br = (Config.System.Menu == "ox" or Config.System.Menu == "gta") and "\n" or "<br>"
--- Checks if the menu system is classified as 'ox' or 'gta'. --- Checks if the current menu system is 'ox' or 'gta' for formatting purposes.
--- --- @return boolean boolean True if using ox or gta menus, otherwise false.
--- This function is used to decide how to make line breaks in menu headers.
---
--- @return boolean Returns `true` if the menu system is 'ox' or 'gta'; otherwise, `false`.
---
--- @usage --- @usage
--- ```lua --- ```lua
--- if isOx() then --- if isOx() then
@@ -279,7 +304,7 @@ function isOx() return (Config.System.Menu == "ox" or Config.System.Menu == "gta
--- Checks if any WarMenu menu is currently open. --- Checks if any WarMenu menu is currently open.
--- ---
--- @return boolean Returns `true` if a WarMenu menu is open; otherwise, `false`. --- @return boolean boolean Returns `true` if a WarMenu menu is open; otherwise, `false`.
--- ---
--- @usage --- @usage
--- ```lua --- ```lua

View File

@@ -1,33 +1,76 @@
-- Create empty Variables -- --[[
Resource Initialization Module
--------------------------------
This module initializes and loads shared data (Items, Vehicles, Jobs, Gangs) from the
various frameworks/inventory systems (OX, QB, ESX, etc.). It also corrects export names,
caches framework exports into simple variables, and prints debug information if enabled.
]]
-------------------------------------------------------------
-- Global Variable Initialization
-------------------------------------------------------------
Items, Vehicles, Jobs, Gangs, Core, ESX = {}, nil, nil, nil, nil, nil Items, Vehicles, Jobs, Gangs, Core, ESX = {}, nil, nil, nil, nil, nil
-- Correct QB inventory export (if needed) from 'qb-inventory' to 'ps-inventory' or 'lj-inventory' -- -------------------------------------------------------------
-- Correct QB Inventory Export
-------------------------------------------------------------
-- Ensure that the QB inventory export is corrected from 'qb-inventory' to 'ps-inventory' or 'lj-inventory' if needed.
Exports.QBInv = (isStarted("ps-inventory") and "ps-inventory") or (isStarted("lj-inventory") and "lj-inventory") or Exports.QBInv Exports.QBInv = (isStarted("ps-inventory") and "ps-inventory") or (isStarted("lj-inventory") and "lj-inventory") or Exports.QBInv
-- Create simple variables based on the corresponding framework exports -- -------------------------------------------------------------
OXLibExport, QBXExport, QBExport, ESXExport, OXCoreExport = Exports.OXLibExport or "", Exports.QBXExport or "", Exports.QBExport or "", Exports.ESXExport or "", Exports.OXCoreExport or "" -- Framework Exports and Inventory Identifiers
-------------------------------------------------------------
OXLibExport, QBXExport, QBExport, ESXExport, OXCoreExport =
Exports.OXLibExport or "",
Exports.QBXExport or "",
Exports.QBExport or "",
Exports.ESXExport or "",
Exports.OXCoreExport or ""
-- Create simple variables based on the corresponding inventory names -- OXInv, QBInv, PSInv, QSInv, CoreInv, CodeMInv, OrigenInv =
OXInv, QBInv, PSInv, QSInv, CoreInv, CodeMInv, OrigenInv = Exports.OXInv or "", Exports.QBInv or "", Exports.PSInv or "", Exports.QSInv or "", Exports.CoreInv or "", Exports.CodeMInv or "", Exports.OrigenInv or "" Exports.OXInv or "",
Exports.QBInv or "",
Exports.PSInv or "",
Exports.QSInv or "",
Exports.CoreInv or "",
Exports.CodeMInv or "",
Exports.OrigenInv or ""
RSGExport, RSGInv =
Exports.RSGExport or "",
Exports.RSGInv or ""
-- QB-Menu export name grabbed from exports.lua --
QBMenuExport = Exports.QBMenuExport or "" QBMenuExport = Exports.QBMenuExport or ""
-- Target exports based on what is loaded --
QBTargetExport, OXTargetExport = Exports.QBTargetExport or "", Exports.OXTargetExport or "" QBTargetExport, OXTargetExport = Exports.QBTargetExport or "", Exports.OXTargetExport or ""
-- If Debug mode is on in the loading script, print the list of found exports -- -------------------------------------------------------------
-- Some may "lie", 'ox_target' attempts to use 'qb-target' exports and this print will say its loaded (which is technically true) -- -- Debug: Print Found Exports
-------------------------------------------------------------
-- Print a list of all exports that are currently started (if debugMode is enabled).
for _, v in pairs(Exports) do for _, v in pairs(Exports) do
if isStarted(v) then debugPrint("^6Bridge^7: '^3"..v.."^7' ^2export found ^7") end if isStarted(v) then
debugPrint("^6Bridge^7: '^3"..v.."^7' export found")
end
end end
OxPlayer = nil
if isStarted(OXCoreExport) then
if not isServer() then
OxPlayer = Ox.GetPlayer()
end
end
-------------------------------------------------------------
-- Resource Variables for Items, Jobs, and Vehicles
-------------------------------------------------------------
local itemResource, jobResource, vehResource = "", "", "" local itemResource, jobResource, vehResource = "", "", ""
-- Load item lists -- -------------------------------------------------------------
-- Complies the items from ox_inventory, qb-core or esx into 'Items' and loads them in a layout similar to qb-core's Shared items.lua -- -- Loading Items
-- For example this makes it so instead of QBCore.Shared.Items[item], you can load 'Item[item]' in the script -- -------------------------------------------------------------
if isStarted(OXInv) then itemResource = OXInv -- Load and compile shared items from the detected inventory system.
if isStarted(OXInv) then
itemResource = OXInv
Items = exports[OXInv]:Items() Items = exports[OXInv]:Items()
for k, v in pairs(Items) do for k, v in pairs(Items) do
if v.client and v.client.image then if v.client and v.client.image then
@@ -39,7 +82,8 @@ if isStarted(OXInv) then itemResource = OXInv
Items[k].thirst = v.client and v.client.thirst or nil Items[k].thirst = v.client and v.client.thirst or nil
end end
elseif isStarted(QBExport) then itemResource = QBExport elseif isStarted(QBExport) then
itemResource = QBExport
Core = Core or exports[QBExport]:GetCoreObject() Core = Core or exports[QBExport]:GetCoreObject()
Items = Core and Core.Shared.Items or nil Items = Core and Core.Shared.Items or nil
if isStarted(QBExport) and not isStarted(QBXExport) then if isStarted(QBExport) and not isStarted(QBXExport) then
@@ -49,21 +93,53 @@ elseif isStarted(QBExport) then itemResource = QBExport
end) end)
end end
elseif isStarted(ESXExport) then itemResource = ESXExport elseif isStarted(ESXExport) then
itemResource = ESXExport
ESX = exports[ESXExport]:getSharedObject() ESX = exports[ESXExport]:getSharedObject()
Items = ESX and ESX.Items or nil while ESX == nil do
end print("Waiting for ESX")
-- If it fails to load items, then it will print the error below -- Wait(0)
-- If it loads them and debug is on, print how many items and where from -- end
if not Items then CreateThread(function()
print("^4ERROR^7: ^2No Core Items detected ^7- ^2Check ^3exports^1.^2lua^7") while not ESX do Wait(0) end
else if isServer() then
debugPrint("^6Bridge^7: ^2Loading ^6"..countTable(Items).." ^3Items^2 from ^7" .. itemResource) Items = ESX.GetItems()
while not createCallback do Wait(100) end
createCallback(getScript()..":getItems", function(source)
return Items
end)
end
if not isServer() then
Items = triggerCallback(getScript()..":getItems")
debugPrint("^6Bridge^7: ^2Loading ^6"..countTable(Items).." ^3Items^2 from ^7"..itemResource)
end
end)
elseif isStarted(RSGExport) then
itemResource = RSGExport
Core = Core or exports[RSGExport]:GetCoreObject()
Items = Core and Core.Shared.Items or nil
if isStarted(RSGExport) and not isStarted(QBXExport) then
RegisterNetEvent('QBCore:Client:UpdateObject', function()
Core = Core or exports[RSGExport]:GetCoreObject()
Items = Core and Core.Shared.Items or nil
end)
end
end end
-- Load Vehicles -- if itemResource == nil then
-- Complies the vehicles from the detected frameworks into a table in the style of qb-cores shared vehicles.lua -- print("^4ERROR^7: ^2No Item info detected ^7- ^2Check ^3starter^1.^2lua^7")
-- For example, instead of using QBCore.Shared.Vehicles[vehicle] you can load 'Vehicles[vehicle]' in the script -- else
while not Items do Wait(100) end
debugPrint("^6Bridge^7: ^2Loading ^6"..countTable(Items).." ^3Items^2 from ^7"..itemResource)
end
-------------------------------------------------------------
-- Loading Vehicles
-------------------------------------------------------------
-- Compile vehicles from the detected frameworks into a unified table.
if isStarted(QBXExport) or isStarted(QBExport) then if isStarted(QBXExport) or isStarted(QBExport) then
Core = Core or exports[QBExport]:GetCoreObject() Core = Core or exports[QBExport]:GetCoreObject()
Vehicles = Core and Core.Shared.Vehicles Vehicles = Core and Core.Shared.Vehicles
@@ -74,64 +150,95 @@ if isStarted(QBXExport) or isStarted(QBExport) then
end) end)
end end
vehResource = QBExport vehResource = QBExport
elseif isStarted(OXCoreExport) then elseif isStarted(OXCoreExport) then
Vehicles = {} Vehicles = {}
for k, v in pairs(Ox.GetVehicleData()) do for k, v in pairs(Ox.GetVehicleData()) do
Vehicles[k] = { model = k, price = v.price, name = v.name, brand = v.make } Vehicles[k] = { model = k, hash = GetHashKey(k), price = v.price, name = v.name, brand = v.make }
end end
vehResource = OXCoreExport vehResource = OXCoreExport
elseif isStarted(ESXExport) then elseif isStarted(ESXExport) then
-- print("^6Bridge^7: ^2Loading ^3Vehicles^2 from ^7"..ESXExport)
-- print("^6Bridge^7: ^2Loading ^6"..countTable(Vehicles).." ^3Vehicles^2 from ^7"..ESXExport)
CreateThread(function() CreateThread(function()
if isServer() then if isServer() then
vehResource = ESXExport
createCallback(getScript()..":getVehiclesPrices", function(source) createCallback(getScript()..":getVehiclesPrices", function(source)
Vehicles = MySQL.query.await('SELECT model, price, name FROM vehicles')
vehResource = ESXExport
return Vehicles return Vehicles
end) end)
while not MySQL do Wait(2000) print("^1Waiting for MySQL to exist") end
Vehicles = MySQL.query.await('SELECT model, price, name FROM vehicles')
--jsonPrint(Vehicles)
--while not createCallback do print("waiting") Wait(100) end
end end
if not isServer() then if not isServer() then
--while not triggerCallback do print("waiting") Wait(100) end
local TempVehicles = triggerCallback(getScript()..":getVehiclesPrices") local TempVehicles = triggerCallback(getScript()..":getVehiclesPrices")
for _, v in pairs(TempVehicles) do for _, v in pairs(TempVehicles) do
Vehicles = Vehicles or {} Vehicles = Vehicles or {}
Vehicles[v.model] = { model = v.model, price = v.price, name = v.name, brand = GetMakeNameFromVehicleModel(v.model):lower():gsub("^%l", string.upper) } Vehicles[v.model] = {
model = v.model,
hash = GetHashKey(v.model),
price = v.price,
name = v.name,
brand = GetMakeNameFromVehicleModel(v.model):lower():gsub("^%l", string.upper)
}
end end
end end
end) end)
elseif isStarted(RSGExport) then
Core = Core or exports[RSGExport]:GetCoreObject()
Vehicles = Core and Core.Shared.Vehicles
if isStarted(RSGExport) then
RegisterNetEvent('RSGExport:Client:UpdateObject', function()
Core = Core or exports[RSGExport]:GetCoreObject()
Vehicles = Core and Core.Shared.Vehicles
end)
end
vehResource = RSGExport
end end
if vehResource == nil then if vehResource == nil then
print("^4ERROR^7: ^2No Vehicle info detected ^7- ^2Check ^3exports^1.^2lua^7") print("^4ERROR^7: ^2No Vehicle info detected ^7- ^2Check ^3starter^1.^2lua^7")
else else
debugPrint("^6Bridge^7: ^2Loading ^6"..countTable(Vehicles).." ^3Vehicles^2 from ^7"..vehResource) CreateThread(function()
while not Vehicles do Wait(1000) print("Waiting") end
debugPrint("^6Bridge^7: ^2Loading ^6"..countTable(Vehicles).." ^3Vehicles^2 from ^7"..vehResource)
end)
end end
-- Load Jobs -- -------------------------------------------------------------
-- Attempts to load the details of jobs and gangs and compile into tables -- -- Loading Jobs and Gangs
-- For example, instead of using QBCore.Shared.Jobs[job] you can load 'Jobs[job]' in the script -- -------------------------------------------------------------
if isStarted(QBXExport) then jobResource = QBXExport -- Compile jobs and gangs from the detected framework.
if isStarted(QBXExport) then
jobResource = QBXExport
Core = Core or exports[QBExport]:GetCoreObject() Core = Core or exports[QBExport]:GetCoreObject()
Jobs, Gangs = exports[QBXExport]:GetJobs(), exports[QBXExport]:GetGangs() Jobs, Gangs = exports[QBXExport]:GetJobs(), exports[QBXExport]:GetGangs()
elseif isStarted(OXCoreExport) then jobResource = OXExport elseif isStarted(OXCoreExport) then
jobResource = OXExport
CreateThread(function() CreateThread(function()
if isServer() then if isServer() then
createCallback(getScript()..":getOxGroups", function(source) createCallback(getScript()..":getOxGroups", function(source)
Jobs = MySQL.query.await('SELECT * FROM `ox_groups`') return Jobs Jobs = MySQL.query.await('SELECT * FROM `ox_groups`')
return Jobs
end) end)
else else
local TempJobs = triggerCallback(getScript()..":getOxGroups") local TempJobs = triggerCallback(getScript()..":getOxGroups")
Jobs = TempJobs or {} Jobs = {}
for k, v in pairs(TempJobs) do for k, v in pairs(TempJobs) do
local grades = {} local grades = {}
for i = 1, #v.grades do grades[i] = { name = v.grades[i], isboss = (i == #v.grades)} end --for i = 1, #v.grades do
-- grades[i] = { name = v.grades[i], isboss = (i == #v.grades) }
--end
Jobs[v.name] = { label = v.label, grades = grades } Jobs[v.name] = { label = v.label, grades = grades }
end end
Gangs = Jobs Gangs = Jobs
end end
end) end)
elseif isStarted(QBExport) then jobResource = QBExport elseif isStarted(QBExport) then
jobResource = QBExport
Core = Core or exports[QBExport]:GetCoreObject() Core = Core or exports[QBExport]:GetCoreObject()
Jobs, Gangs = Core.Shared.Jobs, Core.Shared.Gangs Jobs, Gangs = Core.Shared.Jobs, Core.Shared.Gangs
if isStarted(QBExport) and not isStarted(QBXExport) then if isStarted(QBExport) and not isStarted(QBXExport) then
@@ -142,12 +249,11 @@ elseif isStarted(QBExport) then jobResource = QBExport
end end
elseif isStarted(ESXExport) then elseif isStarted(ESXExport) then
--print("^6Bridge^7: ^2Loading ^3Jobs^7/^3Gangs^2 from ^7"..ESXExport)
ESX = exports[ESXExport]:getSharedObject() ESX = exports[ESXExport]:getSharedObject()
if isServer() then if isServer() then
Jobs = ESX.GetJobs() Jobs = ESX.GetJobs()
for k, v in pairs(Jobs) do for k, v in pairs(Jobs) do
local count = countTable(Jobs[k].grades)-1 local count = countTable(Jobs[k].grades) - 1
Jobs[k].grades[tostring(count)].isBoss = true Jobs[k].grades[tostring(count)].isBoss = true
end end
Gangs = Jobs Gangs = Jobs
@@ -164,7 +270,23 @@ elseif isStarted(ESXExport) then
Gangs = Jobs Gangs = Jobs
end end
end) end)
elseif isStarted(RSGExport) then
jobResource = RSGExport
Core = Core or exports[RSGExport]:GetCoreObject()
Jobs, Gangs = Core.Shared.Jobs, Core.Shared.Gangs
if isStarted(RSGExport) and not isStarted(QBXExport) then
RegisterNetEvent('QBCore:Client:UpdateObject', function()
Core = exports[RSGExport]:GetCoreObject()
Jobs, Gangs = Core.Shared.Jobs, Core.Shared.Gangs
end)
end
end end
if not isStarted(ESXExport) and Jobs then
debugPrint("^6Bridge^7: ^2Loading ^6"..countTable(Jobs).." ^3Jobs^2 from ^7"..jobResource, "^6Bridge^7: ^2Loading ^6"..countTable(Gangs).." ^3Gangs^2 from ^7"..jobResource) if jobResource == nil then
print("^4ERROR^7: ^2No Vehicle info detected ^7- ^2Check ^3starter^1.^2lua^7")
else
while not Jobs do Wait(100) end
debugPrint("^6Bridge^7: ^2Loading ^6"..countTable(Jobs).." ^3Jobs^2 from ^7"..jobResource)
debugPrint("^6Bridge^7: ^2Loading ^6"..countTable(Gangs).." ^3Gangs^2 from ^7"..jobResource)
end end

View File

@@ -1,194 +1,312 @@
local CraftLock = false --[[
Crafting, Selling, and Shop Module
-----------------------------------
This module provides functions for opening crafting menus, handling multi-crafting,
performing the crafting process (with animations and progress bars), selling items,
and opening shop interfaces. It integrates with various inventory and menu systems,
and uses server callbacks to check item carry capacity.
]]
--- Opens a crafting menu based on the provided data. -------------------------------------------------------------
-- Global Variables
-------------------------------------------------------------
CraftLock = false
-- helper filter table for crafting menus
local excludeKeys = {
amount = true, metadata = true, description = true, info = true,
job = true, gang = true, oneUse = true, slot = true,
blueprintRef = true, craftingLevel = true, craftedItems = true,
hasCrafted = true, exp = true, anim = true, time = true,
}
-------------------------------------------------------------
-- Crafting Menu
-------------------------------------------------------------
--- Opens the crafting menu based on provided data.
--- Checks job restrictions, builds the recipe menu, and opens the menu.
--- ---
--- This function checks job requirements, prepares the menu options, and opens the crafting menu. --- @param data table Crafting menu configuration containing:
--- It handles item availability, crafting recipes, and displays appropriate icons and labels. --- - craftable (`table`) Table with Header, Recipes, Anims, and (optionally) craftedItems.
--- - coords (`vector3`) The coordinates where the crafting menu is being opened.
--- - stashTable|stashName (`string\table`) Name(s) of the stash for checking item availability.
--- - job|gang (`string`) Job or gang requirements.
--- - onBack (optional): Function to call when returning.
--- ---
---@param data table A table containing crafting menu data. --- @usage
--- - **craftable** (`table`): The crafting options and settings.
--- - **Header** (`string`): The header/title of the crafting menu.
--- - **Recipes** (`table`): A list of crafting recipes.
--- - **coords** (`vector3`): The coordinates where the crafting menu is being opened.
--- - **stashTable** (`string` or `table`, optional): The stash name(s) to check for item availability.
--- - **stashName** (`string` or `table`, optional): Alias for `stashTable`.
--- - **job** (`string` or `table`, optional): Job(s) required to access the crafting menu.
--- - **gang** (`string` or `table`, optional): Gang(s) required to access the crafting menu.
--- - **onBack** (`function`, optional): Function to call when returning from the menu.
---
---@usage
--- ```lua --- ```lua
--- craftingMenu({ --- craftingMenu({
--- craftable = { --- craftable = {
--- Header = "Weapon Crafting", --- Header = "Weapon Crafting",
--- Recipes = { --- Recipes = {
--- [1] = { --- [1] = {
--- ["weapon_pistol"] = { ["steel"] = 5, ["plastic"] = 2 }, --- ["weapon_pistol"] = { ["steel"] = 5, ["plastic"] = 2 },
--- amount = 1, --- amount = 1,
--- }, --- },
--- -- More recipes... --- -- More recipes...
--- }, --- },
--- Anims = { --- Anims = {
--- animDict = "amb@prop_human_parking_meter@male@idle_a", --- animDict = "amb@prop_human_parking_meter@male@idle_a",
--- anim = "idle_a", --- anim = "idle_a",
--- }, --- },
--- }, --- },
--- coords = vector3(100.0, 200.0, 300.0), --- coords = vector3(100.0, 200.0, 300.0),
--- stashTable = "crafting_stash", --- stashTable = "crafting_stash",
--- job = "mechanic", -- Optional --- job = "mechanic",
--- onBack = function() print("Returning to previous menu") end, --- onBack = function() print("Returning to previous menu") end,
--- }) --- })
--- ```
function craftingMenu(data) function craftingMenu(data)
if CraftLock then return end if CraftLock then return end
-- Job or gang check; exit if not authorized.
if (data.job or data.gang) and not jobCheck(data.job or data.gang) then return end if (data.job or data.gang) and not jobCheck(data.job or data.gang) then return end
-- Display a temporary "thinking" notification.
if Config.System.Menu == "jim" then if Config.System.Menu == "jim" then
triggerNotify(nil, "Thinking", "info") triggerNotify(nil, "Thinking", "info")
else else
openMenu({ { header = "Thinking...", icon = "fas fa-hourglass-end", isMenuHeader = true } }, { header = "Crafting Menu" } ) openMenu({ { header = "Thinking...", icon = "fas fa-hourglass-end", isMenuHeader = true } }, { header = "Crafting Menu" } )
end end
if data.stashTable then data.stashName = data.stashTable end
local Menu, hasjob = {}, false -- Normalize stash name.
data.stashName = data.stashTable or data.stashName
local Menu = {}
local Recipes = data.craftable.Recipes local Recipes = data.craftable.Recipes
local craftedItems = {}
local tempCarryTable = {} local tempCarryTable = {}
-- Build a table of all required ingredients (default quantity is 1).
for i = 1, #Recipes do for i = 1, #Recipes do
for k in pairs(Recipes[i]) do for k in pairs(Recipes[i]) do
if k == "hasCrafted" and not data.craftable.craftedItems then
-- Retreive list of already crafted items from playermetadata to see if we should class this recipe as "new"
craftedItems = GetMetadata(nil, "craftedItems") or {}
data.craftable.craftedItems = craftedItems
end
if k ~= "amount" and k ~= "metadata" and k ~= "job" and k ~= "gang" then if k ~= "amount" and k ~= "metadata" and k ~= "job" and k ~= "gang" then
tempCarryTable[k] = Recipes[i].amount or 1 tempCarryTable[k] = Recipes[i].amount or 1
end end
end end
end end
-- Check if the player can carry the required items (server callback).
local canCarryTable = triggerCallback(getScript()..':server:canCarry', tempCarryTable) local canCarryTable = triggerCallback(getScript()..':server:canCarry', tempCarryTable)
-- Process each recipe to create menu entries.
for i = 1, #Recipes do for i = 1, #Recipes do
if not Recipes[i]["amount"] then Recipes[i]["amount"] = 1 end if not Recipes[i]["amount"] then Recipes[i]["amount"] = 1 end
for k, v in pairs(Recipes[i]) do for k, _ in pairs(Recipes[i]) do
if k ~= "amount" and k ~= "metadata" and k ~= "job" and k ~= "gang" then if not excludeKeys[k] then
local hasjob = true
if Recipes[i].job then if Recipes[i].job then
for l, b in pairs(Recipes[i].job) do for l, b in pairs(Recipes[i].job) do
hasjob = hasJob(l, nil, b) hasjob = hasJob(l, nil, b)
if hasjob == true then break end if hasjob then break end
end end
else hasjob = true end end
local setheader, settext, disable, metadata = "", "", false, (Recipes[i]["metadata"] or nil)
if hasjob then if hasjob then
local setheader, settext, disable, metadata = "", "", false, (Recipes[i]["metadata"] or Recipes[i]["info"] or nil)
local itemTable = {} local itemTable = {}
local metaTable = {} local metaTable = {}
-- Build ingredient details.
for l, b in pairs(Recipes[i][tostring(k)]) do for l, b in pairs(Recipes[i][tostring(k)]) do
settext = settext..(settext ~= "" and br or "")..(Items[l] and Items[l].label or "error - "..l)..(b > 1 and " x"..b or "") settext = settext..(settext ~= "" and br or "")..(Items[l] and Items[l].label or "error - "..l)..(b > 1 and " x"..b or "")
metaTable[Items[l] and Items[l].label or "error - "..l] = b metaTable[Items[l] and Items[l].label or "error - "..l] = b
itemTable[l] = b itemTable[l] = b
Wait(0) Wait(0)
end end
while not canCarryTable do Wait(0) end while not canCarryTable do Wait(0) end
disable = not checkHasItem(data.stashName, itemTable) disable = not checkStashItem(data.stashName, itemTable)
setheader = ((metadata and metadata.label) or (Items[tostring(k)] and Items[tostring(k)].label) or "error - " .. tostring(k)) .. (Recipes[i]["amount"] > 1 and " x" .. Recipes[i]["amount"] or "") setheader = ((metadata and metadata.label) or (Items[tostring(k)] and Items[tostring(k)].label) or "error - "..tostring(k))
..(Recipes[i]["amount"] > 1 and " x"..Recipes[i]["amount"] or "")
if not disable then if not disable then
if not canCarryTable[k] then setheader = setheader .. " 📦" if not canCarryTable[k] then
else setheader = setheader .. " ✔️" end setheader = setheader.." 📦"
elseif not canCarryTable[k] then setheader = setheader .. " 📦" end else
setheader = setheader.." ✔️"
end
elseif not canCarryTable[k] then
setheader = setheader.." 📦"
end
if Recipes[i]["hasCrafted"] ~= nil and craftedItems[k] == nil then
setheader = ""..setheader
end
Menu[#Menu + 1] = { Menu[#Menu + 1] = {
arrow = not disable and canCarryTable[k], arrow = not disable and canCarryTable[k],
disable = isStarted(QBMenuExport) and disable and not canCarryTable[k], isMenuHeader = disable or not canCarryTable[k],
icon = invImg((metadata and metadata.image) or tostring(k)), icon = invImg((metadata and metadata.image) or tostring(k)),
image = invImg((metadata and metadata.image) or tostring(k)), image = invImg((metadata and metadata.image) or tostring(k)),
header = setheader..((disable or not canCarryTable[k]) and "" or ""), header = setheader..((disable or not canCarryTable[k]) and "" or ""),
txt = isStarted(QBMenuExport) and settext or nil, txt = (isStarted(QBMenuExport) or disable) and settext or nil,
--metadata = debugMode and Recipes[i]["metadata"] or nil,
metadata = metaTable, metadata = metaTable,
onSelect = ((not disable and canCarryTable[k]) and (function() onSelect = (not disable and canCarryTable[k]) and function()
local transdata = { item = k, craft = data.craftable.Recipes[i], craftable = data.craftable, coords = data.coords, stashName = data.stashName, onBack = data.onBack, metadata = Recipes[i]["metadata"] } local transdata = {
if Config.Crafting.MultiCraft then multiCraft(transdata) else makeItem(transdata) end item = k,
end) or nil), craft = data.craftable.Recipes[i],
craftable = data.craftable,
coords = data.coords,
stashName = data.stashName,
onBack = data.onBack,
metadata = metadata,
}
if Config.Crafting.MultiCraft then
multiCraft(transdata)
else
makeItem(transdata)
end
end or nil,
} }
end end
end end
Wait(0) Wait(0)
end end
end end
openMenu(Menu, { header = data.craftable.Header, onBack = data.onBack or nil, canClose = true, onExit = function() end, })
openMenu(Menu, {
header = data.craftable.Header,
headertxt = data.craftable.Headertxt,
onBack = data.onBack or nil,
canClose = true,
onExit = data.onExit or (function() end),
})
lookEnt(data.coords) lookEnt(data.coords)
end end
-------------------------------------------------------------
-- Multi-Craft Menu
-------------------------------------------------------------
--- Opens a menu for selecting the quantity to craft. --- Opens a menu for selecting the quantity to craft.
--- ---
--- This function presents the player with options to craft multiple quantities of an item, based on `Config.Crafting.MultiCraftAmounts`. --- Presents the player with multiple crafting quantities based on Config.Crafting.MultiCraftAmounts.
--- ---
---@param data table A table containing crafting data. --- @param data table Crafting configuration containing:
--- - **item** (`string`): The item to craft. --- - item `string`) The item to craft.
--- - **craft** (`table`): The crafting recipe for the item. --- - craft (`table`) The crafting recipe.
--- - **craftable** (`table`): The crafting options and settings. --- - craftable (`table`) Crafting options.
--- - **coords** (`vector3`): The coordinates where the crafting is taking place. --- - coords (`vector3`) where crafting occurs.
--- - **stashName** (`string` or `table`, optional): The stash name(s) to check for item availability. --- - stashName (`string`) The stash name(s) for item availability.
--- - **onBack** (`function`, optional): Function to call when returning from the menu. --- - onBack (`function`) Callback when returning.
--- - **metadata** (`table`, optional): Metadata for the crafted item. --- - metadata (`table`) (optional): Metadata for the crafted item.
--- ---
---@usage --- @usage
--- ```lua --- ```lua
--- multiCraft({ --- multiCraft({
--- item = "weapon_pistol", --- item = "weapon_pistol",
--- craft = { ["weapon_pistol"] = { ["steel"] = 5, ["plastic"] = 2 }, amount = 1 }, --- craft = { ["weapon_pistol"] = { ["steel"] = 5, ["plastic"] = 2 }, amount = 1 },
--- craftable = craftingOptions, --- craftable = craftingOptions,
--- coords = vector3(100.0, 200.0, 300.0), --- coords = vector3(100,200,300),
--- stashName = "crafting_stash", --- stashName = "crafting_stash",
--- onBack = function() craftingMenu(data) end, --- onBack = function() craftingMenu(data) end,
--- metadata = { label = "Custom Pistol", image = "custom_pistol.png" }, --- metadata = { label = "Custom Pistol", image = "custom_pistol.png" },
--- }) --- })
--- ``` --- ```
function multiCraft(data) function multiCraft(data)
local Menu = {} local max = 0
local success = Config.Crafting.MultiCraftAmounts local stashName = nil
local metadata = data.metadata or nil for i = 1, 100 do
Menu[#Menu+1] = {
isMenuHeader = true,
icon = invImg(metadata and metadata.image or data.item),
header = metadata and metadata.label or Items[data.item].label,
}
for k in pairsByKeys(success) do
local settext = ""
local itemTable = {} local itemTable = {}
for l, b in pairs(data.craft[data.item]) do for l, b in pairs(data.craft[data.item]) do
itemTable[l] = (b * k) debugPrint("")
settext = settext..(settext ~= "" and br or "")..Items[l].label..(b*k > 1 and "- x"..b*k or "") itemTable[l] = (b * i)
Wait(0)
end end
local disable, stashname = checkHasItem(data.stashName, itemTable)
Menu[#Menu + 1] = { if data.stashName then
isMenuHeader = not disable, debugPrint("")
arrow = disable, local hasItems, stashname = checkStashItem(data.stashName, itemTable)
header = "Craft - x"..k * data.craft.amount, if hasItems == true then
txt = settext, max += 1
onSelect = function () stashName = stashname
makeItem({item = data.item, craft = data.craft, craftable = data.craftable, amount = k, coords = data.coords, stashName = stashname, stashTable = data.stashName, onBack = data.onBack, metadata = data.metadata }) else
end, break
} end
else
debugPrint("")
local has, _ = hasItem(itemTable, nil, nil)
if has then
max += 1
else
break
end
end
Wait(10)
end
local dialog = createInput(data.craftable.Header, {
((Config.System.Menu == "ox") and {
type = "slider",
label = "How many to craft?",
required = true,
default = 1,
min = 1,
max = max
}) or nil,
((Config.System.Menu == "qb") and {
type = "number",
label = "How many to craft?"..br.."Max: "..max,
name = "amount",
isRecuired = true,
default = 1,
}) or nil,
})
if dialog then
if Config.System.Menu == "ox" then
end
if Config.System.Menu == "qb" then
if dialog["amount"] > max or dialog["amount"] < 1 or dialog["amount"] == nil or dialog["amount"] == "" then
triggerNotify(nil, "Invalid Amount", "error")
craftingMenu(data)
return
end
end
makeItem({
item = data.item,
craft = data.craft,
craftable = data.craftable,
amount = dialog["amount"] or dialog[1],
coords = data.coords,
stashName = stashName or nil,
--stashTable = data.stashName,
onBack = data.onBack,
metadata = data.metadata,
})
end end
openMenu(Menu, { header = data.craftable.Header, onBack = function() craftingMenu(data) end, })
end end
-------------------------------------------------------------
-- Crafting Process
-------------------------------------------------------------
--- Initiates the crafting process for a specified item. --- Initiates the crafting process for a specified item.
--- ---
--- This function handles the crafting animation, progress bar, item removal, and item creation. --- Plays crafting animations, shows progress bars, removes ingredients, and triggers item creation.
--- ---
---@param data table A table containing crafting data. --- @param data table Crafting configuration containing:
--- - **item** (`string`): The item to craft. --- - item `string`) The item to craft.
--- - **craft** (`table`): The crafting recipe for the item. --- - craft (`table`) The crafting recipe.
--- - **craftable** (`table`): The crafting options and settings. --- - craftable (`table`) Crafting options.
--- - **amount** (`number`, optional): The quantity to craft. Default is `1`. --- - amount (`number`) (optional): Quantity to craft (default 1).
--- - **coords** (`vector3`): The coordinates where the crafting is taking place. --- - coords (`vector3`) where crafting occurs.
--- - **stashName** (`string` or `table`, optional): The stash name(s) to remove items from. --- - stashName (`string`) The stash name(s) for item availability.
--- - **stashTable** (`string` or `table`, optional): Alias for `stashName`. --- - onBack (`function`) Callback when returning.
--- - **onBack** (`function`, optional): Function to call when returning from the menu. --- - metadata (`table`) (optional): Metadata for the crafted item.
--- - **metadata** (`table`, optional): Metadata for the crafted item.
--- ---
---@usage --- @usage
--- ```lua --- ```lua
--- makeItem({ --- makeItem({
--- item = "weapon_pistol", --- item = "weapon_pistol",
--- craft = { ["weapon_pistol"] = { ["steel"] = 5, ["plastic"] = 2 }, amount = 1 }, --- craft = { ["weapon_pistol"] = { ["steel"] = 5, ["plastic"] = 2 }, amount = 1 },
--- craftable = craftingOptions, --- craftable = craftingOptions,
--- amount = 2, --- amount = 2,
--- coords = vector3(100.0, 200.0, 300.0), --- coords = vector3(100,200,300),
--- stashName = "crafting_stash", --- stashName = "crafting_stash",
--- onBack = function() craftingMenu(data) end, --- onBack = function() craftingMenu(data) end,
--- metadata = { label = "Custom Pistol", image = "custom_pistol.png" }, --- metadata = { label = "Custom Pistol", image = "custom_pistol.png" },
@@ -197,22 +315,26 @@ end
function makeItem(data) function makeItem(data)
if CraftLock then return end if CraftLock then return end
CraftLock = true CraftLock = true
if data.stashTable then data.stashName = data.stashTable end data.stashName = data.stashTable or data.stashName
local bartime = data.craftable.progressBar and data.craftable.progressBar.time or 5000
local bartext = (data.craftable.progressBar and data.craftable.progressBar.label) or (Loc[Config.Lan].progressbar and Loc[Config.Lan].progressbar["progress_make"]) or "Making a" local bartime = (data.craftable.progressBar and data.craftable.progressBar.time) or 5000
local animDict = data.craftable.Anims and data.craftable.Anims.animDict or "amb@prop_human_parking_meter@male@idle_a" local bartext = (data.craftable.progressBar and data.craftable.progressBar.label)
local anim = data.craftable.Anims and data.craftable.Anims.anim or "idle_a" or (Loc[Config.Lan].progressbar and Loc[Config.Lan].progressbar["progress_make"])
local amount = data.amount and (data.amount ~= 1) and data.amount or 1 or "Making "
local animDict = (data.craftable.Anims and data.craftable.Anims.animDict) or "amb@prop_human_parking_meter@male@idle_a"
local anim = (data.craftable.Anims and data.craftable.Anims.anim) or "idle_a"
local craftAmount = (data.amount and data.amount ~= 1) and data.amount or 1
local metadata = data.metadata or nil local metadata = data.metadata or nil
local prop = data.craftable.Anims and data.craftable.Anims.prop or nil local prop = data.craftable.Anims and data.craftable.Anims.prop or nil
local canReturn = true
local crafted, crafting = true, true local crafted, crafting = true, true
local cam = createTempCam(PlayerPedId(), data.coords) local cam = createTempCam(PlayerPedId(), data.coords)
startTempCam(cam) startTempCam(cam)
for i = 1, amount do for i = 1, craftAmount do
for k, v in pairs(data.craft) do for k, v in pairs(data.craft) do
if k ~= "amount" and k ~= "metadata" and k ~= "job" and k ~= "gang" then if not excludeKeys[k] then
if type(v) == "table" then if type(v) == "table" then
for l, b in pairs(v) do for l, b in pairs(v) do
if crafting and progressBar({ if crafting and progressBar({
@@ -224,7 +346,7 @@ function makeItem(data)
flag = 48, flag = 48,
icon = l, icon = l,
}) then }) then
TriggerEvent((isStarted(QBInv) and QBInvNew and "qb-" or "").."inventory:client:ItemBox", Items[l], "use", b) -- Show item box for each item TriggerEvent((isStarted(QBInv) and QBInvNew and "qb-" or "")..'inventory:client:ItemBox', Items[l], "use", b)
else else
crafted, crafting = false, false crafted, crafting = false, false
break break
@@ -234,9 +356,12 @@ function makeItem(data)
if crafted then if crafted then
local craftProp = nil local craftProp = nil
if prop then if prop then
local model, pos, rot, bone = prop.model, prop.pos, prop.rot, prop.bone craftProp = makeProp({ prop = prop.model, coords = vec4(0, 0, 0, 0), true, true })
craftProp = makeProp({ prop = model, coords = vec4(0, 0, 0, 0), true, true }) AttachEntityToEntity(craftProp, PlayerPedId(), GetPedBoneIndex(PlayerPedId(), prop.bone), prop.pos.x, prop.pos.y, prop.pos.z, prop.rot.x, prop.rot.y, prop.rot.z, true, true, false, true, 1, true)
AttachEntityToEntity(craftProp, PlayerPedId(), GetPedBoneIndex(PlayerPedId(), bone), pos.x, pos.y, pos.z, rot.x, rot.y, rot.z, true, true, false, true, 1, true) end
if data.sound then
local s = data.sound
PlaySoundFromEntity(s.soundId, s.audioName, PlayerPedId(), s.audioRef, true, 0)
end end
if crafting and progressBar({ if crafting and progressBar({
label = bartext..((metadata and metadata.label) or Items[data.item].label), label = bartext..((metadata and metadata.label) or Items[data.item].label),
@@ -248,6 +373,32 @@ function makeItem(data)
icon = data.item, icon = data.item,
}) then }) then
TriggerServerEvent(getScript()..":Crafting:GetItem", data.item, data.craft, data.stashName, metadata) TriggerServerEvent(getScript()..":Crafting:GetItem", data.item, data.craft, data.stashName, metadata)
CreateThread(function()
if data.craft["hasCrafted"] ~= nil then
debugPrint("hasCrafted Found, marking '"..data.item.."' as crafted for player")
data.craftable.craftedItems[data.item] = true
triggerCallback(getScript()..":server:SetMetadata", "craftedItems", data.craftable.craftedItems)
end
Wait(100)
if data.craft["exp"] ~= nil then
craftingLevel += data.craft["exp"].give
jsonPrint(data.craft["exp"])
debugPrint("exp found, giving exp for '"..data.item.."'")
triggerCallback(getScript()..":server:SetMetadata", "craftingLevel", craftingLevel)
end
end)
if data.craftable.Recipes[1].oneUse == true then
removeItem("craftrecipe", 1, nil, data.craftable.Recipes[1].slot)
local breakId = GetSoundId()
PlaySoundFromEntity(breakId, "Drill_Pin_Break", PlayerPedId(), "DLC_HEIST_FLEECA_SOUNDSET", 1, 0)
canReturn = false
end
if data.sound then
StopSound(data.sound.soundId)
end
if data.requiredItemfunc then
data.requiredItemfunc()
end
else else
crafting = false crafting = false
break break
@@ -262,20 +413,27 @@ function makeItem(data)
stopTempCam() stopTempCam()
CraftLock = false CraftLock = false
lockInv(false) lockInv(false)
craftingMenu(data) if canReturn then craftingMenu(data) end
ClearPedTasks(PlayerPedId()) ClearPedTasks(PlayerPedId())
end end
-------------------------------------------------------------
-- Server Event Handler: Crafted Item
-------------------------------------------------------------
--- Server event handler for giving the crafted item to the player. --- Server event handler for giving the crafted item to the player.
--- ---
--- This event is triggered when the crafting process is completed successfully. --- Removes required ingredients from the player's inventory or stash,
--- then adds the crafted item to their inventory.
--- ---
--- @param ItemMake string The item being crafted. --- @param ItemMake string The item being crafted.
--- @param craftable table The crafting recipe and details. --- @param craftable table The crafting recipe and details.
--- @param stashName string|table The stash name(s) to remove items from. --- @param stashName string|table The stash name(s) to remove ingredients from.
--- @param metadata table (optional) Metadata for the crafted item. --- @param metadata table (optional) Metadata for the crafted item.
--- @usage
RegisterNetEvent(getScript()..":Crafting:GetItem", function(ItemMake, craftable, stashName, metadata) RegisterNetEvent(getScript()..":Crafting:GetItem", function(ItemMake, craftable, stashName, metadata)
local src, amount, stashItems = source, craftable and craftable.amount or 1, nil local src = source
local hasItems, hasTable = hasItem(ItemMake, 1, src)
if stashName then if stashName then
local itemRemove = {} local itemRemove = {}
if type(stashName) == "table" then if type(stashName) == "table" then
@@ -299,183 +457,12 @@ RegisterNetEvent(getScript()..":Crafting:GetItem", function(ItemMake, craftable,
else else
if craftable then if craftable then
for k, v in pairs(craftable[ItemMake] or {}) do for k, v in pairs(craftable[ItemMake] or {}) do
TriggerEvent(getScript()..":server:toggleItem", false, tostring(k), v, src) removeItem(tostring(k), v, src)
end end
end end
end end
TriggerEvent(getScript()..":server:toggleItem", true, ItemMake, amount, src, metadata) addItem(ItemMake, craftable.amount or 1, metadata, src)
--if isStarted("core_skills") then exports["core_skills"]:AddExperience(src, 2) end -- Optionally, add experience here:
-- for example:
-- if isStarted("core_skills") then exports["core_skills"]:AddExperience(src, 2) end
end) end)
--- Opens a selling menu based on the provided data.
---
--- This function checks available items to sell, prepares the menu options, and opens the selling menu.
---
---@param data table A table containing selling menu data.
--- - **sellTable** (`table`): The selling options and settings.
--- - **Items** (`table`): A list of items that can be sold with their prices.
--- - **Header** (`string`, optional): The header/title of the selling menu.
--- - **ped** (`number`, optional): The ped entity involved in the selling interaction.
--- - **onBack** (`function`, optional): Function to call when returning from the menu.
---
---@usage
--- ```lua
--- sellMenu({
--- sellTable = {
--- Header = "Sell Items",
--- Items = {
--- ["gold_ring"] = 100,
--- ["diamond"] = 500,
--- },
--- },
--- ped = pedEntity,
--- onBack = function() print("Returning to previous menu") end,
--- })
--- ```
function sellMenu(data)
local origData = data
local Menu = {}
if data.sellTable.Items then
local itemList = {}
for k, v in pairs(data.sellTable.Items) do itemList[k] = 1 end
local _, hasTable = hasItem(itemList)
for k, v in pairsByKeys(data.sellTable.Items) do
Menu[#Menu +1] = {
isMenuHeader = not hasTable[k].hasItem,
icon = invImg(k),
header = Items[k].label.. (hasTable[k].hasItem and "💰 (x"..hasTable[k].count..")" or ""),
txt = Loc[Config.Lan].info["sell_all"]..v.." "..Loc[Config.Lan].info["sell_each"],
onSelect = function()
sellAnim({ item = k, price = v, ped = data.ped, onBack = function() sellMenu(data) end })
end,
}
end
else
for k, v in pairsByKeys(data.sellTable) do
if type(v) == "table" then
Menu[#Menu +1] = {
arrow = true,
header = k,
txt = "Amount of items: "..countTable(v.Items),
onSelect = function()
v.onBack = function() sellMenu(origData) end
v.sellTable = data.sellTable[k]
sellMenu(v)
end,
}
end
end
end
openMenu(Menu, { header = data.sellTable.Header or "Amount of items: "..countTable(data.sellTable.Items), headertxt = data.sellTable.Header and "Amount of items: "..countTable(data.sellTable.Items) or "", canClose = true, onBack = data.onBack })
end
--- Handles the selling animation and item transaction.
---
--- This function plays the selling animation, removes the item from the player's inventory, and gives the player money.
---
---@param data table A table containing selling data.
--- - **item** (`string`): The item to sell.
--- - **price** (`number`): The price per item.
--- - **ped** (`number`, optional): The ped entity involved in the selling interaction.
--- - **onBack** (`function`, optional): Function to call when returning from the menu.
---
---@usage
--- ```lua
--- sellAnim({
--- item = "gold_ring",
--- price = 100,
--- ped = pedEntity,
--- onBack = function() sellMenu(data) end,
--- })
--- ```
function sellAnim(data)
if not hasItem(data.item, 1) then
triggerNotify(nil, Loc[Config.Lan].error["dont_have"].." "..Items[data.item].label, "error")
return
end
for k, v in pairs(GetGamePool('CObject')) do
for _, model in pairs({`p_cs_clipboard`}) do
if GetEntityModel(v) == model then
if IsEntityAttachedToEntity(data.ped, v) then
DeleteObject(v) DetachEntity(v, 0, 0) SetEntityAsMissionEntity(v, true, true)
Wait(100) DeleteEntity(v)
end
end
end
end
TriggerServerEvent(getScript().."Sellitems", data)
lookEnt(data.ped)
local dict = "mp_common"
playAnim(dict, "givetake2_a", 0.3, 2)
playAnim(dict, "givetake2_b", 0.3, 2, data.ped)
Wait(2000)
StopAnimTask(PlayerPedId(), dict, "givetake2_a", 0.5)
StopAnimTask(data.ped, dict, "givetake2_b", 0.5)
if data.onBack then data.onBack() end
end
--- Server event handler for processing the item sale.
---
--- This event removes the sold item from the player's inventory and adds money to their account.
---
---@param data table The data containing item and price information.
RegisterNetEvent(getScript().."Sellitems", function(data)
local src = source
local hasItems, hasTable = hasItem(data.item, 1, src)
if hasItems then
TriggerEvent(getScript()..":server:toggleItem", false, data.item, hasTable[data.item].count, src)
TriggerEvent(getScript()..":server:FundPlayer", (hasTable[data.item].count * data.price), "cash", src)
else
triggerNotify(nil, Loc[Config.Lan].error["dont_have"].." "..Items[data.item].label, "error", src)
end
end)
--- Opens a shop interface for the player.
---
--- This function checks job requirements and opens the shop using the appropriate inventory system.
---
---@param data table A table containing shop data.
--- - **shop** (`string`): The shop identifier.
--- - **items** (`table`): The items available in the shop.
--- - **coords** (`vector3`): The coordinates where the shop interaction is happening.
--- - **job** (`string` or `table`, optional): Job(s) required to access the shop.
--- - **gang** (`string` or `table`, optional): Gang(s) required to access the shop.
---
---@usage
--- ```lua
--- openShop({
--- shop = "weapon_shop",
--- items = weaponShopItems,
--- coords = vector3(100.0, 200.0, 300.0),
--- job = "police",
--- })
--- ```
function openShop(data)
if (data.job or data.gang) and not jobCheck(data.job or data.gang) then return end
if isStarted(OXInv) then
exports[OXInv]:openInventory('shop', { type = data.shop })
elseif isStarted(QBInv) then
if QBInvNew then
TriggerServerEvent(getScript()..':server:OpenShopNewQB', data.shop) -- i hate qb-inv
else
TriggerServerEvent(Config.General.JimShops and "jim-shops:ShopOpen" or "inventory:server:OpenInventory", "shop", data.items.label, data.items)
end
else
TriggerServerEvent(Config.General.JimShops and "jim-shops:ShopOpen" or "inventory:server:OpenInventory", "shop", data.items.label, data.items)
end
lookEnt(data.coords)
end
--- Server event handler for opening a new QB inventory shop.
---
--- This event is triggered when using the new QB inventory system.
---
---@param data table The shop data to open.
RegisterNetEvent(getScript()..':server:OpenShopNewQB', function(data)
exports[QBInv]:OpenShop(source, data)
end)
--- Server-side callback registration for checking if the player can carry items.
if isServer() then
createCallback(getScript()..':server:canCarry', function(source, itemTable) local result = canCarry(itemTable, source) return result end)
end

View File

@@ -1,53 +1,88 @@
local radarTable = {} --[[
Text Drawing Module
---------------------
This module provides functions to display and hide text on screen using
various frameworks: QB, OX, GTA, and ESX.
]]
--- Displays text on the screen using the configured draw text system. --- Displays text on the screen using the configured draw text system.
--- ---
--- This function handles displaying text with optional images or icons using different frameworks like 'qb', 'ox', 'gta', and 'esx'. --- Depending on Config.System.drawText, this function will use different methods to
--- display text along with optional images/icons.
--- ---
---@param image string|nil An optional image or icon to display with the text. Can be a URL, path, or a reference to an icon. --- @param image string|nil Optional image/icon identifier to display with the text.
---@param input table A table of strings, each representing a line of text to display. --- @param input table An array of strings; each string is a line of text to display.
---@param style string|nil An optional style code for default GTA popups (e.g., '~g~' for green text). --- @param style string|nil Optional style code for default GTA popups (e.g., "~g~" for green).
---@param oxStyleTable table|nil An optional table specifying style parameters for the 'ox' draw text system. --- @param oxStyleTable table|nil Optional table specifying style parameters for the OX text UI.
--- ---
---@usage ---@usage
--- ```lua --- ```lua
--- drawText("img_link", { "Test line 1", "Test Line 2" }, "~g~") --- drawText("img_link", { "Test line 1", "Test Line 2" }, "~g~")
--- ``` --- ```
function drawText(image, input, style, oxStyleTable) local text = "" function drawText(image, input, style, oxStyleTable)
if Config.System.drawText == "qb" then local text = ""
for i = 1, #input do if not radarTable then radarTable = {} end
text = text..input[i].."</span>"..(input[i+1] ~= nil and "<br>" or "") end if Config.System.drawText == "qb" then
local text = text:gsub("%:", ":<span style='color:yellow'>") -- Concatenate lines for QB system with HTML line breaks.
if image then
text = '<img src="'..(radarTable[image] or nil)..'" style="width:12px;height:12px">'..text
end
exports[QBExport]:DrawText(text, 'left')
elseif Config.System.drawText == "ox" then
for k, v in pairs(input) do
input[k] = v.." \n"
end
lib.showTextUI(table.concat(input), { icon = (image and radarTable[image] or image) or nil, position = 'left-center', style = oxStyleTable})
elseif Config.System.drawText == "gta" then
for i = 1, #input do if input[i] ~= "" then text = text..input[i].."\n~s~" end end
if image then text = "~BLIP_"..image.."~ "..text end
DisplayHelpMsg(text:gsub("%:", ":~"..(style or "g").."~"))
elseif Config.System.drawText == "esx" then
for i = 1, #input do for i = 1, #input do
text = text..input[i].."</span>"..(input[i+1] ~= nil and "<br>" or "") end text = text..input[i].."</span>"..(input[i + 1] and "<br>" or "")
local text = text:gsub("%:", ":<span style='color:yellow'>") end
if image then text = text:gsub("%:", ":<span style='color:yellow'>")
text = '<img src="'..radarTable[image]..'" style="width:12px;height:12px">'..text if image then
end text = '<img src="'..(radarTable[image] or "")..'" style="width:12px;height:12px">'..text
ESX.TextUI(text, nil) end
end exports[QBExport]:DrawText(text, 'left')
elseif Config.System.drawText == "ox" then
-- Append newline spacing to each input line.
for k, v in pairs(input) do
input[k] = v.." \n"
end
lib.showTextUI(table.concat(input), { icon = (image and radarTable[image] or image) or nil, position = 'left-center', style = oxStyleTable })
elseif Config.System.drawText == "gta" then
-- Concatenate input lines and apply GTA style formatting.
for i = 1, #input do
if input[i] ~= "" then
text = text..input[i].."\n~s~"
end
end
if image then
text = "~BLIP_"..image.."~ "..text
end
DisplayHelpMsg(text:gsub("%:", ":~"..(style or "g").."~"))
elseif Config.System.drawText == "esx" then
-- ESX-based text UI uses similar HTML formatting as QB.
for i = 1, #input do
text = text..input[i].."</span>"..(input[i + 1] and "<br>" or "")
end
text = text:gsub("%:", ":<span style='color:yellow'>")
if image then
text = '<img src="'..(radarTable[image] or "")..'" style="width:12px;height:12px">'..text
end
ESX.TextUI(text, nil)
elseif Config.System.drawText == "red" then
-- Concatenate input lines and apply GTA style formatting.
for i = 1, #input do
if input[i] ~= "" then
text = text..input[i].."\n~q~"
end
end
TriggerEvent("jim-redui:DrawText", text)
end
end end
--- Hides any text currently being displayed on the screen. --- Hides any text currently displayed on the screen.
--- ---
--- This function clears the text displayed by the `drawText` function, using the appropriate method based on the configured draw text system. --- Clears the text using the appropriate method for the configured draw text system.
---
--- @usage
--- ```lua
--- hideText()
--- ```
function hideText() function hideText()
if Config.System.drawText == "qb" then if Config.System.drawText == "qb" then
exports[QBExport]:HideText() exports[QBExport]:HideText()
@@ -57,5 +92,7 @@ function hideText()
ClearAllHelpMessages() ClearAllHelpMessages()
elseif Config.System.drawText == "esx" then elseif Config.System.drawText == "esx" then
ESX.HideUI() ESX.HideUI()
elseif Config.System.drawText == "red" then
TriggerEvent("jim-redui:HideText")
end end
end end

View File

@@ -1,122 +1,161 @@
-- DUI STUFF -- * Experimental * -- if gameName ~= "rdr3" then
--[[
DUI Module (Experimental)
--------------------------
This module handles the creation, modification, and removal of custom DUI (Display UI)
elements using runtime textures. It supports both client and server functionality to update DUI
images dynamically.
]]
scriptTxd = not isServer() and CreateRuntimeTxd(getScript()..'scriptTxd') or nil -- Create a runtime texture dictionary on the client if not running on the server.
customDUIList = {} scriptTxd = not isServer() and CreateRuntimeTxd(getScript()..'scriptTxd') or nil
customDUIList = {}
-- DUI CLIENT -------------------------------------------------------------
function createDui(name, http, size, txd) -- DUI Client Functions
--print(name, http, size, txd) -------------------------------------------------------------
if not customDUIList[name] then
local newTxt = CreateDui(http, math.floor(size.x), math.floor(size.y)) --- Creates or updates a DUI element.
while not GetDuiHandle(newTxt) do Wait(0) end ---
CreateRuntimeTextureFromDuiHandle(txd, name, GetDuiHandle(newTxt)) --- @param name string The unique name for the DUI element.
customDUIList[name] = newTxt --- @param http string The URL to load into the DUI.
SetDuiUrl(customDUIList[name], http) --- @param size table A table with .x and .y fields specifying the DUI dimensions.
else --- @param txd table The runtime texture dictionary where the DUI texture will be created.
SetDuiUrl(customDUIList[name], http) --- @usage
end --- ```lua
end --- createDui("logo", "https://example.com/logo.png", { x = 512, y = 256 }, scriptTxd)
--- ```
function createDui(name, http, size, txd)
if not customDUIList[name] then
local newDui = CreateDui(http, math.floor(size.x), math.floor(size.y))
while not GetDuiHandle(newDui) do Wait(0) end
CreateRuntimeTextureFromDuiHandle(txd, name, GetDuiHandle(newDui))
customDUIList[name] = newDui
SetDuiUrl(customDUIList[name], http)
else
SetDuiUrl(customDUIList[name], http)
end
end
--- Opens a DUI selection input allowing the user to change the DUI image URL.
---
--- @param data table A table containing DUI data:
--- - name: The key name in the DUI list.
--- - texn: The texture name.
--- - texd: The texture dictionary.
--- - size: A table with .x and .y dimensions.
---
--- @usage
--- ```lua
--- DuiSelect({ name = "logo", texn = "logoTex", texd = "someTxd", size = { x = 512, y = 256 } })
--- ```
function DuiSelect(data)
local imagePreview = "![test]("..data.url..")"
--local imagePreview = "<center>- Current Image -<br>" ..
-- "<img src="..data.url.." width=150px><br>" ..
-- "Size: ["..math.floor(data.size.x)..", "..math.floor(data.size.y).."]<br><br>"
local dialog = createInput(imagePreview, {
{ type = "text", text = "dui_url", name = "url", isRequired = true },
})
if dialog then
data.url = dialog.url or dialog[1]
-- Scan URL for valid image extension and banned words.
local searchList = { "png", "jpg", "jpeg", "gif", "webp", "bmp" }
local banList = { "porn" }
local searchFound = false
for _, ext in pairs(searchList) do
if string.find(tostring(data.url), ext) then
searchFound = true
break
end
end
for _, banned in pairs(banList) do
if string.find(tostring(data.url), banned) then
searchFound = false
print("BANNED WORD: "..banned)
break
end
end
if searchFound then
TriggerServerEvent(getScript()..":Server:ChangeDUI", data)
end
end
end
--- Client event handler to update DUI elements.
RegisterNetEvent(getScript()..":Client:ChangeDUI", function(data)
debugPrint("^6Bridge^7: ^2Receiving new DUI ^7- ^6"..data.url.."^7")
if tostring(data.url) ~= "-" then
createDui(data.texn, tostring(data.url), data.size, scriptTxd)
AddReplaceTexture(tostring(data.texd), tostring(data.texn), getScript().."scriptTxd", tostring(data.texn))
end
end)
--- Client event handler to clear DUI elements.
RegisterNetEvent(getScript()..":Client:ClearDUI", function(data)
if customDUIList[tostring(data.texn)] then
RemoveReplaceTexture(tostring(data.texd), tostring(data.texn))
if IsDuiAvailable(customDUIList[tostring(data.texn)]) then
SetDuiUrl(customDUIList[data.name], nil)
end
end
end)
-------------------------------------------------------------
-- DUI Server Functions
-------------------------------------------------------------
--- Server event handler to change DUI settings.
--- If no URL is provided, resets to the preset value.
RegisterNetEvent(getScript()..":Server:ChangeDUI", function(data)
if not data.url then
debugPrint("^6Bridge^7: ^2Preset: ^6"..tostring(data.preset).."^7")
data.url = data.preset
else
for k, v in pairs(Locations[data.name].duiList) do
if v.tex.texn == data.texn then
Locations[data.name].duiList[k].url = data.url
end
end
end
debugPrint("^6Bridge^7: ^3DUI^2 Sending new DUI to all players^7 - ^6"..data.url.."^7")
TriggerClientEvent(getScript()..":Client:ChangeDUI", -1, data)
end)
--- Server event handler to clear DUI settings.
RegisterNetEvent(getScript()..":Server:ClearDUI", function(data)
if data.url == "-" then
for k, v in pairs(Locations[data.name].duiList) do
if v.tex.texn == data.texn then
Locations[data.name].duiList[k].url = "-"
end
end
end
TriggerClientEvent(getScript()..":Client:ClearDUI", -1, data)
end)
-------------------------------------------------------------
-- Resource Cleanup
-------------------------------------------------------------
onResourceStop(function()
for k, v in pairs(duiList or {}) do
for i = 1, #v do
RemoveReplaceTexture(tostring(v[i].tex.texd), tostring(v[i].tex.texn))
end
end
end, true)
-------------------------------------------------------------
-- DUI List Callback (Server)
-------------------------------------------------------------
if isServer() then
createCallback(getScript()..":Server:duiList", function(source)
return duiList
end)
end
function DuiSelect(data)
local image = ""
for k, v in pairs(duiList[data.name]) do
if v.tex.texn == data.texn then
if duiList[data.name][k] then
image = "<center>- Current Image -<br>"..
"<img src="..duiList[data.name][k].url.." width=150px><br>"..
"Size: ["..math.floor(data.size.x)..", "..math.floor(data.size.y).."]<br><br>"
end
end
end
local dialog = exports['qb-input']:ShowInput({
header = image..Loc[Config.Lan].menu["dui_new"],
submitText = Loc[Config.Lan].menu["dui_change"],
inputs = { { type = 'text', isRequired = true, name = 'url', text = Loc[Config.Lan].menu["dui_url"] } } })
if dialog then
if not dialog.url then return end
data.url = dialog.url
--Scan the link to see if it has an image extention otherwise, stop here.
local searchList = { "png", "jpg", "jpeg", "gif", "webp", "bmp" }
--Scan the link for certain terms that will flag it and refuse to show it
local banList = { "porn" } -- I dunno, let me know what links people manage to find
local searchFound = false
for k, v in pairs(searchList) do
if string.find(tostring(data.url), tostring(v))then
searchFound = true
end
end
for k, v in pairs(banList) do
if string.find(tostring(data.url), tostring(v)) then
searchFound = false print("BANNED WORD: "..v)
end
end
if searchFound then
TriggerServerEvent(getScript()..":Server:ChangeDUI", data)
end
end end
end
RegisterNetEvent(getScript()..":Client:ChangeDUI", function(data)
debugPrint("^6Bridge^7: ^2Recieving new DUI ^7- ^6"..data.url.."^7")
if tostring(data.url) ~= "-" then
createDui(data.texn, tostring(data.url), data.size, scriptTxd)
AddReplaceTexture(tostring(data.texd), tostring(data.texn), getScript()..'scriptTxd', tostring(data.texn))
end
end)
RegisterNetEvent(getScript()..":Client:ClearDUI", function(data)
if customDUIList[tostring(data.texn)] then
RemoveReplaceTexture(tostring(data.texd), tostring(data.texn))
if IsDuiAvailable(customDUIList[tostring(data.texn)]) then
SetDuiUrl(customDUIList[data.name], nil)
end
end
end)
-- DUI SERVER
RegisterNetEvent(getScript()..":Server:ChangeDUI", function(data)
-- if no url given, "reset" it back to preset
if not data.url then
for k, v in pairs(duiList[data.name]) do
if v.tex.texn == data.texn then
debugPrint("^6Bridge^7: ^2Preset^7: ^6"..tostring(duiList[data.name][k].preset).."^7")
data.url = duiList[data.name][k].preset
end
end
end
-- if it has a url, update server DUI list and send to players
for k, v in pairs(duiList[data.name]) do
if v.tex.texn == data.texn then
duiList[data.name][k].url = data.url
end
end
debugPrint("^6Bridge^7: ^3DUI^2 Sending new DUI to all players^7 - ^6"..data.url.."^7")
TriggerClientEvent(getScript()..":Client:ChangeDUI", -1, data)
end)
RegisterNetEvent(getScript()..":Server:ClearDUI", function(data)
if data.url == "-" then
for k, v in pairs(duiList[data.name]) do
if v.tex.texn == data.texn then
duiList[data.name][k].url = "-"
end
end
end
-- Clear the DUI from loading
TriggerClientEvent(getScript()..":Client:ClearDUI", -1, data)
--duiList[tostring(data.tex)].url = ""
end)
AddEventHandler('onResourceStop', function(r) if r ~= getScript() then return end
for k, v in pairs(duiList or {}) do
for i = 1, #v do
RemoveReplaceTexture(tostring(v[i].tex.texd), tostring(v[i].tex.texn))
end
end
end)
if isServer() then
createCallback(getScript()..":Server:duiList", function(source)
return duiList
end)
end

View File

@@ -1,15 +1,19 @@
--- Utility Functions for Resource Management and Debugging --[[
--- Utility Functions for Resource Management and Debugging
--- This script provides a set of utility functions for managing resources, debugging, and handling various common tasks within the game environment. ----------------------------------------------------------
--- It includes functions for checking resource states, generating unique keys, formatting numbers and coordinates, handling JSON data, and more. This script provides a set of utility functions for managing resources,
debugging, and handling common tasks in the game environment.
It includes functions to check resource states, generate unique keys,
format numbers and coordinates, handle JSON data, perform raycasts, and more.
]]
--[[ Resource and Environment Checks ]]-- -------------------------------------------------------------
-- Resource and Environment Checks
-------------------------------------------------------------
--- Checks if a specific resource is started. --- Checks if a specific resource is started.
--- --- @param script string The name of the resource.
---@param script string The name of the resource to check. --- @return boolean boolean True if the resource state contains "start", false otherwise.
---@return boolean `true` if the resource state contains "start", otherwise `false`.
---
---@usage ---@usage
--- ```lua --- ```lua
--- if isStarted("myResource") then --- if isStarted("myResource") then
@@ -17,17 +21,13 @@
--- end --- end
--- ``` --- ```
function isStarted(script) function isStarted(script)
return GetResourceState(script):find("start") return GetResourceState(script):find("start") ~= nil
end end
local scriptName = nil local scriptName = nil
--- Retrieves the current resource name. --- Retrieves the current resource name, caching it for efficiency.
--- --- @return string string The current resource name.
--- Caches the resource name after the first call for efficiency.
---
--- @return string scriptName The name of the current resource.
---
--- @usage --- @usage
--- ```lua --- ```lua
--- local currentScript = getScript() --- local currentScript = getScript()
@@ -38,12 +38,8 @@ function getScript()
return scriptName return scriptName
end end
--- Determines if the current execution context is the server. --- Determines if the current context is the server.
--- --- @return boolean boolean True if running on the server, false otherwise.
--- Very helpful for shared files complaining about client functions running on server or vice versa
---
--- @return boolean Returns `true` if running on the server, otherwise `false`.
---
---@usage ---@usage
--- ```lua --- ```lua
--- if isServer() then --- if isServer() then
@@ -56,14 +52,13 @@ function isServer()
return IsDuplicityVersion() return IsDuplicityVersion()
end end
--[[ Debugging Functions ]]-- -------------------------------------------------------------
-- Debugging and JSON Utilities
-------------------------------------------------------------
--- Prints debug messages if debugging mode is enabled. --- Prints debug messages if debugMode is enabled.
--- --- Concatenates all arguments and prints them with debug info.
--- Concatenates all arguments and prints them along with debug information. --- @param ... any One or more values to print.
---
--- @param ... any Multiple arguments to be concatenated and printed.
---
--- @usage --- @usage
--- ```lua --- ```lua
--- debugPrint("Player has joined:", playerName) --- debugPrint("Player has joined:", playerName)
@@ -71,15 +66,13 @@ end
function debugPrint(...) function debugPrint(...)
if debugMode then if debugMode then
local args = {...} local args = {...}
local output = table.concat(args, " ") -- Concatenate all arguments with a space local output = table.concat(args, " ")
print(output, getDebugInfo(debug.getinfo(2, "nSl"))) print(output, getDebugInfo(debug.getinfo(2, "nSl")))
end end
end end
--- Prints event-related debug messages if event debugging is enabled. --- Prints event-related debug messages if event debugging is enabled.
--- --- @param ... any One or more values to print.
--- @param ... any Multiple arguments to be printed.
---
--- @usage --- @usage
--- ```lua --- ```lua
--- eventPrint("Event triggered:", eventName) --- eventPrint("Event triggered:", eventName)
@@ -90,24 +83,22 @@ function eventPrint(...)
end end
end end
-- Function to recursively colorize the JSON data --- Returns the keys of a table in sorted order.
--- @param tbl table The table to sort keys for.
--- @return table table A sorted array of keys.
function getSortedKeys(tbl) function getSortedKeys(tbl)
local keys = {} local keys = {}
for k in pairs(tbl) do keys[#keys + 1] = k end for k in pairs(tbl) do keys[#keys + 1] = k end
table.sort(keys, function(a, b) table.sort(keys, function(a, b)
local numA, numB = tonumber(a), tonumber(b) local numA, numB = tonumber(a), tonumber(b)
if numA and numB then return numA < numB if numA and numB then return numA < numB else return tostring(a) < tostring(b) end
else return tostring(a) < tostring(b) end
end) end)
return keys return keys
end end
--- Recursively colorizes a table for debug printing. --- Recursively colorizes a table for debug printing.
---
--- @param tbl table The table to colorize. --- @param tbl table The table to colorize.
--- @return table colourizedTable The colorized table. --- @return table table A new table with colorized keys and values.
---
--- @usage
--- ```lua --- ```lua
--- local colorizedData = colorizeTable(myTable) --- local colorizedData = colorizeTable(myTable)
--- jsonPrint(colorizedData) --- jsonPrint(colorizedData)
@@ -116,18 +107,19 @@ function colorizeTable(tbl)
local newData, sortedKeys = {}, getSortedKeys(tbl) local newData, sortedKeys = {}, getSortedKeys(tbl)
for _, k in ipairs(sortedKeys) do for _, k in ipairs(sortedKeys) do
local v = tbl[k] local v = tbl[k]
newData["^6"..tostring(k).."^7"] = ((type(v) == "table") and colorizeTable(v)) or (type(v):find("vector") and formatCoord(v)) or "^2"..tostring(v).."^7" newData["^6"..tostring(k).."^7"] =
(type(v) == "table" and colorizeTable(v))
or (tostring(type(v)):find("vector") and formatCoord(v))
or "^2"..tostring(v).."^7"
end end
return newData return newData
end end
--- Encodes a table into an ordered JSON string with indentation. --- Encodes a table into an ordered JSON string with indentation.
---
--- @param data table The table to encode. --- @param data table The table to encode.
--- @param indent string The string used for indentation (e.g., " "). --- @param indent string The indentation string (e.g., " ").
--- @param level number The current indentation level. --- @param level number The current level of indentation.
--- @return string The formatted JSON string. --- @return string The formatted JSON string.
---
--- @usage --- @usage
--- ```lua --- ```lua
--- local jsonString = encodeOrderedJSON(myTable, " ", 0) --- local jsonString = encodeOrderedJSON(myTable, " ", 0)
@@ -143,10 +135,8 @@ function encodeOrderedJSON(data, indent, level)
return table.concat(jsonParts) return table.concat(jsonParts)
end end
--- Prints a table as a colorized and ordered JSON string if debugging mode is enabled. --- Prints a table as a colorized and ordered JSON string if debugMode is enabled.
---
--- @param data table The table to print. --- @param data table The table to print.
---
--- @usage --- @usage
--- ```lua --- ```lua
--- jsonPrint(myTable) --- jsonPrint(myTable)
@@ -158,9 +148,7 @@ function jsonPrint(data)
end end
--- Retrieves the current time formatted for debug prints. --- Retrieves the current time formatted for debug prints.
---
--- @return string string The formatted time string, e.g., "^7(14:23:45)". --- @return string string The formatted time string, e.g., "^7(14:23:45)".
---
--- @usage --- @usage
--- ```lua --- ```lua
--- local currentTime = GetPrintTime() --- local currentTime = GetPrintTime()
@@ -177,9 +165,7 @@ function GetPrintTime()
end end
--- Generates a unique 3-character alphanumeric key. --- Generates a unique 3-character alphanumeric key.
--- --- @return string string The generated key.
--- @return string GeneratedString A randomly generated 3-character string.
---
--- @usage --- @usage
--- ```lua --- ```lua
--- local uniqueKey = keyGen() --- local uniqueKey = keyGen()
@@ -187,20 +173,28 @@ end
--- ``` --- ```
function keyGen() function keyGen()
local charset = { local charset = {
"q","w","e","r","t","y","u","i","o","p","a","s","d","f","g","h","j","k","l","z","x","c","v","b","n","m", "q","w","e","r","t","y","u","i","o","p",
"Q","W","E","R","T","Y","U","I","O","P","A","S","D","F","G","H","J","K","L","Z","X","C","V","B","N","M", "a","s","d","f","g","h","j","k","l",
"z","x","c","v","b","n","m",
"Q","W","E","R","T","Y","U","I","O","P",
"A","S","D","F","G","H","J","K","L",
"Z","X","C","V","B","N","M",
"1","2","3","4","5","6","7","8","9","0" "1","2","3","4","5","6","7","8","9","0"
} }
local GeneratedID = "" local GeneratedID = ""
for i = 1, 3 do GeneratedID = GeneratedID..charset[math.random(1, #charset)] end for i = 1, 3 do
GeneratedID = GeneratedID..charset[math.random(1, #charset)]
end
return GeneratedID return GeneratedID
end end
-------------------------------------------------------------
-- Formatting and Vector Math Functions
-------------------------------------------------------------
--- Formats a number with commas as thousand separators. --- Formats a number with commas as thousand separators.
---
--- @param amount number The number to format. --- @param amount number The number to format.
--- @return string commaValue The formatted number string with commas. --- @return string string The formatted number.
---
--- @usage --- @usage
--- ```lua --- ```lua
--- local formattedNumber = cv(1000000) -- "1,000,000" --- local formattedNumber = cv(1000000) -- "1,000,000"
@@ -208,15 +202,17 @@ end
--- `` --- ``
function cv(amount) function cv(amount)
local formatted = tostring(amount or "0") local formatted = tostring(amount or "0")
while true do formatted, k = string.gsub(formatted, "^(-?%d+)(%d%d%d)", '%1,%2') if (k==0) then break end Wait(0) end while true do
formatted, k = string.gsub(formatted, "^(-?%d+)(%d%d%d)", '%1,%2')
if k == 0 then break end
Wait(0)
end
return formatted return formatted
end end
--- Formats a coordinate vector for debug printing. --- Formats a coordinate vector for debug printing.
--- --- @param coord table A vector3 or vector4 with x, y, z (and optional w).
--- @param coord table A vector3 or vector4 table with `x`, `y`, `z`, and optional `w` components. --- @return string string The formatted coordinate string.
--- @return string The formatted coordinate string with color codes.
---
--- @usage --- @usage
--- ```lua --- ```lua
--- local formattedCoord = formatCoord(vector3(100.0, 200.0, 300.0)) --- local formattedCoord = formatCoord(vector3(100.0, 200.0, 300.0))
@@ -233,47 +229,42 @@ function formatCoord(coord)
return "^5"..vecType.."^7("..components[1]..components[2]..components[3]..components[4].."^7)" return "^5"..vecType.."^7("..components[1]..components[2]..components[3]..components[4].."^7)"
end end
--- Calculates the center point of a list of zones (coordinates). --- Calculates the center point of a list of coordinates.
--- --- @param tbl table An array of vector3 coordinates.
--- @param table table A table of vector3 coordinates.
--- @return vector3 vector3 The center coordinate. --- @return vector3 vector3 The center coordinate.
---
--- @usage --- @usage
--- ```lua --- ```lua
--- local center = getCenterOfZones({vector3(100, 200, 300), vector3(110, 210, 310)}) --- local center = getCenterOfZones({vector3(100, 200, 300), vector3(110, 210, 310)})
--- print("Center of Zones:", center) --- print("Center of Zones:", center)
--- ``` --- ```
function getCenterOfZones(table) function getCenterOfZones(tbl)
local totalX, totalY, totalZ = 0, 0, 0 local totalX, totalY, totalZ = 0, 0, 0
for _, coord in ipairs(tbl) do
for _, coord in ipairs(table) do
totalX = totalX + coord.x totalX = totalX + coord.x
totalY = totalY + coord.y totalY = totalY + coord.y
totalZ = totalZ + coord.z totalZ = totalZ + coord.z
end end
local count = #tbl
local count = #table
return vector3(totalX / count, totalY / count, totalZ / count) return vector3(totalX / count, totalY / count, totalZ / count)
end end
--- Counts the number of keys in a table. --- Counts the number of keys in a table.
--- --- @param tbl table The table to count.
--- @param table table The table to count keys in. --- @return number number The key count.
--- @return number number The number of keys in the table.
---
--- @usage --- @usage
--- ```lua --- ```lua
--- local count = countTable(myTable) --- local count = countTable(myTable)
--- print("Number of keys:", count) --- print("Number of keys:", count)
--- ``` --- ```
function countTable(table) local i = 0 for keys in pairs(table) do i += 1 end return i end function countTable(tbl)
local i = 0
for _ in pairs(tbl) do i = i + 1 end
return i
end
--- Returns an iterator over a table's keys in sorted order.
--- Returns an iterator that iterates over a table's keys in sorted order.
---
--- @param t table The table to iterate over. --- @param t table The table to iterate over.
--- @return function function An iterator function. --- @return function An iterator function for sorted keys.
---
--- @usage --- @usage
--- ```lua --- ```lua
--- for k, v in pairsByKeys(myTable) do --- for k, v in pairsByKeys(myTable) do
@@ -281,7 +272,6 @@ function countTable(table) local i = 0 for keys in pairs(table) do i += 1 end re
--- end --- end
--- ``` --- ```
function pairsByKeys(t) function pairsByKeys(t)
local t = t
if not t then if not t then
print("^1Error^7: ^3Nil ^2table recieved for ^3pairsByKeys^7(), ^2setting to ^7{} ^2to prevent break^7") print("^1Error^7: ^3Nil ^2table recieved for ^3pairsByKeys^7(), ^2setting to ^7{} ^2to prevent break^7")
t = {} t = {}
@@ -289,24 +279,20 @@ function pairsByKeys(t)
local a = {} for n in pairs(t) do a[#a+1] = n end table.sort(a) local i = 0 local iter = function() i += 1 if a[i] == nil then return nil else return a[i], t[a[i]] end end return iter local a = {} for n in pairs(t) do a[#a+1] = n end table.sort(a) local i = 0 local iter = function() i += 1 if a[i] == nil then return nil else return a[i], t[a[i]] end end return iter
end end
--- Creates a new table with consecutive numerical indices sorted by the `id` field. --- Creates a new table with consecutive numerical indices sorted by the 'id' field.
--- --- @param originalTable table The table containing entries with an 'id' field.
--- @param originalTable table The original table with entries containing an `id` field. --- @return table table A sorted table with consecutive indices.
--- @return table The new table with sorted entries and consecutive `id` values.
---
--- @usage --- @usage
--- ```lua
--- local sortedTable = createConsecutiveTable(originalTable) --- local sortedTable = createConsecutiveTable(originalTable)
--- for i, entry in ipairs(sortedTable) do --- for i, entry in ipairs(sortedTable) do
--- print(i, entry) --- print(i, entry)
--- end --- end
--- ```
function createConsecutiveTable(originalTable) function createConsecutiveTable(originalTable)
local sortedEntries = {} local sortedEntries = {}
for _, entry in pairs(originalTable) do for _, entry in pairs(originalTable) do table.insert(sortedEntries, entry) end
table.insert(sortedEntries, entry) table.sort(sortedEntries, function(a, b) return a.id < b.id end)
end
table.sort(sortedEntries, function(a, b)
return a.id < b.id
end)
local newTable = {} local newTable = {}
for newIndex, entry in ipairs(sortedEntries) do for newIndex, entry in ipairs(sortedEntries) do
entry.id = newIndex entry.id = newIndex
@@ -315,94 +301,9 @@ function createConsecutiveTable(originalTable)
return newTable return newTable
end end
--[[ Drawing Functions ]]--
--- Draws 3D text at specified coordinates.
---
--- @param coord table A vector3 table with `x`, `y`, and `z` coordinates.
--- @param text string The text to display.
--- @param highlight boolean (optional) Whether to highlight certain parts of the text.
---
--- @usage
--- ```lua
--- CreateThread(function()
--- while true do
--- DrawText3D(vector3(100, 200, 300), "Hello World", true)
--- Wait(0)
--- end
--- end)
--- ```
function DrawText3D(coord, text, highlight)
SetTextScale(0.30, 0.30)
SetTextFont(0)
SetTextProportional(1)
SetTextColour(255, 255, 255, 215)
SetTextEntry("STRING")
SetTextCentre(true)
local totalLength = string.len(text)
local textMaxLength = textMaxLength or 99 -- max 99
local text = totalLength > textMaxLength and text:sub(1, totalLength - (totalLength - textMaxLength)) or text
AddTextComponentString(highlight and text:gsub("%~w~", "~y~") or text)
SetDrawOrigin(coord.x, coord.y, coord.z, 0)
DrawText(0.0, 0.0)
local count, length = GetLineCountAndMaxLength(text)
local padding = 0.005
local heightFactor = (count / 43) + padding
local weightFactor = (length / 150) + padding
local height = (heightFactor / 2) - padding / 1
local width = (weightFactor / 2) - padding / 1
DrawRect(0.0, height, width, heightFactor, 0, 0, 0, 150)
ClearDrawOrigin()
end
--- Displays a help message on the screen.
---
--- @param text string The text to display as a help message.
---
--- @usage
--- DisplayHelpMsg("Press E to interact")
function DisplayHelpMsg(text)
BeginTextCommandDisplayHelp("STRING")
AddTextComponentScaleform(text)
EndTextCommandDisplayHelp(0, true, false, -1)
end
--- Displays a "Saving/Loading" spinner with a custom message.
---
--- @param text string The message to display alongside the spinner.
---
--- @usage
--- ```lua
--- displaySpinner("Saving data...")
--- ```
function displaySpinner(text)
BeginTextCommandBusyspinnerOn('STRING')
AddTextComponentSubstringPlayerName(text)
EndTextCommandBusyspinnerOn(4)
end
--- Stops the "Saving/Loading" spinner.
---
--- This function is client-side only.
---
--- @usage
--- ```lua
--- stopSpinner()
--- ```
function stopSpinner()
if not isServer() then
BusyspinnerOff()
end
end
--- Concatenates a table of strings into a single string separated by newlines. --- Concatenates a table of strings into a single string separated by newlines.
--- --- @param tbl table The table containing strings.
--- @param tbl table A table containing string elements. --- @return string string The concatenated string.
--- @return string string The concatenated string with newline separators.
---
--- @usage --- @usage
--- ```lua --- ```lua
--- local combinedText = concatenateText({"Line 1", "Line 2", "Line 3"}) --- local combinedText = concatenateText({"Line 1", "Line 2", "Line 3"})
@@ -411,74 +312,69 @@ end
function concatenateText(tbl) function concatenateText(tbl)
local result = "" local result = ""
for i = 1, #tbl do for i = 1, #tbl do
result = result..tbl[i] result = result..tbl[i]..(i < #tbl and "\n" or "")
if i < #tbl then
result = result.."\n" -- Add newline only if it's not the last element
end
end end
return result return result
end end
--- Converts rotation to a direction vector. --- Converts a rotation (degrees) to a direction vector.
--- --- @param rot vector3 A vector3 with rotation values.
--- @param rot vector3 A vector3 containing rotation values --- @return vector3 vector3 The forward direction vector.
--- @return vector3 vector3 A vector3 representing the direction.
---
--- @usage --- @usage
--- ```lua --- ```lua
--- local direction = RotationToDirection({ z = 90 }) --- local direction = RotationToDirection({ z = 90 })
--- print(direction) --- print(direction)
--- ``` --- ```
function RotationToDirection(rot) function RotationToDirection(rot)
local adjust = (math.pi / 180) local adjust = math.pi / 180
return vec3(-math.sin(adjust * rot.z) * math.abs(math.cos(adjust * rot.x)), math.cos(adjust * rot.z) * math.abs(math.cos(adjust * rot.x)), math.sin(adjust * rot.x)) return vec3(
-math.sin(adjust * rot.z) * math.abs(math.cos(adjust * rot.x)),
math.cos(adjust * rot.z) * math.abs(math.cos(adjust * rot.x)),
math.sin(adjust * rot.x)
)
end end
--- Creates a simple text-based progress bar. --- Creates a basic progress bar string.
--- --- @param percentage number Completion percentage (0-100).
--- @param percentage number The completion percentage (0-100). --- @return string string The progress bar (e.g., "█████░░░░░").
--- @return string string A string representing the progress bar, e.g., "█████░░░░░".
---
--- @usage --- @usage
--- ```lua --- ```lua
--- local bar = basicBar(50) -- "█████░░░░░" --- local bar = basicBar(50) -- "█████░░░░░"
--- print(bar) --- print(bar)
--- ``` --- ```
function basicBar(percentage) function basicBar(percentage)
local percentage = math.ceil(percentage) local perc = math.ceil(percentage)
local totalBlocks = 10 local total = 10
local filledBlocks = math.floor((percentage / 100) * totalBlocks) local filled = math.floor((perc / 100) * total)
local emptyBlocks = totalBlocks - filledBlocks local empty = total - filled
return string.rep("", filled)..string.rep("", empty)
local bar = string.rep("", filledBlocks)..string.rep("", emptyBlocks)
return bar
end end
--- Normalizes a 3D vector. --- Normalizes a 3D vector.
--- --- @param vec vector3 A vector3 table.
--- @param vec vector3 A vector3 table with `x`, `y`, and `z` components. --- @return vector3 vector3 A normalized vector.
--- @return vector3 vector3 The normalized vector3.
---
--- @usage --- @usage
--- ```lua --- ```lua
--- local normalizedVec = normalizeVector(vector3(1, 2, 3)) --- local normalizedVec = normalizeVector(vector3(1, 2, 3))
--- print(normalizedVec) --- print(normalizedVec)
--- ``` --- ```
function normalizeVector(vec) function normalizeVector(vec)
local length = math.sqrt(vec.x * vec.x + vec.y * vec.y + vec.z * vec.z) local len = math.sqrt(vec.x^2 + vec.y^2 + vec.z^2)
if length ~= 0 then if len ~= 0 then
return vec3(vec.x / length, vec.y / length, vec.z / length) return vec3(vec.x / len, vec.y / len, vec.z / len)
else else
return vec3(0, 0, 0) return vec3(0, 0, 0)
end end
end end
--- Draws a line between two coordinates for debugging purposes. -------------------------------------------------------------
--- -- Drawing and Raycasting Functions
--- @param startCoords vector3 A vector3 table representing the start point. -------------------------------------------------------------
--- @param endCoords vector3 A vector3 table representing the end point.
--- @param col vector4 A table with `x`, `y`, `z`, `w` representing the color and opacity. --- Draws a line between two coordinates (for debugging).
--- --- @param startCoords vector3 The starting coordinate.
--- @param endCoords vector3 The ending coordinate.
--- @param col vector4 A vector4 specifying color and opacity.
--- @usage --- @usage
--- ```lua --- ```lua
--- drawLine(vector3(100, 200, 300), vector3(150, 250, 350), vector4(255, 0, 0, 255)) --- drawLine(vector3(100, 200, 300), vector3(150, 250, 350), vector4(255, 0, 0, 255))
@@ -486,21 +382,19 @@ end
function drawLine(startCoords, endCoords, col) function drawLine(startCoords, endCoords, col)
if debugMode then if debugMode then
CreateThread(function() CreateThread(function()
local showCount = 1000 local count = 1000
while showCount >= 0 do while count >= 0 do
DrawLine(startCoords.x, startCoords.y, startCoords.z, endCoords.x, endCoords.y, endCoords.z, col.x, col.y, col.z, col.w) DrawLine(startCoords.x, startCoords.y, startCoords.z, endCoords.x, endCoords.y, endCoords.z, col.x, col.y, col.z, col.w)
showCount -= 10 count -= 10
Wait(0) Wait(0)
end end
end) end)
end end
end end
--- Draws a sphere at specified coordinates for debugging purposes. --- Draws a sphere at the specified coordinates (for debugging).
--- --- @param coords vector3 The center of the sphere.
--- @param coords vector3 A vector3 table representing the center of the sphere. --- @param col vector4 A vector4 specifying color and opacity.
--- @param col vector4 A table with `x`, `y`, `z`, `w` representing the color and opacity.
---
--- @usage --- @usage
--- ```lua --- ```lua
--- drawSphere(vector3(100, 200, 300), vector4(0, 255, 0, 255)) --- drawSphere(vector3(100, 200, 300), vector4(0, 255, 0, 255))
@@ -508,24 +402,22 @@ end
function drawSphere(coords, col) function drawSphere(coords, col)
if debugMode then if debugMode then
CreateThread(function() CreateThread(function()
local showCount = 1000 local count = 1000
while showCount >= 0 do while count >= 0 do
DrawSphere(coords.x, coords.y, coords.z, 0.5, col.x, col.y, col.z, col.w) DrawSphere(coords.x, coords.y, coords.z, 0.5, col.x, col.y, col.z, col.w)
showCount -= 1 count -= 1
Wait(10) Wait(10)
end end
end) end)
end end
end end
--- Performs a raycast between two coordinates and returns the result. --- Performs a raycast between two coordinates and returns the results.
--- --- @param startCoords vector3 The starting coordinate.
--- @param startCoords table A vector3 table representing the start point. --- @param endCoords vector3 The ending coordinate.
--- @param endCoords table A vector3 table representing the end point. --- @param entity number|nil An entity to ignore.
--- @param entity number|nil The entity to ignore during the raycast. --- @param flags number|nil Optional raycast flags (default: 4294967295).
--- @param flags number|nil Raycast flags to customize the raycast behavior. Defaults to `4294967295`. --- @return multiple Multiple values returned by GetShapeTestResultIncludingMaterial.
--- @return multiple multiple Returns multiple values from `GetShapeTestResultIncludingMaterial`.
---
--- @usage --- @usage
--- ```lua --- ```lua
--- local hit, hitPos, material = PerformRaycast(startVec, endVec, playerPed, 1) --- local hit, hitPos, material = PerformRaycast(startVec, endVec, playerPed, 1)
@@ -535,47 +427,41 @@ end
--- end --- end
--- ``` --- ```
function PerformRaycast(startCoords, endCoords, entity, flags) function PerformRaycast(startCoords, endCoords, entity, flags)
drawLine(startCoords, endCoords, vec4(0, 0, 255, 255)) drawLine(startCoords, endCoords, vec4(0,0,255,255))
local val1, val2, val3, val4, val5, val6 = GetShapeTestResult(StartExpensiveSynchronousShapeTestLosProbe(startCoords.x, startCoords.y, startCoords.z, endCoords.x, endCoords.y, endCoords.z, flags or 4294967295, entity, 0)) local val1, val2, val3, val4, val5, val6 = GetShapeTestResult(
if val2 then StartExpensiveSynchronousShapeTestLosProbe(
--drawSphere(val3, vec4(255, 0, 255, 0.5)) startCoords.x, startCoords.y, startCoords.z,
end endCoords.x, endCoords.y, endCoords.z,
flags or 4294967295, entity, 0
)
)
return val1, val2, val3, val4, val5, val6 return val1, val2, val3, val4, val5, val6
end end
--- Adjusts the Z-coordinate of a position to align with the ground. --- Adjusts the Z-coordinate of a position to the ground level.
--- --- @param coords vector4 A vector3 or vector4 with x, y, z (and optional w).
--- @param coords vector4 A vector3 or vector4 table with `x`, `y`, `z`, and optional `w` components. --- @return vector3|vector4 vector The coordinates adjusted for ground level.
--- @return vector3|vector4 vector adjusted coordinate with the Z value set to the ground level.
---
--- @usage --- @usage
--- ```lua --- ```lua
--- local groundCoords = adjustForGround(playerCoords) --- local groundCoords = adjustForGround(playerCoords)
--- print("Ground Position:", groundCoords) --- print("Ground Position:", groundCoords)
--- ``` --- ```
function adjustForGround(coords) function adjustForGround(coords)
local coords = coords
local foundGround, zPos = GetGroundZFor_3dCoord(coords.x, coords.y, coords.z + 1.0) local foundGround, zPos = GetGroundZFor_3dCoord(coords.x, coords.y, coords.z + 1.0)
if foundGround then if foundGround then
if coords.w then if coords.w then
coords = vec4(coords.x, coords.y, zPos, coords.w) return vec4(coords.x, coords.y, zPos, coords.w)
else else
coords = vec3(coords.x, coords.y, zPos) return vec3(coords.x, coords.y, zPos)
end end
--debugPrint("^6Bridge^7: Adjusting for ground pos ", coords.z, zPos)
return coords
else else
return coords return coords
end end
end end
--- Ensures that a network vehicle exists by verifying its network ID. --- Ensures a network vehicle exists from its network ID.
--- --- @param vehNetID number The network ID.
--- @param vehNetID number The network ID of the vehicle. --- @return number number The vehicle entity, or 0 if not found.
--- @return number number The vehicle entity if it exists, otherwise `0`.
---
--- @usage --- @usage
--- ```lua --- ```lua
--- local vehicle = ensureNetToVeh(netID) --- local vehicle = ensureNetToVeh(netID)
@@ -601,16 +487,16 @@ function ensureNetToVeh(vehNetID)
return vehicle return vehicle
end end
--- Ensures that a network entity exists by verifying its network ID. --- Ensures a network entity exists from its network ID.
--- --- @param entNetID number The network ID.
--- @param entNetID number The network ID of the entity. --- @return number number The entity, or 0 if not found.
--- @return number The entity if it exists, otherwise `0`.
---
--- @usage --- @usage
--- ```lua
--- local entity = ensureNetToEnt(netID) --- local entity = ensureNetToEnt(netID)
--- if entity ~= 0 then --- if entity ~= 0 then
--- print("Entity exists:", entity) --- print("Entity exists:", entity)
--- end --- end
--- ```
function ensureNetToEnt(entNetID) function ensureNetToEnt(entNetID)
debugPrint("^6Bridge^7: ^3ensureNetToEnt^7: ^2Requesting NetworkDoesNetworkIdExist^7(^6"..entNetID.."^7)") debugPrint("^6Bridge^7: ^3ensureNetToEnt^7: ^2Requesting NetworkDoesNetworkIdExist^7(^6"..entNetID.."^7)")
local timeout = 100 local timeout = 100
@@ -629,7 +515,40 @@ function ensureNetToEnt(entNetID)
return entity return entity
end end
--[[ Material Definitions ]]-- function sendLog(text)
local Player = getPlayer()
local coords = GetEntityCoords(PlayerPedId())
local _, _, _, hour, min, sec = GetLocalTime()
local data = {
script = debug.getinfo(2, "nSl"),
coords = coords,
localTime = { hour = hour, min = min, sec = sec },
firstname = Player.firstname,
lastname = Player.lastname,
source = Player.source,
id = Player.citizenId,
text = text,
}
debugPrint("^5Log Message^7: "..getScript().." - "..Player.firstname.." "..Player.lastname.."("..Player.source..") ["..Player.citizenId.."]", text)
TriggerServerEvent(getScript()..":server:sendlog", data)
end
function sendServerLog(data)
local hour, min, sec = os.date('%H'), os.date('%M'), os.date('%S')
data.serverTime = { house = hour, min = min, sec = sec }
--jsonPrint(data)
debugPrint("^5Log Message^7: "..getScript().." - "..data.firstname.." "..data.lastname.."("..data.source..") ["..data.id.."]", data.text)
-- Add your logger here
end
RegisterNetEvent(getScript()..":server:sendlog", sendServerLog)
-------------------------------------------------------------
-- Material and Prop Functions
-------------------------------------------------------------
--- A table mapping material names to their corresponding hash values. --- A table mapping material names to their corresponding hash values.
--- ---
@@ -851,22 +770,17 @@ local materials = {
temp_30 = 13626292 temp_30 = 13626292
} }
--- Retrieves the ground material at a specified position. --- Retrieves the ground material at a given position.
--- --- @param coords vector3 The coordinate to test.
--- This function performs a raycast downwards from the given coordinates to determine the material type of the ground. --- @return number|nil number The material hash if hit, nil otherwise.
--- --- @return string string The material name.
--- @param coords vector3 The coordinates from which to perform the raycast.
--- @return number|nil number The material hash if found; otherwise, `nil`.
--- @return string string The name of the material.
---
--- @usage --- @usage
--- ```lua --- ```lua
--- local materialHash, materialName = GetGroundMaterialAtPosition(vector3(100, 200, 300)) --- local matHash, matName = GetGroundMaterialAtPosition(vector3(100,200,300))
--- print("Ground material:", materialName) --- print("Material:", matName)
--- ``` --- ```
function GetGroundMaterialAtPosition(coords) function GetGroundMaterialAtPosition(coords)
local endX, endY, endZ = coords.x, coords.y, coords.z - 1.0 local endX, endY, endZ = coords.x, coords.y, coords.z - 1.0
local rayHandle = StartShapeTestCapsule(coords.x, coords.y, coords.z, endX, endY, endZ, 1.0, 1, playerPed, 7) local rayHandle = StartShapeTestCapsule(coords.x, coords.y, coords.z, endX, endY, endZ, 1.0, 1, playerPed, 7)
local _, hit, _, _, materialHash, _ = GetShapeTestResultIncludingMaterial(rayHandle) local _, hit, _, _, materialHash, _ = GetShapeTestResultIncludingMaterial(rayHandle)
local materialName = "Unknown" local materialName = "Unknown"
@@ -876,14 +790,10 @@ function GetGroundMaterialAtPosition(coords)
break break
end end
end end
if hit then return materialHash, materialName if hit then return materialHash, materialName else return nil, materialName end
else return nil, materialName end
end end
--- Retrieves the dimensions of a prop/model. --- Retrieves the dimensions (width, depth, height) of a prop/model.
---
--- This function loads the specified model and returns its width, depth, and height based on its bounding box.
---
--- @param model string The name or hash of the model. --- @param model string The name or hash of the model.
--- @return number number The width of the prop. --- @return number number The width of the prop.
--- @return number number The depth of the prop. --- @return number number The depth of the prop.

View File

@@ -1,25 +1,28 @@
-- INPUT -- --[[
-- Multiscript input script function to create simple input text boxes -- Input Dialog Module
---------------------
This module provides a function to create a simple input dialog compatible with
multiple menu systems (OX, QB, GTA/WarMenu, and ESX). It supports various input
types such as radio buttons, numbers, text, and select dropdowns.
--- Creates a simple input dialog compatible with multiple menu systems. ]]
--- Creates a simple input dialog using the configured menu system.
--- ---
--- This function generates input dialogs for different frameworks (OX, QB, GTA) based on the configuration. --- @param title string The title or header of the input dialog.
--- It supports various input types such as radio buttons, numbers, text, and select dropdowns. --- @param opts table A table of input option definitions. Each option should include:
--- - type (string): The input type ("radio", "number", "text", "select").
--- - label (string, optional): A label for the input (used in radio/select for OX).
--- - text (string, optional): The text prompt for the input.
--- - name (string): The identifier for the input.
--- - isRequired (boolean, optional): Whether input is mandatory.
--- - default (any, optional): The default value.
--- - options (table, optional): A table of choices for "radio" and "select" types.
--- - min (number, optional): Minimum value (for "number" and "select").
--- - max (number, optional): Maximum value.
--- - txt (string, optional): Additional description.
--- ---
---@param title string The title/header of the input dialog. --- @return table|nil table Returns the user's input as a table if submitted, otherwise nil.
---@param opts table A table containing input options. Each option should have a `type` and other relevant fields based on the type.
--- - **type** (`string`): The type of input. Supported types: "radio", "number", "text", "select".
--- - **label** (`string`, optional): The label for the input (used for "radio" and "select" types in OX).
--- - **text** (`string`, optional): The text prompt for the input.
--- - **name** (`string`): The identifier name for the input.
--- - **isRequired** (`boolean`, optional): Whether the input is required.
--- - **default** (`any`, optional): The default value for the input.
--- - **options** (`table`, optional): A table of options for "radio" and "select" types.
--- - **min** (`number`, optional): The minimum value (used for "select" type).
--- - **max** (`number`, optional): The maximum value (used for "number" and "select" types).
--- - **txt** (`string`, optional): Additional text or description for the input.
---
---@return table|nil table Returns the user's input as a table if the dialog is submitted, otherwise returns `nil`.
--- ---
---@usage ---@usage
--- ```lua --- ```lua
@@ -36,15 +39,17 @@
function createInput(title, opts) function createInput(title, opts)
local dialog = nil local dialog = nil
local options = {} local options = {}
local currentNum = 0
if Config.System.Menu == "ox" then if Config.System.Menu == "ox" then
for i = 1, #opts do for i = 1, #opts do
currentNum += 1
if opts[i] == nil then currentNum -= 1 goto skip end
if opts[i].type == "radio" then if opts[i].type == "radio" then
-- Convert radio options to select type for OX -- Convert radio options to select type for OX
for k in pairs(opts[i].options) do for k in pairs(opts[i].options) do
opts[i].options[k].label = opts[i].options[k].text opts[i].options[k].label = opts[i].options[k].text
end end
options[i] = { options[currentNum] = {
type = "select", type = "select",
isRequired = opts[i].isRequired, isRequired = opts[i].isRequired,
label = opts[i].label or opts[i].text, label = opts[i].label or opts[i].text,
@@ -54,16 +59,16 @@ function createInput(title, opts)
} }
end end
if opts[i].type == "number" then if opts[i].type == "number" then
options[i] = { options[currentNum] = {
type = "number", type = opts[i].type,
label = opts[i].text..(opts[i].txt and " - "..opts[i].txt or ""), label = (opts[i].label or opts[i].text)..(opts[i].txt and " - "..opts[i].txt or ""),
isRequired = opts[i].isRequired, isRequired = opts[i].isRequired,
name = opts[i].name, name = opts[i].name,
options = opts[i].options, options = opts[i].options,
} }
end end
if opts[i].type == "text" then if opts[i].type == "text" then
options[i] = { options[currentNum] = {
type = "input", type = "input",
label = opts[i].text..(opts[i].txt and " - "..opts[i].txt or ""), label = opts[i].text..(opts[i].txt and " - "..opts[i].txt or ""),
default = opts[i].default, default = opts[i].default,
@@ -71,8 +76,8 @@ function createInput(title, opts)
} }
end end
if opts[i].type == "select" then if opts[i].type == "select" then
options[i] = { options[currentNum] = {
type = "select", type = opts[i].type,
label = opts[i].text..(opts[i].txt and " - "..opts[i].txt or ""), label = opts[i].text..(opts[i].txt and " - "..opts[i].txt or ""),
isRequired = opts[i].isRequired, isRequired = opts[i].isRequired,
name = opts[i].name, name = opts[i].name,
@@ -82,17 +87,58 @@ function createInput(title, opts)
default = opts[i].default, default = opts[i].default,
} }
end end
if opts[i].type == "checkbox" then
jsonPrint(opts[i])
for k in pairs(opts[i].options) do
if options[currentNum] then currentNum += 1 end
options[currentNum] = {
type = opts[i].type,
label = opts[i].options[k].text..(opts[i].txt and " - "..opts[i].txt or ""),
name = opts[i].options[k].value,
}
end
end
if opts[i].type == "color" then
options[currentNum] = {
type = opts[i].type,
label = opts[i].label,
isRequired = opts[i].isRequired,
format = opts[i].format,
default = opts[i].default,
}
end
if opts[i].type == "slider" then
options[currentNum] = {
type = opts[i].type,
label = opts[i].label,
isRequired = opts[i].required,
min = opts[i].min,
max = opts[i].max,
default = opts[i].default,
}
end
::skip::
end end
dialog = exports[OXLibExport]:inputDialog(title, options) dialog = exports[OXLibExport]:inputDialog(title, options)
return dialog return dialog
end elseif Config.System.Menu == "qb" then
for k, v in pairs(opts) do
if Config.System.Menu == "qb" then currentNum += 1
dialog = exports['qb-input']:ShowInput({ header = title, submitText = "Accept", inputs = opts }) if opts[k] == nil then
currentNum -= 1
else
options[currentNum] = opts[k]
end
end
dialog = exports['qb-input']:ShowInput(
{ header = title, submitText = "Accept", inputs = options }
)
return dialog return dialog
end
if Config.System.Menu == "gta" then elseif Config.System.Menu == "gta" then
WarMenu.CreateMenu(tostring(opts), WarMenu.CreateMenu(tostring(opts),
title, title,
" ", " ",
@@ -152,5 +198,44 @@ function createInput(title, opts)
end end
Wait(0) Wait(0)
end end
elseif Config.System.Menu == "esx" then -- horrible input dialog, not even worth using, get OX
local results = {}
for i, opt in ipairs(opts) do
local prompt = opt.text or opt.label or "Enter value"
-- For radio/select types, append available options in the prompt.
if (opt.type == "radio" or opt.type == "select") and opt.options then
local choices = ""
for j, choice in ipairs(opt.options) do
choices = choices .. choice.text .. " (" .. tostring(choice.value) .. ")"
if j < #opt.options then choices = choices .. ", " end
end
prompt = prompt .. " [" .. choices .. "]"
elseif opt.type == "number" then
prompt = prompt .. " (number between " .. (opt.min or 0) .. " and " .. (opt.max or 100) .. ")"
end
local value = nil
ESX.UI.Menu.Open('dialog', getScript(), 'input_' .. i, {
title = prompt
}, function(data, menu)
value = data.value
menu.close()
end, function(data, menu)
menu.close()
end)
-- Wait until the player submits a value.
while value == nil do
Wait(0)
end
-- Convert to a number if needed.
if opt.type == "number" then
value = tonumber(value)
end
results[opt.name or i] = value
end
return results
end end
end end

163
shared/inventories.lua Normal file
View File

@@ -0,0 +1,163 @@
-------------------------------------------------------------
-- Item Availability & Inventory Retrieval
-------------------------------------------------------------
---
--- Locks or unlocks the player's inventory.
--- Freezes/unfreezes the player's position, sets inventory busy state, and toggles hotbar usage.
---
--- @param toggle boolean True to lock inventory; false to unlock.
---
--- @usage
--- ```lua
--- lockInv(true) -- Lock inventory.
--- lockInv(false) -- Unlock inventory.
--- ```
function lockInv(toggle)
FreezeEntityPosition(PlayerPedId(), toggle)
LocalPlayer.state:set("inv_busy", toggle, true)
TriggerEvent('inventory:client:busy:status', toggle)
TriggerEvent('canUseInventoryAndHotbar:toggle', not toggle)
end
--- Checks if a player has the specified items in their inventory.
---
--- Verifies whether the required quantities are present. Returns a boolean and a table of details.
---
--- @param items string|table A single item name or table with required amounts.
--- @param amount number The required quantity (default 1).
--- @param src number|nil Player source ID (defaults to caller).
--- @return boolean boolean True if all items are available; otherwise, false.
--- @return table|nil table Table detailing counts for each item.
---
---@usage
--- ```lua
--- local hasAll, details = hasItem({"health_potion", "mana_potion"}, 2, playerId)
--- if hasAll then
--- -- Proceed with action
--- else
--- -- Inform the player about missing items
--- end
--- ```
function hasItem(items, amount, src)
local amount = amount and amount or 1
local grabInv, foundInv = getPlayerInv(src)
if type(items) ~= "table" then items = { [items] = amount and amount or 1, } end
if grabInv then
local hasTable = {}
for item, amt in pairs(items) do
if not Items[item] then print("^4ERROR^7: ^2Script can't find ingredient item in Shared Items - ^1"..item.."^7") end
local count = 0
for _, itemData in pairs(grabInv) do
if itemData and itemData.name == item then
count += (itemData.count or itemData.amount or 1)
end
end
foundInv = foundInv:gsub("%-", "^7-^6"):gsub("%_", "^7_^6")
local foundMessage = "^6Bridge^7: ^3hasItem^7[^6"..foundInv.."^7]: "..tostring(item).." ^3"..count.."^7/^3"..amt
if count >= amt then foundMessage = foundMessage.." ^5FOUND^7" else foundMessage = foundMessage .." ^1NOT FOUND^7" end
debugPrint(foundMessage)
hasTable[item] = { hasItem = count >= amt, count = count }
end
for k, v in pairs(hasTable) do
if not v.hasItem then
return false, hasTable
end
end
return true, hasTable
end
end
--- Retrieves a player's inventory based on the active inventory system.
---
--- @param src number|nil The player source ID (if nil, retrieves current player's inventory).
--- @return table|nil table The inventory items.
--- @return string|nil string The name of the inventory system.
---
---@usage
--- ```lua
--- local inventory, system = getPlayerInv(playerId)
--- if inventory then
--- -- Process inventory
--- end
--- ```
function getPlayerInv(src)
local grabInv = nil
local foundInv = ""
if isStarted(OXInv) then
foundInv = OXInv
if src then
grabInv = exports[OXInv]:GetInventoryItems(src)
else
grabInv = exports[OXInv]:GetPlayerItems()
end
elseif isStarted(QSInv) then
foundInv = QSInv
if src then
grabInv = exports[QSInv]:GetInventory(src)
else
grabInv = exports[QSInv]:getUserInventory()
end
elseif isStarted(OrigenInv) then
foundInv = OrigenInv
if src then
grabInv = exports[OrigenInv]:getInventory(src)
else
grabInv = exports[OrigenInv]:getInventory()
end
elseif isStarted(CoreInv) then
foundInv = CoreInv
if src then
grabInv = exports[CoreInv]:getInventory(src)
else
grabInv = exports[CoreInv]:getInventory()
end
elseif isStarted(CodeMInv) then
foundInv = CodeMInv
if src then
grabInv = exports[CodeMInv]:GetInventory(src)
else
grabInv = exports[CodeMInv]:GetClientPlayerInventory()
end
elseif isStarted(QBInv) then
foundInv = QBInv
if src then
grabInv = Core.Functions.GetPlayer(src).PlayerData.items
else
grabInv = Core.Functions.GetPlayerData().items
end
elseif isStarted(PSInv) then
foundInv = PSInv
if src then grabInv = Core.Functions.GetPlayer(src).PlayerData.items
else grabInv = Core.Functions.GetPlayerData().items end
elseif ESX and isStarted(ESXExport) then
foundInv = ESX
if src then
local xPlayer = ESX.GetPlayerFromId(src)
grabInv = xPlayer.inventory
else
local xPlayer = ESX.GetPlayerData() -- Client side, if available
grabInv = xPlayer.inventory
end
elseif isStarted(RSGInv) then
foundInv = RSGInv
if src then
grabInv = Core.Functions.GetPlayer(src).PlayerData.items
else
grabInv = Core.Functions.GetPlayerData().items
end
else
print("^4ERROR^7: ^2No Inventory detected ^7- ^2Check ^3starter^1.^2lua^7")
end
return grabInv, foundInv
end

View File

@@ -1,36 +1,72 @@
--[[
Animal Detection Module
-------------------------
This module determines whether a Ped is an animal and categorizes it as a cat, dog,
or other type (e.g., coyote). It uses predefined model hashes stored in the AnimalPeds table.
Global Flags:
- isCat, isDog, isBigDog, isSmallDog, isCoyote, isAnimal: Booleans to track the player's
current animal classification.
When running client-side (not on the server), the module checks the player's Ped after they load.
Usage Examples:
-- Check if the player's Ped is an animal:
local animalStatus = isPedAnimal()
-- Check if a given Ped is a cat:
if isCat(somePed) then print("This is a cat!") end
-- Determine if a Ped is a dog and whether it's big or small:
local isDogFlag, isBig = isDog(somePed)
-- Retrieve a flat list of all animal model hashes:
local allAnimalModels = getAnimalModels()
]]
-- Global animal classification flags.
isCat, isDog, isBigDog, isSmallDog, isCoyote, isAnimal = false, false, false, false, false, false isCat, isDog, isBigDog, isSmallDog, isCoyote, isAnimal = false, false, false, false, false, false
if not isServer() then if not isServer() then
onPlayerLoaded(function() onPlayerLoaded(function()
Wait(2000) Wait(2000)
-- Reset classification flags
isCat, isDog, isBigDog, isSmallDog, isCoyote = false, false, false, false, false isCat, isDog, isBigDog, isSmallDog, isCoyote = false, false, false, false, false
-- Check if the player's Ped is an animal.
isPedAnimal() isPedAnimal()
if isAnimal then if isAnimal then
local ped = PlayerPedId() local ped = PlayerPedId()
local pedModel = GetEntityModel(ped) local pedModel = GetEntityModel(ped)
-- Determine if the Ped is a cat:
-- Also treat 'ft-raccoon' as a cat unless it is 'ft-sphynx'
isCat = (isCat(ped) or pedModel == `ft-raccoon`) and (pedModel ~= `ft-sphynx`) isCat = (isCat(ped) or pedModel == `ft-raccoon`) and (pedModel ~= `ft-sphynx`)
-- Determine if the Ped is a dog and whether it's big:
isDog, isBigDog = isDog(ped) isDog, isBigDog = isDog(ped)
isSmallDog = not isBigDog isSmallDog = not isBigDog
if isDog and pedModel == `a_c_coyote` then isDog = false end if isDog and pedModel == `a_c_coyote` then isDog = false end
-- Determine if the Ped is a coyote (special case):
isCoyote = (pedModel == `ft-sphynx` or pedModel == `a_c_coyote`) isCoyote = (pedModel == `ft-sphynx` or pedModel == `a_c_coyote`)
-- Special override: if model is 'ft-capmonkey2', treat as a dog.
if pedModel == `ft-capmonkey2` then isDog = true end if pedModel == `ft-capmonkey2` then isDog = true end
end end
end, true) end, true)
--- Determines if a given Ped is classified as an animal. -------------------------------------------------------------
-- Animal Classification Functions
-------------------------------------------------------------
--- Determines whether a given Ped is classified as an animal.
--- ---
--- This function checks whether the specified Ped (or the player's Ped if none is provided) --- Checks if the Ped's model hash appears in any of the animal categories defined in AnimalPeds.
--- is listed within the predefined `AnimalPeds` tables. It iterates through all animal types
--- to verify if the Ped's model hash matches any known animal models.
--- ---
---@param ped number|nil Optional. The Ped entity to check. Defaults to the player's Ped (`PlayerPedId()`). --- @param ped number|nil Optional. The Ped entity to check. Defaults to the player's Ped.
--- --- @return boolean boolean True if the Ped is an animal, otherwise false.
---@return boolean `true` if the Ped is an animal, otherwise `false`.
--- ---
--- @usage --- @usage
--- ```lua --- ```lua
@@ -39,31 +75,24 @@ if not isServer() then
--- ``` --- ```
function isPedAnimal(ped) function isPedAnimal(ped)
local PedModel = GetEntityModel(ped or PlayerPedId()) local PedModel = GetEntityModel(ped or PlayerPedId())
for _, animalCategory in pairs(AnimalPeds) do
for _, animalTypeTable in pairs(AnimalPeds) do for animalModelHash, _ in pairs(animalCategory) do
for animalModelHash, _ in pairs(animalTypeTable) do
if PedModel == animalModelHash then if PedModel == animalModelHash then
isAnimal = true isAnimal = true
break debugPrint("^6Bridge^7: ^2Ped is Animal")
return true
end end
end end
if isAnimal then
debugPrint("^6Debug^7: ^2Ped is Animal^1")
break
end
end end
return false
return isAnimal
end end
--- Checks if a given Ped is classified specifically as a cat. --- Checks if a given Ped is classified as a cat.
--- ---
--- This function verifies whether the specified Ped (or the player's Ped if none is provided) --- Iterates through the CatPeds table and returns true if the Ped's model matches.
--- matches any of the model hashes listed under `AnimalPeds.CatPeds`. It returns `true` if a match is found.
--- ---
---@param ped number|nil Optional. The Ped entity to check. Defaults to the player's Ped (`PlayerPedId()`). --- @param ped number|nil Optional. The Ped entity to check. Defaults to the player's Ped.
--- --- @return boolean True if the Ped is a cat, otherwise false.
---@return boolean `true` if the Ped is a cat, otherwise `false`.
--- ---
---@usage ---@usage
--- ```lua --- ```lua
@@ -78,24 +107,20 @@ if not isServer() then
--- ``` --- ```
function isCat(ped) function isCat(ped)
local PedModel = GetEntityModel(ped or PlayerPedId()) local PedModel = GetEntityModel(ped or PlayerPedId())
for k, v in pairs(AnimalPeds.CatPeds) do for modelHash, _ in pairs(AnimalPeds.CatPeds) do
if PedModel == k then if PedModel == modelHash then
return true return true
end end
end end
return false return false
end end
--- Determines if a given Ped is classified as a dog and identifies its size category. --- Determines if a given Ped is a dog and identifies its size category.
--- ---
--- This function checks whether the specified Ped (or the player's Ped if none is provided) --- Checks the BigDogs and SmallDogs tables to see if the Ped's model matches any dog model.
--- matches any model hashes listed under `AnimalPeds.BigDogs` or `AnimalPeds.SmallDogs`. It returns
--- two values: the first indicates if the Ped is a dog, and the second specifies whether it's a
--- large dog (`true`) or a small dog (`false`). If the Ped is not a dog, the second return value is `nil`.
--- ---
---@param ped number|nil Optional. The Ped entity to check. Defaults to the player's Ped (`PlayerPedId()`). --- @param ped number|nil Optional. The Ped entity to check. Defaults to the player's Ped.
--- ---@return boolean, boolean|nil boolean Returns `true` and `true` if the Ped is a big dog,
---@return boolean, boolean|nil Returns `true` and `true` if the Ped is a big dog,
--- `true` and `false` if it's a small dog, --- `true` and `false` if it's a small dog,
--- or `false` and `nil` if it's not a dog. --- or `false` and `nil` if it's not a dog.
--- ---
@@ -124,27 +149,24 @@ if not isServer() then
--- ``` --- ```
function isDog(ped) function isDog(ped)
local PedModel = GetEntityModel(ped or PlayerPedId()) local PedModel = GetEntityModel(ped or PlayerPedId())
for k, v in pairs(AnimalPeds.BigDogs) do for modelHash, _ in pairs(AnimalPeds.BigDogs) do
if PedModel == k then if PedModel == modelHash then
return true, true return true, true
end end
end end
for modelHash, _ in pairs(AnimalPeds.SmallDogs) do
for k, v in pairs(AnimalPeds.SmallDogs) do if PedModel == modelHash then
if PedModel == k then
return true, false return true, false
end end
end end
return false, nil return false, nil
end end
--- Retrieves a list of all animal model hashes. --- Compiles and returns a flat table of all animal model hashes.
--- ---
--- This function compiles and returns a flat table containing all model hashes --- Iterates through every category in AnimalPeds and collects all model hashes.
--- from the various animal categories defined within the `AnimalPeds` table.
--- It's useful for iterating over or performing bulk operations on all animal models.
--- ---
---@return table table A table containing all animal model hashes. --- @return table table A table containing all animal model hashes.
--- ---
---@usage ---@usage
--- ```lua --- ```lua
@@ -154,289 +176,109 @@ if not isServer() then
--- end --- end
--- ``` --- ```
function getAnimalModels() function getAnimalModels()
local animalModels = {}
for _, animalCategory in pairs(AnimalPeds) do
for modelHash, _ in pairs(animalCategory) do
table.insert(animalModels, modelHash)
end
end
return animalModels
end
--- Compiles and returns a table of animal animations for the ped model.
---
--- Iterates through every category in AnimalPeds and collects all anims.
---
--- @return table table A table containing all current model anims.
---
---@usage
--- ```lua
--- local getAnim = getAnimalAnims(ped)
--- playAnim(getAnim.sitDict, getAnim.sitAnim, -1, 1)
--- ```
function getAnimalAnims(ped)
local model = GetEntityModel(ped)
local animalTable = {} local animalTable = {}
for k in pairs(AnimalPeds) do for _, animalCategory in pairs(AnimalPeds) do
for v in pairs(AnimalPeds[k]) do for k, v in pairs(animalCategory) do
animalTable[#animalTable+1] = v if k == model then
animalTable = v
break
end
end end
end end
return animalTable return animalTable
end end
end end
-------------------------------------------------------------
-- Animal Models Data
-------------------------------------------------------------
-- Define the animal models and their associated animations.
AnimalPeds = { AnimalPeds = {
BigDogs = { BigDogs = {
-- Big Dogs [`a_c_chop`] = { deathAnim = "dead_right", deathDict = "creatures@chop@move", exitAnim = "getup_r", exitDict = "creatures@chop@getup", sitAnim = "sit", sitDict = "creatures@rottweiler@in_vehicle@std_car" },
[`a_c_chop`] = { [`a_c_k9`] = { deathAnim = "dead_right", deathDict = "creatures@chop@move", exitAnim = "getup_r", exitDict = "creatures@chop@getup", sitAnim = "sit", sitDict = "creatures@rottweiler@in_vehicle@std_car" },
deathAnim = "dead_right", deathDict = "creatures@chop@move", [`a_c_husky`] = { deathAnim = "dead_right", deathDict = "creatures@rottweiler@move", exitAnim = "getup_r", exitDict = "creatures@rottweiler@getup", sitAnim = "sit", sitDict = "creatures@rottweiler@in_vehicle@std_car" },
exitAnim = "getup_r", exitDict = "creatures@chop@getup", [`a_c_retriever`] = { deathAnim = "dead_right", deathDict = "creatures@rottweiler@move", exitAnim = "getup_r", exitDict = "creatures@rottweiler@getup", sitAnim = "sit", sitDict = "creatures@rottweiler@in_vehicle@std_car" },
sitAnim = "sit", sitDict = "creatures@rottweiler@in_vehicle@std_car" [`a_c_shepherd`] = { deathAnim = "dead_right", deathDict = "creatures@rottweiler@move", exitAnim = "getup_r", exitDict = "creatures@rottweiler@getup", sitAnim = "sit", sitDict = "creatures@rottweiler@in_vehicle@std_car" },
}, [`a_c_rottweiler`] = { deathAnim = "dead_right", deathDict = "creatures@rottweiler@move", exitAnim = "getup_r", exitDict = "creatures@rottweiler@getup", sitAnim = "sit", sitDict = "creatures@rottweiler@in_vehicle@std_car" },
[`a_c_k9`] = { [`ft-aushep`] = { deathAnim = "dead_right", deathDict = "creatures@rottweiler@move", exitAnim = "getup_r", exitDict = "creatures@rottweiler@getup", sitAnim = "sit", sitDict = "creatures@rottweiler@in_vehicle@std_car" },
deathAnim = "dead_right", deathDict = "creatures@chop@move", [`golden_r`] = { deathAnim = "dead_right", deathDict = "creatures@rottweiler@move", exitAnim = "getup_r", exitDict = "creatures@rottweiler@getup", sitAnim = "sit", sitDict = "creatures@rottweiler@in_vehicle@std_car" },
exitAnim = "getup_r", exitDict = "creatures@chop@getup", [`ft-dobermanv2`] = { deathAnim = "dead_right", deathDict = "creatures@rottweiler@move", exitAnim = "getup_r", exitDict = "creatures@rottweiler@getup", sitAnim = "sit", sitDict = "creatures@rottweiler@in_vehicle@std_car" },
sitAnim = "sit", sitDict = "creatures@rottweiler@in_vehicle@std_car" [`doberman`] = { deathAnim = "dead_right", deathDict = "creatures@rottweiler@move", exitAnim = "getup_r", exitDict = "creatures@rottweiler@getup", sitAnim = "sit", sitDict = "creatures@rottweiler@in_vehicle@std_car" },
}, [`ft-gs`] = { deathAnim = "dead_right", deathDict = "creatures@rottweiler@move", exitAnim = "getup_r", exitDict = "creatures@rottweiler@getup", sitAnim = "sit", sitDict = "creatures@rottweiler@in_vehicle@std_car" },
[`a_c_husky`] = { [`k9_husky`] = { deathAnim = "dead_right", deathDict = "creatures@rottweiler@move", exitAnim = "getup_r", exitDict = "creatures@rottweiler@getup", sitAnim = "sit", sitDict = "creatures@rottweiler@in_vehicle@std_car" },
deathAnim = "dead_right", deathDict = "creatures@rottweiler@move", [`ft-bloodhound`] = { deathAnim = "dead_right", deathDict = "creatures@rottweiler@move", exitAnim = "getup_r", exitDict = "creatures@rottweiler@getup", sitAnim = "sit", sitDict = "creatures@rottweiler@in_vehicle@std_car" },
exitAnim = "getup_r", exitDict = "creatures@rottweiler@getup", [`bernard`] = { deathAnim = "dead_right", deathDict = "creatures@rottweiler@move", exitAnim = "getup_r", exitDict = "creatures@rottweiler@getup", sitAnim = "sit", sitDict = "creatures@rottweiler@in_vehicle@std_car" },
sitAnim = "sit", sitDict = "creatures@rottweiler@in_vehicle@std_car" [`ft-pterrier`] = { deathAnim = "dead_right", deathDict = "creatures@rottweiler@move", exitAnim = "getup_r", exitDict = "creatures@rottweiler@getup", sitAnim = "sit", sitDict = "creatures@rottweiler@in_vehicle@std_car" },
}, [`ft-labrador`] = { deathAnim = "dead_right", deathDict = "creatures@rottweiler@move", exitAnim = "getup_r", exitDict = "creatures@rottweiler@getup", sitAnim = "sit", sitDict = "creatures@rottweiler@in_vehicle@std_car" },
[`a_c_retriever`] = { [`dane`] = { deathAnim = "dead_right", deathDict = "creatures@rottweiler@move", exitAnim = "getup_r", exitDict = "creatures@rottweiler@getup", sitAnim = "sit", sitDict = "creatures@rottweiler@in_vehicle@std_car" },
deathAnim = "dead_right", deathDict = "creatures@rottweiler@move", [`ft_malinois`] = { deathAnim = "dead_right", deathDict = "creatures@rottweiler@move", exitAnim = "getup_r", exitDict = "creatures@rottweiler@getup", sitAnim = "sit", sitDict = "creatures@rottweiler@in_vehicle@std_car" },
exitAnim = "getup_r", exitDict = "creatures@rottweiler@getup", [`abdog`] = { deathAnim = "dead_right", deathDict = "creatures@rottweiler@move", exitAnim = "getup_r", exitDict = "creatures@rottweiler@getup", sitAnim = "sit", sitDict = "creatures@rottweiler@in_vehicle@std_car" },
sitAnim = "sit", sitDict = "creatures@rottweiler@in_vehicle@std_car" [`dalmatian`] = { deathAnim = "dead_right", deathDict = "creatures@rottweiler@move", exitAnim = "getup_r", exitDict = "creatures@rottweiler@getup", sitAnim = "sit", sitDict = "creatures@rottweiler@in_vehicle@std_car" },
}, [`a_c_dalmatian`] = { deathAnim = "dead_right", deathDict = "creatures@rottweiler@move", exitAnim = "getup_r", exitDict = "creatures@rottweiler@getup", sitAnim = "sit", sitDict = "creatures@rottweiler@in_vehicle@std_car" },
[`a_c_shepherd`] = { [`ft-boxer`] = { deathAnim = "dead_right", deathDict = "creatures@rottweiler@move", exitAnim = "getup_r", exitDict = "creatures@rottweiler@getup", sitAnim = "sit", sitDict = "creatures@rottweiler@in_vehicle@std_car" },
deathAnim = "dead_right", deathDict = "creatures@rottweiler@move", [`ft-bs`] = { deathAnim = "dead_right", deathDict = "creatures@rottweiler@move", exitAnim = "getup_r", exitDict = "creatures@rottweiler@getup", sitAnim = "sit", sitDict = "creatures@rottweiler@in_vehicle@std_car" },
exitAnim = "getup_r", exitDict = "creatures@rottweiler@getup", [`chowchow`] = { deathAnim = "dead_right", deathDict = "creatures@rottweiler@move", exitAnim = "getup_r", exitDict = "creatures@rottweiler@getup", sitAnim = "sit", sitDict = "creatures@rottweiler@in_vehicle@std_car" },
sitAnim = "sit", sitDict = "creatures@rottweiler@in_vehicle@std_car" [`a_c_coyote`] = { deathAnim = "dead_right", deathDict = "creatures@coyote@move", exitAnim = "getup_r", exitDict = "creatures@coyote@getup", sitAnim = "base", sitDict = "creatures@coyote@amb@world_coyote_howl@base" },
}, [`a_c_coyote_02`] = { deathAnim = "dead_right", deathDict = "creatures@coyote@move", exitAnim = "getup_r", exitDict = "creatures@coyote@getup", sitAnim = "base", sitDict = "creatures@coyote@amb@world_coyote_howl@base" },
[`a_c_rottweiler`] = {
deathAnim = "dead_right", deathDict = "creatures@rottweiler@move",
exitAnim = "getup_r", exitDict = "creatures@rottweiler@getup",
sitAnim = "sit", sitDict = "creatures@rottweiler@in_vehicle@std_car"
},
[`ft-aushep`] = {
deathAnim = "dead_right", deathDict = "creatures@rottweiler@move",
exitAnim = "getup_r", exitDict = "creatures@rottweiler@getup",
sitAnim = "sit", sitDict = "creatures@rottweiler@in_vehicle@std_car"
},
[`golden_r`] = {
deathAnim = "dead_right", deathDict = "creatures@rottweiler@move",
exitAnim = "getup_r", exitDict = "creatures@rottweiler@getup",
sitAnim = "sit", sitDict = "creatures@rottweiler@in_vehicle@std_car"
},
[`ft-dobermanv2`] = {
deathAnim = "dead_right", deathDict = "creatures@rottweiler@move",
exitAnim = "getup_r", exitDict = "creatures@rottweiler@getup",
sitAnim = "sit", sitDict = "creatures@rottweiler@in_vehicle@std_car"
},
[`doberman`] = {
deathAnim = "dead_right", deathDict = "creatures@rottweiler@move",
exitAnim = "getup_r", exitDict = "creatures@rottweiler@getup",
sitAnim = "sit", sitDict = "creatures@rottweiler@in_vehicle@std_car"
},
[`ft-gs`] = {
deathAnim = "dead_right", deathDict = "creatures@rottweiler@move",
exitAnim = "getup_r", exitDict = "creatures@rottweiler@getup",
sitAnim = "sit", sitDict = "creatures@rottweiler@in_vehicle@std_car"
},
[`k9_husky`] = {
deathAnim = "dead_right", deathDict = "creatures@rottweiler@move",
exitAnim = "getup_r", exitDict = "creatures@rottweiler@getup",
sitAnim = "sit", sitDict = "creatures@rottweiler@in_vehicle@std_car"
},
[`ft-bloodhound`] = {
deathAnim = "dead_right", deathDict = "creatures@rottweiler@move",
exitAnim = "getup_r", exitDict = "creatures@rottweiler@getup",
sitAnim = "sit", sitDict = "creatures@rottweiler@in_vehicle@std_car"
},
[`bernard`] = {
deathAnim = "dead_right", deathDict = "creatures@rottweiler@move",
exitAnim = "getup_r", exitDict = "creatures@rottweiler@getup",
sitAnim = "sit", sitDict = "creatures@rottweiler@in_vehicle@std_car"
},
[`ft-pterrier`] = {
deathAnim = "dead_right", deathDict = "creatures@rottweiler@move",
exitAnim = "getup_r", exitDict = "creatures@rottweiler@getup",
sitAnim = "sit", sitDict = "creatures@rottweiler@in_vehicle@std_car"
},
[`ft-labrador`] = {
deathAnim = "dead_right", deathDict = "creatures@rottweiler@move",
exitAnim = "getup_r", exitDict = "creatures@rottweiler@getup",
sitAnim = "sit", sitDict = "creatures@rottweiler@in_vehicle@std_car"
},
[`dane`] = {
deathAnim = "dead_right", deathDict = "creatures@rottweiler@move",
exitAnim = "getup_r", exitDict = "creatures@rottweiler@getup",
sitAnim = "sit", sitDict = "creatures@rottweiler@in_vehicle@std_car"
},
[`ft_malinois`] = {
deathAnim = "dead_right", deathDict = "creatures@rottweiler@move",
exitAnim = "getup_r", exitDict = "creatures@rottweiler@getup",
sitAnim = "sit", sitDict = "creatures@rottweiler@in_vehicle@std_car"
},
[`abdog`] = {
deathAnim = "dead_right", deathDict = "creatures@rottweiler@move",
exitAnim = "getup_r", exitDict = "creatures@rottweiler@getup",
sitAnim = "sit", sitDict = "creatures@rottweiler@in_vehicle@std_car"
},
[`dalmatian`] = {
deathAnim = "dead_right", deathDict = "creatures@rottweiler@move",
exitAnim = "getup_r", exitDict = "creatures@rottweiler@getup",
sitAnim = "sit", sitDict = "creatures@rottweiler@in_vehicle@std_car"
},
[`a_c_dalmatian`] = {
deathAnim = "dead_right", deathDict = "creatures@rottweiler@move",
exitAnim = "getup_r", exitDict = "creatures@rottweiler@getup",
sitAnim = "sit", sitDict = "creatures@rottweiler@in_vehicle@std_car"
},
[`ft-boxer`] = {
deathAnim = "dead_right", deathDict = "creatures@rottweiler@move",
exitAnim = "getup_r", exitDict = "creatures@rottweiler@getup",
sitAnim = "sit", sitDict = "creatures@rottweiler@in_vehicle@std_car"
},
[`ft-bs`] = {
deathAnim = "dead_right", deathDict = "creatures@rottweiler@move",
exitAnim = "getup_r", exitDict = "creatures@rottweiler@getup",
sitAnim = "sit", sitDict = "creatures@rottweiler@in_vehicle@std_car"
},
[`chowchow`] = {
deathAnim = "dead_right", deathDict = "creatures@rottweiler@move",
exitAnim = "getup_r", exitDict = "creatures@rottweiler@getup",
sitAnim = "sit", sitDict = "creatures@rottweiler@in_vehicle@std_car"
},
[`a_c_coyote`] = {
deathAnim = "dead_right", deathDict = "creatures@coyote@move",
exitAnim = "getup_r", exitDict = "creatures@coyote@getup",
sitAnim = "base", sitDict = "creatures@coyote@amb@world_coyote_howl@base"
},
[`a_c_coyote_02`] = {
deathAnim = "dead_right", deathDict = "creatures@coyote@move",
exitAnim = "getup_r", exitDict = "creatures@coyote@getup",
sitAnim = "base", sitDict = "creatures@coyote@amb@world_coyote_howl@base"
},
}, },
SmallDogs = { SmallDogs = {
-- Small Dogs [`a_c_poodle`] = { deathAnim = "dead_right", deathDict = "creatures@pug@move", exitAnim = "getup_r", exitDict = "creatures@pug@getup", sitAnim = "base", sitDict = "creatures@pug@amb@world_dog_sitting@base" },
[`a_c_poodle`] = { [`ft-chihuahua`] = { deathAnim = "dead_right", deathDict = "creatures@pug@move", exitAnim = "getup_r", exitDict = "creatures@pug@getup", sitAnim = "base", sitDict = "creatures@pug@amb@world_dog_sitting@base" },
deathAnim = "dead_right", deathDict = "creatures@pug@move", [`a_c_pug`] = { deathAnim = "dead_right", deathDict = "creatures@pug@move", exitAnim = "getup_r", exitDict = "creatures@pug@getup", sitAnim = "base", sitDict = "creatures@pug@amb@world_dog_sitting@base" },
exitAnim = "getup_r", exitDict = "creatures@pug@getup", [`a_c_pug_02`] = { deathAnim = "dead_right", deathDict = "creatures@pug@move", exitAnim = "getup_r", exitDict = "creatures@pug@getup", sitAnim = "base", sitDict = "creatures@pug@amb@world_dog_sitting@base" },
sitAnim = "base", sitDict = "creatures@pug@amb@world_dog_sitting@base" [`a_c_westy`] = { deathAnim = "dead_right", deathDict = "creatures@pug@move", exitAnim = "getup_r", exitDict = "creatures@pug@getup", sitAnim = "base", sitDict = "creatures@pug@amb@world_dog_sitting@base" },
}, [`ft-pretriever`] = { deathAnim = "dead_right", deathDict = "creatures@pug@move", exitAnim = "getup_r", exitDict = "creatures@pug@getup", sitAnim = "base", sitDict = "creatures@pug@amb@world_dog_sitting@base" },
[`ft-chihuahua`] = { [`ft-shepk9`] = { deathAnim = "dead_right", deathDict = "creatures@pug@move", exitAnim = "getup_r", exitDict = "creatures@pug@getup", sitAnim = "base", sitDict = "creatures@pug@amb@world_dog_sitting@base" },
deathAnim = "dead_right", deathDict = "creatures@pug@move",
exitAnim = "getup_r", exitDict = "creatures@pug@getup",
sitAnim = "base", sitDict = "creatures@pug@amb@world_dog_sitting@base"
},
[`a_c_pug`] = {
deathAnim = "dead_right", deathDict = "creatures@pug@move",
exitAnim = "getup_r", exitDict = "creatures@pug@getup",
sitAnim = "base", sitDict = "creatures@pug@amb@world_dog_sitting@base"
},
[`a_c_pug_02`] = {
deathAnim = "dead_right", deathDict = "creatures@pug@move",
exitAnim = "getup_r", exitDict = "creatures@pug@getup",
sitAnim = "base", sitDict = "creatures@pug@amb@world_dog_sitting@base"
},
[`a_c_westy`] = {
deathAnim = "dead_right", deathDict = "creatures@pug@move",
exitAnim = "getup_r", exitDict = "creatures@pug@getup",
sitAnim = "base", sitDict = "creatures@pug@amb@world_dog_sitting@base"
},
[`ft-pretriever`] = {
deathAnim = "dead_right", deathDict = "creatures@pug@move",
exitAnim = "getup_r", exitDict = "creatures@pug@getup",
sitAnim = "base", sitDict = "creatures@pug@amb@world_dog_sitting@base"
},
[`ft-shepk9`] = {
deathAnim = "dead_right", deathDict = "creatures@pug@move",
exitAnim = "getup_r", exitDict = "creatures@pug@getup",
sitAnim = "base", sitDict = "creatures@pug@amb@world_dog_sitting@base"
},
}, },
CatPeds = { CatPeds = {
-- Cat [`bshorthair`] = { deathAnim = "dead_right", deathDict = "creatures@cat@move", exitAnim = "getup_r", exitDict = "creatures@cat@getup", sitAnim = "base", sitDict = "creatures@cat@amb@world_cat_sleeping_ledge@base" },
[`bshorthair`] = { [`a_c_cat_01`] = { deathAnim = "dead_right", deathDict = "creatures@cat@move", exitAnim = "getup_r", exitDict = "creatures@cat@getup", sitAnim = "base", sitDict = "creatures@cat@amb@world_cat_sleeping_ledge@base" },
deathAnim = "dead_right", deathDict = "creatures@cat@move", [`ft-sphynx`] = { deathAnim = "dead_right", deathDict = "creatures@coyote@move", exitAnim = "getup_r", exitDict = "creatures@coyote@getup", sitAnim = "base", sitDict = "creatures@coyote@amb@world_coyote_howl@base" },
exitAnim = "getup_r", exitDict = "creatures@cat@getup",
sitAnim = "base", sitDict = "creatures@cat@amb@world_cat_sleeping_ledge@base"
},
[`a_c_cat_01`] = {
deathAnim = "dead_right", deathDict = "creatures@cat@move",
exitAnim = "getup_r", exitDict = "creatures@cat@getup",
sitAnim = "base", sitDict = "creatures@cat@amb@world_cat_sleeping_ledge@base"
},
[`ft-sphynx`] = {
deathAnim = "dead_right", deathDict = "creatures@coyote@move",
exitAnim = "getup_r", exitDict = "creatures@coyote@getup",
sitAnim = "base", sitDict = "creatures@coyote@amb@world_coyote_howl@base"
},
}, },
OtherPeds = { OtherPeds = {
-- Other Animals [`ft-raccoon`] = { deathAnim = "dead_right", deathDict = "creatures@cat@move", exitAnim = "getup_r", exitDict = "creatures@cat@getup", sitAnim = "base", sitDict = "creatures@cat@amb@world_cat_sleeping_ledge@base" },
[`ft-raccoon`] = { [`a_c_hen`] = { deathAnim = "dead_right", deathDict = "creatures@hen@move", exitAnim = "getup_r", exitDict = "creatures@hen@getup" },
deathAnim = "dead_right", deathDict = "creatures@cat@move", [`a_c_rabbit_01`] = { deathAnim = "dead_right", deathDict = "creatures@rabbit@move", exitAnim = "getup_r", exitDict = "creatures@rabbit@getup", sitAnim = "idle_c", sitDict = "creatures@coyote@amb@world_coyote_howl@base" },
exitAnim = "getup_r", exitDict = "creatures@cat@getup", [`a_c_rabbit_02`] = { deathAnim = "dead_right", deathDict = "creatures@rabbit@move", exitAnim = "getup_r", exitDict = "creatures@rabbit@getup", sitAnim = "idle_c", sitDict = "creatures@coyote@amb@world_coyote_howl@base" },
sitAnim = "base", sitDict = "creatures@cat@amb@world_cat_sleeping_ledge@base" [`a_c_rat`] = { deathAnim = "dead_right", deathDict = "creatures@rat@move", exitAnim = "getup_r", exitDict = "creatures@rat@getup" },
}, [`a_c_deer`] = { deathAnim = "dead_right", deathDict = "creatures@deer@move", exitAnim = "getup_r", exitDict = "creatures@deer@getup" },
[`a_c_hen`] = { [`a_c_boar`] = { deathAnim = "dead_right", deathDict = "creatures@boar@move", exitAnim = "getup_r", exitDict = "creatures@boar@getup" },
deathAnim = "dead_right", deathDict = "creatures@hen@move", [`a_c_boar_02`] = { deathAnim = "dead_right", deathDict = "creatures@boar@move", exitAnim = "getup_r", exitDict = "creatures@boar@getup" },
exitAnim = "getup_r", exitDict = "creatures@hen@getup" [`a_c_chicken`] = { deathAnim = "dead_right", deathDict = "creatures@chicken@move", exitAnim = "getup_r", exitDict = "creatures@chicken@getup" },
}, [`a_c_pig`] = { deathAnim = "dead_right", deathDict = "creatures@pig@move", exitAnim = "getup_r", exitDict = "creatures@pig@getup" },
[`a_c_rabbit_01`] = { [`a_c_sharkhammer`] = { deathAnim = "dead_right", deathDict = "creatures@sharkhammer@move", exitAnim = "getup_r", exitDict = "creatures@sharkhammer@getup" },
deathAnim = "dead_right", deathDict = "creatures@rabbit@move", [`a_c_sharktiger`] = { deathAnim = "dead_right", deathDict = "creatures@sharktiger@move", exitAnim = "getup_r", exitDict = "creatures@sharktiger@getup" },
exitAnim = "getup_r", exitDict = "creatures@rabbit@getup", [`a_c_crow`] = { deathAnim = "dead_down", deathDict = "creatures@crow@move", exitAnim = "nill", exitDict = "creatures@pug@move" },
sitAnim = "idle_c", sitDict = "creatures@coyote@amb@world_coyote_howl@base" [`a_c_pigeon`] = { deathAnim = "dead_down", deathDict = "creatures@pigeon@move", exitAnim = "nill", exitDict = "creatures@pug@move" },
},
[`a_c_rabbit_02`] = {
deathAnim = "dead_right", deathDict = "creatures@rabbit@move",
exitAnim = "getup_r", exitDict = "creatures@rabbit@getup",
sitAnim = "idle_c", sitDict = "creatures@coyote@amb@world_coyote_howl@base"
},
[`a_c_rat`] = {
deathAnim = "dead_right", deathDict = "creatures@rat@move",
exitAnim = "getup_r", exitDict = "creatures@rat@getup"
},
[`a_c_deer`] = {
deathAnim = "dead_right", deathDict = "creatures@deer@move",
exitAnim = "getup_r", exitDict = "creatures@deer@getup"
},
[`a_c_boar`] = {
deathAnim = "dead_right", deathDict = "creatures@boar@move",
exitAnim = "getup_r", exitDict = "creatures@boar@getup"
},
[`a_c_boar_02`] = {
deathAnim = "dead_right", deathDict = "creatures@boar@move",
exitAnim = "getup_r", exitDict = "creatures@boar@getup"
},
[`a_c_chicken`] = {
deathAnim = "dead_right", deathDict = "creatures@chicken@move",
exitAnim = "getup_r", exitDict = "creatures@chicken@getup"
},
[`a_c_pig`] = {
deathAnim = "dead_right", deathDict = "creatures@pig@move",
exitAnim = "getup_r", exitDict = "creatures@pig@getup"
},
[`a_c_sharkhammer`] = {
deathAnim = "dead_right", deathDict = "creatures@sharkhammer@move",
exitAnim = "getup_r", exitDict = "creatures@sharkhammer@getup"
},
[`a_c_sharktiger`] = {
deathAnim = "dead_right", deathDict = "creatures@sharktiger@move",
exitAnim = "getup_r", exitDict = "creatures@sharktiger@getup"
},
[`a_c_crow`] = {
deathAnim = "dead_down", deathDict = "creatures@crow@move",
exitAnim = "nill", exitDict = "creatures@pug@move", -- no get up anim
},
[`a_c_pigeon`] = {
deathAnim = "dead_down", deathDict = "creatures@pigeon@move",
exitAnim = "nill", exitDict = "creatures@pug@move", -- no get up anim
},
}, },
Monekys = { Monekys = {
[`ft-chimpanzee`] = { [`ft-chimpanzee`] = { deathAnim = "dead", deathDict = "dead_a", exitAnim = "get_up@sat_on_floor@to_stand", exitDict = "getup_0" },
deathAnim = "dead", deathDict = "dead_a", [`a_c_chimp`] = { deathAnim = "dead", deathDict = "dead_a", exitAnim = "get_up@sat_on_floor@to_stand", exitDict = "getup_0" },
exitAnim = "get_up@sat_on_floor@to_stand", exitDict = "getup_0" [`a_c_chimp_02`] = { deathAnim = "dead", deathDict = "dead_a", exitAnim = "get_up@sat_on_floor@to_stand", exitDict = "getup_0" },
}, [`a_c_rhesus`] = { deathAnim = "dead", deathDict = "dead_a", exitAnim = "get_up@sat_on_floor@to_stand", exitDict = "getup_0" },
[`a_c_chimp`] = { [`ft-capmonkey2`] = { deathAnim = "dead_right", deathDict = "creatures@pug@move", exitAnim = "getup_r", exitDict = "creatures@pug@getup", sitAnim = "base", sitDict = "creatures@pug@amb@world_dog_sitting@base" },
deathAnim = "dead", deathDict = "dead_a",
exitAnim = "get_up@sat_on_floor@to_stand", exitDict = "getup_0"
},
[`a_c_chimp_02`] = {
deathAnim = "dead", deathDict = "dead_a",
exitAnim = "get_up@sat_on_floor@to_stand", exitDict = "getup_0"
},
[`a_c_rhesus`] = {
deathAnim = "dead", deathDict = "dead_a",
exitAnim = "get_up@sat_on_floor@to_stand", exitDict = "getup_0"
},
[`ft-capmonkey2`] = {
deathAnim = "dead_right", deathDict = "creatures@pug@move",
exitAnim = "getup_r", exitDict = "creatures@pug@getup",
sitAnim = "base", sitDict = "creatures@pug@amb@world_dog_sitting@base"
},
} }
} }

File diff suppressed because it is too large Load Diff

View File

@@ -1,17 +1,32 @@
-- Global variable to track duty status --[[
Duty & Interaction Utilities Module
--------------------------------------
This module provides functions related to:
• Determining boss roles from Jobs and Gangs tables.
• Checking a player's job and duty status.
• Toggling duty state.
• Simulating player interactions such as hand washing, using toilets/urinals,
and teleporting via doors.
]]
-------------------------------------------------------------
-- Global Duty Status
-------------------------------------------------------------
onDuty = false onDuty = false
--- Scans the 'Jobs' and 'Gangs' tables to identify roles classified as Bosses. -------------------------------------------------------------
-- Boss Role Detection
-------------------------------------------------------------
--- Scans the 'Jobs' and 'Gangs' tables to identify roles classified as bosses.
--- ---
--- This function iterates through the specified role's grades within the `Jobs` or `Gangs` tables. --- Iterates through the specified role's grades in the Jobs or Gangs table and returns
--- It identifies which grades are marked as bosses (`isboss`) or have bank authorization (`bankAuth`). --- a table mapping the role to the lowest grade number that qualifies as a boss (isboss or bankAuth).
--- The function returns a table where each role maps to the lowest grade number that qualifies as a boss.
--- ---
---@param role string The name of the job or gang role to check for boss grades. --- @param role string The job or gang role to check.
--- @return table table A table with the role mapped to its boss grade number.
--- ---
---@return table table A table containing roles mapped to their respective boss grade numbers. --- @usage
---
---@usage
--- ```lua --- ```lua
--- local bosses = makeBossRoles("police") --- local bosses = makeBossRoles("police")
--- if bosses["police"] then --- if bosses["police"] then
@@ -31,27 +46,30 @@ function makeBossRoles(role)
return boss return boss
end end
--- Checks if the player has a specific job and is on duty. -------------------------------------------------------------
-- Job & Duty Checks
-------------------------------------------------------------
--- Checks if the player has a specific job (or gang) and is on duty.
--- ---
--- This function verifies whether the player possesses the specified job and, if applicable, --- Verifies whether the player possesses the specified role. If the role is defined in the Jobs table,
--- whether they are currently on duty. It provides a notification if the player fails these checks. --- it also checks that the player is clocked in (onDuty). If the check fails, a notification is sent.
--- ---
---@param job string The name of the job or gang to check. --- @param job string The job or gang to check.
--- @return boolean Returns true if the player meets the criteria; false otherwise.
--- ---
---@return boolean Returns `true` if the player has the job (and is on duty if required), otherwise `false`. --- @usage
---
---@usage
--- ```lua --- ```lua
--- if jobCheck("mechanic") then --- if jobCheck("mechanic") then
--- -- Allow access to mechanic-related features --- -- Allow mechanic features.
--- else --- else
--- -- Deny access or notify the player --- -- Deny access.
--- end --- end
--- ``` --- ```
function jobCheck(job) function jobCheck(job)
canDo = true local canDo = true
if Jobs[job] then if Jobs[job] then
if not hasJob(job) or not onDuty then if not hasJob(job) or not getPlayer().onDuty then
triggerNotify(nil, Loc[Config.Lan].error["not_clockedin"]) triggerNotify(nil, Loc[Config.Lan].error["not_clockedin"])
canDo = false canDo = false
end end
@@ -66,20 +84,18 @@ end
--- Toggles the player's duty status. --- Toggles the player's duty status.
--- ---
--- This function switches the player's duty state between on-duty and off-duty. --- Switches the player's duty state between on-duty and off-duty. If using QBcore,
--- It integrates with QBcore's duty system if available; otherwise, it manually toggles the `onDuty` variable --- it triggers the appropriate server event. Otherwise, it manually toggles the onDuty variable and notifies the player.
--- and sends a notification to the player about their new duty status.
--- ---
---@usage --- @usage
--- ```lua --- ```lua
--- toggleDuty() --- toggleDuty() -- Player receives a notification of their new duty status.
--- -- Player will receive a notification indicating their new duty status
--- ``` --- ```
function toggleDuty() function toggleDuty()
onDuty = not onDuty
if isStarted(QBExport) or isStarted(QBXExport) then if isStarted(QBExport) or isStarted(QBXExport) then
TriggerServerEvent("QBCore:ToggleDuty") TriggerServerEvent("QBCore:ToggleDuty")
else else
onDuty = not onDuty
if onDuty then if onDuty then
triggerNotify(nil, "Now on duty", "success") triggerNotify(nil, "Now on duty", "success")
else else
@@ -88,22 +104,24 @@ function toggleDuty()
end end
end end
-------------------------------------------------------------
-- Interaction Functions
-------------------------------------------------------------
--- Initiates the hand-washing action for the player. --- Initiates the hand-washing action for the player.
--- ---
--- This function triggers an animation and a progress bar to simulate the player washing their hands. --- Triggers an animation and a progress bar to simulate hand washing at the specified coordinates.
--- Upon completion, it sends a success notification. If the action is canceled, it notifies the player of the cancellation. --- On success, it notifies the player; if cancelled, it sends an error notification.
--- ---
---@param data table A table containing the coordinates where the hand-washing action takes place. --- @param data table A table containing:
--- - **coords** (`vector3`): The position where the hand-washing animation and camera are focused. --- - coords (vector3): The location where the hand-washing action occurs.
--- ---
---@return void --- @usage
---
---@usage
--- ```lua --- ```lua
--- washHands({ coords = vector3(200.0, 300.0, 40.0) }) --- washHands({ coords = vector3(200.0, 300.0, 40.0) })
--- -- Player will perform the hand-washing animation at the specified location
--- ``` --- ```
function washHands(data) local ped = PlayerPedId() function washHands(data)
local ped = PlayerPedId()
lookEnt(data.coords) lookEnt(data.coords)
local cam = createTempCam(ped, data.coords) local cam = createTempCam(ped, data.coords)
if progressBar({ if progressBar({
@@ -118,22 +136,21 @@ function washHands(data) local ped = PlayerPedId()
}) then }) then
triggerNotify(nil, Loc[Config.Lan].success["washed_hands"], "success") triggerNotify(nil, Loc[Config.Lan].success["washed_hands"], "success")
else else
triggerNotify(nil, Loc[Config.Lan].error["cancel"], 'error') triggerNotify(nil, Loc[Config.Lan].error["cancel"], "error")
end end
ClearPedTasks(ped) ClearPedTasks(ped)
end end
--- Handles the player's interaction with a toilet or urinal. --- Handles the player's interaction with a toilet or urinal.
--- ---
--- This function manages the animations and progress bars associated with using a toilet or urinal. --- Manages animations and progress bars for using a urinal or a toilet. If the action is successful,
--- Depending on whether the interaction is with a urinal (`data.urinal`), it plays the appropriate animation --- it triggers the appropriate server event (urinal usage) or notifies the player if cancelled.
--- and triggers server events upon successful completion. If the action is canceled, it notifies the player.
--- ---
---@param data table A table containing data about the toilet interaction. --- @param data table A table containing:
--- - **urinal** (`boolean`): Indicates whether the interaction is with a urinal (`true`) or a toilet (`false`). --- - urinal (boolean): `true if using a urinal; false for a toilet.`
--- - **sitcoords** (`vector4`): The coordinates and heading for the seating animation when using a toilet. --- - sitcoords (vector4): `Coordinates and heading for seating when using a toilet.`
--- ---
---@usage --- @usage
--- ```lua --- ```lua
--- useToilet({ urinal = true }) --- useToilet({ urinal = true })
--- -- Player uses a urinal with corresponding animations and notifications --- -- Player uses a urinal with corresponding animations and notifications
@@ -154,7 +171,7 @@ function useToilet(data)
TriggerServerEvent(getScript().."server:Urinal") TriggerServerEvent(getScript().."server:Urinal")
else else
lockInv(false) lockInv(false)
triggerNotify(nil, Loc[Config.Lan].error["cancelled"], 'error') triggerNotify(nil, Loc[Config.Lan].error["cancelled"], "error")
end end
else else
TaskStartScenarioAtPosition(PlayerPedId(), "PROP_HUMAN_SEAT_CHAIR_MP_PLAYER", data.sitcoords.x, data.sitcoords.y, data.sitcoords.z, data.sitcoords[4], 0, 1, true) TaskStartScenarioAtPosition(PlayerPedId(), "PROP_HUMAN_SEAT_CHAIR_MP_PLAYER", data.sitcoords.x, data.sitcoords.y, data.sitcoords.z, data.sitcoords[4], 0, 1, true)
@@ -167,24 +184,22 @@ function useToilet(data)
ClearPedTasks(PlayerPedId()) ClearPedTasks(PlayerPedId())
else else
lockInv(false) lockInv(false)
triggerNotify(nil, Loc[Config.Lan].error["cancelled"], 'error') triggerNotify(nil, Loc[Config.Lan].error["cancelled"], "error")
end end
end end
end end
--- Teleports the player to specified coordinates with a fade effect. --- Teleports the player to specified coordinates with a fade effect.
--- ---
--- This function fades the screen out, moves the player to the target coordinates (`data.telecoords`), --- Fades the screen out, moves the player to the target coordinates, sets the player's heading,
--- sets the player's heading, and then fades the screen back in. It's commonly used for door interactions --- then fades the screen back in. Commonly used for door interactions or teleportation points.
--- or teleportation points within the game.
--- ---
---@param data table A table containing teleportation data. --- @param data table A table containing:
--- - **telecoords** (`vector4`): The target coordinates and heading for the teleportation. --- - telecoords (vector4): The target coordinates and heading.
--- ---
---@usage --- @usage
--- ```lua --- ```lua
--- useDoor({ telecoords = vector4(215.76, -810.12, 29.73, 90.0) }) --- useDoor({ telecoords = vector4(215.76, -810.12, 29.73, 90.0) })
--- -- Player is teleported to the specified coordinates with a fade effect
--- ``` --- ```
function useDoor(data) function useDoor(data)
DoScreenFadeOut(500) DoScreenFadeOut(500)

View File

@@ -22,15 +22,21 @@ function createTempCam(ent, coords)
triggerNotify(nil, "ModCam Created", "success") triggerNotify(nil, "ModCam Created", "success")
end end
local camCoords = nil local camCoords = nil
local pointCoords = nil
if type(ent) ~= "vector3" then if type(ent) ~= "vector3" then
camCoords = GetOffsetFromEntityInWorldCoords(ent, 1.0, -0.3, 0.8) camCoords = GetOffsetFromEntityInWorldCoords(ent, 1.0, -0.3, 0.8)
else else
camCoords = ent camCoords = ent
end end
-- Create the camera with specified parameters
cam = CreateCamWithParams("DEFAULT_SCRIPTED_CAMERA", camCoords.x, camCoords.y, camCoords.z + 0.5, 1.0, 0.0, 0.0, 60.00, false, 0) cam = CreateCamWithParams("DEFAULT_SCRIPTED_CAMERA", camCoords.x, camCoords.y, camCoords.z + 0.5, 1.0, 0.0, 0.0, 60.00, false, 0)
-- Point the camera at the target coordinates
PointCamAtCoord(cam, coords) if type(coords) == "number" then
SetCamCoord(cam, GetCamCoord(cam) + vec3(0, 0, 1.0))
PointCamAtEntity(cam, coords)
else
PointCamAtCoord(cam, coords)
end
end end
return cam return cam
end end

View File

@@ -137,11 +137,11 @@ end
--- ``` --- ```
function loadScriptBank(bank) function loadScriptBank(bank)
local timeout = 2000 local timeout = 2000
debugPrint("^6Debug^7: ^2Loading ^3Script ^2AudioBank^7...") debugPrint("^6Bridge^7: ^2Loading ^3Script ^2AudioBank^7...")
while not RequestScriptAudioBank(bank, 0) do Wait(10) timeout -= 10 if timeout <= 0 then break end end while not RequestScriptAudioBank(bank, false) do Wait(10) timeout -= 10 if timeout <= 0 then break end end
local success = RequestScriptAudioBank(bank, 0) local success = RequestScriptAudioBank(bank, false)
debugPrint("^6Debug^7: "..(success and "^3Successfully ^2loaded^7: '^4" or "^1Failed to ^2load^7: '^4")..bank.."^7'") debugPrint("^6Bridge^7: "..(success and "^3Successfully ^2loaded^7: '^4" or "^1Failed to ^2load^7: '^4")..bank.."^7'")
return success return success
end end
@@ -159,14 +159,14 @@ end
--- ``` --- ```
function loadAmbientBank(bank) function loadAmbientBank(bank)
local timeout = 2000 local timeout = 2000
debugPrint("^6Debug^7: ^2Loading ^3Ambient ^2AudioBank^7...") debugPrint("^6Bridge^7: ^2Loading ^3Ambient ^2AudioBank^7...")
while not RequestAmbientAudioBank(bank, 0) do while not RequestAmbientAudioBank(bank, 0) do
Wait(10) Wait(10)
timeout -= 10 timeout -= 10
if timeout <= 0 then break end if timeout <= 0 then break end
end end
local success = RequestAmbientAudioBank(bank, 0) local success = RequestAmbientAudioBank(bank, 0)
debugPrint("^6Debug^7: "..(success and "^3Successfully ^2loaded^7: '^4" or "^1Failed to ^2load^7: '^4")..bank.."^7'") debugPrint("^6Bridge^7: "..(success and "^3Successfully ^2loaded^7: '^4" or "^1Failed to ^2load^7: '^4")..bank.."^7'")
return success return success
end end
@@ -224,16 +224,18 @@ end
--- ```lua --- ```lua
--- playGameSound('DLC_HEIST_HACKING_SNAKE_SOUNDS', 'Beep', vector3(0, 0, 0), false, 15.0) --- playGameSound('DLC_HEIST_HACKING_SNAKE_SOUNDS', 'Beep', vector3(0, 0, 0), false, 15.0)
--- ``` --- ```
function playGameSound(bank, sound, coords, synced, range) function playGameSound(audioBank, soundSet, soundRef, coords, synced, range)
debugPrint("^6Debug^7: ^2Attempting to play: ^3"..sound.." ^7(^4"..bank.."^7')") debugPrint("^6Bridge^7: ^2Attempting to play: ^3"..soundRef.." ^7('^4"..audioBank.."^7')")
loadScriptBank(audioBank)
local range = range or 10.0 local range = range or 10.0
local soundId = GetSoundId() local soundId = GetSoundId()
while not soundId do Wait(10) end while not soundId do Wait(10) end
if type(coords) == "vector3" or type(coords) == "vector4" then if type(coords) == "vector3" or type(coords) == "vector4" then
debugPrint("^6Debug^7: ^2Playing sound from Coord^7: "..formatCoord(coords.xyz)) debugPrint("^6Bridge^7: ^2Playing sound from Coord^7: "..formatCoord(coords.xyz))
PlaySoundFromCoord(soundId, sound, coords.x, coords.y, coords.z, bank, synced, range, 0) PlaySoundFromCoord(soundId, soundRef, coords.x, coords.y, coords.z, soundSet, synced, range, 0)
else else
debugPrint("^6Debug^7: ^2Playing sound from Entity^7: ^4"..coords.."^7") debugPrint("^6Bridge^7: ^2Playing sound from Entity^7: ^4"..coords.."^7")
PlaySoundFromEntity(soundId, sound, coords, bank, synced, 0) PlaySoundFromEntity(soundId, soundRef, coords, soundSet, synced, 1.0)
end end
ReleaseScriptAudioBank(audioBank)
end end

View File

@@ -1,3 +1,5 @@
local blipTable = {}
--- Creates a blip at specified coordinates with given properties. --- Creates a blip at specified coordinates with given properties.
-- --
-- This function adds a map blip at the provided coordinates and sets various display properties such as sprite, color, scale, and more. -- This function adds a map blip at the provided coordinates and sets various display properties such as sprite, color, scale, and more.
@@ -30,31 +32,48 @@
-- local blip = makeBlip(blipData) -- local blip = makeBlip(blipData)
-- ``` -- ```
function makeBlip(data) function makeBlip(data)
local blip = AddBlipForCoord(vec3(data.coords.x, data.coords.y, data.coords.z)) local blip = nil
SetBlipCoords(blip, data.coords.x, data.coords.y, data.coords.z) -- Manually set blip coordinates again as sometimes it just refuses if gameName == "rdr3" then
SetBlipAsShortRange(blip, true) blip = BlipAddForCoords(1664425300, data.coords.x, data.coords.y, data.coords.z)
SetBlipSprite(blip, data.sprite or 106) SetBlipSprite(blip, data.sprite or `blip_shop_market_stall`)
SetBlipColour(blip, data.col or 5) SetBlipScale(blip, data.scale or 0.2)
SetBlipScale(blip, data.scale or 0.7) SetBlipName(blip, data.name)
SetBlipDisplay(blip, data.disp or 6) --BlipSetStyle(blip, data.col or `BLIP_STYLE_CREATOR_DEFAULT`)
if data.category then SetBlipCategory(blip, data.category) end else
BeginTextCommandSetBlipName('STRING') blip = AddBlipForCoord(vec3(data.coords.x, data.coords.y, data.coords.z))
AddTextComponentString(tostring(data.name)) SetBlipCoords(blip, data.coords.x, data.coords.y, data.coords.z) -- Manually set blip coordinates again as sometimes it just refuses
EndTextCommandSetBlipName(blip) SetBlipAsShortRange(blip, true)
-- Handle preview image if certain resources are running SetBlipSprite(blip, data.sprite or 106)
if isStarted("fs_smallresources") or isStarted("blip_info") or isStarted("blipinfo") then SetBlipColour(blip, data.col or 5)
if data.preview then SetBlipScale(blip, data.scale or 0.7)
local txname = string.gsub(tostring(data.name..'preview'..string.gsub(data.coords.z, "%.", "")), "[ ()~]", "") SetBlipDisplay(blip, data.disp or 6)
if data.preview:find("http") or data.preview:find("nui") then if data.category then
createDui(txname, data.preview, vec2(512, 256), scriptTxd) SetBlipCategory(blip, data.category)
else end
CreateRuntimeTextureFromImage(scriptTxd, txname, data.preview) BeginTextCommandSetBlipName('STRING')
AddTextComponentString(tostring(data.name))
EndTextCommandSetBlipName(blip)
-- Handle preview image if certain resources are running
if isStarted("fs_smallresources") or isStarted("blip_info") or isStarted("blipinfo") then
if data.preview then
local txname = string.gsub(tostring(data.name..'preview'..string.gsub(data.coords.z, "%.", "")), "[ ()~]", "")
if data.preview:find("http") or data.preview:find("nui") then
createDui(txname, data.preview, vec2(512, 256), scriptTxd)
else
CreateRuntimeTextureFromImage(scriptTxd, txname, data.preview)
end
exports["fs_smallresources"]:SetBlipInfoImage(blip, getScript()..'scriptTxd', txname)
exports["fs_smallresources"]:SetBlipInfoTitle(blip, data.name, false)
end end
exports["fs_smallresources"]:SetBlipInfoImage(blip, getScript()..'scriptTxd', txname)
exports["fs_smallresources"]:SetBlipInfoTitle(blip, data.name, false)
end end
end end
debugPrint("^6Bridge^7: ^6Blip ^2created^7: '^6"..data.name.."^7' - '"..formatCoord(data.coords).."'") blipTable[blip] = blip
if DoesBlipExist(blip) then
debugPrint("^6Bridge^7: ^6Blip ^2created^7: '^6"..data.name.."^7' - '"..formatCoord(data.coords).."'")
else
print("Error making blip")
end
return blip return blip
end end
@@ -90,30 +109,54 @@ end
-- local blip = makeEntityBlip(blipData) -- local blip = makeEntityBlip(blipData)
-- ``` -- ```
function makeEntityBlip(data) function makeEntityBlip(data)
AddBlipForEntity(data.entity) local blip = nil
local blip = GetBlipFromEntity(data.entity) if gameName == "rdr3" then
SetBlipAsShortRange(blip, true) blip = BlipAddForEntity(1664425300, data.entity)
SetBlipSprite(blip, data.sprite or 106) SetBlipSprite(blip, data.sprite or `blip_ambient_coach`)
SetBlipColour(blip, data.col or 5) SetBlipScale(blip, data.scale or 0.2)
SetBlipScale(blip, data.scale or 0.7) SetBlipName(blip, data.name)
SetBlipDisplay(blip, data.disp or 6)
if data.category then SetBlipCategory(blip, data.category) end else
BeginTextCommandSetBlipName('STRING') AddBlipForEntity(data.entity)
AddTextComponentString(tostring(data.name)) blip = GetBlipFromEntity(data.entity)
EndTextCommandSetBlipName(blip) blipTable[blip] = blip
-- Handle preview image if certain resources are running SetBlipAsShortRange(blip, true)
if isStarted("fs_smallresources") or isStarted("blip-info") or isStarted("blipinfo") then SetBlipSprite(blip, data.sprite or 106)
if data.preview then SetBlipColour(blip, data.col or 5)
local txname = string.gsub(tostring(data.name..'preview'), "[ ()~]", "") SetBlipScale(blip, data.scale or 0.7)
if data.preview:find("http") or data.preview:find("nui") then SetBlipDisplay(blip, data.disp or 6)
createDui(txname, data.preview, vec2(512, 256), scriptTxd) if data.category then SetBlipCategory(blip, data.category) end
else BeginTextCommandSetBlipName('STRING')
CreateRuntimeTextureFromImage(scriptTxd, txname, data.preview) AddTextComponentString(tostring(data.name))
EndTextCommandSetBlipName(blip)
-- Handle preview image if certain resources are running
if isStarted("fs_smallresources") or isStarted("blip-info") or isStarted("blipinfo") then
if data.preview then
local txname = string.gsub(tostring(data.name..'preview'), "[ ()~]", "")
if data.preview:find("http") or data.preview:find("nui") then
createDui(txname, data.preview, vec2(512, 256), scriptTxd)
else
CreateRuntimeTextureFromImage(scriptTxd, txname, data.preview)
end
exports["fs_smallresources"]:SetBlipInfoImage(blip, getScript()..'previewTxd', txname)
exports["fs_smallresources"]:SetBlipInfoTitle(blip, data.name, false)
end end
exports["fs_smallresources"]:SetBlipInfoImage(blip, getScript()..'previewTxd', txname)
exports["fs_smallresources"]:SetBlipInfoTitle(blip, data.name, false)
end end
end end
debugPrint("^6Bridge^7: ^6Blip ^2created for Entity^7: '^6"..data.name.."^7'") blipTable[blip] = blip
if DoesBlipExist(blip) then
debugPrint("^6Bridge^7: ^6Blip ^2created for Entity^7: '^6"..data.name.."^7'")
else
print("Error making blip")
end
return blip return blip
end end
if gameName == "rdr3" then
onResourceStop(function()
for k in pairs(blipTable) do
RemoveBlip(k)
end
end, true)
end

View File

@@ -19,15 +19,17 @@ local Peds = {}
-- makeDistPed(pedData, pedCoords, true, false, 'WORLD_HUMAN_STAND_IMPATIENT', nil, true) -- makeDistPed(pedData, pedCoords, true, false, 'WORLD_HUMAN_STAND_IMPATIENT', nil, true)
-- ``` -- ```
function makeDistPed(data, coords, freeze, collision, scenario, anim, synced) function makeDistPed(data, coords, freeze, collision, scenario, anim, synced)
local zoneCoords = type(data) == "table" and data.coords or coords
local randName = keyGen()..keyGen()
createCirclePoly({ createCirclePoly({
name = keyGen()..keyGen(), name = randName,
coords = vec3(data.coords.x, data.coords.y, data.coords.z - 1.03), coords = vec3(zoneCoords.x, zoneCoords.y, zoneCoords.z - 1.03),
radius = 50.0, radius = 50.0,
onEnter = function() onEnter = function()
Peds[#Peds + 1] = makePed(data, coords, freeze, collision, scenario, anim, synced) Peds[randName] = makePed(data, coords, freeze, collision, scenario, anim, synced)
end, end,
onExit = function() onExit = function()
DeletePed(Peds[#Peds]) DeletePed(Peds[randName])
end, end,
debug = debugMode, debug = debugMode,
}) })
@@ -112,7 +114,14 @@ function makePed(data, coords, freeze, collision, scenario, anim, synced)
else else
model = data model = data
loadModel(model) loadModel(model)
ped = CreatePed(0, model, coords.x, coords.y, coords.z - 1.03, coords.w, synced or false, false) if gameName == "rdr3" then
ped = CreatePed(model, coords.x, coords.y, coords.z - 1.03, coords.w, synced or false, false)
SetEntityVisible(ped, 1) -- SetEntityVisible
SetEntityAlpha(ped, 255, false) -- SetEntityAlpha
SetRandomOutfitVariation(ped, true) -- Invisible without
else
ped = CreatePed(0, model, coords.x, coords.y, coords.z - 1.03, coords.w, synced or false, false)
end
end end
SetEntityInvincible(ped, true) SetEntityInvincible(ped, true)
@@ -125,10 +134,13 @@ function makePed(data, coords, freeze, collision, scenario, anim, synced)
loadAnimDict(anim[1]) loadAnimDict(anim[1])
TaskPlayAnim(ped, anim[1], anim[2], 0.5, 1.0, -1, 1, 0.2, 0, 0, 0) TaskPlayAnim(ped, anim[1], anim[2], 0.5, 1.0, -1, 1, 0.2, 0, 0, 0)
end end
if DoesEntityExist(ped) then
debugPrint("^6Bridge^7: ^1Ped ^2Created^7: '^6"..ped.."^7' | ^2Hash^7: ^7'^5"..(model).."^7' | ^2Coord^7: "..formatCoord(coords)) debugPrint("^6Bridge^7: ^1Ped ^2Created^7: '^6"..ped.."^7' | ^2Hash^7: ^7'^5"..(model).."^7' | ^2Coord^7: "..formatCoord(coords))
else
print("error ped")
end
unloadModel(model) unloadModel(model)
Peds[#Peds + 1] = ped Peds[keyGen()..keyGen()] = ped
return ped return ped
end end
@@ -227,4 +239,8 @@ function GenerateRandomPedData(data)
end end
--- Cleans up all created Peds when the resource stops. --- Cleans up all created Peds when the resource stops.
onResourceStop(function() for i = 1, #Peds do DeletePed(Peds[i]) end end, true) onResourceStop(function()
for k in pairs(Peds) do
DeletePed(Peds[k])
end
end, true)

View File

@@ -28,7 +28,7 @@ function makeProp(data, freeze, synced)
debugPrint("^6Bridge^7: ^1Prop ^2Created^7: '^6"..prop.."^7' | ^2Hash^7: ^7'^6"..data.prop.."^7' | ^2Coord^7: "..formatCoord(data.coords)) debugPrint("^6Bridge^7: ^1Prop ^2Created^7: '^6"..prop.."^7' | ^2Hash^7: ^7'^6"..data.prop.."^7' | ^2Coord^7: "..formatCoord(data.coords))
SetModelAsNoLongerNeeded(data.prop) SetModelAsNoLongerNeeded(data.prop)
Props[#Props + 1] = prop Props[keyGen()..keyGen()] = prop
return prop return prop
end end
@@ -51,17 +51,17 @@ end
--- } --- }
--- makeDistProp(propData, true, false) --- makeDistProp(propData, true, false)
--- ``` --- ```
function makeDistProp(data, freeze, synced) function makeDistProp(data, freeze, synced, range)
local prop = nil local name = keyGen()..keyGen()
createCirclePoly({ createCirclePoly({
name = keyGen()..keyGen(), name = name,
coords = vec3(data.coords.x, data.coords.y, data.coords.z - 1.03), coords = vec3(data.coords.x, data.coords.y, data.coords.z - 1.03),
radius = 50.0, radius = range or 50.0,
onEnter = function() onEnter = function()
prop = makeProp(data, freeze, synced) Props[name] = makeProp(data, freeze, synced)
end, end,
onExit = function() onExit = function()
destroyProp(prop) destroyProp(Props[name])
end, end,
debug = debugMode, debug = debugMode,
}) })
@@ -87,4 +87,8 @@ function destroyProp(entity)
end end
--- Cleans up all created props when the resource stops. --- Cleans up all created props when the resource stops.
onResourceStop(function() for i = 1, #Props do destroyProp(Props[i]) end end, true) onResourceStop(function()
for k in pairs(Props) do
destroyProp(Props[k])
end
end, true)

View File

@@ -17,12 +17,14 @@ function makeVeh(model, coords)
loadModel(model) loadModel(model)
local veh = CreateVehicle(model, coords.x, coords.y, coords.z, coords.w, true, false) local veh = CreateVehicle(model, coords.x, coords.y, coords.z, coords.w, true, false)
SetVehicleHasBeenOwnedByPlayer(veh, true) SetVehicleHasBeenOwnedByPlayer(veh, true)
SetNetworkIdCanMigrate(NetworkGetNetworkIdFromEntity(veh), true) if gameName ~= "rdr3" then
Wait(100) SetNetworkIdCanMigrate(NetworkGetNetworkIdFromEntity(veh), true)
SetVehicleNeedsToBeHotwired(veh, false) Wait(100)
SetVehRadioStation(veh, 'OFF') SetVehicleNeedsToBeHotwired(veh, false)
SetVehicleFuelLevel(veh, 100.0) SetVehRadioStation(veh, 'OFF')
SetVehicleModKit(veh, 0) SetVehicleFuelLevel(veh, 100.0)
SetVehicleModKit(veh, 0)
end
SetVehicleOnGroundProperly(veh) SetVehicleOnGroundProperly(veh)
debugPrint("^6Bridge^7: ^1Veh ^2Created^7: '^6"..veh.."^7' | ^2Hash^7: ^7'^6"..model.."^7' | ^2Coord^7: "..formatCoord(coords)) debugPrint("^6Bridge^7: ^1Veh ^2Created^7: '^6"..veh.."^7' | ^2Hash^7: ^7'^6"..model.."^7' | ^2Coord^7: "..formatCoord(coords))
@@ -31,40 +33,72 @@ function makeVeh(model, coords)
return veh return veh
end end
--- Attempts to gain network control of a vehicle and set it as a mission entity. local distanceVehicles = {}
--- Creates a vehicle that spawns when the player enters a designated polyzone area.
--- ---
--- This function forces synchronization of a vehicle with other players by requesting network control and setting the vehicle as a mission entity. --- This function sets up a circular polyzone; when the player enters the zone, the vehicle is spawned,
--- and when the player exits, the vehicle is deleted.
--- ---
---@param entity number The handle of the vehicle entity to push. ---@param data table A table containing vehicle data.
--- --- - **vehicle** `string`: The model name or hash of the vehicle to spawn.
---@usage --- - **coords** `vector4`: The coordinates where the vehicle will be placed. Should include x, y, z, and w (heading).
--- ```lua ---@param freeze boolean (optional) Whether to freeze the vehicle in place. Defaults to `false`.
--- pushVehicle(vehicle) ---@param synced boolean (optional) Whether the vehicle should be synced across clients. Defaults to `false`.
--- ``` function makeDistVehicle(data, radius, onEnter, onExit)
function pushVehicle(entity) local vehicle = nil
SetVehicleModKit(entity, 0) local zoneId = keyGen() .. keyGen()
if entity ~= 0 and DoesEntityExist(entity) then local zone = createCirclePoly({
if not NetworkHasControlOfEntity(entity) then name = zoneId,
debugPrint("^6Bridge^7: ^3pushVehicle^7: ^2Requesting network control of vehicle^7.") coords = vec3(data.coords.x, data.coords.y, data.coords.z),
NetworkRequestControlOfEntity(entity) radius = radius,
local timeout = 2000 onEnter = function()
while timeout > 0 and not NetworkHasControlOfEntity(entity) do vehicle = makeVeh(data.model, data.coords)
Wait(100) if onEnter then
timeout -= 100 debugPrint("makeDistVehicle onEnter running")
onEnter(vehicle)
end end
if NetworkHasControlOfEntity(entity) then debugPrint("^6Bridge^7: ^3pushVehicle^7: ^2Network has control of entity^7.") end end,
end onExit = function()
if not IsEntityAMissionEntity(entity) then deleteVehicle(vehicle)
debugPrint("^6Bridge^7: ^3pushVehicle^7: ^2Setting vehicle as a ^7'^2mission^7' ^2entity^7.") if onExit then
SetEntityAsMissionEntity(entity, true, true) debugPrint("makeDistVehicle onExit running")
local timeout = 2000 onExit(vehicle)
while timeout > 0 and not IsEntityAMissionEntity(entity) do
Wait(100)
timeout -= 100
end end
if IsEntityAMissionEntity(entity) then debugPrint("^6Bridge^7: ^3pushVehicle^7: ^2Vehicle is a ^7'^2mission^7'^2 entity^7.") end end,
debug = debugMode,
})
distanceVehicles[zoneId] = { zone = zone, vehicle = vehicle }
return zoneId
end
--- Removes a specific distance-based vehicle spawning zone.
---
---@param zoneId string The unique identifier of the zone to remove.
function removeDistVehicleZone(zoneId)
if distanceVehicles[zoneId].zone then
removePolyZone(distanceVehicles[zoneId].zone) -- Adjust this if your polyzone library uses a different removal method.
if distanceVehicles[zoneId].vehicle then
deleteVehicle(distanceVehicles[zoneId].vehicle)
end end
end distanceVehicles[zoneId] = nil
print("Removed polyzone for zoneId: " .. zoneId)
else
print("No zone found with zoneId: " .. zoneId)
end
end
--- Deletes a spawned vehicle.
---
---@param vehicle number The handle of the vehicle entity to delete.
function deleteVehicle(vehicle)
if vehicle then
debugPrint("^6Bridge^7: ^2Destroying Vehicle^7: '^6" .. vehicle .. "^7'")
if IsEntityAttachedToEntity(vehicle, PlayerPedId()) then
SetEntityAsMissionEntity(vehicle)
DetachEntity(vehicle, true, true)
end
DeleteVehicle(vehicle)
end
end end
--- Cleans up all created vehicles when the resource stops. --- Cleans up all created vehicles when the resource stops.

View File

@@ -93,47 +93,90 @@ function progressBar(data)
end end
}) })
elseif Config.System.ProgressBar == "red" then
-- Currently only uses jim-redui if you choose this option
if exports["jim-redui"]:progressBar({
label = data.label,
time = debugMode and 1000 or data.time,
dict = data.dict,
anim = data.anim,
flag = data.flag or 32,
task = data.task,
cancel = true,
}) then
result = true
else
result = false
end
elseif Config.System.ProgressBar == "gta" then elseif Config.System.ProgressBar == "gta" then
local wait = debugMode and 1000 or data.time loadTextureDict("timerbars")
if inProgress then return false end
inProgress = true inProgress = true
if not (data.dead or false) then local wait = debugMode and 1000 or data.time
lockInv(true) local endTime = GetGameTimer() + wait
displaySpinner(data.label) local ped = PlayerPedId()
if data.dict then
playAnim(data.dict, data.anim, -1, (data.flag == 8 and 32 or data.flag) or nil) -- Setup Animation/Task if specified
end if data.dict then
if data.task then playAnim(data.dict, data.anim, -1, data.flag or 32)
TaskStartScenarioInPlace(ped, data.task, -1, true) elseif data.task then
end TaskStartScenarioInPlace(ped, data.task, -1, true)
while inProgress and wait > 0 do end
wait -= 15
local waitTimer = 0 -- Progress bar rendering loop
CreateThread(function()
while GetGameTimer() < endTime and inProgress do
Wait(0)
local elapsed = GetGameTimer()
local percentage = ((elapsed - (endTime - wait)) / wait) * 100
-- Convert to segmented progress (assuming 5 segments here)
local segments = 5 -- Number of segments in the bar
local segmentProgress = {}
local progressPerSegment = 100 / segments
for i = 1, segments do
local segmentStart = (i - 1) * progressPerSegment
local segmentEnd = i * progressPerSegment
if percentage >= segmentEnd then
segmentProgress[i] = 100
elseif percentage <= segmentStart then
segmentProgress[i] = 0
else
segmentProgress[i] = ((percentage - segmentStart) / progressPerSegment) * 100
end
end
percentage = percentage >= 100 and 100 or percentage
-- Draw your segmented progress bar
ShowGTAProgressBar(segmentProgress, data.label, ("%.0f%%"):format(percentage))
-- Controls to disable during progress
DisablePlayerFiring(ped, true) DisablePlayerFiring(ped, true)
DisableControlAction(0, 25, true) -- Disable aim DisableControlAction(0, 25, true) -- Disable aim
DisableControlAction(0, 21, true) -- Disable sprint DisableControlAction(0, 21, true) -- Disable sprint
DisableControlAction(0, 30, true) -- Disable move left/right DisableControlAction(0, 30, true) -- Disable move left/right
DisableControlAction(0, 31, true) -- Disable move forward/back DisableControlAction(0, 31, true) -- Disable move forward/back
DisableControlAction(0, 36, true) -- Disable stealth DisableControlAction(0, 36, true) -- Disable stealth
if data.cam ~= nil then
DisableControlAction(0, 1, true) -- Disable look left/right if data.cancel and (IsControlJustReleased(0, 202) or IsControlJustReleased(0, 177) or IsControlJustReleased(0, 73)) then
DisableControlAction(0, 2, true) -- Disable look up/down inProgress = false
DisableControlAction(0, 106, true) -- Disable vehicle mouse control
end end
if data.cancel then
if IsControlJustReleased(0, 202) or IsControlJustReleased(0, 77) then -- Cancel key (Backspace or Delete)
inProgress = false
waitTimer = 1500
displaySpinner(Loc[Config.Lan].error["cancel"])
end
end
Wait(waitTimer)
end end
inProgress = false end)
if data.dict then stopAnim(data.dict, data.anim, ped) end
ClearPedTasks(ped) -- Wait for completion or cancel
while GetGameTimer() < endTime and inProgress do
Wait(100)
end end
stopSpinner()
result = (wait <= 0) -- Cleanup animations/tasks
if data.dict then stopAnim(data.dict, data.anim, ped) end
ClearPedTasks(ped)
result = inProgress
inProgress = false
end end
while result == nil do Wait(10) end while result == nil do Wait(10) end
@@ -141,26 +184,80 @@ function progressBar(data)
-- Cleanup -- Cleanup
FreezeEntityPosition(ped, false) FreezeEntityPosition(ped, false)
lockInv(false) lockInv(false)
if data.cam then stopTempCam(data.cam) end if data.cam then
stopTempCam(data.cam)
end
if result == false and data.shared then if result == false and data.shared then
debugPrint("^6Bridge^7: ^2Sending cancel to ^6"..storedPID.."^7") debugPrint("^6Bridge^7: ^2Sending cancel to ^6"..storedPID.."^7")
TriggerServerEvent(getScript().."server:sharedProg:cancel", storedPID) TriggerServerEvent(getScript().."server:sharedProg:cancel", storedPID)
end end
storedPID = nil storedPID = nil
if result == false then
currentToken = nil
TriggerServerEvent(getScript()..":clearAuthToken")
end
if result == true and data.request then
TriggerServerEvent(getScript()..":clearAuthToken")
currentToken = triggerCallback(AuthEvent)
end
return result return result
end end
function ShowGTAProgressBar(currentProg, title, level)
local loc = vec2(0.37, 0.90)
local size = vec2(0.3, 0.03)
-- Draw background box
DrawSprite("timerbars", "all_black_bg", loc.x +0.028, loc.y-0.01, 0.15, 0.07, 0.0, 255, 255, 255, 255)
DrawSprite("timerbars", "all_black_bg", loc.x +0.170, loc.y-0.01, 0.15, 0.07, 180.0, 255, 255, 255, 255)
SetTextFont(0)
SetTextProportional(1)
SetTextScale(0.35, 0.35)
SetTextColour(255, 255, 255, 255)
SetTextDropshadow(0, 0, 0, 0, 255)
SetTextDropShadow()
SetTextOutline()
SetTextEntry("STRING")
AddTextComponentString(title)
DrawText(loc.x - size.x / 4 + 0.074, loc.y - 0.034) -- Adjust text position
SetTextFont(0)
SetTextProportional(1)
SetTextScale(0.35, 0.25)
SetTextColour(255, 255, 255, 255)
SetTextEntry("STRING")
AddTextComponentString(level)
DrawText(loc.x - size.x / 4 + 0.246, loc.y - 0.030) -- Right-aligned additional text
local segmentWidth = (size.x + 0.05) / (#currentProg * 2) -- Divide the total width by 18 (9 segments * 2 gaps for each)
local gap = segmentWidth / #currentProg -- Smaller gap between segments
for i = 1, #currentProg do
local segmentX = (loc.x - size.x / 4 ) + 0.075 + (i - 1) * (segmentWidth + gap)
local fillPercentage = currentProg[i]
local progressBarWidth = segmentWidth * (fillPercentage / 100)
-- Semi-transparent background for each segment
DrawRect(segmentX + segmentWidth / 2, loc.y, segmentWidth, size.y / 3.4, 100, 100, 100, 255)
-- Filling progress for each segment
if progressBarWidth > 0 then
DrawRect(segmentX + progressBarWidth / 2, loc.y, progressBarWidth, size.y / 3.4, 93, 182, 229, 255) -- Blue progress
end
end
end
--- Stops the current progress bar. --- Stops the current progress bar.
--- ---
--- This function cancels the progress bar based on the configured progress bar system, handling any necessary cleanup. --- This function cancels the progress bar based on the configured progress bar system, handling any necessary cleanup.
function stopPropgressBar() function stopProgressBar()
if Config.System.ProgressBar == "ox" then if Config.System.ProgressBar == "ox" then
exports[OXLibExport]:cancelProgress() exports[OXLibExport]:cancelProgress()
elseif Config.System.ProgressBar == "qb" then elseif Config.System.ProgressBar == "qb" then
TriggerEvent("progressbar:client:cancel") TriggerEvent("progressbar:client:cancel")
elseif Config.System.ProgressBar == "gta" then elseif Config.System.ProgressBar == "gta" then
inProgress = false inProgress = false
BusyspinnerOff()
end end
end end
@@ -201,9 +298,5 @@ end)
--- This event is triggered when the server wants the client to cancel a shared progress bar. --- This event is triggered when the server wants the client to cancel a shared progress bar.
RegisterNetEvent(getScript()..":client:sharedProg:Cancel", function() RegisterNetEvent(getScript()..":client:sharedProg:Cancel", function()
debugPrint("^6Bridge^7: ^2Receiving cancel progressBar^7") debugPrint("^6Bridge^7: ^2Receiving cancel progressBar^7")
stopPropgressBar() stopProgressBar()
end) end)
--- Cleans up when the resource stops.
--- This event handler ensures that any active spinners or progress bars are stopped when the resource is stopped.
onResourceStop(function() stopSpinner() end, true)

135
shared/metaHandlers.lua Normal file
View File

@@ -0,0 +1,135 @@
--[[
Player Metadata Utilities Module
----------------------------------
This module provides functions for retrieving and setting metadata for players
across different frameworks (QB, ESX, OXCore). It also registers server callbacks
for getting and setting metadata.
]]
-------------------------------------------------------------
-- Player Retrieval
-------------------------------------------------------------
--- Retrieves the player object using the active core export.
---
--- @param source number The server ID of the player.
--- @return table|nil table The player object, or nil if no supported core is detected.
---
--- @usage
--- ```lua
--- local player = GetPlayer(playerId)
--- ```
function GetPlayer(source)
if isStarted(QBExport) then
debugPrint("^6Bridge^7: ^3GetPlayer^7() QBExport")
return exports[QBExport]:GetCoreObject().Functions.GetPlayer(source)
elseif isStarted(QBXExport) then
debugPrint("^6Bridge^7: ^3GetPlayer^7() QBOXExport")
return exports[QBXExport]:GetCoreObject().Functions.GetPlayer(source)
elseif isStarted(ESXExport) then
debugPrint("^6Bridge^7: ^3GetPlayer^7() ESXExport")
return ESX.GetPlayerFromId(source)
elseif isStarted(OXCoreExport) then
debugPrint("^6Bridge^7: ^3GetPlayer^7() OXCoreExport")
return exports[OXCoreExport]:GetPlayer(source)
end
return nil
end
-------------------------------------------------------------
-- Metadata Retrieval
-------------------------------------------------------------
--- Retrieves metadata from a player object.
---
--- If called client-side (player is nil), it triggers a server callback to retrieve metadata.
---
--- @param player table|nil The player object; if nil, metadata is retrieved via a server callback.
--- @param key string The metadata key to retrieve.
--- @return any The value of the requested metadata, or nil if not found.
---
--- @usage
--- ```lua
--- local myMeta = GetMetadata(player, "myKey")
--- ```
function GetMetadata(player, key)
if not player then
debugPrint("^6Bridge^7: ^3GetMetadata^7() calling server: "..key)
return triggerCallback(getScript()..":server:GetMetadata", key)
else
if isStarted(QBExport) or isStarted(QBXExport) then
debugPrint("^6Bridge^7: ^3GetMetadata^7() QBExport or QBXExport", key)
return player.PlayerData.metadata[key]
elseif isStarted(ESXExport) then
debugPrint("^6Bridge^7: ^3GetMetadata^7() ESXExport", key)
return player.getMeta(key)
elseif isStarted(OXCoreExport) then
debugPrint("^6Bridge^7: ^3GetMetadata^7() OXCoreExport", key)
return player.get(key)
end
end
return nil
end
-- Register a server callback for retrieving metadata.
createCallback(getScript()..":server:GetMetadata", function(source, key)
debugPrint("^6Bridge^7: ^3GetMetadata Callback^7 from source: "..tostring(source)..", key: "..tostring(key))
local player = GetPlayer(source)
if not player then
print("Error getting metadata: player not found for source "..tostring(source))
return
end
if type(key) == "table" then
local Metadata = {}
for _, k in ipairs(key) do
Metadata[k] = GetMetadata(player, k)
end
return Metadata
elseif type(key) == "string" then
return GetMetadata(player, key)
end
end)
-------------------------------------------------------------
-- Metadata Setting
-------------------------------------------------------------
--- Sets metadata on a player object.
---
--- The function updates the player's metadata using the active core export.
---
--- @param player table The player object.
--- @param key string The metadata key to set.
--- @param value any The new value for the metadata key.
---
--- @usage
--- ```lua
--- SetMetadata(player, "myKey", "newValue")
--- ```
function SetMetadata(player, key, value)
debugPrint("^6Bridge^7: ^3SetMetadata^7() setting metadata for key: "..key)
if isStarted(QBExport) or isStarted(QBXExport) then
debugPrint("^6Bridge^7: ^3SetMetadata^7() using QBExport/QBXExport")
player.Functions.SetMetaData(key, value)
elseif isStarted(ESXExport) then
debugPrint("^6Bridge^7: ^3SetMetadata^7() using ESXExport")
player.setMeta(key, value)
elseif isStarted(OXCoreExport) then
debugPrint("^6Bridge^7: ^3SetMetadata^7() using OXCoreExport")
player.set(key, value)
end
end
-- Register a server callback for setting metadata.
createCallback(getScript()..":server:SetMetadata", function(source, key, value)
debugPrint("SetMetadata callback triggered for source:", source, "key:", key, "value:", value)
local player = GetPlayer(source)
--[[if not player then
print("Error setting metadata: player not found for source "..tostring(source))
return false
end]]
SetMetadata(player, key, value)
print("Metadata set successfully.", key)
return true
end)

View File

@@ -1,18 +1,28 @@
-- NOTIFICATIONS -- --[[
-- This function is widely used to display notifications to the player, can be used server side or client side -- Notifications Module
----------------------
This module provides a unified interface for displaying notifications using various
notification systems. The active system is determined by the Config.System.Notify setting.
Supported systems include:
• okok
• qb
• ox
• gta (default)
• esx
]]
--- Displays notifications to the player using the configured notification system. --- Displays notifications to the player using the configured notification system.
--- ---
--- This function supports multiple notification systems based on the `Config.System.Notify` setting. --- Supports multiple notification systems based on Config.System.Notify. Can be triggered from both
--- It can be triggered from both client-side and server-side scripts. Depending on the configuration, --- client and server contexts.
--- it utilizes different exports or events to display the notification.
--- ---
---@param title string|nil The title of the notification. Optional, used by certain notification systems. --- @param title string|nil The notification title (optional for some systems).
---@param message string The main message content of the notification. --- @param message string The main message content.
---@param type string The type/category of the notification (e.g., "success", "error", "info"). --- @param type string The notification type ("success", "error", "info").
---@param src number|nil Optional. The server ID of the player to send the notification to. If `nil`, the notification is sent to the caller. --- @param src number|nil Optional server ID; if provided, the notification is sent to that player.
--- ---
---@usage --- @usage
--- ```lua --- ```lua
--- -- Client-side usage without specifying a player (shows to the current player) --- -- Client-side usage without specifying a player (shows to the current player)
--- triggerNotify("Success", "You have completed the task!", "success") --- triggerNotify("Success", "You have completed the task!", "success")
@@ -21,52 +31,89 @@
--- triggerNotify("Alert", "You have been warned for misconduct.", "error", playerId) --- triggerNotify("Alert", "You have been warned for misconduct.", "error", playerId)
--- ``` --- ```
function triggerNotify(title, message, type, src) function triggerNotify(title, message, type, src)
if Config.System.Notify == "okok" then if Config.System.Notify == "okok" then
if not src then TriggerEvent('okokNotify:Alert', title, message, 6000, type) if not src then
else TriggerClientEvent('okokNotify:Alert', src, title, message, 6000, type) end TriggerEvent('okokNotify:Alert', title, message, 6000, type)
elseif Config.System.Notify == "qb" then else
if not src then TriggerEvent("QBCore:Notify", message, type) TriggerClientEvent('okokNotify:Alert', src, title, message, 6000, type)
else TriggerClientEvent("QBCore:Notify", src, message, type) end end
elseif Config.System.Notify == "ox" then elseif Config.System.Notify == "qb" then
if not src then TriggerEvent('ox_lib:notify', {title = title, description = message, type = type or "success"}) if not src then
else TriggerClientEvent('ox_lib:notify', src, { type = type or "success", title = title, description = message }) end TriggerEvent("QBCore:Notify", message, type)
elseif Config.System.Notify == "gta" then else
if not src then TriggerEvent(getScript()..":DisplayGTANotify", title, message) TriggerClientEvent("QBCore:Notify", src, message, type)
else TriggerClientEvent(getScript()..":DisplayGTANotify", src, title, message) end end
elseif Config.System.Notify == "ox" then
if not src then
TriggerEvent('ox_lib:notify', { title = title, description = message, type = type or "success" })
else
TriggerClientEvent('ox_lib:notify', src, { title = title, description = message, type = type or "success" })
end
elseif Config.System.Notify == "gta" then
if isStarted("jim-gtaui") then
if not src then
TriggerEvent("jim-gtaui:Notify", title, message, type)
else
TriggerClientEvent("jim-gtaui:Notify", src, title, message, type)
end
else
if not src then
TriggerEvent(getScript()..":DisplayGTANotify", title, message)
else
TriggerClientEvent(getScript()..":DisplayGTANotify", src, title, message)
end
end
elseif Config.System.Notify == "esx" then elseif Config.System.Notify == "esx" then
if not src then exports["esx_notify"]:Notify(type, 4000, message) if not src then
else TriggerClientEvent(getScript()..":DisplayESXNotify", src, type, title, message) end exports["esx_notify"]:Notify(type, 4000, message)
end else
TriggerClientEvent(getScript()..":DisplayESXNotify", src, type, message)
end
elseif Config.System.Notify == "red" then
if isStarted("jim-redui") then
if not src then
TriggerEvent("jim-redui:Notify", title, message, type)
else
TriggerClientEvent("jim-redui:Notify", src, title, message, type)
end
end
end
end end
-------------------------------------------------------------
-- ESX Notifications
-------------------------------------------------------------
--- Registers a server-side event to display ESX notifications to clients. --- Registers a server-side event to display ESX notifications to clients.
--- ---
--- This event listens for `DisplayESXNotify` and triggers the ESX notification on the client side. --- Listens for DisplayESXNotify events and triggers the ESX notification on the client.
--- ---
--- @param type string The type/category of the notification (e.g., "success", "error", "info"). --- @param type string The notification type.
--- @param title string The title of the notification. --- @param title string The notification title.
--- @param text string The main message content of the notification. --- @param text string The notification message.
--- ---
--- @usage --- @usage
--- ```lua --- ```lua
--- -- Server-side event trigger --- TriggerClientEvent(getScript()..":DisplayESXNotify", playerId, "success", "New achievement unlocked!")
--- TriggerClientEvent(getScript()..":DisplayESXNotify", playerId, "success", "Achievement Unlocked", "You have unlocked a new achievement!")
--- ``` --- ```
RegisterNetEvent(getScript()..":DisplayESXNotify", function(type, title, text) RegisterNetEvent(getScript()..":DisplayESXNotify", function(type, text)
exports["esx_notify"]:Notify(type, 4000, text) exports["esx_notify"]:Notify(type, 4000, text)
end) end)
--- Displays default GTA-style text notifications. -------------------------------------------------------------
-- GTA-style Notifications
-------------------------------------------------------------
--- Displays GTA-style text notifications using native GTA functions.
--- ---
--- This event handles displaying text-based notifications using GTA's native functions. --- Selects an appropriate icon based on the current script (if applicable) and renders the notification.
--- It supports specific scenarios by assigning different icons based on the script name.
--- ---
---@param title string The title or identifier for the notification, used to select the appropriate icon. --- @param title string The notification title/identifier (used to select an icon).
---@param text string The main message content of the notification. --- @param text string The notification message.
--- ---
---@usage --- @usage
--- ```lua --- ```lua
--- -- Client-side event trigger
--- TriggerEvent(getScript()..":DisplayGTANotify", "taxiname", "Taxi service has arrived.") --- TriggerEvent(getScript()..":DisplayGTANotify", "taxiname", "Taxi service has arrived.")
--- ``` --- ```
RegisterNetEvent(getScript()..":DisplayGTANotify", function(title, text) RegisterNetEvent(getScript()..":DisplayGTANotify", function(title, text)
@@ -81,8 +128,13 @@ RegisterNetEvent(getScript()..":DisplayGTANotify", function(title, text)
[Loc[Config.Lan].notify["heliname"]] = "CHAR_BOATSITE2", [Loc[Config.Lan].notify["heliname"]] = "CHAR_BOATSITE2",
} }
end end
BeginTextCommandThefeedPost("STRING") BeginTextCommandThefeedPost("STRING")
AddTextComponentSubstringKeyboardDisplay(text) AddTextComponentSubstringKeyboardDisplay(text)
EndTextCommandThefeedPostMessagetext(iconTable[title] or "CHAR_DEFAULT", iconTable[title] or "CHAR_DEFAULT", true, 1, title, nil, text) EndTextCommandThefeedPostMessagetext(
iconTable[title] or "CHAR_DEFAULT",
iconTable[title] or "CHAR_DEFAULT",
true, 1, title, nil, text
)
EndTextCommandThefeedPostTicker(true, false) EndTextCommandThefeedPostTicker(true, false)
end) end)

166
shared/phones.lua Normal file
View File

@@ -0,0 +1,166 @@
--[[
Phone Mails Module
------------------
This module handles sending phone mails using different phone systems.
Supported systems include:
- gksphone
- yflip-phone
- qs-smartphone
- qs-smartphone-pro
- roadphone
- lb-phone
- qb-phone
- jpr-phonesystem
]]
--- Sends a phone mail using the detected phone system.
--- The function iterates through a prioritized list of supported phone systems.
--- Once an active system is found (via `isStarted`), the corresponding mail function is executed.
---
--- @param data table A table containing the mail data.
--- - subject (string): The email subject.
--- - sender (string): The sender identifier.
--- - message (string): The email body content.
--- - actions (table|nil): Optional action buttons for the email.
--- @usage
--- sendPhoneMail({
--- subject = "Welcome!",
--- sender = "Admin",
--- message = "Thank you for joining our server.",
--- actions = {
--- { label = "Reply", action = replyFunction }
--- }
--- })
function sendPhoneMail(data)
-- Define each supported phone system and its corresponding mail-sending function.
local phoneSystems = {
{ name = "gksphone",
send = function(mailData)
exports["gksphone"]:SendNewMail(mailData)
end,
},
{ name = "yflip-phone",
send = function(mailData)
TriggerServerEvent(getScript()..":yflip:SendMail", mailData)
end,
},
{ name = "qs-smartphone",
send = function(mailData)
TriggerServerEvent('qs-smartphone:server:sendNewMail', mailData)
end,
},
{ name = "qs-smartphone-pro",
send = function(mailData)
TriggerServerEvent('phone:sendNewMail', mailData)
end,
},
{ name = "roadphone",
send = function(mailData)
-- Convert HTML line breaks to newlines for roadphone.
mailData.message = mailData.message:gsub("%<br>", "\n")
exports["roadphone"]:sendMail(mailData)
end,
},
{ name = "lb-phone",
send = function(mailData)
-- Convert HTML line breaks to newlines for lb-phone.
mailData.message = mailData.message:gsub("%<br>", "\n")
TriggerServerEvent(getScript()..":lbphone:SendMail", mailData)
end,
},
{ name = "qb-phone",
send = function(mailData)
TriggerServerEvent('qb-phone:server:sendNewMail', mailData)
end,
},
{ name = "jpr-phonesystem",
send = function(mailData)
TriggerServerEvent(getScript()..":jpr:SendMail", mailData)
end,
},
}
local activePhone = nil
-- Check each phone system in order and use the first active one.
for _, phone in ipairs(phoneSystems) do
if isStarted(phone.name) then
activePhone = phone.name
phone.send(data)
break
end
end
if activePhone then
debugPrint("^6Bridge^7[^3"..activePhone.."^7]: ^2Sending mail to player")
else
print("^6Bridge^7: ^1ERROR ^2Sending mail to player ^7- ^2No supported phone found")
end
end
-------------------------------------------------------------
-- Phone System Event Handlers
-------------------------------------------------------------
--- Handles sending mail for lb-phone.
--- Listens for the `lbphone:SendMail` event and sends an email using lb-phone's API.
---
--- @event lbphone:SendMail
--- @param data table The mail data.
--- - subject (string): The email subject.
--- - message (string): The email content.
--- - buttons (table|nil): Optional action buttons (mapped from data.actions if present).
RegisterNetEvent(getScript()..":lbphone:SendMail", function(data)
local src = source
local phoneNumber = exports["lb-phone"]:GetEquippedPhoneNumber(src)
local emailAddress = exports["lb-phone"]:GetEmailAddress(phoneNumber)
-- Map actions to buttons if provided.
data.buttons = data.actions or data.buttons
exports["lb-phone"]:SendMail({
to = emailAddress,
subject = data.subject,
message = data.message,
actions = data.buttons,
})
end)
--- Handles sending mail for yflip-phone.
--- Listens for the `yflip:SendMail` event and sends an email using yflip-phone's API.
---
--- @event yflip:SendMail
--- @param data table The mail data.
--- - subject (string): The email subject.
--- - sender (string): The sender identifier.
--- - message (string): The email content.
--- - buttons (table|nil): Optional action buttons.
RegisterNetEvent(getScript()..":yflip:SendMail", function(data)
local src = source
exports["yflip-phone"]:SendMail({
title = data.subject,
sender = data.sender,
senderDisplayName = data.sender,
content = data.message,
actions = data.buttons,
}, 'source', src)
end)
--- Handles sending mail for jpr-phonesystem.
--- Listens for the `jpr:SendMail` event and sends an email using jpr-phonesystem's API.
---
--- @event jpr:SendMail
--- @param data table The mail data.
--- - subject (string): The email subject.
--- - sender (string): The sender identifier.
--- - message (string): The email content.
--- - buttons (table|nil): Optional action buttons.
RegisterNetEvent(getScript()..":jpr:SendMail", function(data)
local src = source
local Player = Core.Functions.GetPlayer(src)
TriggerEvent('jpr-phonesystem:server:sendEmail', {
Assunto = data.subject, -- Email subject
Conteudo = data.message, -- Email content
Enviado = data.sender, -- Sender information
Destinatario = Player.PlayerData.citizenid, -- Recipient identifier
Event = {}, -- Optional event details
})
end)

View File

@@ -1,67 +1,52 @@
--- Locks or unlocks the player's inventory. --[[
--- Player Utility & Server Event Handlers Module
--- This function freezes or unfreezes the player's position, sets the inventory busy state, ------------------------------------------------
--- and toggles the ability to use the inventory and hotbar based on the `toggle` parameter. This module provides utility functions for:
--- • Locking/unlocking the player's inventory.
--- @param toggle boolean `true` to lock the inventory, `false` to unlock. • Instantly turning or gradually turning the player to face a target.
--- • Handling player needs (thirst and hunger) via server events.
--- @usage • Charging/funding players (money removal/addition).
--- ```lua • Processing item consumption and applying effects.
--- -- Lock the player's inventory • Checking player job/gang roles and retrieving player information.
--- lockInv(true) • Getting active players near a coordinate.
--- ]]
--- -- Unlock the player's inventory
--- lockInv(false)
--- ```
function lockInv(toggle)
FreezeEntityPosition(PlayerPedId(), toggle)
LocalPlayer.state:set("inv_busy", toggle, true)
TriggerEvent('inventory:client:busy:status', toggle)
TriggerEvent('canUseInventoryAndHotbar:toggle', not toggle)
end
--- Instantly turns an entity to face a specific location or another entity. -------------------------------------------------------------
-- Player Movement
-------------------------------------------------------------
--- Instantly turns an entity to face a target (entity or coordinates) without animation.
--- ---
--- This function calculates the heading from the first entity to the second entity or coordinates --- @param ent number|nil The Ped to turn (defaults to player's Ped if nil).
--- and sets the entity's heading immediately without any animation. --- @param ent2 number|vector3|nil The target entity or coordinates to face.
---
--- @param ent number|nil The Ped entity to turn. Defaults to the player's Ped (`PlayerPedId()`).
--- @param ent2 number|vector3|nil The target entity or coordinates to face. If a vector, it uses the coordinates.
--- ---
--- @usage --- @usage
--- ```lua --- ```lua
--- -- Make the player instantly face a specific location
--- instantLookEnt(nil, vector3(200.0, 300.0, 40.0)) --- instantLookEnt(nil, vector3(200.0, 300.0, 40.0))
---
--- -- Make one entity face another entity
--- instantLookEnt(ped1, ped2) --- instantLookEnt(ped1, ped2)
--- ``` --- ```
function instantLookEnt(ent, ent2) function instantLookEnt(ent, ent2)
local ent = ent or PlayerPedId() local ped = ent or PlayerPedId()
local p1 = GetEntityCoords(ent, true) local p1 = GetEntityCoords(ped, true)
local p2 = type(ent2):find("vector") and ent2 or GetEntityCoords(ent2, true) local p2 = type(ent2) == "vector3" and ent2 or GetEntityCoords(ent2, true)
local dx = p2.x - p1.x local dx = p2.x - p1.x
local dy = p2.y - p1.y local dy = p2.y - p1.y
local heading = GetHeadingFromVector_2d(dx, dy) local heading = GetHeadingFromVector_2d(dx, dy)
debugPrint("^6Bridge^7: ^1Forced ^2Turning Player to^7: '^6"..formatCoord(p2).."^7'") debugPrint("^6Bridge^7: ^1Forced ^2Turning Player to^7: '^6"..formatCoord(p2).."^7'")
SetEntityHeading(ent, heading) SetEntityHeading(ped, heading)
end end
--- Makes the player Ped look towards a specific entity or coordinates with animation. --- Makes the player look towards a specific target with an animated turn.
--- ---
--- This function checks if the player is already facing the target. If not, it triggers a turning animation --- If the player is not already facing the target (entity or coordinates), a turning animation is triggered.
--- to face the specified entity or coordinates.
--- ---
--- @param entity number|vector3|vector4|nil The target entity or coordinates to look at. --- @param entity number|vector3|vector4|nil The target to look at.
--- ---
--- @usage --- @usage
--- ```lua --- ```lua
--- -- Make the player look at a specific location
--- lookEnt(vector3(200.0, 300.0, 40.0)) --- lookEnt(vector3(200.0, 300.0, 40.0))
---
--- -- Make the player look at another entity
--- lookEnt(pedEntity) --- lookEnt(pedEntity)
--- ``` --- ```
function lookEnt(entity) function lookEnt(entity)
@@ -86,15 +71,12 @@ function lookEnt(entity)
end end
end end
--- Server event handler for handling urinal usage. -------------------------------------------------------------
--- -- Server Event Handlers for Needs
--- This event decreases the player's thirst based on a random amount and updates their thirst level. -------------------------------------------------------------
---
--- @usage --- Server event handler for urinal usage.
--- ```lua --- Decreases player's thirst by a random amount.
--- -- Triggered when a player uses a urinal
--- TriggerServerEvent(getScript()..":server:Urinal")
--- ```
RegisterNetEvent(getScript()..":server:Urinal", function() RegisterNetEvent(getScript()..":server:Urinal", function()
local src = source local src = source
local Player = getPlayer(src) local Player = getPlayer(src)
@@ -103,43 +85,27 @@ RegisterNetEvent(getScript()..":server:Urinal", function()
setThirst(src, getPlayer(src).thirst - thirst) setThirst(src, getPlayer(src).thirst - thirst)
end) end)
--- Server event handler for setting player needs. --- Server event handler for setting player needs (thirst or hunger).
---
--- This event updates the player's thirst or hunger based on the provided type and amount.
--- ---
--- @event --- @event
--- @param type string The type of need to set ("thirst" or "hunger"). --- @param type string "thirst" or "hunger".
--- @param amount number The amount to set the need to. --- @param amount number New value to set.
--- RegisterNetEvent(getScript()..":server:setNeed", function(needType, amount)
--- @return void
---
--- @usage
--- ```lua
--- -- Set the player's thirst level
--- TriggerServerEvent(getScript()..":server:setNeed", "thirst", 50)
---
--- -- Set the player's hunger level
--- TriggerServerEvent(getScript()..":server:setNeed", "hunger", 75)
--- ```
RegisterNetEvent(getScript()..":server:setNeed", function(type, amount)
local src = source local src = source
if type == "thirst" then if needType == "thirst" then
setThirst(src, amount) setThirst(src, amount)
elseif type == "hunger" then elseif needType == "hunger" then
setHunger(src, amount) setHunger(src, amount)
end end
end) end)
--- Sets the player's thirst level. --- Sets the player's thirst level.
--- ---
--- This function updates the player's thirst based on the active inventory system. --- @param src number The player's server ID.
--- --- @param thirst number The new thirst level.
--- @param src number The server ID of the player.
--- @param thirst number The new thirst level to set.
--- ---
--- @usage --- @usage
--- ```lua --- ```lua
--- -- Set a player's thirst to 80
--- setThirst(playerId, 80) --- setThirst(playerId, 80)
--- ``` --- ```
function setThirst(src, thirst) function setThirst(src, thirst)
@@ -154,14 +120,11 @@ end
--- Sets the player's hunger level. --- Sets the player's hunger level.
--- ---
--- This function updates the player's hunger based on the active inventory system. --- @param src number The player's server ID.
--- --- @param hunger number The new hunger level.
--- @param src number The server ID of the player.
--- @param hunger number The new hunger level to set.
--- ---
--- @usage --- @usage
--- ```lua --- ```lua
--- -- Set a player's hunger to 60
--- setHunger(playerId, 60) --- setHunger(playerId, 60)
--- ``` --- ```
function setHunger(src, hunger) function setHunger(src, hunger)
@@ -174,105 +137,117 @@ function setHunger(src, hunger)
end end
end end
--- Server event handler for charging a player. -------------------------------------------------------------
-- Economy Event Handlers
-------------------------------------------------------------
--- Charges a player by removing money from their account.
--- ---
--- This event removes money from a player based on the specified type ("cash" or "bank"). --- @param cost number The amount to charge.
--- --- @param type string "cash" or "bank".
--- @event --- @param newsrc number|nil Optional player ID; defaults to event source.
--- @param cost number The amount of money to charge.
--- @param type string The type of money to charge ("cash" or "bank").
--- @param newsrc number|nil Optional. The server ID of the player. If `nil`, uses the event source.
--- ---
--- @usage --- @usage
--- ```lua --- ```lua
--- -- Charge a player $100 in cash
--- chargePlayer(100, "cash", playerId) --- chargePlayer(100, "cash", playerId)
---
--- -- Charge the source $250 from the bank
--- chargePlayer(250, "bank", src,)
--- ``` --- ```
function chargePlayer(cost, type, newsrc) function chargePlayer(cost, moneyType, newsrc)
local src = newsrc or source local src = newsrc or source
local fundResource = "" local fundResource = ""
if type == "cash" then if cost < 0 then
debugPrint("^1Error^7: ^7SRC: ^3"..src.." ^2Tried to charge a minus value^7", cost)
return
end
if moneyType == "cash" then
if isStarted(OXInv) then fundResource = OXInv if isStarted(OXInv) then fundResource = OXInv
exports[OXInv]:RemoveItem(src, "money", cost) exports[OXInv]:RemoveItem(src, "money", cost)
elseif isStarted(QBExport) or isStarted(QBXExport) then fundResource = QBExport elseif isStarted(QBExport) or isStarted(QBXExport) then
fundResource = QBExport
Core.Functions.GetPlayer(src).Functions.RemoveMoney("cash", cost) Core.Functions.GetPlayer(src).Functions.RemoveMoney("cash", cost)
elseif isStarted(ESXExport) then fundResource = ESXExport elseif isStarted(RSGExport) then
local Player = ESX.GetPlayerFromId(src) fundResource = QBExport
Player.removeMoney(cost, "") Core.Functions.GetPlayer(src).Functions.RemoveMoney("cash", cost)
elseif isStarted(ESXExport) then
fundResource = ESXExport
ESX.GetPlayerFromId(src).removeMoney(cost, "")
end end
end elseif moneyType == "bank" then
if type == "bank" then
if isStarted(QBExport) or isStarted(QBXExport) then fundResource = QBExport if isStarted(QBExport) or isStarted(QBXExport) then fundResource = QBExport
Core.Functions.GetPlayer(src).Functions.RemoveMoney("bank", cost) Core.Functions.GetPlayer(src).Functions.RemoveMoney("bank", cost)
elseif isStarted(ESXExport) then fundResource = ESXExport elseif isStarted(ESXExport) then fundResource = ESXExport
local Player = ESX.GetPlayerFromId(src) ESX.GetPlayerFromId(src).removeMoney(cost, "")
Player.removeMoney(cost, "")
end end
end end
if fundResource == "" then print("error - check exports.lua")
if fundResource == "" then
print("Cannot charge player - check starter.lua")
else else
debugPrint("^6Bridge^7: ^2Charging ^2Player^7: '^6"..cost.."^7'", type, fundResource) debugPrint("^6Bridge^7: ^2Charging ^2Player^7: '^6"..cost.."^7'", moneyType, fundResource)
end end
end end
RegisterNetEvent(getScript()..":server:ChargePlayer", chargePlayer) RegisterNetEvent(getScript()..":server:ChargePlayer", function(cost, moneyType, newsrc)
debugPrint(GetInvokingResource())
if GetInvokingResource() and GetInvokingResource() ~= getScript() and GetInvokingResource() ~= "qb-core" then
debugPrint("^1Error^7: ^1Possible exploit^7, ^1vital function was called from an external resource^7")
return
end
chargePlayer(cost, moneyType, newsrc)
end)
--- Server event handler for funding a player. --- Funds a player by adding money to their account.
--- ---
--- This event adds money to a player based on the specified type ("cash" or "bank"). --- @param fund number The amount to add.
--- --- @param type string "cash" or "bank".
--- @event --- @param newsrc number|nil Optional player ID; defaults to event source.
--- @param fund number The amount of money to add.
--- @param type string The type of money to add ("cash" or "bank").
--- @param newsrc number|nil Optional. The server ID of the player. If `nil`, uses the event source.
--- ---
--- @usage --- @usage
--- ```lua --- ```lua
--- -- Add $150 to a player's cash --- fundPlayer(150, "cash", playerId)
--- fundPlayer(playerId, 150, "cash")
---
--- -- Add $300 to the event source's bank account
--- fundPlayer(playerId, 300, "bank")
--- ``` --- ```
function fundPlayer(fund, type, newsrc) function fundPlayer(fund, moneyType, newsrc)
local src = newsrc or source local src = newsrc or source
local fundResource = "" local fundResource = ""
if type == "cash" then
if isStarted(OXInv) then fundResource = OXInv if moneyType == "cash" then
if isStarted(OXInv) then
fundResource = OXInv
exports[OXInv]:AddItem(src, "money", fund) exports[OXInv]:AddItem(src, "money", fund)
elseif isStarted(QBExport) or isStarted(QBXExport) then fundResource = QBExport elseif isStarted(QBExport) or isStarted(QBXExport) then
fundResource = QBExport
Core.Functions.GetPlayer(src).Functions.AddMoney("cash", fund) Core.Functions.GetPlayer(src).Functions.AddMoney("cash", fund)
elseif isStarted(ESXExport) then fundResource = ESXExport elseif isStarted(ESXExport) then
local Player = ESX.GetPlayerFromId(src) fundResource = ESXExport
Player.addMoney(fund, "") PlayESX.GetPlayerFromId(src).addMoney(fund, "")
end end
end elseif moneyType == "bank" then
if type == "bank" then if isStarted(QBExport) or isStarted(QBXExport) then
if isStarted(QBExport) or isStarted(QBXExport) then fundResource = QBExport fundResource = QBExport
Core.Functions.GetPlayer(src).Functions.AddMoney("bank", fund) Core.Functions.GetPlayer(src).Functions.AddMoney("bank", fund)
elseif isStarted(ESXExport) then fundResource = ESXExport elseif isStarted(ESXExport) then
local Player = ESX.GetPlayerFromId(src) fundResource = ESXExport
Player.addMoney(fund, "") ESX.GetPlayerFromId(src).addMoney(fund, "")
end end
end end
if fundResource == "" then print("error - check exports.lua")
if fundResource == "" then
print("Cannot fund player - check starter.lua")
else else
debugPrint("^6Bridge^7: ^2Funding ^2Player^7: '^2"..fund.."^7'", type, fundResource) debugPrint("^6Bridge^7: ^2Funding Player: '^2"..fund.."^7'", moneyType, fundResource)
end end
end end
RegisterNetEvent(getScript()..":server:FundPlayer", fundPlayer) -------------------------------------------------------------
-- Item Consumption & Effects
-------------------------------------------------------------
--- Handles successful consumption of an item. --- Handles successful consumption of an item.
--- ---
--- This function plays a consumption animation, removes the item from the inventory, --- Plays a consumption animation, removes the item, updates player needs, handles alcohol effects,
--- updates the player's hunger and thirst based on the item consumed, --- and checks for random rewards.
--- handles alcohol effects, and checks for random rewards.
--- ---
--- @param itemName string The name of the item consumed. --- @param itemName string The name of the consumed item.
--- @param type string The type/category of the item (e.g., "alcohol"). --- @param type string The category of the item (e.g., "alcohol").
--- @param data table Additional data (e.g., hunger and thirst values).
--- ---
--- @usage --- @usage
--- ```lua --- ```lua
@@ -283,10 +258,12 @@ RegisterNetEvent(getScript()..":server:FundPlayer", fundPlayer)
--- ConsumeSuccess("beer", "alcohol") --- ConsumeSuccess("beer", "alcohol")
--- ``` --- ```
function ConsumeSuccess(itemName, type, data) function ConsumeSuccess(itemName, type, data)
local hunger = data and data.hunger or Items[itemName].hunger or nil local hunger = data and data.hunger or Items[itemName].hunger
local thirst = data and data.thirst or Items[itemName].thirst or nil local thirst = data and data.thirst or Items[itemName].thirst
ExecuteCommand("e c") ExecuteCommand("e c")
removeItem(itemName, 1) removeItem(itemName, 1)
if isStarted(ESXExport) then if isStarted(ESXExport) then
if hunger then if hunger then
TriggerServerEvent(getScript()..":server:setNeed", "hunger", hunger * 10000) TriggerServerEvent(getScript()..":server:setNeed", "hunger", hunger * 10000)
@@ -302,7 +279,9 @@ function ConsumeSuccess(itemName, type, data)
TriggerServerEvent(getScript()..":server:setNeed", "thirst", Core.Functions.GetPlayerData().metadata["thirst"] + thirst) TriggerServerEvent(getScript()..":server:setNeed", "thirst", Core.Functions.GetPlayerData().metadata["thirst"] + thirst)
end end
end end
if type == "alcohol" then alcoholCount += 1
if type == "alcohol" then
alcoholCount = (alcoholCount or 0) + 1
if alcoholCount > 1 and alcoholCount < 4 then if alcoholCount > 1 and alcoholCount < 4 then
TriggerEvent("evidence:client:SetStatus", "alcohol", 200) TriggerEvent("evidence:client:SetStatus", "alcohol", 200)
elseif alcoholCount >= 4 then elseif alcoholCount >= 4 then
@@ -310,19 +289,20 @@ function ConsumeSuccess(itemName, type, data)
AlienEffect() AlienEffect()
end end
end end
getRandomReward(itemName) -- check if a reward item should be given
getRandomReward(itemName)
end end
--- Checks if a player has a specific job and grade. -------------------------------------------------------------
-- Player Job & Information Utilities
-------------------------------------------------------------
--- Checks if a player has a specific job or gang (and optionally meets a minimum grade).
--- ---
--- This function verifies whether the player has the specified job and, if a grade is provided, --- @param job string The job or gang name to check.
--- whether the player's grade meets the required level. It supports multiple inventory systems. --- @param source number|nil Optional player source; if nil, checks current player.
--- --- @param grade number|nil Optional minimum grade level.
--- @param job string The name of the job or gang to check. --- @return boolean, boolean boolean Returns true and duty status if the check passes; false otherwise.
--- @param source number|nil Optional. The server ID of the player to check. If `nil`, checks the current player.
--- @param grade number|nil Optional. The minimum grade level required.
---
--- @return boolean, boolean Returns `true` and `duty status` if the player has the job (and grade if specified), otherwise `false`.
--- ---
--- @usage --- @usage
--- ```lua --- ```lua
@@ -338,7 +318,8 @@ end
--- -- Allow gang leader actions --- -- Allow gang leader actions
--- end --- end
--- ``` --- ```
function hasJob(job, source, grade) local hasJob, duty = false, true function hasJob(job, source, grade)
local hasJobFlag, duty = false, true
if source then if source then
local src = tonumber(source) local src = tonumber(source)
if not src then print(tostring(source).." is not a valid player source") end if not src then print(tostring(source).." is not a valid player source") end
@@ -348,113 +329,117 @@ function hasJob(job, source, grade) local hasJob, duty = false, true
info = ESX.GetPlayerData(src).job info = ESX.GetPlayerData(src).job
Wait(100) Wait(100)
end end
if info.name == job then hasJob = true end if info.name == job then hasJobFlag = true end
elseif isStarted(OXCoreExport) then elseif isStarted(OXCoreExport) then
local chunk = assert(load(LoadResourceFile('ox_core', ('imports/%s.lua'):format('server')), ('@@ox_core/%s'):format(file))) local chunk = assert(load(LoadResourceFile('ox_core', ('imports/%s.lua'):format('server')), ('@@ox_core/%s'):format(file)))
chunk() chunk()
local player = Ox.GetPlayer(tonumber(src)) local player = Ox.GetPlayer(src)
for k, v in pairs(player.getGroups()) do for k, v in pairs(player.getGroups()) do
if k == job then hasJob = true end if k == job then hasJobFlag = true end
end end
elseif isStarted(QBXExport) then elseif isStarted(QBXExport) then
local jobinfo = exports[QBXExport]:GetPlayer(src).PlayerData.job local jobinfo = exports[QBXExport]:GetPlayer(src).PlayerData.job
if jobinfo.name == job then hasJob = true if jobinfo.name == job then
hasJobFlag = true
duty = exports[QBXExport]:GetPlayer(src).PlayerData.job.onduty duty = exports[QBXExport]:GetPlayer(src).PlayerData.job.onduty
if grade and not (grade <= jobinfo.grade.level) then hasJob = false end if grade and not (grade <= jobinfo.grade.level) then hasJobFlag = false end
end end
local ganginfo = exports[QBXExport]:GetPlayer(src).PlayerData.gang local ganginfo = exports[QBXExport]:GetPlayer(src).PlayerData.gang
if ganginfo.name == job then hasJob = true if ganginfo.name == job then
if grade and not (grade <= ganginfo.grade.level) then hasJob = false end hasJobFlag = true
if grade and not (grade <= ganginfo.grade.level) then hasJobFlag = false end
end end
elseif isStarted(QBExport) and not isStarted(QBXExport) then elseif isStarted(QBExport) and not isStarted(QBXExport) then
if Core.Functions.GetPlayer then -- support older qb-core functions if Core.Functions.GetPlayer then
local player = Core.Functions.GetPlayer(src) local player = Core.Functions.GetPlayer(src)
if not player then print("Player not found for src: "..src) end if not player then print("Player not found for src: "..src) end
local jobinfo = player.PlayerData.job local jobinfo = player.PlayerData.job
if jobinfo.name == job then hasJob = true if jobinfo.name == job then
duty = Core.Functions.GetPlayer(src).PlayerData.job.onduty hasJobFlag = true
if grade and not (grade <= jobinfo.grade.level) then hasJob = false end duty = player.PlayerData.job.onduty
if grade and not (grade <= jobinfo.grade.level) then hasJobFlag = false end
end end
local ganginfo = Core.Functions.GetPlayer(src).PlayerData.gang local ganginfo = player.PlayerData.gang
if ganginfo.name == job then hasJob = true if ganginfo.name == job then
if grade and not (grade <= ganginfo.grade.level) then hasJob = false end hasJobFlag = true
if grade and not (grade <= ganginfo.grade.level) then hasJobFlag = false end
end end
else -- support newer qb-core exports else
local jobinfo = exports[QBExport]:GetPlayer(src).PlayerData.job local jobinfo = exports[QBExport]:GetPlayer(src).PlayerData.job
if jobinfo.name == job then hasJob = true if jobinfo.name == job then
hasJobFlag = true
duty = exports[QBExport]:GetPlayer(src).PlayerData.job.onduty duty = exports[QBExport]:GetPlayer(src).PlayerData.job.onduty
if grade and not (grade <= jobinfo.grade.level) then hasJob = false end if grade and not (grade <= jobinfo.grade.level) then hasJobFlag = false end
end end
local ganginfo = exports[QBExport]:GetPlayer(src).PlayerData.gang local ganginfo = exports[QBExport]:GetPlayer(src).PlayerData.gang
if ganginfo.name == job then hasJob = true if ganginfo.name == job then
if grade and not (grade <= ganginfo.grade.level) then hasJob = false end hasJobFlag = true
if grade and not (grade <= ganginfo.grade.level) then hasJobFlag = false end
end end
end end
else else
print("^4ERROR^7: ^2No Core detected for hasJob ^7- ^2Check ^3exports^1.^2lua^7") print("^4ERROR^7: ^2No Core detected for hasJob ^7- ^2Check ^3starter^1.^2lua^7")
end end
else else
if isStarted(ESXExport) then -- Client-side check.
while not ESX do Wait(10) end if isStarted(ESXExport) and ESX ~= nil then
local info = ESX.GetPlayerData().job local info = ESX.GetPlayerData().job
while not info do while not info do
info = ESX.GetPlayerData().job info = ESX.GetPlayerData().job
Wait(100) Wait(100)
end end
if info.name == job then hasJob = true end if info.name == job then hasJobFlag = true end
elseif isStarted(OXCoreExport) then elseif isStarted(OXCoreExport) then
for k, v in pairs(exports[OXCoreExport]:GetPlayerData().groups) do local info = OxPlayer.getGroups()
if k == job then hasJob = true end break for k, v in pairs(info) do
if k == job then hasJobFlag = true break end
end end
elseif isStarted(QBXExport) then elseif isStarted(QBXExport) then
local jobinfo = QBX.PlayerData.job local info = exports[QBXExport]:GetPlayerData()
if jobinfo.name == job then hasJob = true if info.job.name == job then
duty = QBX.PlayerData.job.onduty hasJobFlag = true
if grade and not (grade <= jobinfo.grade.level) then hasJob = false end duty = info.job.onduty
if grade and not (grade <= info.job.grade.level) then hasJobFlag = false end
end end
local ganginfo = QBX.PlayerData.gang if info.gang.name == job then
if ganginfo.name == job then hasJob = true hasJobFlag = true
if grade and not (grade <= ganginfo.grade.level) then hasJob = false end if grade and not (grade <= info.gang.grade.level) then hasJobFlag = false end
end end
elseif isStarted(QBExport) and not isStarted(QBXExport) then elseif isStarted(QBExport) and not isStarted(QBXExport) then
local info = nil local info = nil
Core.Functions.GetPlayerData(function(PlayerData) Core.Functions.GetPlayerData(function(PlayerData) info = PlayerData end)
info = PlayerData
end)
local jobinfo = info.job local jobinfo = info.job
if jobinfo.name == job then hasJob = true if jobinfo.name == job then
hasJobFlag = true
duty = jobinfo.onduty duty = jobinfo.onduty
if grade and not (grade <= jobinfo.grade.level) then hasJob = false end if grade and not (grade <= jobinfo.grade.level) then hasJobFlag = false end
end end
local ganginfo = info.gang local ganginfo = info.gang
if ganginfo.name == job then if ganginfo.name == job then
hasJob = true hasJobFlag = true
if grade and not (grade <= ganginfo.grade.level) then hasJob = false end if grade and not (grade <= ganginfo.grade.level) then hasJobFlag = false end
end end
else else
print("^4ERROR^7: ^2No Core detected for hasJob() ^7- ^2Check ^3exports^1.^2lua^7") print("^4ERROR^7: ^2No Core detected for hasJob() ^7- ^2Check ^3starter^1.^2lua^7")
end end
end end
return hasJob, duty return hasJobFlag, duty
end end
--- Retrieves basic information about a player. --- Retrieves basic player information (name, cash, bank, job, etc.) based on the active core/inventory system.
--- ---
--- This function gathers the player's name, cash balance, and bank balance --- Can be called server-side (passing a player source) or client-side (for current player).
--- based on the active inventory system. It can be called server-side or client-side.
--- ---
---@param source number|nil Optional. The server ID of the player. If `nil`, retrieves info for the current player. --- @param source number|nil Optional player server ID.
--- @return table A table containing player details.
--- ---
---@return table table A table containing the player's `name`, `cash`, and `bank` balances. --- @usage
---
---@usage
--- ```lua --- ```lua
--- -- Get information for a specific player --- -- Get information for a specific player
--- local playerInfo = getPlayer(playerId) --- local playerInfo = getPlayer(playerId)
@@ -467,7 +452,8 @@ end
function getPlayer(source) function getPlayer(source)
local Player = {} local Player = {}
debugPrint("^6Bridge^7: ^2Getting ^3Player^2 info^7") debugPrint("^6Bridge^7: ^2Getting ^3Player^2 info^7")
if source then -- If called from server
if source then
local src = tonumber(source) local src = tonumber(source)
if isStarted(ESXExport) then if isStarted(ESXExport) then
local info = ESX.GetPlayerFromId(src) local info = ESX.GetPlayerFromId(src)
@@ -475,6 +461,18 @@ function getPlayer(source)
name = info.getName(), name = info.getName(),
cash = info.getMoney(), cash = info.getMoney(),
bank = info.getAccount("bank").money, bank = info.getAccount("bank").money,
firstname = info.variables.firstName,
lastname = info.variables.lastName,
source = info.source,
job = info.job.name,
--jobBoss = info.job.isboss,
--gang = info.gang.name,
--gangBoss = info.gang.isboss,
onDuty = info.job.onDuty,
--account = info.charinfo.account,
citizenId = info.identifier,
} }
elseif isStarted(OXCoreExport) then elseif isStarted(OXCoreExport) then
@@ -482,23 +480,47 @@ function getPlayer(source)
local import = LoadResourceFile('ox_core', file) local import = LoadResourceFile('ox_core', file)
local chunk = assert(load(import, ('@@ox_core/%s'):format(file))) local chunk = assert(load(import, ('@@ox_core/%s'):format(file)))
chunk() chunk()
local player = Ox.GetPlayer(tonumber(src)) local player = Ox.GetPlayer(src)
Player = { Player = {
firstname = player.firstName,
lastname = player.lastName ,
name = ('%s %s'):format(player.firstName, player.lastName), name = ('%s %s'):format(player.firstName, player.lastName),
cash = exports[OXInv]:Search(src, 'count', "money"), cash = exports[OXInv]:Search(src, 'count', "money"),
bank = 0, bank = 0,
} source = src,
--job = OxPlayer.getGroups(),
--jobBoss = info.job.isboss,
--gang = OxPlayer.getGroups(),
--gangBoss = info.gang.isboss,
--onDuty = info.job.onduty,
--account = info.charinfo.account,
citizenId = player.stateId,
}
elseif isStarted(QBXExport) then elseif isStarted(QBXExport) then
local info = exports[QBXExport]:GetPlayer(src) local info = exports[QBXExport]:GetPlayer(src)
Player = { Player = {
firstname = info.PlayerData.charinfo.firstname,
lastname = info.PlayerData.charinfo.lastname,
name = info.PlayerData.charinfo.firstname.." "..info.PlayerData.charinfo.lastname, name = info.PlayerData.charinfo.firstname.." "..info.PlayerData.charinfo.lastname,
cash = exports[OXInv]:Search(src, 'count', "money"), cash = exports[OXInv]:Search(src, 'count', "money"),
bank = info.Functions.GetMoney("bank"), bank = info.Functions.GetMoney("bank"),
source = info.PlayerData.source,
job = info.PlayerData.job.name,
jobBoss = info.PlayerData.job.isboss,
jobInfo = info.PlayerData.job,
gang = info.PlayerData.gang.name,
gangInfo = info.PlayerData.gang,
gangBoss = info.PlayerData.gang.isboss,
onDuty = info.PlayerData.job.onduty,
account = info.PlayerData.charinfo.account,
citizenId = info.PlayerData.citizenid,
isDead = info.PlayerData.metadata["isdead"],
isDown = info.PlayerData.metadata["inlaststand"],
charInfo = info.charinfo,
} }
elseif isStarted(QBExport) and not isStarted(QBXExport) then elseif isStarted(QBExport) and not isStarted(QBXExport) then
if Core.Functions.GetPlayer ~= nil then -- support older qb-core functions if Core.Functions.GetPlayer then
local info = Core.Functions.GetPlayer(src).PlayerData local info = Core.Functions.GetPlayer(src).PlayerData
Player = { Player = {
firstname = info.charinfo.firstname, firstname = info.charinfo.firstname,
@@ -509,15 +531,21 @@ function getPlayer(source)
source = info.source, source = info.source,
job = info.job.name, job = info.job.name,
jobBoss = info.job.isboss, jobBoss = info.job.isboss,
jobInfo = info.job,
gang = info.gang.name, gang = info.gang.name,
gangBoss = info.gang.isboss, gangBoss = info.gang.isboss,
gangInfo = info.gang,
onDuty = info.job.onduty, onDuty = info.job.onduty,
account = info.charinfo.account, account = info.charinfo.account,
citizenId = info.citizenid, citizenId = info.citizenid,
isDead = info.metadata["isdead"],
isDown = info.metadata["inlaststand"],
charInfo = info.charinfo,
} }
end
else elseif isStarted(RSGExport) then
local info = exports[QBExport]:GetPlayer(src).PlayerData -- this was added to new core then removed? if Core.Functions.GetPlayer then
local info = Core.Functions.GetPlayer(src).PlayerData
Player = { Player = {
firstname = info.charinfo.firstname, firstname = info.charinfo.firstname,
lastname = info.charinfo.lastname, lastname = info.charinfo.lastname,
@@ -527,36 +555,64 @@ function getPlayer(source)
source = info.source, source = info.source,
job = info.job.name, job = info.job.name,
jobBoss = info.job.isboss, jobBoss = info.job.isboss,
jobInfo = info.job,
gang = info.gang.name, gang = info.gang.name,
gangBoss = info.gang.isboss, gangBoss = info.gang.isboss,
gangInfo = info.gang,
onDuty = info.job.onduty, onDuty = info.job.onduty,
account = info.charinfo.account, account = info.charinfo.account,
citizenId = info.citizenid, citizenId = info.citizenid,
isDead = info.metadata["isdead"],
isDown = info.metadata["inlaststand"],
charInfo = info.charinfo,
} }
end end
else else
print("^4ERROR^7: ^2No Core detected for getPlayer() ^7- ^2Check ^3exports^1.^2lua^7") print("^4ERROR^7: ^2No Core detected for getPlayer() - Check starter.lua")
end end
else else
-- Client-side: Get current player info.
if isStarted(ESXExport) and ESX ~= nil then if isStarted(ESXExport) and ESX ~= nil then
local info = ESX.GetPlayerData() local info = ESX.GetPlayerData()
local cash, bank = 0, 0 local cash, bank = 0, 0
for k, v in pairs(ESX.GetPlayerData().accounts) do for k, v in pairs(info.accounts) do
if v.name == "money" then cash = v.money end if v.name == "money" then cash = v.money end
if v.name == "bank" then bank = v.money end if v.name == "bank" then bank = v.money end
end end
Player = { Player = {
name = ('%s %s'):format(info.firstName, info.lastName), firstname = info.firstName,
lastname = info.lastName,
name = info.firstName.." "..info.lastName,
cash = cash, cash = cash,
bank = bank, bank = bank,
source = GetPlayerServerId(PlayerId()),
job = info.job.name,
--jobBoss = info.job.isboss,
--gang = info.gang.name,
--gangBoss = info.gang.isboss,
onDuty = info.job.onDuty,
--account = info.charinfo.account,
citizenId = info.identifier,
isDead = IsEntityDead(PlayerPedId()),
isDown = IsPedDeadOrDying(PlayerPedId(), true)
} }
elseif isStarted(OXCoreExport) then elseif isStarted(OXCoreExport) then
local info = exports[OXCoreExport]:GetPlayerData()
Player = { Player = {
name = info.firstName.." "..info.lastName, firstname = OxPlayer.get("firstName"),
lastname = OxPlayer.get("lastName"),
name = OxPlayer.get("firstName").." "..OxPlayer.get("lastName"),
cash = exports[OXInv]:Search('count', "money"), cash = exports[OXInv]:Search('count', "money"),
bank = 0, bank = 0,
source = GetPlayerServerId(PlayerId()),
job = OxPlayer.getGroups(),
--jobBoss = info.job.isboss,
gang = OxPlayer.getGroups(),
--gangBoss = info.gang.isboss,
--onDuty = info.job.onduty,
--account = info.charinfo.account,
citizenId = OxPlayer.userId,
isDead = IsEntityDead(PlayerPedId()),
isDown = IsPedDeadOrDying(PlayerPedId(), true)
} }
elseif isStarted(QBXExport) then elseif isStarted(QBXExport) then
local info = exports[QBXExport]:GetPlayerData() local info = exports[QBXExport]:GetPlayerData()
@@ -569,11 +625,16 @@ function getPlayer(source)
source = info.source, source = info.source,
job = info.job.name, job = info.job.name,
jobBoss = info.job.isboss, jobBoss = info.job.isboss,
jobInfo = info.job,
gang = info.gang.name, gang = info.gang.name,
gangBoss = info.gang.isboss, gangBoss = info.gang.isboss,
gangInfo = info.gang,
onDuty = info.job.onduty, onDuty = info.job.onduty,
account = info.charinfo.account, account = info.charinfo.account,
citizenId = info.citizenid, citizenId = info.citizenid,
isDead = info.metadata["isdead"],
isDown = info.metadata["inlaststand"],
charInfo = info.charinfo,
} }
elseif isStarted(QBExport) and not isStarted(QBXExport) then elseif isStarted(QBExport) and not isStarted(QBXExport) then
local info = nil local info = nil
@@ -587,15 +648,67 @@ function getPlayer(source)
source = info.source, source = info.source,
job = info.job.name, job = info.job.name,
jobBoss = info.job.isboss, jobBoss = info.job.isboss,
jobInfo = info.job,
gang = info.gang.name, gang = info.gang.name,
gangBoss = info.gang.isboss, gangBoss = info.gang.isboss,
gangInfo = info.gang,
onDuty = info.job.onduty, onDuty = info.job.onduty,
account = info.charinfo.account, account = info.charinfo.account,
citizenId = info.citizenid, citizenId = info.citizenid,
isDead = info.metadata["isdead"],
isDown = info.metadata["inlaststand"],
charInfo = info.charinfo,
}
elseif isStarted(RSGExport) then
local info = nil
Core.Functions.GetPlayerData(function(PlayerData) info = PlayerData end)
Player = {
firstname = info.charinfo.firstname,
lastname = info.charinfo.lastname,
name = info.charinfo.firstname.." "..info.charinfo.lastname,
cash = info.money["cash"],
bank = info.money["bank"],
source = info.source,
job = info.job.name,
jobBoss = info.job.isboss,
jobInfo = info.job,
gang = info.gang.name,
gangBoss = info.gang.isboss,
gangInfo = info.gang,
onDuty = info.job.onduty,
account = info.charinfo.account,
citizenId = info.citizenid,
isDead = info.metadata["isdead"],
isDown = info.metadata["inlaststand"],
charInfo = info.charinfo,
} }
else else
print("^4ERROR^7: ^2No Core detected for hasJob ^7- ^2Check ^3exports^1.^2lua^7") print("^4ERROR^7: ^2No Core detected for hasJob ^7- ^2Check ^3starter^1.^2lua^7")
end end
end end
return Player return Player
end end
--- Retrieves all active players within a given radius from the specified coordinates.
---
--- @param coords vector3 The reference coordinates.
--- @param radius number The radius within which to find players.
--- @return table table An array of player IDs.
---
--- @usage
--- ```lua
--- local nearbyPlayers = GetPlayersFromCoords(vector3(100, 200, 30), 20)
--- ```
function GetPlayersFromCoords(coords, radius)
local players = {}
for _, playerId in ipairs(GetActivePlayers()) do
local ped = GetPlayerPed(playerId)
if ped and DoesEntityExist(ped) then
local playerCoords = GetEntityCoords(ped)
if #(coords - playerCoords) <= radius then
players[#players + 1] = playerId
end
end
end
return players
end

View File

@@ -1,45 +1,61 @@
-- This automatically detects what polyzone script it should use to create a polyzone -- --[[
-- if ox_lib is detected, it will automatically use that instead of PolyZone -- PolyZone Management Module
-- createPoly({ name = 'name', debug = true, points = { vec2(), vec2() }, onEnter = function() end, onExit = function() end, }) ----------------------------
--- This module automatically detects the available polyzone library (ox_lib or PolyZone)
and creates polygonal and circular zones accordingly. It also provides a function to remove
previously created zones.
Functions:
• createPoly(data) - Creates a polygonal zone.
• createCirclePoly(data) - Creates a circular zone.
• removePolyZone(Location) - Removes a created zone.
]]
-------------------------------------------------------------
-- Polygonal Zone Creation
-------------------------------------------------------------
--- Creates a polygonal zone using the detected polyzone library (ox_lib or PolyZone). --- Creates a polygonal zone using the detected polyzone library (ox_lib or PolyZone).
--- ---
--- This function automatically detects whether `ox_lib` or `PolyZone` is active and creates a polygonal zone accordingly. --- Automatically checks which polyzone script is active. When using ox_lib, it converts the provided
--- It supports setting up entry and exit callbacks for the zone. --- 2D points to 3D (setting a constant z value) and sets a thickness value. For PolyZone, it creates the zone
--- and attaches onEnter and onExit callbacks.
--- ---
---@param data table A table containing the zone configuration. --- @param data table Zone configuration table with the following keys:
--- - **name** (`string`): The name of the zone. --- - name (string): The zone's identifier.
--- - **debug** (`boolean`): Whether to enable debug mode for the zone. --- - debug (boolean): Whether debug mode is enabled.
--- - **points** (`table`): A list of `vec2` points defining the polygon. --- - points (table): A list of vec2 points defining the polygon.
--- - **onEnter** (`function`): Callback function to execute when a player enters the zone. --- - onEnter (function): Callback when a player enters the zone.
--- - **onExit** (`function`): Callback function to execute when a player exits the zone. --- - onExit (function): Callback when a player exits the zone.
--- ---
---@return table|nil table Returns the created zone object or `nil` if creation failed. --- @return table|nil table Returns the created zone object or nil if creation failed.
--- ---
---@usage ---@usage
--- ```lua ---```lua
--- createPoly({ ---createPoly({
--- name = 'testZone', --- name = 'testZone',
--- debug = true, --- debug = true,
--- points = { vec2(100.0, 100.0), vec2(200.0, 100.0), vec2(200.0, 200.0), vec2(100.0, 200.0) }, --- points = { vec2(100.0, 100.0), vec2(200.0, 100.0), vec2(200.0, 200.0), vec2(100.0, 200.0) },
--- onEnter = function() print("Entered Test Zone") end, --- onEnter = function() print("Entered Test Zone") end,
--- onExit = function() print("Exited Test Zone") end, --- onExit = function() print("Exited Test Zone") end,
--- }) ---})
--- ``` ---```
function createPoly(data) function createPoly(data)
local Location = nil local Location = nil
if isStarted(OXLibExport) then -- if it finds ox_lib, use it instead of PolyZone if isStarted(OXLibExport) then
debugPrint("^6Bridge^7: ^2Creating new poly with ^7'^4"..OXLibExport.."^7': "..data.name) debugPrint("^6Bridge^7: ^2Creating new poly with ^7'^4"..OXLibExport.."^7': "..data.name)
-- Convert 2D points to 3D with a fixed Z coordinate (e.g., 12.0)
for i = 1, #data.points do for i = 1, #data.points do
data.points[i] = vec3(data.points[i].x, data.points[i].y, 12.0) data.points[i] = vec3(data.points[i].x, data.points[i].y, 12.0)
end end
data.thickness = 1000 data.thickness = 1000 -- Set a default thickness value
Location = lib.zones.poly(data) Location = lib.zones.poly(data)
elseif isStarted("PolyZone") then elseif isStarted("PolyZone") then
debugPrint("^6Bridge^7: ^2Creating new poly with ^7'^4PolyZone^7': "..data.name) debugPrint("^6Bridge^7: ^2Creating new poly with ^7'^4PolyZone^7': "..data.name)
Location = PolyZone:Create(data.points, { name = data.name, debugPoly = data.debug }) Location = PolyZone:Create(data.points, { name = data.name, debugPoly = data.debug })
Location:onPlayerInOut(function(isPointInside) Location:onPlayerInOut(function(isPointInside)
if isPointInside then data.onEnter() else data.onExit() end if isPointInside then data.onEnter() else data.onExit() end
end) end)
else else
print("^4ERROR^7: ^2No PolyZone creation script detected ^7- ^2Check ^3exports^1.^2lua^7") print("^4ERROR^7: ^2No PolyZone creation script detected ^7- ^2Check ^3exports^1.^2lua^7")
@@ -47,21 +63,25 @@ function createPoly(data)
return Location return Location
end end
-------------------------------------------------------------
-- Circular Zone Creation
-------------------------------------------------------------
--- Creates a circular zone using the detected polyzone library (ox_lib or PolyZone). --- Creates a circular zone using the detected polyzone library (ox_lib or PolyZone).
--- ---
--- This function automatically detects whether `ox_lib` or `PolyZone` is active and creates a circular zone accordingly. --- When using ox_lib, it creates a sphere zone. For PolyZone, it creates a CircleZone and attaches
--- It supports setting up entry and exit callbacks for the zone. --- onEnter and onExit callbacks.
--- ---
---@param data table A table containing the circular zone configuration. --- @param data table Zone configuration with the following keys:
--- - **name** (`string`): The name of the circular zone. --- - name (string): The zone's identifier.
--- - **coords** (`vector3`): The center coordinates of the circle. --- - coords (vector3): The center of the circle.
--- - **radius** (`number`): The radius of the circle. --- - radius (number): The radius of the circle.
--- - **onEnter** (`function`): Callback function to execute when a player enters the zone. --- - onEnter (function): Callback when a player enters the zone.
--- - **onExit** (`function`): Callback function to execute when a player exits the zone. --- - onExit (function): Callback when a player exits the zone.
--- ---
---@return table|nil table Returns the created circular zone object or `nil` if creation failed. --- @return table|nil table Returns the created circular zone object or nil if creation failed.
--- ---
---@usage --- @usage
--- ```lua --- ```lua
--- createCirclePoly({ --- createCirclePoly({
--- name = 'circleZone', --- name = 'circleZone',
@@ -73,7 +93,7 @@ end
--- ``` --- ```
function createCirclePoly(data) function createCirclePoly(data)
local Location = nil local Location = nil
if isStarted(OXLibExport) then -- if it finds ox_lib, use it instead of PolyZone if isStarted(OXLibExport) then
debugPrint("^6Bridge^7: ^2Creating new ^3Cricle^2 poly with ^7"..OXLibExport.." "..data.name) debugPrint("^6Bridge^7: ^2Creating new ^3Cricle^2 poly with ^7"..OXLibExport.." "..data.name)
Location = lib.zones.sphere(data) Location = lib.zones.sphere(data)
elseif isStarted("PolyZone") then elseif isStarted("PolyZone") then
@@ -87,26 +107,30 @@ function createCirclePoly(data)
end end
end) end)
else else
print("^4ERROR^7: ^2No PolyZone creation script detected ^7- ^2Check ^3exports^1.^2lua^7") print("^4ERROR^7: ^2No PolyZone creation script detected ^7- ^2Check ^3starter^1.^2lua^7")
end end
debugPrint("^6Bridge^7: ^2Zone Stats - Coords: "..formatCoord(data.coords).." Radius: "..data.radius) debugPrint("^6Bridge^7: ^2Zone Stats - Coords: "..formatCoord(data.coords).." Radius: "..data.radius)
return Location return Location
end end
-------------------------------------------------------------
-- PolyZone Removal Function
-------------------------------------------------------------
--- Removes a previously created polyzone. --- Removes a previously created polyzone.
--- ---
--- This function detects the active polyzone library (`ox_lib` or `PolyZone`) and removes the specified zone accordingly. --- Detects the active polyzone library and calls the appropriate removal method.
--- ---
--- @param Location table The zone object to be removed. --- @param Location table The zone object to be removed.
--- ---
--- @usage --- @usage
--- ```lua --- ```lua
--- local zone = createPoly({...}) --- local zone = createPoly({...})
--- -- Later in the code ---
--- removePolyZone(zone) --- removePolyZone(zone)
--- ``` --- ```
function removePolyZone(Location) function removePolyZone(Location)
if isStarted(OXLibExport) then -- if it finds ox_lib, use it instead of PolyZone if isStarted(OXLibExport) then
debugPrint("^6Bridge^7: ^2Removing ^2poly with ^7"..OXLibExport) debugPrint("^6Bridge^7: ^2Removing ^2poly with ^7"..OXLibExport)
Location:remove() Location:remove()
elseif isStarted("PolyZone") then elseif isStarted("PolyZone") then

View File

@@ -1,61 +0,0 @@
function makeInstructionalButtons(info)
local build = RequestScaleformMovie("instructional_buttons")
while not HasScaleformMovieLoaded(build) do Wait(0) end
DrawScaleformMovieFullscreen(build, 255, 255, 255, 0, 0)
BeginScaleformMovieMethod(build, "CLEAR_ALL")
EndScaleformMovieMethod()
BeginScaleformMovieMethod(build, "SET_CLEAR_SPACE")
ScaleformMovieMethodAddParamInt(200)
EndScaleformMovieMethod()
for i = 1, #info do
BeginScaleformMovieMethod(build, "SET_DATA_SLOT")
ScaleformMovieMethodAddParamInt(i - 1)
for k = 1, #info[i].keys do
ScaleformMovieMethodAddParamPlayerNameString(GetControlInstructionalButton(2, info[i].keys[k], true))
end
BeginTextCommandScaleformString("STRING")
AddTextComponentSubstringKeyboardDisplay(info[i].text)
EndTextCommandScaleformString()
EndScaleformMovieMethod()
end
BeginScaleformMovieMethod(build, "DRAW_INSTRUCTIONAL_BUTTONS")
EndScaleformMovieMethod()
BeginScaleformMovieMethod(build, "SET_BACKGROUND_COLOUR")
ScaleformMovieMethodAddParamInt(0)
ScaleformMovieMethodAddParamInt(0)
ScaleformMovieMethodAddParamInt(0)
ScaleformMovieMethodAddParamInt(80)
EndScaleformMovieMethod()
DrawScaleformMovieFullscreen(build, 255, 255, 255, 255, 0)
end
-- Testing showing variables on the screen instead of only in f8
function debugScaleForm(textTable, loc)
if debugMode then
-- Define the display position (top left corner)
local loc = loc or vec2(0.05, 0.65)
-- Calculate dynamic height based on the number of lines in the textTable
local lineHeight = 0.025 -- Height of each line of text
local totalHeight = #textTable * lineHeight -- Dynamic height based on number of lines
local boxPadding = 0.01 -- Padding to add around the text inside the box
local size = vec2(0.18, totalHeight + boxPadding * 2) -- Width remains fixed, height is dynamic
DrawRect(loc.x + size.x / 2, loc.y + size.y / 2, size.x, size.y, 0, 0, 0, 255)
for i = 1, #textTable do
local textLine = textTable[i]
SetTextScale(0.30, 0.30)
BeginTextCommandDisplayText("STRING")
AddTextComponentSubstringKeyboardDisplay(textLine)
EndTextCommandDisplayText(loc.x + 0.005, loc.y + (i - 1) * lineHeight + 0.01)
end
end
end

View File

@@ -1,6 +1,17 @@
--[[
BigMessage Module
-----------------
This module provides a flexible way to display large, attention-grabbing messages
on screen using a Scaleform movie ("MP_BIG_MESSAGE_FREEMODE"). It supports multiple
message types (mission passed, colored shard, old-style, simple shard, rank-up, weapon purchased,
and large multiplayer messages), including customizable transitions and durations.
]]
BigMessage = {} BigMessage = {}
BigMessage.__index = BigMessage BigMessage.__index = BigMessage
--- Creates a new BigMessage instance.
--- @return table table A new BigMessage object.
function BigMessage:new() function BigMessage:new()
local self = setmetatable({}, BigMessage) local self = setmetatable({}, BigMessage)
self.scaleform = nil self.scaleform = nil
@@ -15,6 +26,7 @@ function BigMessage:new()
return self return self
end end
--- Loads the Scaleform movie if it has not been loaded yet.
function BigMessage:Load() function BigMessage:Load()
if self.scaleform then return end if self.scaleform then return end
self.scaleform = RequestScaleformMovie("MP_BIG_MESSAGE_FREEMODE") self.scaleform = RequestScaleformMovie("MP_BIG_MESSAGE_FREEMODE")
@@ -23,7 +35,8 @@ function BigMessage:Load()
end end
end end
-- Dispose of the scaleform --- Disposes of the Scaleform movie.
--- If manualDispose is true, executes a transition before disposing.
function BigMessage:Dispose() function BigMessage:Dispose()
if not self.scaleform then return end if not self.scaleform then return end
@@ -34,8 +47,8 @@ function BigMessage:Dispose()
ScaleformMovieMethodAddParamBool(self.transitionPreventAutoExpansion) ScaleformMovieMethodAddParamBool(self.transitionPreventAutoExpansion)
EndScaleformMovieMethod() EndScaleformMovieMethod()
-- Wait a fraction of the transition duration (in milliseconds)
Wait((self.transitionDuration * 0.5) * 1000) Wait((self.transitionDuration * 0.5) * 1000)
self.manualDispose = false self.manualDispose = false
end end
@@ -46,8 +59,10 @@ function BigMessage:Dispose()
self.isDisplaying = false self.isDisplaying = false
end end
--- Updates the display by drawing the Scaleform movie fullscreen.
function BigMessage:Update() function BigMessage:Update()
if not self.scaleform then return end if not self.scaleform then return end
DrawScaleformMovieFullscreen(self.scaleform, 255, 255, 255, 255, 0) DrawScaleformMovieFullscreen(self.scaleform, 255, 255, 255, 255, 0)
if self.manualDispose then return end if self.manualDispose then return end
@@ -60,6 +75,7 @@ function BigMessage:Update()
ScaleformMovieMethodAddParamBool(self.transitionPreventAutoExpansion) ScaleformMovieMethodAddParamBool(self.transitionPreventAutoExpansion)
EndScaleformMovieMethod() EndScaleformMovieMethod()
self.transitionExecuted = true self.transitionExecuted = true
-- Extend duration slightly for smooth transition
self.duration = self.duration + ((self.transitionDuration * 0.5) * 1000) self.duration = self.duration + ((self.transitionDuration * 0.5) * 1000)
else else
self:Dispose() self:Dispose()
@@ -67,14 +83,20 @@ function BigMessage:Update()
end end
end end
--- Sets the transition properties for disposing the message.
--- @param transition string The transition function name (default: "TRANSITION_OUT").
--- @param duration number The duration for the transition (default: 0.4).
--- @param preventAutoExpansion boolean Whether to prevent auto-expansion (default: true).
function BigMessage:SetTransition(transition, duration, preventAutoExpansion) function BigMessage:SetTransition(transition, duration, preventAutoExpansion)
self.transition = transition or "TRANSITION_OUT" self.transition = transition or "TRANSITION_OUT"
self.transitionDuration = duration or 0.4 self.transitionDuration = duration or 0.4
self.transitionPreventAutoExpansion = preventAutoExpansion or true self.transitionPreventAutoExpansion = preventAutoExpansion or true
end end
--- Starts a thread to continuously update the HUD until the message is done.
function BigMessage:StartUpdate() function BigMessage:StartUpdate()
if self.isDisplaying then return end if self.isDisplaying then return end
self.isDisplaying = true self.isDisplaying = true
CreateThread(function() CreateThread(function()
while self.isDisplaying do while self.isDisplaying do
@@ -85,10 +107,13 @@ function BigMessage:StartUpdate()
end end
--- Displays a mission passed message. --- Displays a mission passed message.
--- --- @param msg string The message to display.
--- @param msg string The main message to display. --- @param duration number|nil The duration (in milliseconds) to display the message (default: 5000).
--- @param duration number|nil The duration in milliseconds the message should be displayed. Defaults to 5000. --- @param manualDispose boolean|nil Whether to manually dispose the Scaleform after display (default: false).
--- @param manualDispose boolean|nil Whether to manually dispose of the scaleform after the message. Defaults to false. --- @usage
--- ```lua
--- BigMessage:ShowMissionPassedMessage("MISSION PASSED", 5000)
--- ```
function BigMessage:ShowMissionPassedMessage(msg, duration, manualDispose) function BigMessage:ShowMissionPassedMessage(msg, duration, manualDispose)
duration = duration or 5000 duration = duration or 5000
self:Load() self:Load()
@@ -109,13 +134,12 @@ function BigMessage:ShowMissionPassedMessage(msg, duration, manualDispose)
end end
--- Displays a colored shard message. --- Displays a colored shard message.
--- --- @param msg string The main message.
--- @param msg string The main message to display.
--- @param desc string The description text. --- @param desc string The description text.
--- @param textColor number The color index for the text. --- @param textColor number The text color index.
--- @param bgColor number The color index for the background. --- @param bgColor number The background color index.
--- @param duration number|nil The duration in milliseconds the message should be displayed. Defaults to 5000. --- @param duration number|nil Duration in milliseconds (default: 5000).
--- @param manualDispose boolean|nil Whether to manually dispose of the scaleform after the message. Defaults to false. --- @param manualDispose boolean|nil Whether to manually dispose the Scaleform (default: false).
function BigMessage:ShowColoredShard(msg, desc, textColor, bgColor, duration, manualDispose) function BigMessage:ShowColoredShard(msg, desc, textColor, bgColor, duration, manualDispose)
duration = duration or 5000 duration = duration or 5000
self:Load() self:Load()
@@ -134,12 +158,9 @@ function BigMessage:ShowColoredShard(msg, desc, textColor, bgColor, duration, ma
end end
--- Displays an old-style mission passed message. --- Displays an old-style mission passed message.
--- --- @param msg string The message.
--- @param msg string The main message to display. --- @param duration number|nil Duration in milliseconds (default: 5000).
--- @param duration number|nil The duration in milliseconds the message should be displayed. Defaults to 5000. --- @param manualDispose boolean|nil Whether to manually dispose (default: false).
--- @param manualDispose boolean|nil Whether to manually dispose of the scaleform after the message. Defaults to false.
---
--- @return void
function BigMessage:ShowOldMessage(msg, duration, manualDispose) function BigMessage:ShowOldMessage(msg, duration, manualDispose)
duration = duration or 5000 duration = duration or 5000
self:Load() self:Load()
@@ -155,13 +176,10 @@ function BigMessage:ShowOldMessage(msg, duration, manualDispose)
end end
--- Displays a simple shard message. --- Displays a simple shard message.
--- --- @param msg string The main message.
--- @param msg string The main message to display.
--- @param subtitle string The subtitle text. --- @param subtitle string The subtitle text.
--- @param duration number|nil The duration in milliseconds the message should be displayed. Defaults to 5000. --- @param duration number|nil Duration in milliseconds (default: 5000).
--- @param manualDispose boolean|nil Whether to manually dispose of the scaleform after the message. Defaults to false. --- @param manualDispose boolean|nil Whether to manually dispose (default: false).
---
--- @return void
function BigMessage:ShowSimpleShard(msg, subtitle, duration, manualDispose) function BigMessage:ShowSimpleShard(msg, subtitle, duration, manualDispose)
duration = duration or 5000 duration = duration or 5000
self:Load() self:Load()
@@ -178,12 +196,11 @@ function BigMessage:ShowSimpleShard(msg, subtitle, duration, manualDispose)
end end
--- Displays a rank-up message. --- Displays a rank-up message.
--- --- @param msg string The main message.
--- @param msg string The main message to display.
--- @param subtitle string The subtitle text. --- @param subtitle string The subtitle text.
--- @param rank number The rank level achieved. --- @param rank number The rank level achieved.
--- @param duration number|nil The duration in milliseconds the message should be displayed. Defaults to 5000. --- @param duration number|nil Duration in milliseconds (default: 5000).
--- @param manualDispose boolean|nil Whether to manually dispose of the scaleform after the message. Defaults to false. --- @param manualDispose boolean|nil Whether to manually dispose (default: false).
function BigMessage:ShowRankupMessage(msg, subtitle, rank, duration, manualDispose) function BigMessage:ShowRankupMessage(msg, subtitle, rank, duration, manualDispose)
duration = duration or 5000 duration = duration or 5000
self:Load() self:Load()
@@ -203,12 +220,11 @@ function BigMessage:ShowRankupMessage(msg, subtitle, rank, duration, manualDispo
end end
--- Displays a weapon purchased message. --- Displays a weapon purchased message.
--- --- @param bigMessage string The main message.
--- @param bigMessage string The main message to display.
--- @param weaponName string The name of the weapon purchased. --- @param weaponName string The name of the weapon purchased.
--- @param weaponHash number The hash identifier of the weapon. --- @param weaponHash number The weapon hash.
--- @param duration number|nil The duration in milliseconds the message should be displayed. Defaults to 5000. --- @param duration number|nil Duration in milliseconds (default: 5000).
--- @param manualDispose boolean|nil Whether to manually dispose of the scaleform after the message. Defaults to false. --- @param manualDispose boolean|nil Whether to manually dispose (default: false).
function BigMessage:ShowWeaponPurchasedMessage(bigMessage, weaponName, weaponHash, duration, manualDispose) function BigMessage:ShowWeaponPurchasedMessage(bigMessage, weaponName, weaponHash, duration, manualDispose)
duration = duration or 5000 duration = duration or 5000
self:Load() self:Load()
@@ -228,10 +244,9 @@ function BigMessage:ShowWeaponPurchasedMessage(bigMessage, weaponName, weaponHas
end end
--- Displays a large multiplayer message. --- Displays a large multiplayer message.
--- --- @param msg string The main message.
--- @param msg string The main message to display. --- @param duration number|nil Duration in milliseconds (default: 5000).
--- @param duration number|nil The duration in milliseconds the message should be displayed. Defaults to 5000. --- @param manualDispose boolean|nil Whether to manually dispose (default: false).
--- @param manualDispose boolean|nil Whether to manually dispose of the scaleform after the message. Defaults to false.
function BigMessage:ShowMpMessageLarge(msg, duration, manualDispose) function BigMessage:ShowMpMessageLarge(msg, duration, manualDispose)
duration = duration or 5000 duration = duration or 5000
self:Load() self:Load()
@@ -254,11 +269,10 @@ function BigMessage:ShowMpMessageLarge(msg, duration, manualDispose)
end end
--- Displays a "Wasted" multiplayer message. --- Displays a "Wasted" multiplayer message.
--- --- @param msg string The main message.
--- @param msg string The main message to display.
--- @param subtitle string The subtitle text. --- @param subtitle string The subtitle text.
--- @param duration number|nil The duration in milliseconds the message should be displayed. Defaults to 5000. --- @param duration number|nil Duration in milliseconds (default: 5000).
--- @param manualDispose boolean|nil Whether to manually dispose of the scaleform after the message. Defaults to false. --- @param manualDispose boolean|nil Whether to manually dispose (default: false).
function BigMessage:ShowMpWastedMessage(msg, subtitle, duration, manualDispose) function BigMessage:ShowMpWastedMessage(msg, subtitle, duration, manualDispose)
duration = duration or 5000 duration = duration or 5000
self:Load() self:Load()
@@ -274,4 +288,19 @@ function BigMessage:ShowMpWastedMessage(msg, subtitle, duration, manualDispose)
self:StartUpdate() self:StartUpdate()
end end
--- Starts the update loop for displaying the message.
function BigMessage:StartUpdate()
if self.isDisplaying then return end
self.isDisplaying = true
CreateThread(function()
while self.isDisplaying do
Wait(0)
self:Update()
end
end)
end
-- Create an instance of BigMessage and return it.
BigMessage = BigMessage:new()
return BigMessage return BigMessage

View File

@@ -1,6 +1,18 @@
--[[
CountdownHandler Module
-------------------------
This module provides a countdown HUD using a Scaleform movie ("COUNTDOWN").
It handles loading, updating, and disposing of the scaleform, as well as
playing sounds and displaying messages for each countdown tick.
TriggerNetEvent(getScript()..":startCountdown", 5, 25)
]]
CountdownHandler = {} CountdownHandler = {}
CountdownHandler.__index = CountdownHandler CountdownHandler.__index = CountdownHandler
--- Creates a new CountdownHandler instance.
--- @return table table A new CountdownHandler object.
function CountdownHandler:new() function CountdownHandler:new()
local self = setmetatable({}, CountdownHandler) local self = setmetatable({}, CountdownHandler)
self.scaleform = nil self.scaleform = nil
@@ -9,14 +21,18 @@ function CountdownHandler:new()
return self return self
end end
--- Loads the "COUNTDOWN" scaleform movie.
function CountdownHandler:Load() function CountdownHandler:Load()
if self.scaleform then return end if self.scaleform then
return
end
self.scaleform = RequestScaleformMovie("COUNTDOWN") self.scaleform = RequestScaleformMovie("COUNTDOWN")
while not HasScaleformMovieLoaded(self.scaleform) do while not HasScaleformMovieLoaded(self.scaleform) do
Wait(0) Wait(0)
end end
end end
--- Disposes of the currently loaded scaleform movie.
function CountdownHandler:Dispose() function CountdownHandler:Dispose()
if self.scaleform then if self.scaleform then
SetScaleformMovieAsNoLongerNeeded(self.scaleform) SetScaleformMovieAsNoLongerNeeded(self.scaleform)
@@ -24,15 +40,19 @@ function CountdownHandler:Dispose()
end end
end end
--- Updates the HUD by drawing the scaleform movie fullscreen.
function CountdownHandler:Update() function CountdownHandler:Update()
if self.scaleform then if self.scaleform then
DrawScaleformMovieFullscreen(self.scaleform, 255, 255, 255, 255, 0) DrawScaleformMovieFullscreen(self.scaleform, 255, 255, 255, 255, 0)
end end
end end
--- Displays a message on the countdown HUD.
--- @param message string The message to display.
function CountdownHandler:ShowMessage(message) function CountdownHandler:ShowMessage(message)
local r, g, b, a = self.colour.r, self.colour.g, self.colour.b, self.colour.a local r, g, b, a = self.colour.r, self.colour.g, self.colour.b, self.colour.a
-- Set the message in the scaleform.
BeginScaleformMovieMethod(self.scaleform, "SET_MESSAGE") BeginScaleformMovieMethod(self.scaleform, "SET_MESSAGE")
ScaleformMovieMethodAddParamPlayerNameString(message) ScaleformMovieMethodAddParamPlayerNameString(message)
ScaleformMovieMethodAddParamInt(r) ScaleformMovieMethodAddParamInt(r)
@@ -41,6 +61,7 @@ function CountdownHandler:ShowMessage(message)
ScaleformMovieMethodAddParamBool(true) ScaleformMovieMethodAddParamBool(true)
EndScaleformMovieMethod() EndScaleformMovieMethod()
-- Trigger a fade effect (optional).
BeginScaleformMovieMethod(self.scaleform, "FADE_MP") BeginScaleformMovieMethod(self.scaleform, "FADE_MP")
ScaleformMovieMethodAddParamPlayerNameString(message) ScaleformMovieMethodAddParamPlayerNameString(message)
ScaleformMovieMethodAddParamInt(r) ScaleformMovieMethodAddParamInt(r)
@@ -49,17 +70,14 @@ function CountdownHandler:ShowMessage(message)
EndScaleformMovieMethod() EndScaleformMovieMethod()
end end
--- Starts the countdown with the specified number and HUD color. --- Starts the countdown HUD.
--- --- @param number number|nil The starting number for the countdown (default: 3).
--- @param number number|nil The starting number for the countdown. Defaults to 3. --- @param hudColour number|nil The HUD colour index (default: 18).
--- @param hudColour number|nil The HUD color index. Defaults to 18. --- @return boolean boolean True when the countdown has finished.
---
--- @return boolean `true` when the countdown has finished.
---
--- @usage --- @usage
--- ```lua --- ```lua
--- -- Start a countdown of 5 seconds with HUD color 25
--- if CountdownHandler:Start(5, 25) then --- if CountdownHandler:Start(5, 25) then
--- -- When run in an if statement, the script will wait until its finished to continue
--- print("Countdown Complete") --- print("Countdown Complete")
--- end --- end
--- ``` --- ```
@@ -68,6 +86,7 @@ function CountdownHandler:Start(number, hudColour)
number = number or 3 number = number or 3
hudColour = hudColour or 18 hudColour = hudColour or 18
-- Get HUD colour using framework function; alternatives could be added here.
local r, g, b, a = GetHudColour(hudColour) local r, g, b, a = GetHudColour(hudColour)
self.colour = { r = r, g = g, b = b, a = a } self.colour = { r = r, g = g, b = b, a = a }
@@ -81,18 +100,17 @@ function CountdownHandler:Start(number, hudColour)
end end
end) end)
-- Begin the countdown -- Countdown logic
CreateThread(function() CreateThread(function()
local currentNumber = number local currentNumber = number
while currentNumber > 0 do while currentNumber > 0 do
-- Play countdown sound
playSound("Count") playSound("Count")
self:ShowMessage(tostring(currentNumber)) self:ShowMessage(tostring(currentNumber))
Wait(1000) Wait(1000)
currentNumber = currentNumber - 1 currentNumber = currentNumber - 1
end end
playSound("Go")
playSound("Go")
self:ShowMessage("GO") self:ShowMessage("GO")
finished = true finished = true
@@ -101,14 +119,15 @@ function CountdownHandler:Start(number, hudColour)
self:Dispose() self:Dispose()
finished = true finished = true
end) end)
while not finished do Wait(10) end while not finished do Wait(10) end
return true return true
end end
-- Create an instance of CountdownHandler -- Create a singleton instance of CountdownHandler.
CountdownHandler = CountdownHandler:new() CountdownHandler = CountdownHandler:new()
-- Optional: Register an event to start the countdown -- Register an event to start the countdown.
RegisterNetEvent(getScript()..":startCountdown", function(number, hudColour) RegisterNetEvent(getScript()..":startCountdown", function(number, hudColour)
CountdownHandler:Start(number, hudColour) CountdownHandler:Start(number, hudColour)
end) end)

View File

@@ -1,40 +1,43 @@
-------------------------------------------------------------
-- Debug Text Display Functionality
-------------------------------------------------------------
--- Displays debug information on the player's screen. --- Draws debug text on the screen if debugMode is enabled.
--- ---
--- This function renders a semi-transparent box with multiple lines of text for debugging purposes. --- Calculates a background rectangle based on the number of text lines and renders each line on-screen.
--- It is controlled by the `debugMode` flag and can be positioned dynamically on the screen.
--- ---
--- @param textTable table A table containing strings to display. --- @param textTable table An array of strings to display.
--- @param loc vector2|nil Optional. The screen position to display the debug box. Defaults to `vec2(0.05, 0.65)`. --- @param loc vector2 (Optional) Top-left coordinate for the text box (default: vec2(0.05, 0.65)).
--- ---
--- @usage --- @usage
--- ```lua --- ```lua
--- debugScaleForm({ ---CreateThread(function()
--- "Player Position: X=123.45 Y=678.90 Z=12.34", --- while true do
--- "Current Action: Running", --- debugScaleForm({
--- }) --- "Line 1: Debug info",
--- "Line 2: More info"
--- })
--- Wait(0)
--- end
---end)
--- ``` --- ```
function debugScaleForm(textTable, loc) function debugScaleForm(textTable, loc)
if debugMode then if debugMode then
-- Define the display position (top left corner) loc = loc or vec2(0.05, 0.65)
local loc = loc or vec2(0.05, 0.65)
-- Calculate dynamic height based on the number of lines in the textTable local lineHeight = 0.025 -- Height per line.
local lineHeight = 0.025 -- Height of each line of text local totalHeight = #textTable * lineHeight
local totalHeight = #textTable * lineHeight -- Dynamic height based on number of lines local boxPadding = 0.01 -- Padding around the text.
local boxPadding = 0.01 -- Padding to add around the text inside the box local size = vec2(0.18, totalHeight + boxPadding * 2)
local size = vec2(0.18, totalHeight + boxPadding * 2) -- Width remains fixed, height is dynamic
DrawRect(loc.x + size.x / 2, loc.y + size.y / 2, size.x, size.y, 0, 0, 0, 255) -- Draw background rectangle.
DrawRect(loc.x + size.x / 2, loc.y + size.y / 2, size.x, size.y, 0, 0, 0, 200)
-- Render each line of text.
for i = 1, #textTable do for i = 1, #textTable do
local textLine = textTable[i]
SetTextScale(0.30, 0.30) SetTextScale(0.30, 0.30)
BeginTextCommandDisplayText("STRING") BeginTextCommandDisplayText("STRING")
AddTextComponentSubstringKeyboardDisplay(textLine) AddTextComponentSubstringKeyboardDisplay(textTable[i])
EndTextCommandDisplayText(loc.x + 0.005, loc.y + (i - 1) * lineHeight + 0.01) EndTextCommandDisplayText(loc.x + 0.005, loc.y + (i - 1) * lineHeight + 0.01)
end end
end end

View File

@@ -1,30 +1,45 @@
--- Creates instructional buttons using the detected polyzone library (ox_lib or PolyZone). -------------------------------------------------------------
-- Instructional Buttons Functionality
-------------------------------------------------------------
--- Loads and draws instructional buttons on-screen using a scaleform movie.
--- ---
--- This function generates instructional buttons on the player's screen based on the provided information. --- Requests the "instructional_buttons" scaleform, clears previous data, sets clear space,
--- It supports different polyzone libraries by automatically detecting which one is active. --- creates data slots for each button option provided in `info`, and then draws the scaleform fullscreen.
--- ---
---@param info table A table containing the instructional buttons configuration. --- @param info table An array of tables, where each table represents a button option:
--- - **keys** (`table`): A list of control keys to display. --- - keys (table): An array of key codes (e.g., {38, 29}) to display.
--- - **text** (`string`): The description text for the buttons. --- - text (string): The label for the button.
--- ---
---@usage --- @usage
--- ```lua --- ```lua
--- makeInstructionalButtons({ ---CreateThread(function()
--- { keys = { 38 }, text = "Interact" }, --- while true do
--- { keys = { 47 }, text = "Pick Up" }, --- makeInstructionalButtons({
--- }) --- { keys = {38, 29}, text = "Open Menu" },
--- { keys = {45}, text = "Close Menu" }
--- })
--- Wait(0)
--- end
---end)
--- ``` --- ```
function makeInstructionalButtons(info) function makeInstructionalButtons(info)
local build = RequestScaleformMovie("instructional_buttons") local build = RequestScaleformMovie("instructional_buttons")
while not HasScaleformMovieLoaded(build) do Wait(0) end while not HasScaleformMovieLoaded(build) do Wait(0) end
-- Draw the scaleform fullscreen (initial draw).
DrawScaleformMovieFullscreen(build, 255, 255, 255, 0, 0) DrawScaleformMovieFullscreen(build, 255, 255, 255, 0, 0)
-- Clear previous instructions.
BeginScaleformMovieMethod(build, "CLEAR_ALL") BeginScaleformMovieMethod(build, "CLEAR_ALL")
EndScaleformMovieMethod() EndScaleformMovieMethod()
-- Set clear spacing between buttons.
BeginScaleformMovieMethod(build, "SET_CLEAR_SPACE") BeginScaleformMovieMethod(build, "SET_CLEAR_SPACE")
ScaleformMovieMethodAddParamInt(200) ScaleformMovieMethodAddParamInt(200)
EndScaleformMovieMethod() EndScaleformMovieMethod()
-- Add each button option to the scaleform.
for i = 1, #info do for i = 1, #info do
BeginScaleformMovieMethod(build, "SET_DATA_SLOT") BeginScaleformMovieMethod(build, "SET_DATA_SLOT")
ScaleformMovieMethodAddParamInt(i - 1) ScaleformMovieMethodAddParamInt(i - 1)
@@ -37,8 +52,11 @@ function makeInstructionalButtons(info)
EndScaleformMovieMethod() EndScaleformMovieMethod()
end end
-- Draw the instructional buttons.
BeginScaleformMovieMethod(build, "DRAW_INSTRUCTIONAL_BUTTONS") BeginScaleformMovieMethod(build, "DRAW_INSTRUCTIONAL_BUTTONS")
EndScaleformMovieMethod() EndScaleformMovieMethod()
-- Set a translucent black background.
BeginScaleformMovieMethod(build, "SET_BACKGROUND_COLOUR") BeginScaleformMovieMethod(build, "SET_BACKGROUND_COLOUR")
ScaleformMovieMethodAddParamInt(0) ScaleformMovieMethodAddParamInt(0)
ScaleformMovieMethodAddParamInt(0) ScaleformMovieMethodAddParamInt(0)
@@ -46,5 +64,47 @@ function makeInstructionalButtons(info)
ScaleformMovieMethodAddParamInt(80) ScaleformMovieMethodAddParamInt(80)
EndScaleformMovieMethod() EndScaleformMovieMethod()
-- Final full-screen draw with full opacity.
DrawScaleformMovieFullscreen(build, 255, 255, 255, 255, 0) DrawScaleformMovieFullscreen(build, 255, 255, 255, 255, 0)
end end
-- EXPERIMENTAL --
-- RedM Button Prompts --
-- Creates the promot, then shows it, this needs to be run in a loop
local promptGroups = {}
function makeRedInstructionalButtons(info, title)
if not promptGroups[title] then -- Create group if not exists
promptGroups[title] = {
title = CreateVarString(10, 'LITERAL_STRING', title),
id = GetRandomIntInRange(0, 0xffffff),
prompts = {},
}
for i = 1, #info do
promptGroups[title].prompts[i] = {
keys = info[i].keys,
text = info[i].text,
}
local keyTitle = CreateVarString(10, 'LITERAL_STRING', info[i].text)
-- Create one prompt per entry
local promptSet = UiPromptRegisterBegin()
-- Register all keys for this prompt
for k = 1, #info[i].keys do
PromptSetControlAction(promptSet, info[i].keys[k])
end
PromptSetText(promptSet, keyTitle)
PromptSetEnabled(promptSet, true)
PromptSetVisible(promptSet, true)
PromptSetGroup(promptSet, promptGroups[title].id)
PromptRegisterEnd(promptSet)
end
end
PromptSetActiveGroupThisFrame(promptGroups[title].id, promptGroups[title].title)
end
onResourceStop(function()
for k, v in pairs(promptGroups) do
print("^5Bridge^7: ^2Removing Prompt Group^7: ^3" .. k .. "^7")
PromptDelete(promptGroups[k].id, 1)
end
end, true)

View File

@@ -0,0 +1,115 @@
-------------------------------------------------------------
-- 3D Text Rendering
-------------------------------------------------------------
--- Draws 3D text at specified world coordinates.
---
--- Configures text properties, draws the text, and displays a background rectangle behind it.
---
--- @param coord table A vector3 with x, y, and z coordinates.
--- @param text string The text to display.
--- @param highlight boolean (Optional) If true, highlights parts of the text.
---
--- @usage
--- ```lua
--- CreateThread(function()
--- while true do
--- DrawText3D(vector3(100, 200, 300), "Hello World", true)
--- Wait(0)
--- end
--- end)
--- ```
function DrawText3D(coord, text, highlight)
SetTextScale(0.30, 0.30)
SetTextFont(0)
SetTextProportional(1)
SetTextColour(255, 255, 255, 215)
SetTextEntry("STRING")
SetTextCentre(true)
local totalLength = string.len(text)
local textMaxLength = 99 -- max 99
local text = totalLength > textMaxLength and text:sub(1, totalLength - (totalLength - textMaxLength)) or text
AddTextComponentString(highlight and text:gsub("%~w~", "~y~") or text)
SetDrawOrigin(coord.x, coord.y, coord.z, 0)
DrawText(0.0, 0.0)
local count, length = GetLineCountAndMaxLength(text)
local padding = 0.005
local heightFactor = (count / 43) + padding
local weightFactor = (length / 150) + padding
local height = (heightFactor / 2) - padding / 1
local width = (weightFactor / 2) - padding / 1
DrawRect(0.0, height, width, heightFactor, 0, 0, 0, 150)
ClearDrawOrigin()
end
--- Calculates the number of lines and the maximum line length from the given text.
---
--- @param text string The text to analyze.
--- @return number, number The line count and maximum line length.
---
--- @usage
--- ```lua
--- local count, maxLen = GetLineCountAndMaxLength("Hello World")
--- ```
function GetLineCountAndMaxLength(text)
local lineCount, maxLength = 0, 0
for line in text:gmatch("[^\n]+") do
lineCount += 1
local lineLength = string.len(line)
if lineLength > maxLength then
maxLength = lineLength
end
end
if lineCount == 0 then lineCount = 1 end
return lineCount, maxLength
end
-------------------------------------------------------------
-- Additional UI Helpers
-------------------------------------------------------------
--- Displays a help message on the screen.
---
--- @param text string The message to display.
---
--- @usage
--- ```lua
--- DisplayHelpMsg("Press E to interact")
--- ```
function DisplayHelpMsg(text)
BeginTextCommandDisplayHelp("STRING")
AddTextComponentScaleform(text)
EndTextCommandDisplayHelp(0, true, false, -1)
end
--- Displays a "Saving/Loading" spinner with a custom message.
---
--- @param text string The message to display alongside the spinner.
---
--- @usage
--- ```lua
--- displaySpinner("Saving data...")
--- ```
function displaySpinner(text)
BeginTextCommandBusyspinnerOn('STRING')
AddTextComponentSubstringPlayerName(text)
EndTextCommandBusyspinnerOn(4)
end
--- Stops the "Saving/Loading" spinner.
---
--- This function should only be called client-side.
---
--- @usage
--- ```lua
--- stopSpinner()
--- ```
function stopSpinner()
if not isServer() then
BusyspinnerOff()
end
end

View File

@@ -1,3 +1,21 @@
--- Creates and displays a timer HUD on the screen.
--- Draws a title (if provided) and a series of timer bars from the supplied data.
---
--- @param title string|nil Optional title to display at the top of the HUD.
--- @param data table A table of timer bar entries. Each entry should include:
--- - stat (string): The statistic name.
--- - value (string): The value to display.
--- - multi (number|nil): Optional, indicates multiple checkpoints (e.g., progress levels).
--- @param alpha number|nil Optional alpha value (transparency) for the HUD; defaults to 255.
---
--- @usage
--- ```lua
--- createTimerHud("Timer", {
--- { stat = "Health", value = "85%" },
--- { stat = "Armor", value = "50%", multi = 2 },
--- { stat = "Stamina", value = "100%" },
--- }, 255)
--- ```
function createTimerHud(title, data, alpha) function createTimerHud(title, data, alpha)
loadTextureDict("timerbars") loadTextureDict("timerbars")

219
shared/shops.lua Normal file
View File

@@ -0,0 +1,219 @@
-------------------------------------------------------------
-- Selling Menu and Animation
-------------------------------------------------------------
--- Opens a selling menu with available items and prices.
---
--- @param data table Contains selling menu data:
--- - sellTable (`table`) Table with Header and Items (item names and prices).
--- - ped (optional) (`number`) Ped entity involved.
--- - onBack (optional) (`function`) Callback for returning.
--- @usage
--- ```lua
--- sellMenu({
--- sellTable = {
--- Header = "Sell Items",
--- Items = {
--- ["gold_ring"] = 100,
--- ["diamond"] = 500,
--- },
--- },
--- ped = pedEntity,
--- onBack = function() print("Returning to previous menu") end,
--- })
--- ```
function sellMenu(data)
local origData = data
local Menu = {}
if data.sellTable.Items then
local itemList = {}
for k, v in pairs(data.sellTable.Items) do itemList[k] = 1 end
local _, hasTable = hasItem(itemList)
for k, v in pairsByKeys(data.sellTable.Items) do
Menu[#Menu + 1] = {
isMenuHeader = not hasTable[k].hasItem,
icon = invImg(k),
header = Items[k].label..(hasTable[k].hasItem and "💰 (x"..hasTable[k].count..")" or ""),
txt = Loc[Config.Lan].info["sell_all"]..v.." "..Loc[Config.Lan].info["sell_each"],
onSelect = function()
sellAnim({ item = k, price = v, ped = data.ped, onBack = function() sellMenu(data) end })
end,
}
end
else
for k, v in pairsByKeys(data.sellTable) do
if type(v) == "table" then
Menu[#Menu + 1] = {
arrow = true,
header = k,
txt = "Amount of items: "..countTable(v.Items),
onSelect = function()
v.onBack = function() sellMenu(origData) end
v.sellTable = data.sellTable[k]
sellMenu(v)
end,
}
end
end
end
openMenu(Menu, {
header = data.sellTable.Header or "Amount of items: "..countTable(data.sellTable.Items),
headertxt = data.sellTable.Header and "Amount of items: "..countTable(data.sellTable.Items) or "",
canClose = true,
onBack = data.onBack,
})
end
--- Plays the selling animation and processes the sale transaction.
---
--- Checks if the player has the item, plays animations, triggers the server event for selling,
--- and then calls the onBack callback if provided.
---
--- @param data table Contains:
--- `- item: The item to sell.
--- `- price: Price per item.
--- `- ped (optional): Ped entity involved.
--- `- onBack (optional): Callback to call on completion.
---@usage
--- ```lua
--- sellAnim({
--- item = "gold_ring",
--- price = 100,
--- ped = pedEntity,
--- onBack = function() sellMenu(data) end,
--- })
--- ```
function sellAnim(data)
if not hasItem(data.item, 1) then
triggerNotify(nil, Loc[Config.Lan].error["dont_have"].." "..Items[data.item].label, "error")
return
end
-- Remove any attached clipboard objects.
for _, obj in pairs(GetGamePool('CObject')) do
for _, model in pairs({ `p_cs_clipboard` }) do
if GetEntityModel(obj) == model and IsEntityAttachedToEntity(data.ped, obj) then
DeleteObject(obj)
DetachEntity(obj, 0, 0)
SetEntityAsMissionEntity(obj, true, true)
Wait(100)
DeleteEntity(obj)
end
end
end
TriggerServerEvent(getScript().."Sellitems", data)
lookEnt(data.ped)
local dict = "mp_common"
playAnim(dict, "givetake2_a", 0.3, 2)
playAnim(dict, "givetake2_b", 0.3, 2, data.ped)
Wait(2000)
StopAnimTask(PlayerPedId(), dict, "givetake2_a", 0.5)
StopAnimTask(data.ped, dict, "givetake2_b", 0.5)
if data.onBack then data.onBack() end
end
--- Server event handler for processing item sales.
--- Removes sold items from inventory and funds the player based on the sale.
RegisterNetEvent(getScript().."Sellitems", function(data)
local src = source
local hasItems, hasTable = hasItem(data.item, 1, src)
if hasItems then
removeItem(data.item, hasTable[data.item].count, src)
fundPlayer((hasTable[data.item].count * data.price), "cash", src)
else
triggerNotify(nil, Loc[Config.Lan].error["dont_have"].." "..Items[data.item].label, "error", src)
end
end)
-------------------------------------------------------------
-- Shop Interface
-------------------------------------------------------------
--- Opens a shop interface for the player.
---
--- Checks job/gang restrictions, then uses the active inventory system to open the shop.
--- @param data table Contains:
--- - shop (`string`) The shop identifier.
--- - items (`table`) The items available in the shop.
--- - coords (`vector3`) where the shop is located.
--- - job/gang (optional) (`string`) Job or gang requirements.
---@usage
--- ```lua
--- openShop({
--- shop = "weapon_shop",
--- items = weaponShopItems,
--- coords = vector3(100.0, 200.0, 300.0),
--- job = "police",
--- })
--- ```
function openShop(data)
if (data.job or data.gang) and not jobCheck(data.job or data.gang) then return end
if Config.General.JimShops then
TriggerServerEvent("jim-shops:ShopOpen", "shop", data.items.label, data.items)
elseif isStarted(OXInv) then
exports[OXInv]:openInventory('shop', { type = data.shop })
elseif isStarted(QBInv) then
if QBInvNew then
TriggerServerEvent(getScript()..':server:OpenShopNewQB', data.shop)
else
TriggerServerEvent("inventory:server:OpenInventory", "shop", data.items.label, data.items)
end
elseif isStarted(RSGInv) then
TriggerServerEvent(getScript()..':server:OpenShopNewRSG', data.shop)
end
lookEnt(data.coords)
end
--- Server event handler for opening a shop using the new QB inventory system.
RegisterNetEvent(getScript()..':server:OpenShopNewQB', function(data)
exports[QBInv]:OpenShop(source, data)
end)
RegisterNetEvent(getScript()..':server:OpenShopNewRSG', function(data)
exports[RSGInv]:OpenShop(source, data)
end)
--- Registers a shop with the active inventory system.
--- Supports either OXInv or QBInv (with QBInvNew flag).
---
--- @param name string Unique shop identifier.
--- @param label string Display name for the shop.
--- @param items table List of available shop items.
--- @param society string|nil (Optional) Society identifier for shared shops.
--- @usage
--- ```lua
--- registerShop("weaponShop", "Weapon Shop", weaponItems, "society_weapons")
--- ```
function registerShop(name, label, items, society)
if isStarted(OXInv) then
debugPrint("^6Bridge^7: ^2Registering ^3OX ^2Store^7:", name, label)
exports[OXInv]:RegisterShop(name, {
name = label,
inventory = items,
society = society,
})
elseif isStarted(QBInv) and QBInvNew then
debugPrint("^6Bridge^7: ^2Registering ^3QB ^2Store^7:", name, label)
exports[QBInv]:CreateShop({
name = name,
label = label,
slots = #items,
items = items,
society = society,
})
elseif isStarted(RSGInv) then
debugPrint("^6Bridge^7: ^2Registering ^3RSG ^2Store^7:", name, label)
exports[RSGInv]:CreateShop({
name = name,
label = label,
slots = #items,
items = items,
society = society,
})
end
end

156
shared/skillcheck.lua Normal file
View File

@@ -0,0 +1,156 @@
local activeSkillCheck = false
function skillCheck(data)
local result = false
if Config.System.skillCheck == "qb" then
local Skillbar = exports["qb-minigames"]:Skillbar()
if Skillbar then
result = true
else
result = false
end
elseif Config.System.skillCheck == "ox" then
local Skillbar = exports[OXLibExport]:skillCheck(
{
"easy",
"easy",
"easy"
},
{
"1",
"2",
"3",
"4"
})
if Skillbar then
result = true
else
result = false
end
elseif Config.System.skillCheck == "gta" then
loadTextureDict("timerbars")
local successes = 0
local barsRequired = 3
for bar = 1, barsRequired do
debugPrint("^6Bridge^7: ^2Starting Bar ^3"..bar.."^7/^3"..barsRequired.."^7")
activeSkillCheck = true
local width, height = 0.2, 0.01
local x, y = 0.5, 0.8
-- Random highlighted zone
local highlightSize = math.random(10, 20) / 100
local highlightStart = math.random(10, 50) / 100
local highlightEnd = highlightStart + highlightSize
local highlightAlpha = 0
local cursorPos = 0.0
local cursorSpeed = 0.025
local movingRight = true
while activeSkillCheck do
Wait(0)
makeInstructionalButtons({
{ keys = { 177 }, text = "Exit" },
{ keys = { 38 }, text = "Confirm" },
})
createScaleBars(x, y, width, height)
local pulse = (math.sin(GetGameTimer() / 250) + 1) / 2 -- Creates a pulsing effect
highlightAlpha = math.floor(150 + (pulse * 105)) -- Pulsing between 150 and 255 alpha
-- Draw highlighted zone (success area) with pulsing effect
DrawRect(x - width / 2 + (highlightStart + highlightSize / 2) * width, y, highlightSize * width, height+0.001, 93, 182, 229, highlightAlpha )
-- Draw moving cursor
DrawRect(x - width / 2 + cursorPos * width, y, 0.002, height + 0.01, 255, 255, 255, 255)
-- Move cursor
if movingRight then
cursorPos += cursorSpeed
if cursorPos >= 1.0 then movingRight = false end
else
cursorPos -= cursorSpeed
if cursorPos <= 0.0 then movingRight = true end
end
if IsControlJustPressed(0, 177) then -- Backspace to cancel
local displayTime = GetGameTimer() + 2000
PlaySoundFrontend(-1, 'Highlight_Cancel', 'DLC_HEIST_PLANNING_BOARD_SOUNDS', 1)
while GetGameTimer() < displayTime do
Wait(0)
createScaleBars(x, y, width, height)
DrawRect(x - width / 2 + (highlightStart + highlightSize / 2) * width, y, highlightSize * width, height+0.001, 228, 52, 52, 255)
DrawRect(x - width / 2 + cursorPos * width, y, 0.002, height + 0.01, 255, 255, 255, 255)
drawSuccessText(x, y, "Failed", 228, 52, 52)
end
return false
end
-- Check for keypress (E)
if IsControlJustPressed(0, 38) then
activeSkillCheck = false
result = cursorPos >= highlightStart and cursorPos <= highlightEnd
if result then
PlaySoundFrontend(-1, "YES", "HUD_FRONTEND_DEFAULT_SOUNDSET", true)
else
PlaySoundFrontend(-1, 'Highlight_Cancel', 'DLC_HEIST_PLANNING_BOARD_SOUNDS', 1)
end
local displayTime = GetGameTimer() + 2000
while GetGameTimer() < displayTime do
Wait(0)
createScaleBars(x, y, width, height)
-- Draw highlighted zone
DrawRect(x - width / 2 + (highlightStart + highlightSize / 2) * width, y, highlightSize * width, height+0.001, result and 93 or 228, result and 182 or 52, result and 229 or 52, 180)
-- Draw stationary cursor at result position
DrawRect(x - width / 2 + cursorPos * width, y, 0.002, height + 0.01, 255, 255, 255, 255)
-- Display result text
drawSuccessText(x, y, result and "Success" or "Failed", result and 114 or 228, result and 204 or 52, result and 144 or 52)
end
if result then
successes += 1
else
return false
end
end
end
end
activeSkillCheck = false
debugPrint("^6Bridge^7: ^2Skill Check Result^7: ^3" .. successes .. "^7/^3" .. barsRequired.."^7")
return successes == barsRequired
else
result = true
end
return result
end
function drawSuccessText(x, y, text, r, g, b)
SetTextFont(8)
SetTextScale(0.45, 0.45)
SetTextColour(r, g, b, 255)
SetTextDropshadow(0, 0, 0, 0, 255)
SetTextEdge(2, 0, 0, 0, 150)
SetTextDropShadow()
SetTextOutline()
SetTextCentre(true)
SetTextEntry("STRING")
SetTextCentre(true)
SetTextEntry("STRING")
AddTextComponentString(text)
DrawText(x, y + 0.03)
end
function createScaleBars(x, y, width, height)
-- Draw background box
DrawSprite("timerbars", "all_black_bg", x - (width / 4) - 0.006, y, (width / 2) + 0.08, height + 0.04, 0.0, 255, 255, 255, 255)
DrawSprite("timerbars", "all_black_bg", x + (width / 4) + 0.006, y, (width / 2) + 0.08, height + 0.04, 180.0, 255, 255, 255, 255)
-- Draw full bar (dark background)
DrawRect(x, y, width, height, 100, 100, 100, 255)
end

180
shared/societybank.lua Normal file
View File

@@ -0,0 +1,180 @@
--[[
Society Banking Module
------------------------
This module provides functions to interact with society bank accounts across
different banking systems. Supported systems include:
• qb-banking
• esx_society *testing*
• Renewed-Banking
• fd_banking
• okokBanking
]]
--- Retrieves the current balance of a society's bank account.
--- @param society string The identifier of the society.
--- @return number number The current account balance.
--- @usage
--- ```lua
--- local balance = getSocietyAccount("police")
--- print("Police account balance: $"..balance)
--- ```
function getSocietyAccount(society)
local bankScript, amount = "", 0
if society == nil or society == "none" then return amount end
if isStarted("qb-banking") then
bankScript = "qb-banking"
if not exports["qb-banking"]:GetAccount(society) then
if Jobs[society] then
print("^6Bridge^7: ^2Making new bank account in ^7'^3qb-banking^7' ^2for ^7'^3"..society.."^7'")
exports["qb-banking"]:CreateJobAccount(society, 0)
Wait(150)
elseif Gangs[society] then
print("^6Bridge^7: ^2Making new bank account in ^7'^3qb-banking^7' ^2for ^7'^3"..society.."^7'")
exports["qb-banking"]:CreateGangAccount(society, 0)
Wait(150)
end
end
amount = exports["qb-banking"]:GetAccountBalance(society)
--elseif isStarted("esx_society") then
-- bankScript = "esx_society"
-- -- Since esx_society does not have a native client export for retrieving money,
-- -- we use a server callback to get the final amount.
-- amount = triggerCallback(getScript()..":getESXSocietyAccount", society) or 0
elseif isStarted("Renewed-Banking") then
bankScript = "Renewed-Banking"
amount = exports["Renewed-Banking"]:getAccountMoney(society)
elseif isStarted("fd_banking") then
bankScript = "fd_banking"
amount = exports["fd_banking"]:GetAccount(society)
elseif isStarted("okokBanking") then
bankScript = "okokBanking"
amount = exports['okokBanking']:GetAccount(society)
end
if bankScript == "" then
print("^1Error^7: ^3GetSocietyAccount^7: ^2No supported banking script found")
else
debugPrint("^6Bridge^7: ^3"..bankScript.."^7: ^2Retrieved account ^7'^6"..society.."^7' ($"..amount..")")
end
return amount
end
--- Deducts funds from a society's bank account.
--- @param society string The identifier of the society.
--- @param amount number The amount of money to remove.
--- @usage
--- ```lua
--- chargeSociety("police", 1000)
--- ```
function chargeSociety(society, amount)
local bankScript, newAmount = "", 0
if isStarted("qb-banking") then
bankScript = "qb-banking"
if not exports["qb-banking"]:GetAccount(society) then
if Jobs[society] then
print("^6Bridge^7: ^2Making new bank account in ^7'^3qb-banking^7' ^2for ^7'^3"..society.."^7'")
exports["qb-banking"]:CreateJobAccount(society, 0) Wait(150) -- make new account if return "null"
elseif Gangs[society] then
print("^6Bridge^7: ^2Making new bank account in ^7'^3qb-banking^7' ^2for ^7'^3"..society.."^7'")
exports["qb-banking"]:CreateGangAccount(society, 0) Wait(150) -- make new account if return "null"
end
end
exports["qb-banking"]:RemoveMoney(society, amount)
--elseif isStarted("esx_society") then
-- bankScript = "esx_society"
-- TriggerEvent("esx_society:withdrawMoney", society, amount)
elseif isStarted("Renewed-Banking") then
bankScript = "Renewed-Banking"
exports['Renewed-Banking']:removeAccountMoney(society, amount)
elseif isStarted("fd_banking") then
bankScript = "fd_banking"
exports["fd_banking"]:RemoveMoney(society, amount)
elseif isStarted("okokBanking") then
bankScript = "okokBanking"
exports['okokBanking']:RemoveMoney(society, amount)
end
if bankScript == "" then
print("^1Error^7: ^3ChargeSociety^7: ^2No supported banking script found")
else
newAmount = getSocietyAccount(society)
debugPrint("^6Bridge^7: ^3"..bankScript.."^7: ^2Removing $"..amount.." from account '^6"..society.."^7' ($"..newAmount..")")
end
end
--- Adds funds to a society's bank account.
--- @param society string The identifier of the society.
--- @param amount number The amount of money to add.
--- @usage
--- ```lua
--- fundSociety("police", 500)
--- ```
function fundSociety(society, amount)
local bankScript, newAmount = "", 0
if isStarted("qb-banking") then
bankScript = "qb-banking"
if not exports["qb-banking"]:GetAccount(society) then
if Jobs[society] then
print("^6Bridge^7: ^2Making new bank account in ^7'^3qb-banking^7' ^2for ^7'^3"..society.."^7'")
exports["qb-banking"]:CreateJobAccount(society, 0)
Wait(150)
elseif Gangs[society] then
print("^6Bridge^7: ^2Making new bank account in ^7'^3qb-banking^7' ^2for ^7'^3"..society.."^7'")
exports["qb-banking"]:CreateGangAccount(society, 0)
Wait(150)
end
end
exports["qb-banking"]:AddMoney(society, amount)
--elseif isStarted("esx_society") then
-- bankScript = "esx_society"
-- -- Use the esx_society event to deposit money.
-- TriggerServerEvent('esx_society:depositMoney', society, amount)
-- -- Use callback to return the updated balance.
-- newAmount = triggerCallback(getScript()..":getESXSocietyAccount", society) or 0
elseif isStarted("Renewed-Banking") then
bankScript = "Renewed-Banking"
exports['Renewed-Banking']:addAccountMoney(society, amount)
newAmount = exports["Renewed-Banking"]:getAccountMoney(society)
elseif isStarted("fd_banking") then
bankScript = "fd_banking"
exports["fd_banking"]:AddMoney(society, amount)
elseif isStarted("okokBanking") then
bankScript = "okokBanking"
exports['okokBanking']:AddMoney(society, amount)
end
if bankScript == "" then
print("^1Error^7: ^3FundSociety^7: ^2No supported banking script found")
else
newAmount = getSocietyAccount(society)
debugPrint("^6Bridge^7: ^3"..bankScript.."^7: ^2Adding ^7$"..amount.." ^2to account ^7'^6"..society.."^7' ($"..newAmount..")")
end
end
-- other
if isStarted("esx_society") then
createCallback(getScript()..":getESXSocietyAccount", function(source, society)
-- Example query adjust table/field names to match your esx_society implementation.
local result = MySQL.scalar.await('SELECT money FROM society_money WHERE society = ?', { society })
return result or 0
end)
end

View File

@@ -1,46 +1,113 @@
--[[
Stash Management Module
-------------------------
This module handles stash-related operations including:
• Retrieving stash items (from server or local cache).
• Checking for required items in stashes.
• Opening stashes using different inventory systems.
• Removing items from stashes.
• Checking if a stash has specific items.
]]
-- Global variable to hold the current stash (used in callbacks).
local stash
-- If running on the server, create a callback to retrieve stash items.
if isServer() then if isServer() then
createCallback(getScript()..':server:GetStashItems', function(source, stashName) local stash = getStash(stashName) return stash end) createCallback(getScript()..':server:GetStashItems', function(source, stashName)
stash = getStash(stashName)
return stash
end)
end end
local stashCache ={} -- Local cache for stashes.
local stashCache = {}
--- Retrieves (or updates) a local stash cache entry with a timeout.
--- When the cache is empty or expired, it triggers a server callback to update the items.
---
--- @param stashName string The name of the stash.
--- @param stop boolean (Optional) If true, clears the entire stash cache.
--- @return boolean True if items exist in cache (and recheck is skipped), false otherwise.
---
--- @usage
--- ```lua
--- local cached = GetStashTimeout("playerStash")
--- ```
function GetStashTimeout(stashName, stop) function GetStashTimeout(stashName, stop)
if stop then stashCache = {} return end if stop then
local stash = stashCache[stashName] stashCache = {}
return
end
-- Retrieve cache for this stash, or initialize if not present.
stash = stashCache[stashName]
if not stash then if not stash then
debugPrint("^6Bridge^7: ^2Local Stash ^7'^3"..stashName.."^7'^2 cache ^1not ^2found^7, ^2need to grab from server^7")
stashCache[stashName] = { items = {}, timeout = 0 } stashCache[stashName] = { items = {}, timeout = 0 }
stash = stashCache[stashName] stash = stashCache[stashName]
else
debugPrint("^6Bridge^7: ^2Local Stash ^7'^3"..stashName.."^7'^2 cache found^7")
end end
if #stash.items > 0 then return true end
if stash.timeout <= 0 then -- If there are already items in cache, skip recheck.
stash.items = triggerCallback(getScript()..':server:GetStashItems', stashName) if countTable(stashCache[stashName].items) > 0 then
stash.timeout = 10000 debugPrint("^6Bridge^7: '^3"..stashName.." ^2Items found in cache, skipping recheck")
return true
end
-- If timeout has expired, update the stash items from the server.
if stashCache[stashName].timeout <= 0 then
stashCache[stashName].items = triggerCallback(getScript()..':server:GetStashItems', stashName)
stashCache[stashName].timeout = 15000 -- Timeout in milliseconds.
CreateThread(function() CreateThread(function()
while stash.timeout > 0 do stash.timeout -= 1000 Wait(1000) end while stashCache[stashName] and stashCache[stashName].timeout > 0 do
stashCache[stashName].timeout -= 1000
Wait(1000)
end
debugPrint("^6Bridge^7: ^2Local Stash ^7'^3"..stashName.."^7'^2 cache timed out^7, ^3Clearing^7")
stashCache[stashName] = nil stashCache[stashName] = nil
end) end)
end end
return false return false
end end
function checkHasItem(stashes, itemTable) --- Checks if the specified stashes have the required items.
if not stashes then return hasItem(itemTable), nil end ---
--- If multiple stashes are provided (as a table), it iterates over each until all required items are found.
---
--- @param stashes string|table Either a single stash name or a table of stash names.
--- @param itemTable table A table where keys are item names and values are the required amounts.
--- @return boolean, string|nil `boolean, string` true and the stash name if found, otherwise false and nil.
---
--- @usage
--- ```lua
--- local found, stashName = checkStashItem({"playerStash", "storageStash"}, { iron = 2, wood = 5 })
--- ```
function checkStashItem(stashes, itemTable)
if not stashes then
return hasItem(itemTable), nil
end
if type(stashes) == "table" then if type(stashes) == "table" then
local succeses = 0 local successes = 0
local itemCount = 0 local itemCount = countTable(itemTable)
for _, item in pairs(itemTable) do itemCount += 1 end -- Iterate over each provided stash name.
for _, name in pairs(stashes) do for _, name in pairs(stashes) do
Wait(10) -- Delay to avoid multiple callbacks issues.
GetStashTimeout(name) GetStashTimeout(name)
for item, amount in pairs(itemTable) do for item, amount in pairs(itemTable) do
debugPrint("^6Bridge^7: ^2Checking"..(name and " ^7'^6"..name.."^7'" or "").." ^2ingredients^7 - ^6"..item.."^7") debugPrint("^6Bridge^7: ^2Checking "..(name and " '^3"..name.."^7'" or "").." ingredients - ^6"..item.."^7")
if stashhasItem(stashCache[name].items, item, amount) then if stashhasItem(stashCache[name].items, item, amount) then
succeses += 1 successes += 1
if succeses == itemCount then return true, name end if successes == itemCount then
return true, name
end
end end
end end
end end
else else
debugPrint("^6Bridge^7: ^2Checking"..(stashes and " ^7'^6"..stashes.."^7'" or "").." ^2ingredients^7 - ^6"..k.."^7") debugPrint("^6Bridge^7: ^2Checking "..(stashes and " '^3"..stashes.."^7'" or "").." ingredients")
GetStashTimeout(stashes) GetStashTimeout(stashes)
return stashhasItem(stashCache[stashes].items, itemTable), stashes return stashhasItem(stashCache[stashes].items, itemTable), stashes
end end
@@ -48,56 +115,139 @@ function checkHasItem(stashes, itemTable)
return false, nil return false, nil
end end
-------------------------------------------------------------
-- Stash Opening Functions
-------------------------------------------------------------
-- Stash Items --- Opens a stash using the active inventory system.
---
--- Checks for job or gang restrictions before opening the stash.
---
--- @param data table A table containing stash data:
--- - stash (string): The stash identifier.
--- - label (string): Display label.
--- - maxWeight (number|nil): Maximum weight (default 600000).
--- - slots (number|nil): Number of slots (default 40).
--- - stashOptions (table|nil): Additional options for the stash.
--- - job/gang (string|nil): Restriction for access.
--- - coords (vector3): Coordinates to "look" at.
---
--- @usage
--- ```lua
--- openStash({ stash = "playerStash", label = "Player Stash", coords = vector3(100, 200, 30) })
--- ```
function openStash(data) function openStash(data)
if (data.job or data.gang) and not jobCheck(data.job or data.gang) then return end if (data.job or data.gang) and not jobCheck(data.job or data.gang) then return end
if isStarted(OXInv) then if isStarted(OXInv) then
exports[OXInv]:openInventory('stash', data.stash) exports[OXInv]:openInventory('stash', data.stash)
elseif isStarted(CoreInv) then
TriggerServerEvent('core_inventory:server:openInventory', data.stash, 'stash')
elseif isStarted(CodeMInv) then elseif isStarted(CodeMInv) then
exports[CodeMInv]:OpenStash(data.stash, StashWeight, 100) TriggerServerEvent('codem-inventory:server:openstash', data.stash, data.slots, data.maxWeight, data.label)
elseif isStarted(OrigenInv) then
exports[OrigenInv]:openInventory('stash', data.stash, { label = data.label })
elseif isStarted(QBInv) then elseif isStarted(QBInv) then
if QBInvNew then if QBInvNew then
TriggerServerEvent(getScript()..':server:OpenStashQB', { stashName = data.stash, label = data.label, maxweight = data.maxWeight or 600000, slots = data.slots or 40 }) TriggerServerEvent(getScript()..':server:OpenStashQB', {
stashName = data.stash,
label = data.label,
maxweight = data.maxWeight or 600000,
slots = data.slots or 40
})
else else
TriggerEvent("inventory:client:SetCurrentStash", data.stash) TriggerEvent("inventory:client:SetCurrentStash", data.stash)
TriggerServerEvent("inventory:server:OpenInventory", "stash", data.stash, data.stashOptions) TriggerServerEvent("inventory:server:OpenInventory", "stash", data.stash, data.stashOptions)
end end
elseif isStarted(RSGInv) then
TriggerServerEvent(getScript()..':server:OpenStashRSG', {
stashName = data.stash,
label = data.label,
maxweight = data.maxWeight or 600000,
slots = data.slots or 40
})
else else
--Fallback to these commands
TriggerEvent("inventory:client:SetCurrentStash", data.stash) TriggerEvent("inventory:client:SetCurrentStash", data.stash)
TriggerServerEvent("inventory:server:OpenInventory", "stash", data.stash, data.stashOptions) TriggerServerEvent("inventory:server:OpenInventory", "stash", data.stash, data.stashOptions)
end end
lookEnt(data.coords) lookEnt(data.coords)
end end
-- Register an event for opening QB stashes.
RegisterNetEvent(getScript()..':server:OpenStashQB', function(data) RegisterNetEvent(getScript()..':server:OpenStashQB', function(data)
exports[QBInv]:OpenInventory(source, data.stashName, data) exports[QBInv]:OpenInventory(source, data.stashName, data)
end) end)
function getStash(stashName) local stashResource = "" RegisterNetEvent(getScript()..':server:OpenStashRSG', function(data)
if type(stashName) ~= "string" then return print("Stash name was not a string %s(%s)", stashName, type(stashName)) end exports[RSGInv]:OpenInventory(source, data.stashName, data)
end)
-------------------------------------------------------------
-- Stash Retrieval Function
-------------------------------------------------------------
--- Retrieves stash items from the active inventory system.
---
--- This function converts the raw stash items into a standardized table using the global Items lookup.
---
--- @param stashName string The identifier for the stash.
--- @return stashTable table A table of items from the stash.
---
--- @usage
--- ```lua
--- local items = getStash("playerStash")
--- ```
function getStash(stashName)
local stashResource = ""
if type(stashName) ~= "string" then
print("^6Bridge^7: ^2Stash name was not a string ^3"..stashName.."^7(^3"..type(stashName).."^7)")
return {}
end
local stashItems, items = {}, {} local stashItems, items = {}, {}
if isStarted(OXInv) then stashResource = OXInv if isStarted(OXInv) then
stashResource = OXInv
stashItems = exports[OXInv]:Inventory(stashName).items stashItems = exports[OXInv]:Inventory(stashName).items
elseif isStarted(QSInv) then stashResource = QSInv elseif isStarted(QSInv) then
stashResource = QSInv
stashItems = exports[QSInv]:GetStashItems(stashName) stashItems = exports[QSInv]:GetStashItems(stashName)
elseif isStarted(CoreInv) then stashResource = CoreInv elseif isStarted(CoreInv) then
stashResource = CoreInv
stashItems = exports[CoreInv]:getInventory(stashName) stashItems = exports[CoreInv]:getInventory(stashName)
elseif isStarted(CodeMInv) then stashResource = CodeMInv elseif isStarted(CodeMInv) then
stashItems = exports[CodeMInv]:GetInventoryItems('Stash', stashName) stashResource = CodeMInv
stashItems = exports[CodeMInv]:GetStashItems(stashName)
elseif isStarted(OrigenInv) then stashResource = OrigenInv elseif isStarted(OrigenInv) then
stashItems = exports[OrigenInv]:GetStashItems(stashName) stashResource = OrigenInv
stashItems = exports[OrigenInv]:getInventory(stashName)
elseif isStarted(PSInv) then stashResource = PSInv elseif isStarted(PSInv) then
stashResource = PSInv
local result = MySQL.scalar.await('SELECT items FROM stashitems WHERE stash = ?', { stashName }) local result = MySQL.scalar.await('SELECT items FROM stashitems WHERE stash = ?', { stashName })
if result then stashItems = json.decode(result) end if result then stashItems = json.decode(result) end
elseif isStarted(QBInv) then stashResource = QBInv
elseif isStarted(QBInv) then
stashResource = QBInv
local result = MySQL.scalar.await("SELECT items FROM "..(QBInvNew and "inventories" or "stashitem").." WHERE identifier = ?", { stashName }) local result = MySQL.scalar.await("SELECT items FROM "..(QBInvNew and "inventories" or "stashitem").." WHERE identifier = ?", { stashName })
if result then stashItems = json.decode(result) end if result then stashItems = json.decode(result) end
elseif isStarted(RSGInv) then
stashResource = RSGInv
stashItems = exports[RSGInv]:GetInventory(stashName)
end end
debugPrint("^6Bridge^7: ^2Retrieving ^3Stash^2 with ^7"..stashResource) debugPrint("^6Bridge^7: ^2Retrieving ^3Stash^2 with ^7"..stashResource)
@@ -105,8 +255,8 @@ function getStash(stashName) local stashResource = ""
for _, item in pairs(stashItems) do for _, item in pairs(stashItems) do
local itemInfo = Items[item.name:lower()] local itemInfo = Items[item.name:lower()]
if itemInfo then if itemInfo then
local indexNum = #items+1 -- Added to help recreate missing slot numbers local indexNum = #items + 1 -- Fallback index if slot is missing.
items[(item.slot and item.slot) or indexNum] = { items[(item.slot or indexNum)] = {
name = itemInfo.name or nil, name = itemInfo.name or nil,
amount = tonumber(item.amount) or tonumber(item.count), amount = tonumber(item.amount) or tonumber(item.count),
info = item.info or "", info = item.info or "",
@@ -122,18 +272,34 @@ function getStash(stashName) local stashResource = ""
} }
end end
end end
debugPrint("^6Bridge^7: ^3GetStashItems^7: ^2Stash information for ^7'^6"..stashName.."^7' ^2retrieved^7") debugPrint("^6Bridge^7: ^3GetStashItems^7: ^2Stash information for '^6"..stashName.."^7' retrieved")
end end
jsonPrint(items)
return items return items
end end
function stashRemoveItem(stashItems, stashName, items) local amount = amount and amount or 1 -------------------------------------------------------------
-- print("stashItems: "..json.encode(stashItems, { indent = true})) -- Stash Item Removal Function
-- print("stashName: "..json.encode(stashName, { indent = true})) -------------------------------------------------------------
-- print("items: "..json.encode(items, { indent = true}))
--- Removes items from a stash using the active inventory system.
---
--- Iterates over the provided items and adjusts the stash contents accordingly.
---
--- @param stashItems table The current stash items.
--- @param stashName string|table The stash identifier (or table of identifiers).
--- @param items table A table of items to remove (keys are item names, values are amounts).
---
--- @usage
--- ```lua
--- stashRemoveItem(currentItems, "playerStash", { iron = 2, wood = 5 })
--- ```
function stashRemoveItem(stashItems, stashName, items)
if type(stashName) ~= "table" then
stashName = { stashName }
end
if isStarted(OXInv) then if isStarted(OXInv) then
for k, v in pairs(items) do for k, v in pairs(items) do
debugPrint("^6Bridge^7: ^2Removing item from ^3Stash^2 with ^7"..OXInv, k, v)
if type(stashName) == "table" then if type(stashName) == "table" then
for _, name in pairs(stashName) do for _, name in pairs(stashName) do
local success = exports[OXInv]:RemoveItem(name, k, v) local success = exports[OXInv]:RemoveItem(name, k, v)
@@ -148,19 +314,19 @@ function stashRemoveItem(stashItems, stashName, items) local amount = amount and
end end
elseif isStarted(QSInv) then elseif isStarted(QSInv) then
for k, v in pairs(items) do for k, v in pairs(items) do
for l in pairs(stashItems) do for l in pairs(stashItems) do
if stashItems[l].name == k then if stashItems[l].name == k then
if (stashItems[l].amount - v) <= 0 then if (stashItems[l].amount - v) <= 0 then
debugPrint("^6Bridge^7: ^2None of this item left in stash ^3Stash^7", k, v) debugPrint("^6Bridge^7: ^2None of this item left in stash ^3Stash^7", k, v)
stashItems[l] = nil stashItems[l] = nil
else else
debugPrint("^6Bridge^7: ^2Removing item from ^3Stash^2 with ^7"..QBInv, k, v) debugPrint("^6Bridge^7: ^2Removing item from ^3Stash^2 with ^7"..QBInv, k, v)
exports[QSInv]:RemoveItemIntoStash(stashName, k, v, l) exports[QSInv]:RemoveItemIntoStash(stashName, k, v, l)
end
end end
end end
end end
end
elseif isStarted(CoreInv) then elseif isStarted(CoreInv) then
for k, v in pairs(items) do for k, v in pairs(items) do
@@ -182,8 +348,8 @@ function stashRemoveItem(stashItems, stashName, items) local amount = amount and
end end
end end
end end
debugPrint("^6Bridge^7: ^3saveStash^7: ^2Saving ^3QB^2 stash ^7'^6"..stashName.."^7'") exports[CodeMInv]:UpdateStash(stashName, stashItems)
debugPrint("^6Bridge^7: ^3saveStash^7: ^2Saving ^3CodeM^2 stash ^7'^6"..stashName.."^7'")
elseif isStarted(OrigenInv) then elseif isStarted(OrigenInv) then
for k, v in pairs(items) do for k, v in pairs(items) do
exports[OrigenInv]:RemoveFromStash(stashName, k, v) exports[OrigenInv]:RemoveFromStash(stashName, k, v)
@@ -205,7 +371,11 @@ function stashRemoveItem(stashItems, stashName, items) local amount = amount and
end end
end end
debugPrint("^6Bridge^7: ^3saveStash^7: ^2Saving ^3QB^2 stash ^7'^6"..stashName.."^7'") debugPrint("^6Bridge^7: ^3saveStash^7: ^2Saving ^3QB^2 stash ^7'^6"..stashName.."^7'")
MySQL.Async.insert('INSERT INTO stashitems (stash, items) VALUES (:stash, :items) ON DUPLICATE KEY UPDATE items = :items', { ['stash'] = stashName, ['items'] = json.encode(stashItems) }) MySQL.Async.insert('INSERT INTO stashitems (stash, items) VALUES (:stash, :items) ON DUPLICATE KEY UPDATE items = :items', {
['stash'] = stashName,
['items'] = json.encode(stashItems)
})
elseif isStarted(QBInv) then elseif isStarted(QBInv) then
if QBInvNew then if QBInvNew then
for k, v in pairs(items) do for k, v in pairs(items) do
@@ -213,36 +383,56 @@ function stashRemoveItem(stashItems, stashName, items) local amount = amount and
debugPrint("^6Bridge^7: ^2Removing item from ^3Stash^2 with ^7"..QBInv, k, v) debugPrint("^6Bridge^7: ^2Removing item from ^3Stash^2 with ^7"..QBInv, k, v)
end end
debugPrint("^6Bridge^7: ^3saveStash^7: ^2Saving ^3QB^2 stash ^7'^6"..stashName[1].."^7'") debugPrint("^6Bridge^7: ^3saveStash^7: ^2Saving ^3QB^2 stash ^7'^6"..stashName[1].."^7'")
MySQL.Async.insert('INSERT INTO inventories (identifier, items) VALUES (:stash, :items) ON DUPLICATE KEY UPDATE items = :items', { ['stash'] = stashName[1], ['items'] = json.encode(stashItems) }) MySQL.Async.insert('INSERT INTO inventories (identifier, items) VALUES (:stash, :items) ON DUPLICATE KEY UPDATE items = :items', {
['stash'] = stashName[1],
['items'] = json.encode(stashItems)
})
else else
for k, v in pairs(items) do for k, v in pairs(items) do
for l in pairs(stashItems) do for l in pairs(stashItems) do
if stashItems[l].name == k then if stashItems[l].name == k then
if (stashItems[l].amount - v) <= 0 then if (stashItems[l].amount - v) <= 0 then
if Config.System.Debug then debugPrint("^6Bridge^7: ^2None of this item left in stash ^3Stash^7", k, v)
print("^6Bridge^7: ^2None of this item left in stash ^3Stash^7", k, v)
end
stashItems[l] = nil stashItems[l] = nil
else else
if Config.System.Debug then debugPrint("^6Bridge^7: ^2Removing item from ^3Stash^2 with "..QBInv, k, v)
print("^6Bridge^7: ^2Removing item from ^3Stash^2 with ^7"..QBInv, k, v)
end
stashItems[l].amount -= v stashItems[l].amount -= v
end end
end end
end end
end end
debugPrint("^6Bridge^7: ^3saveStash^7: ^2Saving ^3QB^2 stash ^7'^6"..stashName.."^7'") debugPrint("^6Bridge^7: ^3saveStash^7: ^2Saving ^3QB^2 stash '^6"..stashName.."^7'")
MySQL.Async.insert('INSERT INTO stashitems (stash, items) VALUES (:stash, :items) ON DUPLICATE KEY UPDATE items = :items', { ['stash'] = stashName, ['items'] = json.encode(stashItems) }) MySQL.Async.insert('INSERT INTO stashitems (stash, items) VALUES (:stash, :items) ON DUPLICATE KEY UPDATE items = :items', {
['stash'] = stashName,
['items'] = json.encode(stashItems)
})
end end
else else
print("^4ERROR^7: ^2No Inventory detected ^7- ^2Check ^3exports^1.^2lua^7") print("^4ERROR^7: ^2No Inventory detected ^7- ^2Check ^3starter^1.^2lua^7")
end end
end end
RegisterNetEvent(getScript()..":server:stashRemoveItem", stashRemoveItem) RegisterNetEvent(getScript()..":server:stashRemoveItem", stashRemoveItem)
-------------------------------------------------------------
-- Stash Item Availability Check
-------------------------------------------------------------
--- Checks whether a stash has the required amount of specific items.
---
--- It iterates through the provided items and tallies available quantities.
---
--- @param stashItems table The items available in the stash.
--- @param items string|table The item name or table of required items (key: item, value: amount).
--- @param amount number (Optional) The required amount (if a single item is provided).
--- @return boolean, table (`boolean, string`) Returns true (and a table with counts) if all items are available; false otherwise.
---
--- @usage
--- ```lua
--- local hasAll, details = stashhasItem(currentStashItems, { iron = 2, wood = 5 })
--- ```
function stashhasItem(stashItems, items, amount) function stashhasItem(stashItems, items, amount)
local invs = {OXInv, QSInv, CoreInv, CodeMInv, OrigenInv, QBInv, PSInv} local invs = { OXInv, QSInv, CoreInv, CodeMInv, OrigenInv, QBInv, PSInv }
local foundInv = "" local foundInv = ""
for _, inv in ipairs(invs) do for _, inv in ipairs(invs) do
if isStarted(inv) then if isStarted(inv) then
@@ -251,9 +441,11 @@ function stashhasItem(stashItems, items, amount)
end end
end end
-- Ensure items is a table.
if type(items) ~= "table" then items = { [items] = amount and amount or 1, } end if type(items) ~= "table" then items = { [items] = amount and amount or 1, } end
local hasTable = {} local hasTable = {}
for item, amount in pairs(items) do for item, requiredAmount in pairs(items) do
local count = 0 local count = 0
for _, itemData in pairs(stashItems) do for _, itemData in pairs(stashItems) do
if itemData and (itemData.name == item) then if itemData and (itemData.name == item) then
@@ -261,11 +453,13 @@ function stashhasItem(stashItems, items, amount)
end end
end end
local debugMsg = string.format("^6Bridge^7: ^3stashHasItem^7[^6%s^7]: %s '%s' ^3%d^7/^3%d^7", foundInv, (count >= amount and "^5FOUND^7" or "^1NOT FOUND^7"), item, count, amount) local debugMsg = string.format("^6Bridge^7: ^3stashHasItem^7[^6%s^7]: %s '%s' ^3%d^7/^3%d^7", foundInv, (count >= requiredAmount and "^5FOUND^7" or "^1NOT FOUND^7"), item, count, requiredAmount)
debugPrint(debugMsg) debugPrint(debugMsg)
hasTable[item] = { hasItem = (count >= amount), count = count } hasTable[item] = { hasItem = (count >= requiredAmount), count = count }
end end
for k, v in pairs(hasTable) do if v.hasItem == false then return false, hasTable end end for k, v in pairs(hasTable) do if v.hasItem == false then return false, hasTable end end
return true, hasTable return true, hasTable
end end

View File

@@ -1,9 +1,33 @@
-- This is for experimental targets based on GTA in-world text prompts -- --[[
local TextTargets = {} Experimental GTA In-World Text Prompts Targets Module
-------------------------------------------------------
This module handles the creation, removal, and management of in-world text targets
for interacting with entities and zones using GTA text prompts. It supports multiple
targeting systems: OX Target, QB Target, or a fallback using DrawText3D.
Available functionalities:
• createEntityTarget - Creates a target for a specific entity.
• createBoxTarget - Creates a box-shaped zone target.
• createCircleTarget - Creates a circular zone target.
• createModelTarget - Creates a target for specified models.
• removeEntityTarget - Removes a target from an entity.
• removeZoneTarget - Removes a zone target.
Fallback: If no targeting system is detected (or if disabled via Config.System.DontUseTarget),
the module uses DrawText3D prompts. This is experimental and may not work as expected.
]]
-------------------------------------------------------------
-- Utility Data & Tables
-------------------------------------------------------------
---
local KEY_TABLE = { 38, 29, 47, 23, 45, }
-- Mapping of key codes to human-readable key names.
local Keys = { local Keys = {
[322] = "ESC", [288] = "F1", [289] = "F2", [170] = "F3", [166] = "F5", [322] = "ESC", [288] = "F1", [289] = "F2", [170] = "F3", [166] = "F5",
[167] = "F6", [168] = "F7", [169] = "F8", [56] = "F9", [57] = "F10", [167] = "F6", [168] = "F7", [169] = "F8", [56] = "F9", [57] = "F10",
[243] = "~", [157] = "1", [158] = "2", [160] = "3", [164] = "4", [165] = "5", [243] = "~", [157] = "1", [158] = "2", [160] = "3", [164] = "4", [165] = "5",
[159] = "6", [161] = "7", [162] = "8", [163] = "9", [84] = "-", [83] = "=", [159] = "6", [161] = "7", [162] = "8", [163] = "9", [84] = "-", [83] = "=",
[177] = "BACKSPACE", [37] = "TAB", [177] = "BACKSPACE", [37] = "TAB",
[44] = "Q", [32] = "W", [38] = "E", [45] = "R", [245] = "T", [246] = "Y", [44] = "Q", [32] = "W", [38] = "E", [45] = "R", [245] = "T", [246] = "Y",
@@ -15,67 +39,83 @@ local Keys = {
[244] = "M", [82] = ",", [81] = "." [244] = "M", [82] = ",", [81] = "."
} }
-- Target Creation -- -- Tables for storing created targets for the fallback system and zone management.
-- Target Entities, this is more based on qb-target's style of target creation, and translates those into ox or qb-target code -- local TextTargets = {} -- For fallback DrawText3D targets.
local targetEntities = {} local targetEntities = {} -- For entity targets.
local boxTargets = {} -- For box-shaped zone targets.
local circleTargets = {} -- For circular zone targets.
-------------------------------------------------------------
-- Entity Target Creation
-------------------------------------------------------------
--- Creates a target for an entity with specified options and interaction distance. --- Creates a target for an entity with specified options and interaction distance.
--- Supports different targeting systems (OX Target, QB Target, or custom DrawText3D)
--- based on the server configuration.
--- ---
--- This function supports different targeting systems (OX Target, QB Target, or custom DrawText3D targets) --- @param entity number The entity ID for which the target is created.
--- based on the server configuration. It translates qb-target style options into the appropriate format --- @param opts table Array of option tables. Each option should include:
--- for the detected targeting system. --- - icon (string): The icon to display.
--- - label (string): The text label for the option.
--- - item (string|nil): (Optional) An associated item.
--- - job (string|nil): (Optional) The job required to interact.
--- - gang (string|nil): (Optional) The gang required to interact.
--- - action (function|nil): (Optional) The function executed on selection.
--- @param dist number The interaction distance for the target.
--- ---
---@param entity number The entity ID to create a target for. --- @usage
---@param opts table A table of option configurations for the target.
--- - **icon** (`string`): The icon to display for the option.
--- - **label** (`string`): The label text for the option.
--- - **item** (`string|nil`): (Optional) The item associated with the option.
--- - **job** (`string|nil`): (Optional) The job required to interact with the option.
--- - **gang** (`string|nil`): (Optional) The gang required to interact with the option.
--- - **action** (`function|nil`): (Optional) The function to execute when the option is selected.
---@param dist number The interaction distance for the target.
---
---@usage
--- ```lua --- ```lua
--- createEntityTarget(entityId, { ---createEntityTarget(entityId, {
--- { icon = "fas fa-car", label = "Open Vehicle", action = openVehicle }, --- {
--- { icon = "fas fa-lock", label = "Lock Vehicle", action = lockVehicle } --- action = function()
--- }, 2.5) --- openStorage()
--- end,
--- icon = "fas fa-box",
--- job = "police",
--- label = "Open Storage",
--- },
---}, 2.0)
--- ``` --- ```
function createEntityTarget(entity, opts, dist) function createEntityTarget(entity, opts, dist)
-- Store the target entity for later cleanup.
targetEntities[#targetEntities + 1] = entity targetEntities[#targetEntities + 1] = entity
local entityCoords = GetEntityCoords(entity)
if Config.System.DontUseTarget then -- Fallback: Use DrawText3D if targeting systems are disabled or unavailable.
debugPrint("^6Bridge^7: ^2Creating new ^3Entity^2 target with ^6DrawText ^7"..entity) if Config.System.DontUseTarget or (not isStarted(OXTargetExport) and not isStarted(QBTargetExport)) then
local entityCoords = GetEntityCoords(entity)
debugPrint("^6Bridge^7: ^2Creating new ^3Entity^2 target with DrawText for entity ^7"..entity)
local existingTarget = nil local existingTarget = nil
for key, target in pairs(TextTargets) do for _, target in pairs(TextTargets) do
if #(target.coords - entityCoords) < 0.01 then -- Adjust the threshold for coordinate matching if #(target.coords - entityCoords) < 0.01 then
existingTarget = target existingTarget = target
break break
end end
end end
if existingTarget then if existingTarget then
-- Combine options
local keyTable = { 38, 29, 303, 45, 46, 47, 48 } -- Extend key table as needed
for i = 1, #opts do for i = 1, #opts do
local key = keyTable[#existingTarget.options + i] local key = KEY_TABLE[#existingTarget.options + i]
opts[i].key = key opts[i].key = key
existingTarget.buttontext[#existingTarget.buttontext + 1] = " ~b~[~w~"..Keys[key].."~b~] ~w~"..opts[i].label existingTarget.buttontext[#existingTarget.buttontext + 1] = " ~b~[~w~" .. Keys[key] .. "~b~] ~w~" .. opts[i].label
existingTarget.options[#existingTarget.options + 1] = opts[i] existingTarget.options[#existingTarget.options + 1] = opts[i]
end end
updateCachedText(existingTarget)
else else
-- Create new target
local tempText = {} local tempText = {}
local keyTable = { 38, 29, 303, 45, 46, 47, 48 }
for i = 1, #opts do for i = 1, #opts do
opts[i].key = keyTable[i] opts[i].key = KEY_TABLE[i]
tempText[#tempText + 1] = " ~b~[~w~"..Keys[opts[i].key].."~b~] ~w~"..opts[i].label tempText[#tempText + 1] = " ~b~[~w~" .. Keys[opts[i].key] .. "~b~] ~w~" .. opts[i].label
end end
TextTargets[entity] = { coords = vec3(entityCoords.x, entityCoords.y, entityCoords.z), buttontext = tempText, options = opts, dist = dist } TextTargets[entity] = {
coords = vec3(entityCoords.x, entityCoords.y, entityCoords.z),
buttontext = tempText,
options = opts,
dist = dist,
text = table.concat(tempText, "\n")
}
end end
elseif isStarted(OXTargetExport) then elseif isStarted(OXTargetExport) then
debugPrint("^6Bridge^7: ^2Creating new ^3Entity^2 target with ^6"..OXTargetExport.." ^7"..entity) debugPrint("^6Bridge^7: ^2Creating new ^3Entity ^2target with ^6"..OXTargetExport.." ^2for entity ^7"..entity)
local options = {} local options = {}
for i = 1, #opts do for i = 1, #opts do
options[i] = { options[i] = {
@@ -84,91 +124,107 @@ function createEntityTarget(entity, opts, dist)
item = opts[i].item or nil, item = opts[i].item or nil,
groups = opts[i].job or opts[i].gang, groups = opts[i].job or opts[i].gang,
onSelect = opts[i].action, onSelect = opts[i].action,
canInteract = function(_, distance) distance = dist,
return distance < dist and true or false canInteract = opts[i].canInteract or nil,
end
} }
end end
exports[OXTargetExport]:addLocalEntity(entity, options) exports[OXTargetExport]:addLocalEntity(entity, options)
elseif isStarted(QBTargetExport) then elseif isStarted(QBTargetExport) then
debugPrint("^6Bridge^7: ^2Creating new ^3Entity^2 target with ^6"..QBTargetExport.." ^7"..entity) debugPrint("^6Bridge^7: ^2Creating new ^3Entity ^2target with ^6"..QBTargetExport.." ^2for entity ^7"..entity)
local options = { options = opts, distance = dist } local options = { options = opts, distance = dist }
exports[QBTargetExport]:AddTargetEntity(entity, options) exports[QBTargetExport]:AddTargetEntity(entity, options)
end end
end end
local boxTargets = {} -------------------------------------------------------------
-- Box Zone Target Creation
-------------------------------------------------------------
--- Creates a box-shaped target zone with specified options and interaction distance. --- Creates a box-shaped target zone with specified options and interaction distance.
--- --- Supports different targeting systems based on the server configuration.
--- This function supports different targeting systems (OX Target, QB Target, or custom DrawText3D targets)
--- based on the server configuration. It translates qb-target style options into the appropriate format
--- for the detected targeting system.
---
---@param data table A table containing the box zone configuration. ---@param data table A table containing the box zone configuration.
--- - **name** (`string`): The name identifier for the zone. --- - name (`string`): The name identifier for the zone.
--- - **coords** (`vector3`): The center coordinates of the box. --- - coords (`vector3`): The center coordinates of the box.
--- - **width** (`number`): The width of the box. --- - width (`number`): The width of the box.
--- - **height** (`number`): The height of the box. --- - height (`number`): The height of the box.
--- - **options** (`table`): A table with additional options: --- - options (`table`): A table with additional options:
--- - **heading** (`number`): The rotation angle of the box. --- - heading (`number`): The rotation angle of the box.
--- - **debugPoly** (`boolean`): Whether to enable debug mode for the zone. --- - debugPoly (`boolean`): Whether to enable debug mode for the zone.
--- ---
---@param opts table A table of option configurations for the target. ---@param opts table A table of option configurations for the target.
--- - **icon** (`string`): The icon to display for the option. --- - icon (`string`): The icon to display for the option.
--- - **label** (`string`): The label text for the option. --- - label (`string`): The label text for the option.
--- - **item** (`string|nil`): (Optional) The item associated with the option. --- - item (`string|nil`): (Optional) The item associated with the option.
--- - **job** (`string|nil`): (Optional) The job required to interact with the option. --- - job (`string|nil`): (Optional) The job required to interact with the option.
--- - **gang** (`string|nil`): (Optional) The gang required to interact with the option. --- - gang (`string|nil`): (Optional) The gang required to interact with the option.
--- - **onSelect** (`function|nil`): (Optional) The function to execute when the option is selected. --- - onSelect (`function|nil`): (Optional) The function to execute when the option is selected.
---@param dist number The interaction distance for the target. ---@param dist number The interaction distance for the target.
--- ---
---@return string|table name identifier or target object of the created zone. ---@return string|table name identifier or target object of the created zone.
--- ---
---@usage ---@usage
--- ```lua ---```lua
--- createBoxTarget({ ---createBoxTarget(
--- name = 'storageBox', --- {
--- coords = vector3(100.0, 200.0, 30.0), --- 'storageBox',
--- width = 2.0, --- vector3(100.0, 200.0, 30.0),
--- height = 2.0, --- 2.0,
--- options = { heading = 0, debugPoly = false } --- 2.0,
--- }, { --- {
--- { icon = "fas fa-box", label = "Open Storage", action = openStorage } --- name = 'storageBox',
--- }, 1.5) --- heading = 100.0,
--- ``` --- debugPoly = true,
--- minZ = 27.0,
--- maxZ = 32.0,
--- },
--- },
---{
--- {
--- action = function()
--- openStorage()
--- end,
--- icon = "fas fa-box",
--- job = "police",
--- label = "Open Storage",
--- },
---}, 2.0)
---```
function createBoxTarget(data, opts, dist) function createBoxTarget(data, opts, dist)
if Config.System.DontUseTarget then if Config.System.DontUseTarget or (not isStarted(OXTargetExport) and not isStarted(QBTargetExport)) then
debugPrint("^6Bridge^7: ^2Creating new ^3Box^2 target with ^6DrawText ^7"..data[1]) debugPrint("^6Bridge^7: ^2Creating new ^3Box^2 target with ^6DrawText ^2 for zone ^7"..data[1])
local existingTarget = nil local existingTarget = nil
for key, target in pairs(TextTargets) do for _, target in pairs(TextTargets) do
if #(target.coords - data[2]) < 0.01 then -- Adjust the threshold as needed for coordinate precision if #(target.coords - data[2]) < 0.01 then
existingTarget = target existingTarget = target
break break
end end
end end
local keyTable = { 38, 29, 303, 45, 46, 47, 48 }
if existingTarget then if existingTarget then
-- Combine options
for i = 1, #opts do for i = 1, #opts do
local key = keyTable[#existingTarget.options + i] local key = KEY_TABLE[#existingTarget.options + i]
opts[i].key = key opts[i].key = key
existingTarget.buttontext[#existingTarget.buttontext+1] = " ~b~[~w~"..Keys[key].."~b~] ~w~"..opts[i].label existingTarget.buttontext[#existingTarget.buttontext + 1] = " ~b~[~w~" .. Keys[key] .. "~b~] ~w~" .. opts[i].label
existingTarget.options[#existingTarget.options+1] = opts[i] existingTarget.options[#existingTarget.options + 1] = opts[i]
end end
updateCachedText(existingTarget)
else else
-- Create new target
local tempText = {} local tempText = {}
for i = 1, #opts do for i = 1, #opts do
opts[i].key = keyTable[i] opts[i].key = KEY_TABLE[i]
tempText[#tempText+1] = " ~b~[~w~"..Keys[opts[i].key].."~b~] ~w~"..opts[i].label tempText[#tempText + 1] = " ~b~[~w~" .. Keys[opts[i].key] .. "~b~] ~w~" .. opts[i].label
end end
TextTargets[data[1]] = { coords = data[2], buttontext = tempText, options = opts, dist = 1.5 } TextTargets[data[1]] = {
coords = data[2],
buttontext = tempText,
options = opts,
dist = dist,
text = table.concat(tempText, "\n")
}
end end
return data[1] return data[1]
elseif isStarted(OXTargetExport) then elseif isStarted(OXTargetExport) then
debugPrint("^6Bridge^7: ^2Creating new ^3Box^2 target with ^6"..OXTargetExport.." ^7"..data[1]) debugPrint("^6Bridge^7: ^2Creating new ^3Box^2 target with ^6"..OXTargetExport.." ^2for zone ^7"..data[1])
local options = {} local options = {}
for i = 1, #opts do for i = 1, #opts do
options[i] = { options[i] = {
@@ -177,9 +233,8 @@ function createBoxTarget(data, opts, dist)
item = opts[i].item or nil, item = opts[i].item or nil,
groups = opts[i].job or opts[i].gang, groups = opts[i].job or opts[i].gang,
onSelect = opts[i].onSelect or opts[i].action, onSelect = opts[i].onSelect or opts[i].action,
canInteract = function(_, distance) distance = dist,
return distance < dist and true or false canInteract = opts[i].canInteract or nil,
end
} }
end end
if not data[5].useZ then if not data[5].useZ then
@@ -193,39 +248,38 @@ function createBoxTarget(data, opts, dist)
debug = data[5].debugPoly, debug = data[5].debugPoly,
options = options options = options
}) })
boxTargets[#boxTargets+1] = target boxTargets[#boxTargets + 1] = target
return target return target
elseif isStarted(QBTargetExport) then elseif isStarted(QBTargetExport) then
debugPrint("^6Bridge^7: ^2Creating new ^3Box^2 target with ^6"..QBTargetExport.." ^7"..data[1]) debugPrint("^6Bridge^7: ^2Creating new ^3Box^2 target with ^6"..QBTargetExport.." ^2for zone ^7"..data[1])
local options = { options = opts, distance = dist } local options = { options = opts, distance = dist }
local target = exports[QBTargetExport]:AddBoxZone(data[1], data[2], data[3], data[4], data[5], options) local target = exports[QBTargetExport]:AddBoxZone(data[1], data[2], data[3], data[4], data[5], options)
boxTargets[#boxTargets+1] = target boxTargets[#boxTargets + 1] = target
return data[1] return data[1]
end end
end end
local circleTargets = {} -------------------------------------------------------------
-- Circle Zone Target Creation
-------------------------------------------------------------
--- Creates a circular target zone with specified options and interaction distance. --- Creates a circular target zone with specified options and interaction distance.
--- --- Supports different targeting systems based on server configuration.
--- This function supports different targeting systems (OX Target, QB Target, or custom DrawText3D targets)
--- based on the server configuration. It translates qb-target style options into the appropriate format
--- for the detected targeting system.
--- ---
---@param data table A table containing the circle zone configuration. ---@param data table A table containing the circle zone configuration.
--- - **name** (`string`): The name identifier for the zone. --- - name (`string`): The name identifier for the zone.
--- - **coords** (`vector3`): The center coordinates of the circle. --- - coords (`vector3`): The center coordinates of the circle.
--- - **radius** (`number`): The radius of the circle. --- - radius (`number`): The radius of the circle.
--- - **options** (`table`): A table with additional options: --- - options (`table`): A table with additional options:
--- - **debugPoly** (`boolean`): Whether to enable debug mode for the zone. --- - debugPoly (`boolean`): Whether to enable debug mode for the zone.
--- ---
---@param opts table A table of option configurations for the target. ---@param opts table A table of option configurations for the target.
--- - **icon** (`string`): The icon to display for the option. --- - icon (`string`): The icon to display for the option.
--- - **label** (`string`): The label text for the option. --- - label (`string`): The label text for the option.
--- - **item** (`string|nil`): (Optional) The item associated with the option. --- - item (`string|nil`): (Optional) The item associated with the option.
--- - **job** (`string|nil`): (Optional) The job required to interact with the option. --- - job (`string|nil`): (Optional) The job required to interact with the option.
--- - **gang** (`string|nil`): (Optional) The gang required to interact with the option. --- - gang (`string|nil`): (Optional) The gang required to interact with the option.
--- - **onSelect** (`function|nil`): (Optional) The function to execute when the option is selected. --- - onSelect (`function|nil`): (Optional) The function to execute when the option is selected.
---@param dist number The interaction distance for the target. ---@param dist number The interaction distance for the target.
--- ---
---@return string|table name identifier or target object of the created zone. ---@return string|table name identifier or target object of the created zone.
@@ -243,37 +297,40 @@ local circleTargets = {}
--- ``` --- ```
function createCircleTarget(data, opts, dist) function createCircleTarget(data, opts, dist)
if Config.System.DontUseTarget then if Config.System.DontUseTarget then
debugPrint("^6Bridge^7: ^2Creating new ^3Circle^2 target with ^6DrawText ^7"..data[1]) debugPrint("^6Bridge^7: ^2Creating new ^3Circle ^2target with ^6DrawText ^2for zone ^7"..data[1])
local existingTarget = nil local existingTarget = nil
for key, target in pairs(TextTargets) do for _, target in pairs(TextTargets) do
if #(target.coords - data[2]) < 0.01 then -- Adjust the threshold for precision if #(target.coords - data[2]) < 0.01 then
existingTarget = target existingTarget = target
break break
end
end end
end
if existingTarget then if existingTarget then
-- Combine options for i = 1, #opts do
local keyTable = { 38, 29, 303, 45, 46, 47, 48 } -- Extend key table as needed local key = KEY_TABLE[#existingTarget.options + i]
for i = 1, #opts do opts[i].key = key
local key = keyTable[#existingTarget.options + i] existingTarget.buttontext[#existingTarget.buttontext + 1] = " ~b~[~w~" .. Keys[key] .. "~b~] ~w~" .. opts[i].label
opts[i].key = key existingTarget.options[#existingTarget.options + 1] = opts[i]
existingTarget.buttontext[#existingTarget.buttontext+1] = " ~b~[~w~"..Keys[key].."~b~] ~w~"..opts[i].label
existingTarget.options[#existingTarget.options+1] = opts[i]
end
else
-- Create new target
local tempText = ""
local keyTable = { 38, 29, 303, 45, 46, 47, 48 }
for i = 1, #opts do
opts[i].key = keyTable[i]
tempText[#tempText+1] = " ~b~[~w~"..Keys[opts[i].key].."~b~] ~w~"..opts[i].label
end
TextTargets[data[1]] = { coords = data[2], buttontext = tempText, options = opts, dist = dist }
end end
return data[1] updateCachedText(existingTarget)
else
local tempText = {}
for i = 1, #opts do
opts[i].key = KEY_TABLE[i]
tempText[#tempText + 1] = " ~b~[~w~" .. Keys[opts[i].key] .. "~b~] ~w~" .. opts[i].label
end
TextTargets[data[1]] = {
coords = data[2],
buttontext = tempText,
options = opts,
dist = dist,
text = table.concat(tempText, "\n")
}
end
return data[1]
elseif isStarted(OXTargetExport) then elseif isStarted(OXTargetExport) then
debugPrint("^6Bridge^7: ^2Creating new ^3Sphere^2 target with ^6"..OXTargetExport.." ^7"..data[1]) debugPrint("^6Bridge^7: ^2Creating new ^3Circle ^2target with ^6"..OXTargetExport.." ^2for zone ^7"..data[1])
local options = {} local options = {}
for i = 1, #opts do for i = 1, #opts do
options[i] = { options[i] = {
@@ -282,9 +339,8 @@ function createCircleTarget(data, opts, dist)
item = opts[i].item or nil, item = opts[i].item or nil,
groups = opts[i].job or opts[i].gang, groups = opts[i].job or opts[i].gang,
onSelect = opts[i].onSelect or opts[i].action, onSelect = opts[i].onSelect or opts[i].action,
canInteract = function(_, distance) distance = dist,
return distance < dist and true or false canInteract = opts[i].canInteract or nil,
end
} }
end end
local target = exports[OXTargetExport]:addSphereZone({ local target = exports[OXTargetExport]:addSphereZone({
@@ -293,37 +349,116 @@ function createCircleTarget(data, opts, dist)
debug = data[4].debugPoly, debug = data[4].debugPoly,
options = options options = options
}) })
circleTargets[#circleTargets+1] = target circleTargets[#circleTargets + 1] = target
return target return target
elseif isStarted(QBTargetExport) then elseif isStarted(QBTargetExport) then
debugPrint("^6Bridge^7: ^2Creating new ^3Circle^2 target with ^6"..QBTargetExport.." ^7"..data[1]) debugPrint("^6Bridge^7: ^2Creating new ^3Circle ^2target with ^6"..QBTargetExport.." ^2for zone ^7"..data[1])
local options = { options = opts, distance = dist } local options = { options = opts, distance = dist }
local target = exports[QBTargetExport]:AddCircleZone(data[1], data[2], data[3], data[4], options) local target = exports[QBTargetExport]:AddCircleZone(data[1], data[2], data[3], data[4], options)
circleTargets[#circleTargets+1] = target circleTargets[#circleTargets + 1] = target
return data[1] return data[1]
end end
end end
-- Simple function to remove an entity target created within the script -- -------------------------------------------------------------
--- Removes a previously created entity target. -- Model Target Creation
-------------------------------------------------------------
--- Creates a target for models with specified options and interaction distance.
--- Supports different targeting systems (OX Target, QB Target) based on server configuration.
--- ---
--- This function removes the target associated with the specified entity based on the active targeting system. --- @param models table Array of model identifiers.
--- @param opts table Array of option tables (same structure as in createEntityTarget).
--- @param dist number The interaction distance for the target.
---
--- @usage
--- ```lua
---createModelTarget({ model1, model2 },
---{
--- {
--- action = function()
--- openStorage()
--- end,
--- icon = "fas fa-box",
--- job = "police",
--- label = "Open Storage",
--- },
---}, 2.0)
---```
function createModelTarget(models, opts, dist)
if Config.System.DontUseTarget or (not isStarted(OXTargetExport) and not isStarted(QBTargetExport)) then
if type(models) ~= "table" then
models = { models }
end
local tempText = {}
for i = 1, #opts do
opts[i].key = KEY_TABLE[i]
tempText[#tempText + 1] = " ~b~[~w~" .. Keys[opts[i].key] .. "~b~] ~w~" .. opts[i].label
end
local keyStr = ""
for i, m in ipairs(models) do
keyStr = keyStr .. tostring(m) .. (i < #models and "_" or "")
end
local targetKey = "model_" .. keyStr
TextTargets[targetKey] = {
models = models,
buttontext = tempText,
options = opts,
dist = dist,
coords = vec3(0, 0, 0),
text = table.concat(tempText, "\n")
}
elseif isStarted(OXTargetExport) then
debugPrint("^6Bridge^7: ^2Creating new ^3Model^2 target with ^6"..OXTargetExport)
local options = {}
for i = 1, #opts do
options[i] = {
icon = opts[i].icon,
label = opts[i].label,
item = opts[i].item or nil,
groups = opts[i].job or opts[i].gang,
onSelect = opts[i].action,
distance = dist,
canInteract = opts[i].canInteract or nil,
}
end
exports[OXTargetExport]:addModel(models, options)
elseif isStarted(QBTargetExport) then
debugPrint("^6Bridge^7: ^2Creating new ^3Model^2 target with ^6"..QBTargetExport)
local options = { options = opts, distance = dist }
exports[QBTargetExport]:AddTargetModel(models, options)
end
end
-------------------------------------------------------------
-- Target Removal Functions
-------------------------------------------------------------
--- Removes a previously created entity target.
--- ---
--- @param entity number The entity ID whose target should be removed. --- @param entity number The entity ID whose target should be removed.
--- ---
--- @usage --- @usage
--- ```lua
--- removeEntityTarget(entityId) --- removeEntityTarget(entityId)
--- ```
function removeEntityTarget(entity) function removeEntityTarget(entity)
if isStarted(QBTargetExport) then exports[QBTargetExport]:RemoveTargetEntity(entity) end if isStarted(QBTargetExport) then
if isStarted(OXTargetExport) then exports[OXTargetExport]:removeLocalEntity(entity, nil) end exports[QBTargetExport]:RemoveTargetEntity(entity)
if Config.System.DontUseTarget then TextTargets[entity] = nil end end
if isStarted(OXTargetExport) then
exports[OXTargetExport]:removeLocalEntity(entity, nil)
end
if Config.System.DontUseTarget or (not isStarted(OXTargetExport) and not isStarted(QBTargetExport)) then
TextTargets[entity] = nil
end
end end
-- Simple function to remove circle or box targets in the script --
--- Removes a previously created zone target. --- Removes a previously created zone target.
--- ---
--- This function removes the target associated with the specified zone based on the active targeting system.
---
--- @param target string|table The name identifier or target object of the zone to remove. --- @param target string|table The name identifier or target object of the zone to remove.
--- ---
--- @usage --- @usage
@@ -332,73 +467,146 @@ end
--- removeZoneTarget(targetObject) --- removeZoneTarget(targetObject)
--- ``` --- ```
function removeZoneTarget(target) function removeZoneTarget(target)
if isStarted(QBTargetExport) then exports[QBTargetExport]:RemoveZone(target) end if isStarted(QBTargetExport) then
if isStarted(OXTargetExport) then exports[OXTargetExport]:removeZone(target, true) end exports[QBTargetExport]:RemoveZone(target)
if Config.System.DontUseTarget then TextTargets[target] = nil end end
if isStarted(OXTargetExport) then
exports[OXTargetExport]:removeZone(target, true)
end
if Config.System.DontUseTarget or (not isStarted(OXTargetExport) and not isStarted(QBTargetExport)) then
TextTargets[target] = nil
end
end end
-- If no target script is found, default to DrawText3D targets -- * experimental * --- Removes a previously created model target.
if Config.System.DontUseTarget and not isServer() then ---
--- @param model table The model ID whose target should be removed.
---
--- @usage
--- ```lua
--- removeModelTarget(model)
--- ```
function removeModelTarget(model)
if isStarted(QBTargetExport) then
exports[QBTargetExport]:RemoveTargetModel(model, "Test")
end
if isStarted(OXTargetExport) then
exports[OXTargetExport]:removeModel(model, nil)
end
if Config.System.DontUseTarget or (not isStarted(OXTargetExport) and not isStarted(QBTargetExport)) then
TextTargets[entity] = nil
end
end
-------------------------------------------------------------
-- Fallback: DrawText3D Targets (Experimental)
-------------------------------------------------------------
-- If no targeting system is detected and this is a client script, use DrawText3D for targets.
if (Config.System.DontUseTarget or (not isStarted(OXTargetExport) and not isStarted(QBTargetExport))) and not isServer() then
CreateThread(function() CreateThread(function()
local wait = 1000
while true do while true do
local pedCoords = GetEntityCoords(PlayerPedId()) local pedCoords = GetEntityCoords(PlayerPedId())
local camCoords = GetGameplayCamCoord() local camCoords = GetGameplayCamCoord()
local camRotation = GetGameplayCamRot(2) -- Get camera rotation in degrees local camRot = GetGameplayCamRot(2)
local camForwardVector = RotationToDirection(camRotation) -- Convert rotation to direction vector local camForward = RotationToDirection(camRot)
local closestTarget, closestDist = nil, math.huge
local closestTarget = nil local notificationShown = false
local closestDist = math.huge local targetEntity = nil
-- Update model targets and determine the closest target.
for k, v in pairs(TextTargets) do for _, target in pairs(TextTargets) do
local targetCoords = v.coords if target.models then
local dist = #(pedCoords - targetCoords) for _, model in ipairs(target.models) do
local vecToTarget = targetCoords - camCoords local entity = GetClosestObjectOfType(pedCoords.x, pedCoords.y, pedCoords.z, target.dist, model, false, false, false)
if entity and entity ~= 0 then
-- Normalize the vector to the target target.coords = GetEntityCoords(entity)
local vecToTargetNormalized = normalizeVector(vecToTarget) targetEntity = entity
break
-- Dot product to check if facing the target
local dot = camForwardVector.x * vecToTargetNormalized.x + camForwardVector.y * vecToTargetNormalized.y + camForwardVector.z * vecToTargetNormalized.z
local isFacingTarget = dot > 0.5 -- Adjust threshold as needed
if dist <= v.dist and isFacingTarget then
if dist < closestDist then
closestDist = dist
closestTarget = v
end
end
end
for k, v in pairs(TextTargets) do
local isClosest = (v == closestTarget)
if #(pedCoords - v.coords) <= v.dist then
for i = 1, #v.options do
if IsControlJustPressed(0, v.options[i].key) and isClosest then
if v.options[i].onSelect then v.options[i].onSelect() end
if v.options[i].action then v.options[i].action() end
end end
end end
DrawText3D(vec3(v.coords.x, v.coords.y, v.coords.z + 0.7), concatenateText(v.buttontext), isClosest) end
local dist = #(pedCoords - target.coords)
if dist <= target.dist then
local vecToTarget = target.coords - camCoords
local normVec = normalizeVector(vecToTarget)
local dot = camForward.x * normVec.x + camForward.y * normVec.y + camForward.z * normVec.z
if dot > 0.5 and dist < closestDist then
closestDist = dist
closestTarget = target
end
end end
end end
Wait(0)
-- Render targets, listen for key presses and display the help notification.
for key, target in pairs(TextTargets) do
if #(pedCoords - target.coords) <= target.dist then
local isClosest = (target == closestTarget)
for i, opt in ipairs(target.options) do
if IsControlJustPressed(0, opt.key) and isClosest then
if opt.onSelect then opt.onSelect(targetEntity) end
if opt.action then opt.action(targetEntity) end
end
end
notificationShown = true
ShowFloatingHelpNotification(vec3(target.coords.x, target.coords.y, target.coords.z + 0.7), target.text)
end
end
-- If no notification was drawn this frame, clear help messages.
if notificationShown then
wait = 0
else
ClearAllHelpMessages()
wait = 1000
end
Wait(wait)
end end
end) end)
end end
-- If the current loaded script is stopped, automatically remove targets -- function ShowFloatingHelpNotification(coord, text, highlight)
AddTextEntry("FloatingText", text)
SetFloatingHelpTextWorldPosition(1, coord.x, coord.y, coord.z)
SetFloatingHelpTextStyle(1, 1, 62, -1, 3, 0)
BeginTextCommandDisplayHelp("FloatingText")
EndTextCommandDisplayHelp(2, false, false, -1)
end
function updateCachedText(target)
target.text = table.concat(target.buttontext, "\n")
end
-------------------------------------------------------------
-- Cleanup on Resource Stop
-------------------------------------------------------------
-- When the current resource stops, remove all targets.
onResourceStop(function() onResourceStop(function()
-- Remove entity targets.
for i = 1, #targetEntities do for i = 1, #targetEntities do
if isStarted(OXTargetExport) then exports[OXTargetExport]:removeLocalEntity(targetEntities[i], nil) if isStarted(OXTargetExport) then
elseif isStarted(QBTargetExport) then exports[QBTargetExport]:RemoveTargetEntity(targetEntities[i]) end exports[OXTargetExport]:removeLocalEntity(targetEntities[i], nil)
elseif isStarted(QBTargetExport) then
exports[QBTargetExport]:RemoveTargetEntity(targetEntities[i])
end
end end
-- Remove box zone targets.
for i = 1, #boxTargets do for i = 1, #boxTargets do
if isStarted(OXTargetExport) then exports[OXTargetExport]:removeZone(boxTargets[i], true) if isStarted(OXTargetExport) then
elseif isStarted(QBTargetExport) then exports[QBTargetExport]:RemoveZone(boxTargets[i].name) end exports[OXTargetExport]:removeZone(boxTargets[i], true)
elseif isStarted(QBTargetExport) then
exports[QBTargetExport]:RemoveZone(boxTargets[i].name)
end
end end
-- Remove circle zone targets.
for i = 1, #circleTargets do for i = 1, #circleTargets do
if isStarted(OXTargetExport) then exports[OXTargetExport]:removeZone(circleTargets[i], true) if isStarted(OXTargetExport) then
elseif isStarted(QBTargetExport) then exports[QBTargetExport]:RemoveZone(circleTargets[i].name) end exports[OXTargetExport]:removeZone(circleTargets[i], true)
elseif isStarted(QBTargetExport) then
exports[QBTargetExport]:RemoveZone(circleTargets[i].name)
end
end end
end, true) end, true)

View File

@@ -1,22 +1,29 @@
-- Get Vehicle Info -- --[[
local lastCar = nil Vehicle Info & Properties Module
local carInfo = {} ----------------------------------
This module provides utilities for:
- Retrieving vehicle information from a Vehicles table.
- Getting and setting vehicle properties using the active framework.
- Comparing vehicle property differences.
- Synchronizing vehicle properties across clients.
- Managing network control of vehicles.
- Finding the closest vehicle to a given position.
]]
--- Searches the 'Vehicles' table for a specific vehicle's 'name', 'price', and 'class'. -- Cached vehicle info to avoid unnecessary re-searches.
local lastCar, carInfo = nil, {}
--- Searches the 'Vehicles' table for a specific vehicle's details.
--- If the vehicle differs from the last searched, it retrieves its model and updates the carInfo table.
--- The table includes the vehicle's name, price, and class information.
--- ---
--- This function checks if the provided vehicle is different from the last searched vehicle. --- @param vehicle number The entity ID of the vehicle to search for.
--- If it's a new vehicle, it retrieves its model and searches the 'Vehicles' table for matching entries. --- @return table|nil table A table containing the vehicle's details or nil if the vehicle is invalid.
--- It populates the `carInfo` table with the vehicle's name, price, and class.
--- If the vehicle is not found in the table, it defaults to using the vehicle's display name and sets the price to 0.
--- ---
---@param vehicle number The entity ID of the vehicle to search for. --- @usage
---
---@return table|nil table containing the vehicle's `name`, `price`, and `class`, or `nil` if the vehicle is invalid.
---
---@usage
--- ```lua --- ```lua
--- local info = searchCar(vehicleEntity) --- local info = searchCar(vehicleEntity)
--- print(info.name, info.price, info.class) --- print(info.name, info.price, info.class.name, info.class.index)
--- ``` --- ```
function searchCar(vehicle) function searchCar(vehicle)
if lastCar ~= vehicle then -- If same car, use previous info if lastCar ~= vehicle then -- If same car, use previous info
@@ -78,27 +85,26 @@ function searchCar(vehicle)
end end
end end
-- Vehicle Properties -- -------------------------------------------------------------
-- Vehicle Properties Functions
-------------------------------------------------------------
--- Retrieves the properties of a given vehicle. --- Retrieves the properties of a given vehicle using the active framework.
---
--- This function fetches the vehicle's properties based on the active framework (QBCore or ox).
--- It utilizes the framework's native functions or events to obtain the vehicle's mod list and other details.
--- ---
--- @param vehicle number The entity ID of the vehicle. --- @param vehicle number The entity ID of the vehicle.
--- --- @return table|nil table A table containing the vehicle's properties or nil if invalid.
--- @return table|nil table containing the vehicle's properties, or `nil` if the vehicle is invalid or the framework is not detected.
--- ---
--- @usage --- @usage
--- ```lua --- ```lua
--- local props = getVehicleProperties(vehicleEntity) --- local props = getVehicleProperties(vehicleEntity)
--- if props then --- if props then
--- -- Manipulate vehicle properties --- -- Use vehicle properties
--- end --- end
--- ``` --- ```
function getVehicleProperties(vehicle) function getVehicleProperties(vehicle)
if not vehicle then return nil end
local properties = {} local properties = {}
if vehicle == nil then return nil end
if isStarted(QBExport) and not isStarted(QBXExport) then if isStarted(QBExport) and not isStarted(QBXExport) then
properties = Core.Functions.GetVehicleProperties(vehicle) properties = Core.Functions.GetVehicleProperties(vehicle)
debugPrint("^6Bridge^7: ^2Getting Vehicle Properties ^7[^6"..QBExport.."^7] - [^3"..vehicle.."^7] - [^3"..GetEntityModel(vehicle).."^7/^3"..properties.model.."^7] - [^3"..properties.plate.."^7]") debugPrint("^6Bridge^7: ^2Getting Vehicle Properties ^7[^6"..QBExport.."^7] - [^3"..vehicle.."^7] - [^3"..GetEntityModel(vehicle).."^7/^3"..properties.model.."^7] - [^3"..properties.plate.."^7]")
@@ -109,30 +115,28 @@ function getVehicleProperties(vehicle)
return properties return properties
end end
--- Sets the properties of a given vehicle. --- Sets the properties of a given vehicle if changes are detected.
--- It compares the current properties with the new ones and applies the update using the active framework.
--- ---
--- This function applies the provided properties to the vehicle using the active framework's functions or events. --- @param vehicle number The entity ID of the vehicle.
--- It first retrieves the current properties and checks for differences before applying the new ones. --- @param props table The new properties to apply.
--- ---
---@param vehicle number The entity ID of the vehicle. --- @usage
---@param props table The properties to set on the vehicle.
---
---@usage
--- ```lua --- ```lua
--- setVehicleProperties(vehicleEntity, newProperties) --- setVehicleProperties(vehicleEntity, newProperties)
--- ``` --- ```
function setVehicleProperties(vehicle, props) function setVehicleProperties(vehicle, props)
local oldProps = getVehicleProperties(vehicle)
if checkDifferences(vehicle, props) then if checkDifferences(vehicle, props) then
--if debugMode then debugDifferences(vehicle, props) end
if not DoesEntityExist(vehicle) then if not DoesEntityExist(vehicle) then
print(("Unable to set vehicle properties for '%s' (entity does not exist)"):format(vehicle)) print("Unable to set vehicle properties for '"..vehicle.."' (^1entity does not exist^7)")
end end
if isStarted(QBExport) and not isStarted(QBXExport) then if isStarted(QBExport) and not isStarted(QBXExport) then
Core.Functions.SetVehicleProperties(vehicle, props) Core.Functions.SetVehicleProperties(vehicle, props)
debugPrint("^6Bridge^7: ^2Setting Vehicle Properties ^7[^6"..QBExport.."^7] - [^3"..vehicle.."^7] - [^3"..GetEntityModel(vehicle).."^7/^3"..props.model.."^7] - [^3"..props.plate.."^7]") debugPrint("^6Bridge^7: ^2Setting Vehicle Properties ^7[^6"..QBExport.."^7] - [^3"..vehicle.."^7] - [^3"..GetEntityModel(vehicle).."^7/^3"..props.model.."^7] - [^3"..props.plate.."^7]")
else elseif isStarted(OXLibExport) then
TriggerServerEvent(getScript()..":ox:setVehicleProperties", VehToNet(vehicle), props) lib.setVehicleProperties(vehicle, props, false)
debugPrint("^6Bridge^7: ^2Setting Vehicle Properties ^7[^6"..OXLibExport.."^7] - [^3"..vehicle.."^7] - [^3"..GetEntityModel(vehicle).."^7/^3"..props.model.."^7] - [^3"..props.plate.."^7]")
end end
else else
debugPrint("^6Bridge^7: ^2No Changes Found ^7 [^3"..vehicle.."^7] - [^3"..GetEntityModel(vehicle).."^7/^3"..props.model.."^7] - [^3"..props.plate.."^7]") debugPrint("^6Bridge^7: ^2No Changes Found ^7 [^3"..vehicle.."^7] - [^3"..GetEntityModel(vehicle).."^7/^3"..props.model.."^7] - [^3"..props.plate.."^7]")
@@ -140,16 +144,13 @@ function setVehicleProperties(vehicle, props)
end end
--- Checks for differences between the current and new vehicle properties. --- Checks for differences between the current and new vehicle properties.
--- Compares properties using JSON encoding for deep comparison and logs differences.
--- ---
--- This function compares each property of the vehicle to determine if any changes have been made. --- @param vehicle number The entity ID of the vehicle.
--- It logs the differences for debugging purposes. --- @param newProps table The new properties to compare.
--- @return boolean `true` if differences are found; `false` otherwise.
--- ---
---@param vehicle number The entity ID of the vehicle. --- @usage
---@param newProps table The new properties to compare against the current ones.
---
---@return boolean `true` if differences are found, `false` otherwise.
---
---@usage
--- ```lua --- ```lua
--- if checkDifferences(vehicleEntity, newProperties) then --- if checkDifferences(vehicleEntity, newProperties) then
--- setVehicleProperties(vehicleEntity, newProperties) --- setVehicleProperties(vehicleEntity, newProperties)
@@ -158,58 +159,58 @@ end
function checkDifferences(vehicle, newProps) function checkDifferences(vehicle, newProps)
local oldProps = getVehicleProperties(vehicle) local oldProps = getVehicleProperties(vehicle)
debugPrint("^6Bridge^7: ^2Finding differences in ^3Vehicle Properties^7") debugPrint("^6Bridge^7: ^2Finding differences in ^3Vehicle Properties^7")
local allow = false local differencesFound = true
for k in pairs(oldProps) do for k in pairs(oldProps) do
if json.encode(oldProps[k]) ~= json.encode(newProps[k]) then if json.encode(oldProps[k]) ~= json.encode(newProps[k]) then
allow = true differencesFound = true
debugPrint("^6Bridge^7: ^5Old ^7[^3"..k.."^7] - "..json.encode(oldProps[k], { indent = true })) debugPrint("^6Bridge^7: ^5Old ^7[^3"..k.."^7] - "..json.encode(oldProps[k], { indent = true }))
debugPrint("^6Bridge^7: ^5New ^7[^3"..k.."^7] - "..json.encode(newProps[k], { indent = true })) debugPrint("^6Bridge^7: ^5New ^7[^3"..k.."^7] - "..json.encode(newProps[k], { indent = true }))
end end
end end
return allow
return differencesFound
end end
--- Handles setting vehicle properties received from the server. -------------------------------------------------------------
-- Vehicle Properties Synchronization
-------------------------------------------------------------
--- Event handler for setting vehicle properties received from the server.
--- Listens for the `ox:setVehicleProperties` event and applies the properties.
--- ---
--- This event listens for the `ox:setVehicleProperties` event and applies the received properties to the vehicle. --- @event `getScript()..ox:setVehicleProperties`
--- --- @param netId number The network ID of the vehicle.
---@event --- @param props table The new vehicle properties.
---@param netId number The network ID of the vehicle.
---@param props table The properties to set on the vehicle.
---
---@usage
--- -- Server-side: TriggerClientEvent(getScript()..":ox:setVehicleProperties", netId, properties)
RegisterNetEvent(getScript()..":ox:setVehicleProperties", function(netId, props) RegisterNetEvent(getScript()..":ox:setVehicleProperties", function(netId, props)
local vehicle = NetworkGetEntityFromNetworkId(netId) local vehicle = NetworkGetEntityFromNetworkId(netId)
local value = props local value = props
Entity(vehicle).state[getScript()..':setVehicleProperties'] = value Entity(vehicle).state[getScript()..':setVehicleProperties'] = value
end) end)
--- Handles state bag changes for setting vehicle properties. --- Handles state bag changes for updating vehicle properties.
--- When the state bag changes, the new properties are applied to the vehicle.
--- ---
--- This handler listens for changes to the vehicle's state bag and applies the new properties accordingly. --- @param bagName string The state bag's name.
--- --- @param key string The key that changed.
---@param bagName string The name of the state bag. --- @param value table The new state value.
---@param key string The key that changed.
---@param value table The new value of the state.
---
---@usage
--- -- Automatically handled when the state bag changes
AddStateBagChangeHandler(getScript()..':setVehicleProperties', '', function(bagName, _, value) AddStateBagChangeHandler(getScript()..':setVehicleProperties', '', function(bagName, _, value)
if not value or not GetEntityFromStateBagName then return end if not value or not GetEntityFromStateBagName then return end
local entity = GetEntityFromStateBagName(bagName) local entity = GetEntityFromStateBagName(bagName)
local networked = not bagName:find('localEntity') local networked = not bagName:find('localEntity')
debugPrint("^6Bridge^7: ^2Setting Vehicle Properties ^7[^6"..OXLibExport.."^7] - [^3"..entity.."^7] - [^3"..GetEntityModel(entity).."^7] - [^3"..value.plate.."^7]") debugPrint("^6Bridge^7: ^2Setting Vehicle Properties ^7[^6"..OXLibExport.."^7] - [^3"..entity.."^7] - [^3"..GetEntityModel(entity).."^7] - [^3"..value.plate.."^7]")
if networked and NetworkGetEntityOwner(entity) ~= cache.playerId then return end if networked then return end
if lib.setVehicleProperties(entity, value) then if lib.setVehicleProperties(entity, value) then
Entity(entity).state:set('setVehicleProperties', nil, true) Entity(entity).state:set('setVehicleProperties', nil, true)
end end
end) end)
--- Pushes a vehicle to other players by syncing it. -------------------------------------------------------------
--- -- Vehicle Control Functions
-------------------------------------------------------------
--- This function ensures that the vehicle is controlled by the current player and is set as a mission entity. --- This function ensures that the vehicle is controlled by the current player and is set as a mission entity.
--- It requests network control and sets the vehicle accordingly to synchronize changes across clients. --- It requests network control and sets the vehicle accordingly to synchronize changes across clients.
--- ---
@@ -222,6 +223,7 @@ end)
function pushVehicle(entity) function pushVehicle(entity)
SetVehicleModKit(entity, 0) SetVehicleModKit(entity, 0)
if entity ~= 0 and DoesEntityExist(entity) then if entity ~= 0 and DoesEntityExist(entity) then
-- Request network control if not already controlled.
if not NetworkHasControlOfEntity(entity) then if not NetworkHasControlOfEntity(entity) then
debugPrint("^6Bridge^7: ^3pushVehicle^7: ^2Requesting network control of vehicle^7.") debugPrint("^6Bridge^7: ^3pushVehicle^7: ^2Requesting network control of vehicle^7.")
NetworkRequestControlOfEntity(entity) NetworkRequestControlOfEntity(entity)
@@ -231,11 +233,13 @@ function pushVehicle(entity)
timeout = timeout - 100 timeout = timeout - 100
end end
if NetworkHasControlOfEntity(entity) then if NetworkHasControlOfEntity(entity) then
debugPrint("^6Bridge^7: ^3pushVehicle^7: ^2Network has control of entity^7.") debugPrint("^6Bridge^7: ^3pushVehicle^7: ^2Network now has control of the entity^7.")
end end
end end
-- Set as mission entity if not already set.
if not IsEntityAMissionEntity(entity) then if not IsEntityAMissionEntity(entity) then
debugPrint("^6Bridge^7: ^3pushVehicle^7: ^2Setting vehicle as a ^7'^2mission^7' &2entity^7.") debugPrint("^6Bridge^7: ^3pushVehicle^7: ^2Setting vehicle as a ^7'^2mission^7' ^2entity^7.")
SetEntityAsMissionEntity(entity, true, true) SetEntityAsMissionEntity(entity, true, true)
local timeout = 2000 local timeout = 2000
while timeout > 0 and not IsEntityAMissionEntity(entity) do while timeout > 0 and not IsEntityAMissionEntity(entity) do
@@ -248,3 +252,48 @@ function pushVehicle(entity)
end end
end end
end end
--- Finds the closest vehicle to the specified coordinates.
--- The function uses different APIs based on whether a source is provided.
---
--- @param coords table|vector3 (Optional) The reference coordinates. If nil, uses the player's position.
--- @param src boolean (Optional) If true, uses GetPlayerPed(source) and GetAllVehicles.
--- @return number|number closestVehicle|closestDistance The closest vehicle entity and its distance.
---
--- @usage
--- ```lua
--- local closestVeh, distance = getClosestVehicle({ x = 100, y = 200, z = 30 }, src)
--- ```
function getClosestVehicle(coords, src)
local ped, vehicles, closestDistance, closestVehicle
if src then
ped = GetPlayerPed(src)
vehicles = GetAllVehicles()
else
ped = PlayerPedId()
vehicles = GetGamePool('CVehicle')
end
local closestDistance, closestVehicle = -1, -1
if coords then
if type(coords) == 'table' then
coords = vec3(coords.x, coords.y, coords.z)
end
else
coords = GetEntityCoords(ped)
end
for i = 1, #vehicles, 1 do
local vehicleCoords = GetEntityCoords(vehicles[i])
local distance = #(vehicleCoords - coords)
if closestDistance == -1 or distance < closestDistance then
closestDistance = distance
closestVehicle = vehicles[i]
end
end
return closestVehicle, closestDistance
end

View File

@@ -1,47 +0,0 @@
-- Version check for jim_bridge --
function CheckBridgeVersion()
if isServer() then
local currentVersion = "^3"..GetResourceMetadata("jim_bridge", 'version'):gsub("%.", "^7.^3").."^7"
PerformHttpRequest('https://raw.githubusercontent.com/jimathy/jim_bridge/master/version.txt', function(err, newestVersion, headers)
if not newestVersion then print("^1Currently unable to run a version check for ^7'^3jim_bridge^7' ("..currentVersion.."^7)") return end
newestVersion = "^3"..newestVersion:sub(1, -2):gsub("%.", "^7.^3"):gsub("%\r", "").."^7"
print(newestVersion == currentVersion and "^7'^3jim_bridge^7' - ^6You are running the latest version.^7 ("..currentVersion..")" or "^7'^3jim_bridge^7' - ^1You are currently running an outdated version^7, ^1please update^7!")
end)
end
end
--CheckBridgeVersion()
-- Print Script names
function capitalize(str)
return (str:gsub("^%l", string.upper):gsub("%-%l", function(letter) return "-" .. string.upper(letter:sub(2)) end))
end
local scriptName = ("^2"..capitalize(getScript()):gsub("%-", "^7-^2"):gsub("%_", "^7_^2")) or ""
local scriptVersion = ("^5"..GetResourceMetadata(getScript(), 'version', nil):gsub("%.", "^7.^5")) or ""
local scriptDescription = ("^2"..GetResourceMetadata(getScript(), 'description', nil)) or ""
local scriptAuthor = ("^2by ^4"..GetResourceMetadata(getScript(), 'author', nil):gsub("%and", "^7and^4")) or ""
print(scriptName.." ^7v"..scriptVersion.."^7 - "..scriptDescription.." "..scriptAuthor.."^7")
-- Loaded script Version Check, requires CheckVersion() to be placed in a server file
function CheckVersion()
if isServer() then
local currentVersion = "^3"..GetResourceMetadata(getScript(), 'version'):gsub("%.", "^7.^3").."^7"
PerformHttpRequest('https://raw.githubusercontent.com/jimathy/UpdateVersions/master/'..getScript()..'.txt', function(err, newestVersion, headers)
if not newestVersion then
PerformHttpRequest('https://raw.githubusercontent.com/jimathy/'..getScript()..'/master/version.txt', function(err, freeVersion, headers)
if not freeVersion then print("^1Currently unable to run a version check for ^7'^3"..getScript().."^7' ("..currentVersion.."^7)") return end
local currentVersion = "^3"..GetResourceMetadata(getScript(), 'version'):gsub("%.", "^7.^3").."^7"
freeVersion = "^3"..freeVersion:sub(1, -2):gsub("%.", "^7.^3"):gsub("%\r", "").."^7"
print("^6Version Check^7: ^2Running^7: "..currentVersion.." ^2Latest^7: "..freeVersion)
print(freeVersion == currentVersion and "^7'^3"..getScript().."^7' - ^6You are running the latest version.^7 ("..currentVersion..")" or "^7'^3"..getScript().."^7' - ^1You are currently running an outdated version^7, ^1please update^7!")
end)
else
newestVersion = "^3"..newestVersion:sub(1, -2):gsub("%.", "^7.^3"):gsub("%\r", "").."^7"
print("^6Version Check^7: ^2Running^7: "..currentVersion.." ^2Latest^7: "..newestVersion)
print(newestVersion == currentVersion and '^6You are running the latest version.^7 ('..currentVersion..')' or "^1You are currently running an outdated version^7, ^1please update^7!")
end
end)
end
end
--CheckVersion()

View File

@@ -1,166 +1,21 @@
-- Phone Mails
--- Sends a phone mail using the detected phone system.
---
--- This function detects the active phone resource (e.g., gksphone, yflip-phone, qb-phone, etc.)
--- and sends a mail using the appropriate method for that phone system.
---
--- @param data table A table containing the mail data.
--- - **subject** (`string`): The subject of the email.
--- - **sender** (`string`): The sender of the email.
--- - **message** (`string`): The body content of the email.
--- - **actions** (`table|nil`): (Optional) Action buttons associated with the email.
---
--- @usage
--- ```lua
--- sendPhoneMail({
--- subject = "Welcome!",
--- sender = "Admin",
--- message = "Thank you for joining our server.",
--- actions = {
--- { label = "Reply", action = replyFunction }
--- }
--- })
--- ```
function sendPhoneMail(data) local phoneResource = ""
if isStarted("gksphone") then phoneResource = "gksphone"
exports["gksphone"]:SendNewMail(data)
elseif isStarted("yflip-phone") then phoneResource = "yflip-phone"
TriggerServerEvent(getScript()..":yflip:SendMail", data)
elseif isStarted("qs-smartphone") then phoneResource = "qs-smartphone"
TriggerServerEvent('qs-smartphone:server:sendNewMail', data)
elseif isStarted("qs-smartphone-pro") then phoneResource = "qs-smartphone-pro"
TriggerServerEvent('phone:sendNewMail', data)
elseif isStarted("roadphone") then phoneResource = "roadphone"
data.message = data.message:gsub("%<br>", "\n")
exports['roadphone']:sendMail(data)
elseif isStarted("lb-phone") then phoneResource = "lb-phone"
data.message = data.message:gsub("%<br>", "\n")
TriggerServerEvent(getScript()..":lbphone:SendMail", data)
elseif isStarted("qb-phone") then phoneResource = "qb-phone"
TriggerServerEvent('qb-phone:server:sendNewMail', data)
elseif isStarted("jpr-phonesystem") then phoneResource = "jpr-phonesystem"
TriggerServerEvent(getScript()..":jpr:SendMail", data)
end
if phoneResource ~= "" then debugPrint("^6Bridge^7[^3"..phoneResource.."^7]: ^2Sending mail to player")
else print("^6Bridge^7: ^1ERROR ^2Sending mail to player ^7 - ^2No supported phone found") end
end
--- Handles sending mail for lb-phone.
---
--- This event listens for the `lbphone:SendMail` event and sends an email using lb-phone's API.
---
--- @event
--- @param data table The mail data.
--- - **subject** (`string`): The subject of the email.
--- - **message** (`string`): The body content of the email.
--- - **buttons** (`table|nil`): (Optional) Action buttons associated with the email.
---
--- @usage
--- ```
--- -- Server-side:
--- TriggerClientEvent(getScript()..":lbphone:SendMail", data)
--- ```
RegisterNetEvent(getScript()..":lbphone:SendMail", function(data)
local src = source
local phoneNumber = exports["lb-phone"]:GetEquippedPhoneNumber(src)
local emailAddress = exports["lb-phone"]:GetEmailAddress(phoneNumber)
if data.actions then data.buttons = data.actions end
exports["lb-phone"]:SendMail({
to = emailAddress,
subject = data.subject,
message = data.message,
actions = data.buttons,
})
end)
--- Handles sending mail for yflip-phone.
---
--- This event listens for the `yflip:SendMail` event and sends an email using yflip-phone's API.
---
--- @event
--- @param data table The mail data.
--- - **subject** (`string`): The subject of the email.
--- - **sender** (`string`): The sender of the email.
--- - **message** (`string`): The body content of the email.
--- - **buttons** (`table|nil`): (Optional) Action buttons associated with the email.
---
--- @usage
--- ```lua
--- -- Server-side:
--- TriggerClientEvent(getScript()..":yflip:SendMail", data)
--- ```
RegisterNetEvent(getScript()..":yflip:SendMail", function(data)
local src = source
exports["yflip-phone"]:SendMail({
title = data.subject,
sender = data.sender,
senderDisplayName = data.sender,
content = data.message,
actions = data.buttons,
}, 'source', src)
end)
--- Handles sending mail for jpr-phonesystem.
---
--- This event listens for the `jpr:SendMail` event and sends an email using jpr-phonesystem's API.
---
--- @event
--- @param data table The mail data.
--- - **subject** (`string`): The subject of the email.
--- - **sender** (`string`): The sender of the email.
--- - **message** (`string`): The body content of the email.
--- - **buttons** (`table|nil`): (Optional) Action buttons associated with the email.
---
--- @return void
---
--- @usage
--- ```lua
--- -- Server-side:
--- TriggerClientEvent(getScript()..":jpr:SendMail", data)
--- ```
RegisterNetEvent(getScript()..":jpr:SendMail", function(data)
local src = source
local Player = Core.Functions.GetPlayer(src)
TriggerEvent('jpr-phonesystem:server:sendEmail', {
Assunto = data.subject, -- Subject
Conteudo = data.message, -- Content
Enviado = data.sender, -- Submitted by
Destinatario = Player.PlayerData.citizenid, -- Target
Event = {}, -- Optional
})
end)
-- Server-Side Functions for Registering Commands, Stashes, and Shops
--- Registers a command with the active command system. --- Registers a command with the active command system.
--- --- This function supports multiple command systems (OXLib, qb-core, ESX Legacy).
--- This function detects whether the server is using OXLib or qb-core for command registration
--- and registers the command accordingly.
--- ---
--- @param command string The name of the command to register. --- @param command string The name of the command to register.
--- @param options table A table containing command options. --- @param options table A table containing command options.
--- - **help** (`string`): The help description for the command. --- - help (`string`): The help description for the command.
--- - **params** (`table`): A table of parameters for the command. --- - params (`table`): A table of parameters for the command.
--- - **callback** (`function`): The function to execute when the command is called. --- - callback (`function`): The function to execute when the command is called.
--- - **autocomplete** (`function|nil`): (Optional) A function for autocompletion. --- - autocomplete (`function|nil`): (Optional) A function for autocompletion.
--- - **restrictedGroup** (`string|nil`): (Optional) The user group required to execute the command. --- - restrictedGroup (`string|nil`): (Optional) The user group required to execute the command.
--- ---
--- @usage --- @usage
--- ````lua --- ```lua
--- -- Server Side:
--- registerCommand("greet", { --- registerCommand("greet", {
--- "Greets the player", --- "Greets the player",
--- { name = "name", help = "Name of the player to greet" }, --- { name = "name", help = "Name of the player to greet" },
--- function(source, args) print("Hello, " .. args[1] .. "!") end, --- function(source, args) print("Hello, "..args[1].."!") end,
--- nil, --- nil,
--- "admin" --- "admin"
--- }) --- })
@@ -170,25 +25,35 @@ function registerCommand(command, options)
debugPrint("^6Bridge^7: ^2Registering ^3Command^2 with ^7"..OXLibExport, command) debugPrint("^6Bridge^7: ^2Registering ^3Command^2 with ^7"..OXLibExport, command)
lib.addCommand(command, { help = options[1], restricted = options[5] and "group."..options[5] or nil }, options[4]) lib.addCommand(command, { help = options[1], restricted = options[5] and "group."..options[5] or nil }, options[4])
elseif isStarted(QBExport) and not isStarted(QBXExport) then elseif isStarted(QBExport) and not isStarted(QBXExport) then
debugPrint("^6Bridge^7: ^2Registering ^3Command^2 with ^7 "..QBExport, command) debugPrint("^6Bridge^7: ^2Registering ^3Command^2 with ^7"..QBExport, command)
Core.Commands.Add(command, options[1], options[2], options[3], options[4], options[5] and options[5] or nil) Core.Commands.Add(command, options[1], options[2], options[3], options[4], options[5] or nil)
elseif isStarted(ESXExport) then
debugPrint("^6Bridge^7: ^2Registering ^3Command^2 with ^7ESX Legacy", command)
ESX.RegisterCommand(command, options[5] or 'admin', function(xPlayer, args, showError)
options[4](xPlayer.source, args, showError)
end, false, { help = options[1] })
end end
end end
--- Registers a stash with the active inventory system. --- Registers a stash with the active inventory system.
--- Supports either OXInv or QSInv.
--- ---
--- This function detects whether the server is using OXInv or QSInv and registers the stash accordingly. --- @param name string Unique stash identifier.
--- --- @param label string Display name for the stash.
--- @param name string The unique identifier for the stash. --- @param slots number|nil (Optional) Number of slots (default 50).
--- @param label string The display name for the stash. --- @param weight number|nil (Optional) Maximum weight (default 4000000).
--- @param slots number|nil (Optional) The number of slots in the stash. Defaults to 50. --- @param owner string|nil (Optional) Owner identifier for personal stashes.
--- @param weight number|nil (Optional) The maximum weight the stash can hold. Defaults to 4,000,000. --- @param coords table|nil (Optional) Coordinates for the stash location.
--- @param owner string|nil (Optional) The owner identifier for personal stashes.
--- @param coords table|nil (Optional) The coordinates for the stash location.
---
--- @usage --- @usage
--- ```lua --- ```lua
--- registerStash("playerStash", "Player Stash", 100, 8000000, "player123", { x = 100.0, y = 200.0, z = 30.0 }) --- registerStash(
--- "playerStash",
--- "Player Stash",
--- 100,
--- 8000000,
--- "player123",
--- { x = 100.0, y = 200.0, z = 30.0 }
--- )
--- ``` --- ```
function registerStash(name, label, slots, weight, owner, coords) function registerStash(name, label, slots, weight, owner, coords)
if isStarted(OXInv) then if isStarted(OXInv) then
@@ -196,65 +61,45 @@ function registerStash(name, label, slots, weight, owner, coords)
exports[OXInv]:RegisterStash(name, label, slots or 50, weight or 4000000, owner or nil) exports[OXInv]:RegisterStash(name, label, slots or 50, weight or 4000000, owner or nil)
elseif isStarted(QSInv) then elseif isStarted(QSInv) then
debugPrint("^6Bridge^7: ^2Registering ^3QS ^2Stash^7:", name, label) debugPrint("^6Bridge^7: ^2Registering ^3QS ^2Stash^7:", name, label)
exports[QSInv]:RegisterStash(name, slots or 50, weight or 4000000) exports[QSInv]:RegisterStash(nil, name, slots or 50, weight or 4000000)
--elseif isStarted(CoreInv) then
-- debugPrint("^6Bridge^7: ^2Registering ^3CoreInv ^2Stash^7:", name, label)
-- exports[CoreInv]:openHolder(nil, name, 'stash', nil, nil, false, nil)
elseif isStarted(OrigenInv) then
debugPrint("^6Bridge^7: ^2Registering ^3OrigenInv ^2Stash^7:", name, label)
exports["origen_inventory"]:registerStash(name, label, slots or 50, weight or 4000000)
end end
end end
--- Registers a shop with the active inventory system.
---
--- This function detects whether the server is using OXInv or QBInv and registers the shop accordingly.
---
--- @param name string The unique identifier for the shop.
--- @param label string The display name for the shop.
--- @param items table The list of items available in the shop.
--- @param society string|nil (Optional) The society identifier for shared shops.
---
--- @usage
--- ```lua
--- registerShop("weaponShop", "Weapon Shop", weaponItems, "society_weapons")
--- ```
function registerShop(name, label, items, society)
if isStarted(OXInv) then
debugPrint("^6Bridge^7: ^2Registering ^3OX ^2Store^7:", name, label)
exports[OXInv]:RegisterShop(
name, {
name = label,
inventory = items,
society = society,
}
)
elseif isStarted(QBInv) and QBInvNew then
debugPrint("^6Bridge^7: ^2Registering ^3QB ^2Store^7:", name, label)
print(json.encode(items, {indent = true}))
exports[QBInv]:CreateShop({
name = name,
label = label,
slots = #items,
items = items,
society = society,
})
end
end
-- Server-Side Event Registration
if isServer() then if isServer() then
--- Registers an event to create an OX stash from the server. --- Registers an event to create an OX stash from the server.
--- When triggered, it calls registerStash with the provided parameters.
--- ---
--- @event --- @event server:makeOXStash
--- @param name string The unique identifier for the stash. --- @param name string Unique stash identifier.
--- @param label string The display name for the stash. --- @param label string Display name for the stash.
--- @param slots number|nil (Optional) The number of slots in the stash. --- @param slots number|nil (Optional) Number of slots.
--- @param weight number|nil (Optional) The maximum weight the stash can hold. --- @param weight number|nil (Optional) Maximum weight.
--- @param owner string|nil (Optional) The owner identifier for personal stashes. --- @param owner string|nil (Optional) Owner identifier.
--- @param coords table|nil (Optional) The coordinates for the stash location. --- @param coords table|nil (Optional) Stash coordinates.
---
--- @usage --- @usage
--- ```lua --- ```lua
--- -- Server-side:
--- TriggerEvent(getScript()..":server:makeOXStash", name, label, slots, weight, owner, coords) --- TriggerEvent(getScript()..":server:makeOXStash", name, label, slots, weight, owner, coords)
--- ``` --- ```
RegisterNetEvent(getScript()..":server:makeOXStash", function(name, label, slots, weight, owner, coords) RegisterNetEvent(getScript()..":server:makeOXStash", function(name, label, slots, weight, owner, coords, token)
local src = source or nil
if src then
debugPrint("^1Auth^7: ^2Auth token received^7, ^2checking against server cache^7..")
if token ~= validTokens[src] then
debugPrint("^1Auth^7: ^1Tokens don't match! ^7", token, validTokens[src])
else
debugPrint("^1Auth^7: ^2Client and Server Auth tokens match^7!", token, validTokens[src])
validTokens[src] = nil
end
end
registerStash(name, label, slots, weight, owner, coords) registerStash(name, label, slots, weight, owner, coords)
end) end)
end end

View File

@@ -1,3 +1,5 @@
gameName = not IsDuplicityVersion() and GetCurrentGameName()
Exports = { Exports = {
QBExport = "qb-core", QBExport = "qb-core",
QBXExport = "qbx_core", QBXExport = "qbx_core",
@@ -17,28 +19,75 @@ Exports = {
QBMenuExport = "qb-menu", QBMenuExport = "qb-menu",
QBTargetExport = "qb-target", QBTargetExport = "qb-target",
OXTargetExport = "ox_target" OXTargetExport = "ox_target",
-- REDM
RSGExport = "rsg-core",
RSGInv = "rsg-inventory"
} }
-- Required variables -- Required variables
debugMode = Config.System.Debug debugMode = Config.System.Debug
-- Check server convars for hard set defaults
if Config and Config.System then
if Config.System.Debug then
if GetConvar("jim_DisableDebug", "false") == "true" then
debugMode = false
end
if GetConvar("jim_DisableEventDebug", "false") == "true" then
Config.System.EventDebug = false
end
end
Config.System.Menu = GetConvar("jim_menuScript", Config.System.Menu)
Config.System.Notify = GetConvar("jim_notifyScript", Config.System.Notify)
Config.System.ProgressBar = GetConvar("jim_progressBarScript", Config.System.ProgressBar)
Config.System.drawText = GetConvar("jim_drawTextScript", Config.System.drawText)
Config.System.skillCheck = GetConvar("jim_skillCheckScript", Config.System.skillCheck)
if GetConvar("jim_dontUseTarget", "false") == "true" then
Config.System.DontUseTarget = true
end
end
QBInvNew = true QBInvNew = true
InventoryWeight = 120000 InventoryWeight = 120000
-- Testing loading the core files here instead of in fxmanifests
--for k, v in pairs({ -- This is a specific load order
-- [Exports.OXLibExport] = "init.lua",
-- [Exports.OXCoreExport] = "lib/init.lua",
-- [Exports.ESXExport] = "imports.lua",
-- [Exports.QBXExport] = "modules/playerdata.lua",
--}) do
-- if GetResourceState(k) == "started" then
-- print("^5Loading^7: '"..k.."/"..v.."' ^2into ^7'"..GetCurrentResourceName().."' ...")
-- local fileLoader = assert(load(LoadResourceFile(k, (v)), ('@@'..k..'/'..v)))
-- fileLoader()
-- print("^2Success^7: ^2loaded ^1Core ^2file^7: ^3"..k.."^7/^3"..(v):gsub("/", "^7/^3"):gsub("%.lua", "^7.lua").."^7")
-- else
-- if debugMode then
-- print("^3Warning^7: ^3"..k.." ^2not found^7, ^2skipping")
-- end
-- end
--end
-- Load files here into the invoking script -- Load files here into the invoking script
for _, v in pairs({ -- This is a specific load order for _, v in pairs({ -- This is a specific load order
'helpers.lua', -- needs to be first 'helpers.lua', -- needs to be first
'_loaders.lua', '_loaders.lua',
'_eventDebug.lua', '_eventDebug.lua',
'coreloader.lua', -- needs to be second to load all core related stuff before everything else
'callback.lua', 'callback.lua',
'coreloader.lua', -- needs to be second to load all core related stuff before everything else
'duifunctions.lua', 'duifunctions.lua',
-- Native Scaleforms -- Native Scaleforms
'scaleforms/scaleform_basic.lua',
'scaleforms/bigMessageInstance.lua', 'scaleforms/bigMessageInstance.lua',
'scaleforms/countDownHandler.lua', 'scaleforms/countDownHandler.lua',
'scaleforms/debugScaleform.lua', 'scaleforms/debugScaleform.lua',
@@ -56,9 +105,13 @@ for _, v in pairs({ -- This is a specific load order
'wrapperfunctions.lua', 'wrapperfunctions.lua',
'polyZone.lua', 'polyZone.lua',
'inventories.lua',
'itemcontrol.lua', 'itemcontrol.lua',
'playerfunctions.lua', 'playerfunctions.lua',
'metaHandlers.lua',
'jobfunctions.lua', 'jobfunctions.lua',
'societybank.lua',
'phones.lua',
-- Interactions -- Interactions
'targets.lua', 'targets.lua',
@@ -66,9 +119,11 @@ for _, v in pairs({ -- This is a specific load order
'input.lua', 'input.lua',
'notify.lua', 'notify.lua',
'drawText.lua', 'drawText.lua',
'skillcheck.lua',
-- Crafting / Shops / Stashes -- Crafting / Shops / Stashes
'crafting.lua', 'crafting.lua',
'shops.lua',
'stashcontrol.lua', 'stashcontrol.lua',
-- Kind of "other" -- Kind of "other"
@@ -76,14 +131,16 @@ for _, v in pairs({ -- This is a specific load order
'scaleEntity.lua', 'scaleEntity.lua',
'vehicles.lua', 'vehicles.lua',
'effects.lua', 'effects.lua',
'versioncheck.lua'
-- Do version check last
'_scriptversioncheck.lua'
}) do }) do
if debugMode then if debugMode then
print("^5Loading^7: 'jim_bridge/shared/"..v.."' ^2into ^7'"..GetCurrentResourceName().."' ...") --print("^5Loading^7: 'jim_bridge/shared/"..v.."' ^2into ^7'"..GetCurrentResourceName().."' ...")
end end
local fileLoader = assert(load(LoadResourceFile('jim_bridge', ('shared/'..v)), ('@@jim_bridge/shared/'..v))) local fileLoader = assert(load(LoadResourceFile('jim_bridge', ('shared/'..v)), ('@@jim_bridge/shared/'..v)))
fileLoader() fileLoader()
if debugMode then if debugMode then
print("^5Success^7: ^2loaded file^7: 'jim_bridge/shared/"..v.."'!") print("^5Success^7: ^2loaded file^7: ^3"..(v):gsub("/", "^7/^3"):gsub("%.lua", "^7.lua").."^7")
end end
end end

View File

@@ -1 +1 @@
1.2 2.0.01