⚒️FUNCTION UTILITY

To create a new command in the modules/client/data/cl_command.lua file and set permissions, follow these steps:

Creating a New Command

  1. Open the modules/client/data/cl_command.lua file.

  2. Add a new command entry similar to existing ones. For example, to add a new command called examplecommand:

  3. LGF.Command:CreateCommand({
        {
            name = "examplecommand",
            description = "Description of the example command.",
            permission = 'example.useCommand',
            Data = function(source, args)
                -- Command logic here
            end
        }
    })

    Setting Permissions

    1. Open the config.lua file.

    2. Add the permission for the new command in the CFG.CommandPerms table. For example:

    3. CFG.CommandPerms = {
          ['admin'] = {
              ['cache.getPlayerCache'] = true,
              ['cache.clearPlayerCache'] = true,
              ['admin.createVehicle'] = true,
              ['example.useCommand'] = true -- Add this line
          },
          ['mod'] = {
              ['cache.getCache'] = false,
              ['example.useCommand'] = false -- Add this line
          }
      }

      Following these steps will ensure that the new command is created and the necessary permissions are set.

To create an example command, follow these steps:

LGF.Command:CreateCommand({
    {
        name = "teleport", -- Create Command Name
        description = "Teleport at Coords.",-- Create Description
        permission = 'function.teleport', -- Create Permission
        Data = function(source, args)
            local CachePed = exports.LGF_Utility:cachePed() -- Get entity Cache
            local Ped = CachePed.ped -- Declare Ped Entity
            local coords = vec4(0.0, 0.0, 0.0, 0.0) -- Put your coords
            SetEntityCoords(Ped, coords.x, coords.y, coords.z, true, false, false, false)
            SetEntityHeading(Ped, coords.w)
        end
    }
})

Setting Permissions

  1. Open the config.lua file.

  2. Add the permission for the new command in the CFG.CommandPerms table. For example:

  3.  CFG.CommandPerms = {
         ['admin'] = {
             ['cache.getPlayerCache'] = true,
             ['cache.clearPlayerCache'] = true,
             ['admin.createVehicle'] = true,
             ['function.teleport'] = true -- Add this line
         },
         ['mod'] = {
             ['cache.getPlayerCache'] = false,
             ['cache.clearPlayerCache'] = false,
             ['admin.createVehicle'] = false,
             ['function.teleport'] = false-- Add this line
         }
     }
  4. Verify that the command is correctly added in cl_command.lua.

  5. Check the permissions in config.lua to ensure they are properly configured.

  6. Look at the server logs for possible error messages that can provide clues.

By following these steps, you can successfully add and test new commands in your Lua-based game scripts.

Last updated