Custom Console Commands

RAGE Plugin Hook Documentation

[This is preliminary documentation and is subject to change.]

Plugins can define their own console commands.

Custom console commands in plugins are defined by defining static methods in static classes and marking them with the ConsoleCommandAttribute attribute.
If a name is not provided for the ConsoleCommandAttribute attribute, the console command will be registered with the name of the method.
If the method name starts with "Command_", this tag will be removed from the registered name. Eg. if the method name is "Command_RemoveAllPedsAndVehicles", the console command will be named "RemoveAllPedsAndVehicles".

This is an example of a custom console command that removes all Peds and Vehicles, except players, and the local player's vehicle from the game world.

C#
public static class MyConsoleCommands
{
    [Rage.Attributes.ConsoleCommand]
    public static void Command_RemoveAllPedsAndVehicles()
    {
        foreach(Ped ped in World.GetAllPeds())
        {
            if (!ped.IsPlayer)
            {
                ped.Delete();
            }
        }

        Vehicle playersVehicle = Game.LocalPlayer.Character.CurrentVehicle;
        foreach(Vehicle vehicle in World.GetAllVehicles())
        {
            if (!playersVehicle.Exists() || vehicle != playersVehicle)
            {
                vehicle.Delete();
            }
        }
    }
}