A utility module for handling prompt interactions, specifically designed to manage hold-mode prompt completions with automatic disabling and re-enabling.
Overview
The PromptHelper provides utilities for safely handling prompt interactions, particularly for hold-mode prompts. It includes built-in safeguards to prevent prompt spam and ensures proper state management.
local promptId = PromptBuilder:new()
:setText("Hold to interact")
:setControl(`INPUT_CONTEXT`)
:setMode('Hold', 2000)
:build()
-- In your main loop
if promptHelper:hasPromptHoldModeCompleted(promptId) then
-- Action was completed
print("Player completed the hold interaction!")
-- Perform your action here
end
-- Disable for 5 seconds after completion
if promptHelper:hasPromptHoldModeCompleted(promptId, 5000) then
-- Long action that takes time
TriggerServerEvent('perform:long:action')
end
-- Disable for half a second for quick actions
if promptHelper:hasPromptHoldModeCompleted(quickPromptId, 500) then
-- Quick action
DoSomethingQuick()
end
local tick = scheduler:setTick(function()
-- Check multiple prompts
if promptHelper:hasPromptHoldModeCompleted(doorPrompt, 1500) then
OpenDoor()
end
if promptHelper:hasPromptHoldModeCompleted(shopPrompt, 2000) then
TriggerEvent('shop:open')
end
if promptHelper:hasPromptHoldModeCompleted(vehiclePrompt) then
-- Uses default 1000ms disable time
EnterVehicle()
end
end)
local barbershopPrompt = PromptBuilder:new()
:setText("Hold to use barbershop")
:setControl(`INPUT_CONTEXT`)
:setMode('Hold', 2000)
:setPoint(barbershopCoords)
:setRadius(2.0)
:build()
local tick = scheduler:setTick(function()
if promptHelper:hasPromptHoldModeCompleted(barbershopPrompt, 3000) then
-- Animate to chair
animToSeatOnChair(GetEntityCoords(PlayerPedId()))
-- Wait for animation to complete
CreateThread(function()
while not Citizen.InvokeNative(0xAA135F9482C82CC3, PlayerPedId(), `PROP_PLAYER_BARBER_SEAT`) do
Wait(100)
end
-- Open barbershop menu
TriggerEvent("appearance:shop:menu", "barbershop")
end)
end
-- Display the prompt group
PromptSetActiveGroupThisFrame(promptGroupId, CreateVarString(10, 'LITERAL_STRING', "Barbershop"))
end)
-- For quick actions (0.5-1 second)
promptHelper:hasPromptHoldModeCompleted(quickActionPrompt, 500)
-- For normal actions (1-2 seconds)
promptHelper:hasPromptHoldModeCompleted(normalPrompt, 1000)
-- For slow actions like animations (2+ seconds)
promptHelper:hasPromptHoldModeCompleted(animationPrompt, 3000)
local tick = scheduler:setTick(function()
if promptHelper:hasPromptHoldModeCompleted(promptId) then
-- Perform action
PerformAction()
-- Optionally clear the tick if one-time use
scheduler:clearTick(tick)
end
end)
local isProcessing = false
if not isProcessing and promptHelper:hasPromptHoldModeCompleted(promptId, 2000) then
isProcessing = true
-- Perform long-running action
CreateThread(function()
DoLongAction()
Wait(5000)
isProcessing = false
end)
end