LibertyCode
LibertyCode
  • Welcome
  • lc_adminmenu
    • Introduction
    • Installation
    • Avatars
    • Screenshots
    • Bridge
      • Server
      • Client
    • Player functions
    • Permissions
      • Permission Groups
      • Discord Permissions
    • Exports
Powered by GitBook
On this page
  1. lc_adminmenu

Player functions

PreviousClientNextPermissions

Last updated 4 months ago

  • label: string

  • permission?: string - Optional permission name

  • args?: table - Example below

  • onClick: fun(player)

Since version 1.5.0 you can add arguments to player actions, here is an example:

bridge/[your framework]/player_actions/actions_list.lua
---@class PlayerAction
---@field label string
---@field permission? string
---@field args? PlayerActionArgument[]
---@field onClick fun(player, args)

---@class PlayerActionArgument
---@field label? string
---@field placeholder? string Only for "text" inputs
---@field type 'text' | 'number' | 'range'
---@field value? string | number You can set default value
---@field min? number
---@field max? number
---@field step? number Only for "range" inputs

---@type PlayerAction[]
return {
  ...,
  {
    label = 'Give Item',
    permission = 'give_item',
    args = {
      {
        label = 'Item name',
        placeholder = 'bread',
        type = 'text'
      },
      {
        label = 'Amount',
        type = 'range',
        value = 1,
        min = 1,
        max = 250
      }
    },
    onClick = function(player, args)
      --[[
        args[1] - Item name
        args[2] - Amount
      ]]
    
      if #args[1] == 0 then
        return false, 'Invalid item name'
      end

      local attempt_give_item = lib.callback.await('lc_admin:player_actions:esx:attemptGiveItem', 100, player.source, args[1], args[2])
      if not attempt_give_item then
        return false, 'Invalid item name'
      end

      return true
    end
  },
  {
    label = 'Custom action',
    onClick = function(player)
      print(json.encode(player, {indent=true}))
      TriggerServerEvent('example:customAction', player)
    end
  }
}

Permissions
Page cover image