fivem commands example lua

Here is an example of a Lua script for a FiveM command:

RegisterCommand("heal", function(source, args, rawCommand)
    local playerPed = GetPlayerPed(source)
    SetEntityHealth(playerPed, 200)
end, false)

Explanation:

  1. RegisterCommand is a function used to define a new command in FiveM. In this case, we are creating a command named "heal".

  2. The function function(source, args, rawCommand) is the callback function that is executed when the command is triggered. It takes three parameters:

  3. source represents the player who triggered the command.

  4. args is a table containing any additional arguments passed with the command. In this example, we don't use any arguments.
  5. rawCommand is a string containing the raw command that was entered.

  6. local playerPed = GetPlayerPed(source) retrieves the player's character model (ped) based on the source parameter, which represents the player who triggered the command.

  7. SetEntityHealth(playerPed, 200) sets the health of the player's character model to 200. This command effectively heals the player.

Note: This Lua script is a basic example and may require additional code or error handling depending on the specific requirements of your FiveM server.