Create easy to use prompts for your REDM resource.
Example
Notes
The order of created prompts is the order of showing them (top to bottom).
If you show multiple groups at the same time then pages/tabs are created automatically.
If you use multiple keys per prompt then hold/hold complete modes are not supported.
Consider how many pages/tabs are able to shown at the same time by the client.
Consider how many prompts per page/tab are able to shown at the same time by the client.
If your resource stops or restarts all groups and prompts are automatically destroyed.
Per default prompt groups are not shown during the player is dead. You can change this with showOnDeath().
-------------------------------------------------------------------------------- Step 1: Get Prompts API---------------------------------------------------------------------------------@typeNssLibsPromptsApilocal prompts_api = exports.nss_libs:getPromptsApi(GetCurrentResourceName())-------------------------------------------------------------------------------- Step 2: Create a group (page/tab) of prompts---------------------------------------------------------------------------------@typeNssLibsPromptsGroupApilocal group = prompts_api.createGroup('GROUP_LABEL')-------------------------------------------------------------------------------- Step 3A: Create Prompt with one key------------------------------------------------------------------------------local SPACEBAR =0xD9D0E1C0---@typeNssLibsPromptsPromptApilocal prompt_spacebar = group.addJustPressedPrompt('PROMPT_LABEL', SPACEBAR, function()print('Spacebar just pressed')-- DO YOUR STUFF HEREend)-------------------------------------------------------------------------------- Step 3B: Create Prompt with multiple keys------------------------------------------------------------------------------local KEY_LEFT =0xA65EBAB4local KEY_RIGHT =0xDEB34313---@typeNssLibsPromptsPromptApilocal prompt_left_right = group.addJustPressedPrompt('PROMPT_LABEL', KEY_LEFT, function()print('Left just pressed')-- DO YOUR STUFF HEREend)prompt_left_right:addKey(KEY_RIGHT, function()print('Right just pressed')-- DO YOUR STUFF HEREend)-------------------------------------------------------------------------------- Step 3C: Create Prompt with on-press and on-release callbacks-------------------------------------------------------------------------------- This example works only with addJustPressedPrompt, addPressedPrompt,-- addStandardHoldPrompt, addStandardizedHoldPrompt and only safe for single key prompts.local KEY_DOWN =0x05CA7C52localon_press=function()print('Down key pressed')-- DO YOUR STUFF HEREendlocalon_release=function()print('Down key released')-- DO YOUR STUFF HEREend---@typeNssLibsPromptsPromptApilocal prompt_down = group.addJustPressedPrompt('PROMPT_LABEL', KEY_DOWN, on_press, on_release)-------------------------------------------------------------------------------- Step 4: Show the group ;)------------------------------------------------------------------------------group.show()
Methods
exports.nss_libs:getPromptsApi(resource_name)
Returns a prompts API NssLibsPromptsApi for the given resource.
resource_name - The name of the resource that wants to use the API.
NssLibsPromptsApi
.createGroup(label)
Returns a group API NssLibsPromptsGroupApi.
label - The label of the group.
.setLinkChunkModeNearest()
Affects only NssLibsPromptsGroupApi.linkToCoords.
Sets the reaction mode for chunk grid linked prompt groups to nearest. Only the nearest result will be shown.
Returns NssLibsPromptsApi.
.setLinkChunkModeAll()
Affects only NssLibsPromptsGroupApi.linkToCoords.
Sets the reaction mode for chunk grid linked prompt groups to all. All results will be shown.
This is the default mode.
Returns NssLibsPromptsApi.
colors (table)
Table of color functions. Each function has an optional str attribute. If str is not given only the color code will be returned.
release_callback (optional) - Change the behaviour: If set then the callback will be fired if key is pressed like an on press event and release_callback is fired if key is released.
.addJustReleasedPrompt(label, key, callback)
Like addJustPressedPrompt but executes the callback if the key is just released.
Like addJustPressedPrompt but executes the callback repeatedly while the button has been pressed since the start pressing if no release_callback is set.
If the release_callback is set then the callback will be fired only once after the button indicator is filled (like a press event with delay to prevent press by mistake). If you want this behaviour and do not want to use the release_callback for actions then use an empty function for release_callback, see example:
Important If you use multiple keys per prompt then "hold"/"hold complete" modes are not supported.
sensitivity_in_meters (float) - The sensitivity in meters for movement measuring. Default is 0.005.
Note: The sensitivity is measured in all axis (x, y, z). So if the player stands in water or floats in the water then it is possible that a movement is detected if the player goes up and down by the waves of the water. In this case set the sensitivity to a higher value.
Note: This affects all current and future prompts of the group.
Returns NssLibsPromptsGroupApi.
.allowDuringHogtied() / .forbidDuringHogtied()
Allows/forbids all prompts of the group to be shown while player is hogtied.
Note: This affects only existing prompts during the call. If you add new prompts after the call then the new prompts are not affected by this call.
Returns NssLibsPromptsGroupApi.
.setAllPromptsToStandardRestrictionsOnFoot()
Set standard restrictions for all prompts of the group while player is on foot.
Note: This affects only existing prompts during the call. If you add new prompts after the call then the new prompts are not affected by this call.
Returns NssLibsPromptsGroupApi.
.showOnMovement() / .hideOnMovement()
New since version 0.30.0
Show (default) / hides the group if it is usually visible and the player moves.
Note: This affects all current and future prompts of the group.
Returns NssLibsPromptsGroupApi.
.isHideOnMovement()
New since version 0.30.0
Returns true if the group should be hidden if it is usually visible but the player moves.
release_callback (optional) - Change the behaviour: If set then the callback will be fired if key is pressed line an on press event and release_callback is fired if key is released. Works only for specific prompt types, see NssLibsPromptsGroupApi for more information.
Important If you use multiple keys per prompt then hold/hold complete modes are not supported.
Returns NssLibsPromptsPromptApi.
.setLabel(label)
Sets the label of the prompt.
label - The label of the prompt.
Returns NssLibsPromptsPromptApi.
.enable()
Enables the prompt. This is the default state.
Returns NssLibsPromptsPromptApi.
.disable()
Disables the prompt.
Returns NssLibsPromptsPromptApi.
.show()
Shows the prompt. This is the default state.
Returns NssLibsPromptsPromptApi.
.hide()
Hides the prompt.
Returns NssLibsPromptsPromptApi.
.destroy()
Destroys the prompt. This prompt is never usable again.
.allowOnMount() / .forbidOnMount()
Allows/forbids the prompt to be shown while player is mounted.
Returns NssLibsPromptsPromptApi.
.allowInWater() / .forbidInWater()
Allows/forbids the prompt to be shown while player is in water.
Returns NssLibsPromptsPromptApi.
.allowInVehicle() / .forbidInVehicle()
Allows/forbids the prompt to be shown while player is in vehicle.
Returns NssLibsPromptsPromptApi.
.allowOnFloor() / .forbidOnFloor()
Allows/forbids the prompt to be shown while player is on floor.
Returns NssLibsPromptsPromptApi.
.allowInAir() / .forbidInAir()
Allows/forbids the prompt to be shown while player is in air.
Returns NssLibsPromptsPromptApi.
.allowDuringDeath() / .forbidDuringDeath()
Allows/forbids the prompt to be shown while player is dead.
Returns NssLibsPromptsPromptApi.
.allowDuringMovement() / .forbidDuringMovement()
Allows/forbids the prompt to be shown while player is moving.
Returns NssLibsPromptsPromptApi.
.allowDuringHogtied() / .forbidDuringHogtied()
Allows/forbids the prompt to be shown while player is hogtied.
Returns NssLibsPromptsPromptApi.
NssLibsPromptsLinkerGroupToCoordsApi
.activate()
Activates the linker.
Returns NssLibsPromptsLinkerGroupToCoordsApi.
.deactivate()
Deactivates the linker. This is the default state.
Returns NssLibsPromptsLinkerGroupToCoordsApi.
.isActive()
Returns true if the linker is active.
.destroy()
Destroy (removes) the link between group and coords.
Named keys
Instead of key hashes you can use key names since version v0.26.1 of nss_libs. The following key names are available:
All alphabetical characters except K, N, T, Y, Ü, Ö, Ä, and ß
1, 2, 3, 4, 5, 6, 7, 8
RIGHTBRACKET, LEFTBRACKET
MOUSE1, MOUSE2, MOUSE3, MWUP
CTRL, TAB, SHIFT, LALT
SPACEBAR, ENTER, BACKSPACE, DEL
PGUP, PGDN
F1, F4, F6
DOWN, UP, LEFT, RIGHT
Note: Sometimes keys not working as expected. This is a limitation of the game. In other cases the keys are used by other resources.
Dev notes
UiPromptHasHoldModeCompleted is currently tricky. It fires during the hold mode is fulfilled. But this is not so good if we have to check if the hold mode is fulfilled and when it was released after hold. So two callbacks, one for "hold started" and one for "hold stopped", are good.
---------------------------------------------------------------------------------------------
-- Delayed press event example
---------------------------------------------------------------------------------------------
local SPACEBAR = 0xD9D0E1C0
local callback = function()
print('Spacebar pressed after delay')
-- DO YOUR STUFF HERE
end
local release_callback = function()
-- Do nothing
end
---@type NssLibsPromptsPromptApi
local prompt_spacebar = group.addStandardHoldPrompt('PROMPT_LABEL', SPACEBAR, callback, release_callback)
------------------------------------------------------------------------------
-- Step 1-3: Get API and create group and prompt
------------------------------------------------------------------------------
---@type NssLibsPromptsApi
local prompts_api = exports.nss_libs:getPromptsApi(GetCurrentResourceName())
---@type NssLibsPromptsGroupApi
local group = prompts_api.createGroup('GROUP_LABEL')
local SPACEBAR = 0xD9D0E1C0
---@type NssLibsPromptsPromptApi
local prompt_spacebar = group.addJustPressedPrompt('PROMPT_LABEL', SPACEBAR, function()
print('Spacebar just pressed')
-- DO YOUR STUFF HERE
end)
------------------------------------------------------------------------------
-- Step 4: Link to coords
------------------------------------------------------------------------------
local x = 0.0
local y = 0.0
local z = 0.0
local radius = 2.0
---@type NssLibsPromptsLinkerGroupToCoordsApi
local linker_api = group.linkToCoords(x, y, z, radius)
------------------------------------------------------------------------------
-- Step 5: Activate link
------------------------------------------------------------------------------
linker_api.activate()
------------------------------------------------------------------------------
-- Step 1-3: Get API and create group and prompt
------------------------------------------------------------------------------
---@type NssLibsPromptsApi
local prompts_api = exports.nss_libs:getPromptsApi(GetCurrentResourceName())
---@type NssLibsPromptsGroupApi
local group = prompts_api.createGroup('GROUP_LABEL')
local SPACEBAR = 0xD9D0E1C0
---@type NssLibsPromptsPromptApi
local prompt_spacebar = group.addJustPressedPrompt('PROMPT_LABEL', SPACEBAR, function()
print('Spacebar just pressed')
-- DO YOUR STUFF HERE
end)
------------------------------------------------------------------------------
-- Step 4: Link to entity
------------------------------------------------------------------------------
local entity_id = 12 -- Example entity
local radius = 2.0
-- Optional callback
-- Sometimes entity ids changes because entity was out of sight, so this callback injects the current entity id.
local inject_entity_id_cb = function()
-- You can inject the entity id here
return 14 -- Example of changed entity id
end
---@type NssLibsPromptsLinkerGroupToCoordsApi
local linker_api = group.linkToEntity(entity_id, radius, inject_entity_id_cb)
------------------------------------------------------------------------------
-- Step 5: Activate link
------------------------------------------------------------------------------
linker_api.activate()
------------------------------------------------------------------------------
-- Step 1-3: Get API and create group and prompt
------------------------------------------------------------------------------
---@type NssLibsPromptsApi
local prompts_api = exports.nss_libs:getPromptsApi(GetCurrentResourceName())
---@type NssLibsPromptsGroupApi
local group = prompts_api.createGroup('GROUP_LABEL')
local SPACEBAR = 0xD9D0E1C0
---@type NssLibsPromptsPromptApi
local prompt_spacebar = group.addJustPressedPrompt('PROMPT_LABEL', SPACEBAR, function()
print('Spacebar just pressed')
-- DO YOUR STUFF HERE
end)
------------------------------------------------------------------------------
-- Step 4: Link to entity models
------------------------------------------------------------------------------
local entity_herbs_model_hashes = { 477619010, 85102137, -1707502213 } -- Some bushes
local radius = 2.0
---@type NssLibsPromptsLinkerGroupToCoordsApi
local linker_api = group.linkToEntityModels(entity_herbs_model_hashes, radius)
------------------------------------------------------------------------------
-- Step 5: Activate link
------------------------------------------------------------------------------
linker_api.activate()
group.forbidDuringMovement() -- Enables the prompts only on stand still
group.setMovementDetectionSensitivity(0.5) -- Set the movement sensitivity to 0.5 meters. If the player moves more than 0.5 meters in any direction then the prompts are disabled.