From 088c2e094a91d8c87d9f628efe584d3d1c527115 Mon Sep 17 00:00:00 2001 From: Matin <22664859+MatinHQ@users.noreply.github.com> Date: Tue, 8 Aug 2023 14:26:06 +0330 Subject: [PATCH] feat(web/skillcheck): ability to cancel skillcheck (#364) * - (FEAT) Added feature to cancel skillcheck - (FEAT) Added feature to check is any active skillcheck * - Fix hiding UI * - return actual boolean * - Fix focus does not reset properly * Update skillcheck wrappers --- package/client/resource/interface/skillcheck.ts | 4 ++++ resource/interface/client/skillcheck.lua | 13 +++++++++++++ web/src/features/skillcheck/index.tsx | 5 +++++ 3 files changed, 22 insertions(+) diff --git a/package/client/resource/interface/skillcheck.ts b/package/client/resource/interface/skillcheck.ts index cbb5e5b..ddce631 100644 --- a/package/client/resource/interface/skillcheck.ts +++ b/package/client/resource/interface/skillcheck.ts @@ -2,3 +2,7 @@ type SkillCheckDifficulty = 'easy' | 'medium' | 'hard' | { areaSize: number; spe export const skillCheck = (difficulty: SkillCheckDifficulty | SkillCheckDifficulty[], inputs?: string[]) => exports.ox_lib.skillCheck(difficulty); + +export const skillCheckActive = (): boolean => exports.ox_lib.skillCheckActive(); + +export const cancelSkillCheck = (): void => exports.ox_lib.cancelSkillCheck(); \ No newline at end of file diff --git a/resource/interface/client/skillcheck.lua b/resource/interface/client/skillcheck.lua index b33064d..a7f3908 100644 --- a/resource/interface/client/skillcheck.lua +++ b/resource/interface/client/skillcheck.lua @@ -22,6 +22,19 @@ function lib.skillCheck(difficulty, inputs) return Citizen.Await(skillcheck) end +function lib.cancelSkillCheck() + if not skillcheck then + error('No skillCheck is active') + end + + SendNUIMessage({action = 'skillCheckCancel'}) +end + +---@return boolean +function lib.skillCheckActive() + return skillcheck ~= nil +end + RegisterNUICallback('skillCheckOver', function(success, cb) cb(1) diff --git a/web/src/features/skillcheck/index.tsx b/web/src/features/skillcheck/index.tsx index 6760b56..1452360 100644 --- a/web/src/features/skillcheck/index.tsx +++ b/web/src/features/skillcheck/index.tsx @@ -80,6 +80,11 @@ const SkillCheck: React.FC = () => { setVisible(true); }); + useNuiEvent('skillCheckCancel', () => { + setVisible(false); + fetchNui('skillCheckOver', false); + }); + const handleComplete = (success: boolean) => { if (!dataRef.current) return; if (!success || !Array.isArray(dataRef.current.difficulty)) {