mirror of
https://github.com/jimathy/jim_bridge.git
synced 2026-08-17 05:56:02 +01:00
Move GTA notify, target, skillcheck to /ui_modules
I've separated the built-in custom native GTA Notifications, skillcheck and draw text targets to separate files to be loaded along side `jim_bridge`
This now makes it so they only load once instead of with every single script, and each one can call on it
This change also makes these systems able to be called outside of `jim_bridge`
For example in my test server I'm currently using:
```lua
function QBCore.Functions.Notify(text, texttype, length, icon)
CreateThread(function()
exports.jim_bridge:Notify(nil, text, icon)
end)
end
```
This commit is contained in:
@@ -194,7 +194,7 @@ function openMenu(Menu, data)
|
||||
exports[QBMenuExport]:openMenu(Menu)
|
||||
|
||||
elseif Config.System.Menu == "gta" then
|
||||
WarMenu.CreateMenu(tostring(Menu), data.header, data.headertxt or " ", {
|
||||
WarMenu.CreateMenu(tostring(Menu), data.header, " ", {
|
||||
titleColor = { 222, 255, 255 },
|
||||
maxOptionCountOnScreen = 15,
|
||||
width = 0.25,
|
||||
@@ -232,6 +232,7 @@ function openMenu(Menu, data)
|
||||
if pressed and not Menu[k].isMenuHeader then
|
||||
WarMenu.CloseMenu()
|
||||
close = false
|
||||
Wait(10)
|
||||
Menu[k].onSelect()
|
||||
end
|
||||
end
|
||||
|
||||
@@ -50,18 +50,10 @@ function triggerNotify(title, message, type, src)
|
||||
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
|
||||
if not src then
|
||||
exports.jim_bridge:Notify(title, message, type)
|
||||
else
|
||||
if not src then
|
||||
TriggerEvent(getScript()..":DisplayGTANotify", title, message)
|
||||
else
|
||||
TriggerClientEvent(getScript()..":DisplayGTANotify", src, title, message)
|
||||
end
|
||||
TriggerClientEvent("jim-bridge:Notify", src, title, message, type)
|
||||
end
|
||||
elseif Config.System.Notify == "esx" then
|
||||
if not src then
|
||||
@@ -116,25 +108,25 @@ end)
|
||||
--- ```lua
|
||||
--- TriggerEvent(getScript()..":DisplayGTANotify", "taxiname", "Taxi service has arrived.")
|
||||
--- ```
|
||||
RegisterNetEvent(getScript()..":DisplayGTANotify", function(title, text)
|
||||
local iconTable = {}
|
||||
if getScript() == "jim-npcservice" then
|
||||
iconTable = {
|
||||
[Loc[Config.Lan].notify["taxiname"]] = "CHAR_TAXI",
|
||||
[Loc[Config.Lan].notify["limoname"]] = "CHAR_CASINO",
|
||||
[Loc[Config.Lan].notify["ambiname"]] = "CHAR_CALL911",
|
||||
[Loc[Config.Lan].notify["pilotname"]] = "CHAR_DEFAULT",
|
||||
[Loc[Config.Lan].notify["planename"]] = "CHAR_BOATSITE2",
|
||||
[Loc[Config.Lan].notify["heliname"]] = "CHAR_BOATSITE2",
|
||||
}
|
||||
end
|
||||
|
||||
BeginTextCommandThefeedPost("STRING")
|
||||
AddTextComponentSubstringKeyboardDisplay(text)
|
||||
EndTextCommandThefeedPostMessagetext(
|
||||
iconTable[title] or "CHAR_DEFAULT",
|
||||
iconTable[title] or "CHAR_DEFAULT",
|
||||
true, 1, title, nil, text
|
||||
)
|
||||
EndTextCommandThefeedPostTicker(true, false)
|
||||
end)
|
||||
--RegisterNetEvent(getScript()..":DisplayGTANotify", function(title, text)
|
||||
-- local iconTable = {}
|
||||
-- if getScript() == "jim-npcservice" then
|
||||
-- iconTable = {
|
||||
-- [Loc[Config.Lan].notify["taxiname"]] = "CHAR_TAXI",
|
||||
-- [Loc[Config.Lan].notify["limoname"]] = "CHAR_CASINO",
|
||||
-- [Loc[Config.Lan].notify["ambiname"]] = "CHAR_CALL911",
|
||||
-- [Loc[Config.Lan].notify["pilotname"]] = "CHAR_DEFAULT",
|
||||
-- [Loc[Config.Lan].notify["planename"]] = "CHAR_BOATSITE2",
|
||||
-- [Loc[Config.Lan].notify["heliname"]] = "CHAR_BOATSITE2",
|
||||
-- }
|
||||
-- end
|
||||
--
|
||||
-- BeginTextCommandThefeedPost("STRING")
|
||||
-- AddTextComponentSubstringKeyboardDisplay(text)
|
||||
-- EndTextCommandThefeedPostMessagetext(
|
||||
-- iconTable[title] or "CHAR_DEFAULT",
|
||||
-- iconTable[title] or "CHAR_DEFAULT",
|
||||
-- true, 1, title, nil, text
|
||||
-- )
|
||||
-- EndTextCommandThefeedPostTicker(true, false)
|
||||
--end)
|
||||
@@ -30,127 +30,10 @@ function skillCheck(data)
|
||||
result = false
|
||||
end
|
||||
elseif Config.System.skillCheck == "gta" then
|
||||
loadTextureDict("timerbars")
|
||||
local successes = 0
|
||||
local barsRequired = 3
|
||||
exports.jim_bridge:skillCheck()
|
||||
|
||||
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
|
||||
@@ -20,24 +20,7 @@
|
||||
-------------------------------------------------------------
|
||||
-- Utility Data & Tables
|
||||
-------------------------------------------------------------
|
||||
---
|
||||
local KEY_TABLE = { 38, 29, 47, 23, 45, 159, 162, 163 }
|
||||
|
||||
-- Mapping of key codes to human-readable key names.
|
||||
local Keys = {
|
||||
[322] = "ESC", [288] = "F1", [289] = "F2", [170] = "F3", [166] = "F5",
|
||||
[167] = "F6", [168] = "F7", [169] = "F8", [56] = "F9", [57] = "F10",
|
||||
[243] = "~", [157] = "1", [158] = "2", [160] = "3", [164] = "4", [165] = "5",
|
||||
[159] = "6", [161] = "7", [162] = "8", [163] = "9", [84] = "-", [83] = "=",
|
||||
[177] = "BACKSPACE", [37] = "TAB",
|
||||
[44] = "Q", [32] = "W", [38] = "E", [45] = "R", [245] = "T", [246] = "Y",
|
||||
[303] = "U", [199] = "P",
|
||||
[39] = "[", [40] = "]", [18] = "ENTER", [137] = "CAPS",
|
||||
[34] = "A", [8] = "S", [9] = "D", [23] = "F", [47] = "G",
|
||||
[74] = "H", [311] = "K", [182] = "L", [21] = "LEFTSHIFT",
|
||||
[20] = "Z", [73] = "X", [26] = "C", [0] = "V", [29] = "B", [249] = "N",
|
||||
[244] = "M", [82] = ",", [81] = "."
|
||||
}
|
||||
|
||||
-- Tables for storing created targets for the fallback system and zone management.
|
||||
local TextTargets = {} -- For fallback DrawText3D targets.
|
||||
@@ -82,38 +65,9 @@ function createEntityTarget(entity, opts, dist)
|
||||
|
||||
-- Fallback: Use DrawText3D if targeting systems are disabled or unavailable.
|
||||
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
|
||||
for _, target in pairs(TextTargets) do
|
||||
if #(target.coords - entityCoords) < 0.01 then
|
||||
existingTarget = target
|
||||
break
|
||||
end
|
||||
end
|
||||
debugPrint("^6Bridge^7: ^2Creating new ^3Entity ^2target with ^6"..OXTargetExport.." ^2for entity ^7"..entity)
|
||||
exports.jim_bridge:createEntityTarget(entity, opts, dist)
|
||||
|
||||
if existingTarget then
|
||||
for i = 1, #opts do
|
||||
local key = KEY_TABLE[#existingTarget.options + i]
|
||||
opts[i].key = key
|
||||
existingTarget.buttontext[#existingTarget.buttontext + 1] = " ~b~[~w~" .. Keys[key] .. "~b~] ~w~" .. opts[i].label
|
||||
existingTarget.options[#existingTarget.options + 1] = opts[i]
|
||||
end
|
||||
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[entity] = {
|
||||
coords = vec3(entityCoords.x, entityCoords.y, entityCoords.z),
|
||||
buttontext = tempText,
|
||||
options = opts,
|
||||
dist = dist,
|
||||
text = table.concat(tempText, "\n")
|
||||
}
|
||||
end
|
||||
elseif isStarted(OXTargetExport) then
|
||||
debugPrint("^6Bridge^7: ^2Creating new ^3Entity ^2target with ^6"..OXTargetExport.." ^2for entity ^7"..entity)
|
||||
local options = {}
|
||||
@@ -129,10 +83,12 @@ function createEntityTarget(entity, opts, dist)
|
||||
}
|
||||
end
|
||||
exports[OXTargetExport]:addLocalEntity(entity, options)
|
||||
|
||||
elseif isStarted(QBTargetExport) then
|
||||
debugPrint("^6Bridge^7: ^2Creating new ^3Entity ^2target with ^6"..QBTargetExport.." ^2for entity ^7"..entity)
|
||||
local options = { options = opts, distance = dist }
|
||||
exports[QBTargetExport]:AddTargetEntity(entity, options)
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
@@ -192,37 +148,8 @@ end
|
||||
function createBoxTarget(data, opts, dist)
|
||||
if Config.System.DontUseTarget or (not isStarted(OXTargetExport) and not isStarted(QBTargetExport)) then
|
||||
debugPrint("^6Bridge^7: ^2Creating new ^3Box^2 target with ^6DrawText ^2 for zone ^7"..data[1])
|
||||
local existingTarget = nil
|
||||
for _, target in pairs(TextTargets) do
|
||||
if #(target.coords - data[2]) < 0.01 then
|
||||
existingTarget = target
|
||||
break
|
||||
end
|
||||
end
|
||||
return exports.jim_bridge:createZoneTarget(data, opts, dist)
|
||||
|
||||
if existingTarget then
|
||||
for i = 1, #opts do
|
||||
local key = KEY_TABLE[#existingTarget.options + i]
|
||||
opts[i].key = key
|
||||
existingTarget.buttontext[#existingTarget.buttontext + 1] = " ~b~[~w~" .. Keys[key] .. "~b~] ~w~" .. opts[i].label
|
||||
existingTarget.options[#existingTarget.options + 1] = opts[i]
|
||||
end
|
||||
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
|
||||
debugPrint("^6Bridge^7: ^2Creating new ^3Box^2 target with ^6"..OXTargetExport.." ^2for zone ^7"..data[1])
|
||||
local options = {}
|
||||
@@ -250,12 +177,14 @@ function createBoxTarget(data, opts, dist)
|
||||
})
|
||||
boxTargets[#boxTargets + 1] = target
|
||||
return target
|
||||
|
||||
elseif isStarted(QBTargetExport) then
|
||||
debugPrint("^6Bridge^7: ^2Creating new ^3Box^2 target with ^6"..QBTargetExport.." ^2for zone ^7"..data[1])
|
||||
local options = { options = opts, distance = dist }
|
||||
local target = exports[QBTargetExport]:AddBoxZone(data[1], data[2], data[3], data[4], data[5], options)
|
||||
boxTargets[#boxTargets + 1] = target
|
||||
return data[1]
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
@@ -298,37 +227,8 @@ end
|
||||
function createCircleTarget(data, opts, dist)
|
||||
if Config.System.DontUseTarget then
|
||||
debugPrint("^6Bridge^7: ^2Creating new ^3Circle ^2target with ^6DrawText ^2for zone ^7"..data[1])
|
||||
local existingTarget = nil
|
||||
for _, target in pairs(TextTargets) do
|
||||
if #(target.coords - data[2]) < 0.01 then
|
||||
existingTarget = target
|
||||
break
|
||||
end
|
||||
end
|
||||
return exports.jim_bridge:createZoneTarget(data, opts, dist)
|
||||
|
||||
if existingTarget then
|
||||
for i = 1, #opts do
|
||||
local key = KEY_TABLE[#existingTarget.options + i]
|
||||
opts[i].key = key
|
||||
existingTarget.buttontext[#existingTarget.buttontext + 1] = " ~b~[~w~" .. Keys[key] .. "~b~] ~w~" .. opts[i].label
|
||||
existingTarget.options[#existingTarget.options + 1] = opts[i]
|
||||
end
|
||||
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
|
||||
debugPrint("^6Bridge^7: ^2Creating new ^3Circle ^2target with ^6"..OXTargetExport.." ^2for zone ^7"..data[1])
|
||||
local options = {}
|
||||
@@ -387,30 +287,8 @@ end
|
||||
---```
|
||||
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
|
||||
return exports.jim_bridge:createModelTarget(models, opts, dist)
|
||||
|
||||
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 = {}
|
||||
@@ -453,7 +331,7 @@ function removeEntityTarget(entity)
|
||||
exports[OXTargetExport]:removeLocalEntity(entity, nil)
|
||||
end
|
||||
if Config.System.DontUseTarget or (not isStarted(OXTargetExport) and not isStarted(QBTargetExport)) then
|
||||
TextTargets[entity] = nil
|
||||
exports.jim_bridge:removeEntityTarget(entity)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -474,7 +352,7 @@ function removeZoneTarget(target)
|
||||
exports[OXTargetExport]:removeZone(target, true)
|
||||
end
|
||||
if Config.System.DontUseTarget or (not isStarted(OXTargetExport) and not isStarted(QBTargetExport)) then
|
||||
TextTargets[target] = nil
|
||||
exports.jim_bridge:removeZoneTarget(target)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -494,7 +372,7 @@ function removeModelTarget(model)
|
||||
exports[OXTargetExport]:removeModel(model, nil)
|
||||
end
|
||||
if Config.System.DontUseTarget or (not isStarted(OXTargetExport) and not isStarted(QBTargetExport)) then
|
||||
TextTargets[entity] = nil
|
||||
exports.jim_bridge:removeZoneTarget(target)
|
||||
end
|
||||
end
|
||||
-------------------------------------------------------------
|
||||
|
||||
Reference in New Issue
Block a user