Skip to content

Latest commit

 

History

History
54 lines (37 loc) · 2.53 KB

File metadata and controls

54 lines (37 loc) · 2.53 KB

C++

C++ is a powerful and high-performance programming language used for system-level scripting. This section covers how to utilize C++ for scripting in Game Command Terminal 2, including details on functions, memory management, and tips for optimal performance.

C++ Loader

The C++ scripts in your project are native plugins compiled into .dll or .asi files. On startup, the custom loader checks the Scripts/ folder for any .dll or .asi and calls LoadLibrary for each of them. This gives you access to RDR2's internals, custom utilities, graphics routines, gamepad input - everything you need to create rich game systems.

Core Includes & Modules

Every script should pull in the core headers that expose your engine’s API:

#include "Game.h"           // Top-level game API (network functions, player/ped helpers, etc.)
#include "Console.hpp"      // Logging and Input functions: Print, Error, Input, InputFromList
#include "Functions.h"      // GCT2 functions (Restart, RunScript, GetGCT2Folder, etc.)
#include "Graphics++.hpp"   // 2D drawing primitives, Implemented with ImGui
#include "Gamepad.hpp"      // Polling controller buttons, sticks, triggers

Script Code

In the main function you can implement the logic of your script:

If you throw some c++ exception, it will be caught and displayed in the console as an error

// Scripts/YourScript/script.cpp
#include "Console.hpp"
#include "Functions.h"

void main()
{
    // Called once, then your loop runs until unload
    while (GCT2::IsScriptsStillWorking())
    {
        throw std::runtime_error("Not implement yet");
    }
}

Available Documentation

For details on additional functions available in the GCT2 C++ Scripts, please refer to the documentation:

  • Functions Documentation — Contains descriptions and examples of all custom functions provided by GCT2.
  • Folder Path: GCT2/Docs/C++/Functions.md.

By leveraging C++ within GCT2, developers can enhance gameplay, create custom mechanics, and interact with the game world dynamically.

You can also explore the scripts in the Scripts\features folder and in Scripts\examples to get a better understanding of how everything works and take code templates for yourself

Native Functions

To call an in-game native function, specify the namespace in which the function resides and use dot notation to access it, passing the required parameters. You can view the full list of native functions here.