# FUNCTION UTILITY

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. ```lua
   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. ```lua
      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:

```lua
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. ```lua
    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.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://legacy-script.gitbook.io/legacy-script/lgf-utility/function-utility.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
