Skip to content

Latest commit

 

History

History
1394 lines (907 loc) · 22.1 KB

File metadata and controls

1394 lines (907 loc) · 22.1 KB

GCTV Python Functions Documentation

This documentation was generated by ChatGPT.

The GCTV Python API allows script authors to interact with the engine, memory, input devices, GCTV global variables, and more through native Python modules.

Table of Contents


GCT

GetGCTVersion

Prototype:

GCT.GetGCTVersion() -> int

Description: Returns the version of the GCTV engine as an integer.

Example:

import GCT

version = GCT.GetGCTVersion()
print("GCTV Version:", version)

GetGCTStringVersion

Prototype:

GCT.GetGCTStringVersion() -> str

Description: Returns the current version of the GCTV engine as a formatted string.

Example:

import GCT

version = GCT.GetGCTStringVersion()
print("GCTV String Version:", version)

GetGCTFolder

Prototype:

GCT.GetGCTFolder() -> str

Description: Returns the absolute path to the GCT working directory.

Example:

import GCT

path = GCT.GetGCTFolder()
print("GCT root folder:", path)

RunScript

Prototype:

GCT.RunScript(path: str) -> bool

Description: Runs another script from a given path. Returns True if successful.

Example:

import GCT

if not GCT.RunScript("custom/my_script.py"):
    print("Failed to run the script.")

Restart

Prototype:

GCT.Restart() -> None

Description: Restarts all running scripts.

Example:

import GCT

GCT.Restart()

IsScriptsStillWorking

Prototype:

GCT.IsScriptsStillWorking() -> bool

Description: Returns True if scripts are still executing; False if all scripts have stopped.


IsPressedKey

Prototype:

GCT.IsPressedKey(keyCode: int) -> bool

Description: Checks if a specific key is currently being pressed.

Example:

import GCT
from GTAV import PLAYER, ENTITY

key = GCT.ConvertStringToKeyCode("Space+W")

while GCT.IsScriptsStillWorking():
    if GCT.IsPressedKey(key):
        # Character Direction
        forward_vector = ENTITY.GET_ENTITY_FORWARD_VECTOR(PLAYER.PLAYER_PED_ID())

        # Increases the character's speed
        ENTITY.SET_ENTITY_VELOCITY(PLAYER.PLAYER_PED_ID(), 20*forward_vector[0], 20*forward_vector[1], 2*forward_vector[2])

IsDoubleClickedKey

Prototype:

GCT.IsDoubleClickedKey(keyCode: int) -> int

Description: Checks if a specific key is currently pressed. if it has been pressed only once, returns 1 if it has been pressed twice, returns 2 if it has not been pressed, returns 0.

Example:

import GCT
from GTAV import PLAYER, ENTITY

while GCT.IsScriptsStillWorking():
    if not ENTITY.IS_ENTITY_IN_AIR(PLAYER.PLAYER_PED_ID()) and GCT.IsDoubleClickedKey(GCT.ConvertStringToKeyCode("Space")) == 2:
        ENTITY.SET_ENTITY_VELOCITY(PLAYER.PLAYER_PED_ID(), 0, 0, 20.0)

ConvertStringToKeyCode

Prototype:

GCT.ConvertStringToKeyCode(keyName: str) -> int

Description: Converts a key name like "Ctrl+W" into a corresponding key code.

Example:

import GCT

nuclear_missile_launch_keycode = GCT.ConvertStringToKeyCode("Ctrl+1+L+F5")
print("Key code is", nuclearMissileLaunchKeyCode)

GetMousePos

Prototype:

GCT.GetMousePos() -> tuple[int, int]

Description: Retrieves the current mouse position as a table with keys x and y.


SetMousePos

Prototype:

GCT.SetMousePos(x: int, y: int) -> None

Description: Sets the mouse cursor to the specified (x, y) screen coordinates.


New

Prototype:

GCT.New(size: int) → int

Description: Allocates memory for a new object and returns its pointer.

Example:

import GCT

PED_STRUCT_SIZE = 4096

ped_struct = GCT.New(PED_STRUCT_SIZE)

NewPointer

Prototype:

GCT.New(value: int) → int

Description: Allocates memory for a new pointer.

Example:

import GCT

print(GCT.NewPointer(0x7FF6DC4FADE6))

NewPed

Prototype:

GCT.NewPed(pedID: int) → int

Description: Creates a new pointer to Ped entity and writes the specified value there.

Example:

import GCT
from GTAV import PLAYER

local_player_ped_pointer = GCT.NewPed(PLAYER.PLAYER_PED_ID())

NewVehicle

Prototype:

GCT.NewVehicle(vehicleID: int) → int

Description: Creates a new pointer to Vehicle entity and writes the specified value there.

Example:

import GCT
from GTAV import PLAYER, PED

local_player_veh = GCT.NewVehicle(PED.GET_VEHICLE_PED_IS_IN(PLAYER.PLAYER_PED_ID(), True))

NewObject

Prototype:

GCT.NewObject(objectID: int) → int

Description: Creates a new pointer to Object entity and writes the specified value there.


NewVector3

Prototype:

GCT.NewVector3(vector: dict) -> int

Description: Allocates memory for a new 3D vector based on a dict with keys x, y, and z, and returns its pointer.

Example:

import GCT

vec_ptr = GCT.NewVector3({"x": 1.0, "y": 2.0, "z": 3.0})

Delete

Prototype:

GCT.Delete(pointer: int) -> None

Description: Frees the memory allocated at the specified pointer.

Example:

import GCT
from GTAV import PLAYER

ped = PLAYER.PLAYER_PED_ID()
ptr = GCT.NewPed(ped)

if ptr:
    GCT.Delete(ptr)
else:
    print(f"Failed to create pointer to ped: {ped}")

DeleteVector3

Prototype:

GCT.DeleteVector3(pointer: int) -> None

Description: Frees memory allocated for a 3D vector.

Example:

import GCT

vec_ptr = GCT.NewVector3({"x": 1.0, "y": 2.0, "z": 3.0})

if vec_ptr:
    GCT.DeleteVector3(vec_ptr)

GetAllEntities

Prototype:

GCT.GetAllEntities() -> list[int]

Description: Retrieves all game entities as a Python list.

Example:

import GCT

entities = GCT.GetAllEntities()

print(f"Entities count is {len(entities)}")

GetAllPeds

Prototype:

GCT.GetAllPeds() -> list[int]

Description: Retrieves all ped entities as a Python list.

Example:

import GCT
from GTAV import PLAYER, ENTITY

peds = GCT.GetAllPeds()

for ped in peds:
    if ENTITY.GET_ENTITY_HEALTH(ped) > 0 and ped is not PLAYER.PLAYER_PED_ID():
        ENTITY.SET_ENTITY_HEALTH(ped, 0, PLAYER.PLAYER_PED_ID(), 0)

GetAllVehicles

Prototype:

GCT.GetAllVehicles() -> list[int]

Description: Retrieves all vehicle entities as a Python list.

Example:

import GCT
from GTAV import PLAYER, PED
from random import choice

vehs = GCT.GetAllVehicles()

# Sets the player in a random vehicle in the driver's seat.
PED.SET_PED_INTO_VEHICLE(PLAYER.PLAYER_PED_ID(), choice(vehs), -1) 

GetAllObjects

Prototype:

GCT.GetAllObjects() -> list[int]

Description: Retrieves all object entities as a Python list.


NativeCall

Prototype:

GCT.NativeCall(functions_hash: int, return_type: str, args: list)

Description: Calls a native game function by its hash with the provided arguments. returnType must be: "str|long|int|pointer|float|bool" long -> 32-bit integer int -> 64-bit integer

Example:

import GCT

function_hash = GCT.HashString("SET_RAIN") # MISC.SET_RAIN(intensity: float) -> None

intensity = 0.6
GCT.NativeCall(function_hash, "None", [intensity])

HashString

Prototype:

GCT.HashString(string: str) -> int

Description: Converts a string to a 64-bit hash.

Example:

import GCT
import Game

# HUD.GET_STREET_NAME_FROM_HASH_KEY(street_hash: int) -> str
function_hash = GCT.HashString("GET_STREET_NAME_FROM_HASH_KEY") 

street_hash_ptr = GCT.New(4)
crossing_road = GCT.New(4)
x, y, z = ENTITY.GET_ENTITY_COORDS(PLAYER.PLAYER_PED_ID(), True)

# Returns the hash of the street the player is currently on.
PATHFIND.GET_STREET_NAME_AT_COORD(x, y, z, street_hash_ptr, crossing_road)
    
street_hash = Game.ReadInt(street_hash_ptr)
GCT.Delete(street_hash_ptr)
GCT.Delete(crossing_road)

# Calling native function GET_STREET_NAME_FROM_HASH_KEY
street_name = GCT.NativeCall(function_hash, "str", [street_hash])
print(f"Player on the {street_name} street")

DisplayError

Prototype:

GCT.DisplayError(message: str) -> None

Description: Displays an error message with alert formatting in the terminal.


BindCommand

Prototype:

GCT.BindCommand(commandName: str, callback: Callable) -> bool

Description: Binds a Python function to a custom terminal command.

Example:

import GCT

def my_command1():
    print("My Command!")

def nocops_mode():
    raise NotImplementedError("Soon...")

def blame_lamar():
    GCT.Restart()

def summon_chop():
    from GTAV import ENTITY, PED, PLAYER, MISC
    
    model = MISC.GET_HASH_KEY("A_C_Chop_02")

    # Load model here

    coords = ENTITY.GET_ENTITY_COORDS(PLAYER.PLAYER_PED_ID(), True)
    chop = PED.CREATE_PED(28, model, coords[0]+3.0, coords[1]+1.0, coords[2]+0.2, 0.0, True, True)
    
    if chop:
        print("Created:", chop)
    else:
        print("Failed to create chop ;(")

# Define a dictionary with commands and their functions
commands = {
    "my_command1": my_command1,
    "nocops mode" : nocops_mode,
    "blame lamar": blame_lamar,
    "summon chop": summon_chop
}

for command, function in commands.items():
    if not GCT.BindCommand(command, function):
       GCT.DisplayError(True, f"Failed to register the command: {command}")

UnBindCommand

Prototype:

GCT.UnBindCommand(commandName: str) -> bool

Description: Removes a command binding.

Example:

import GCT

GCT.UnBindCommand("my_command1")

IsCommandExist

Prototype:

GCT.IsCommandExist(commandName: str) -> bool

Description: Checks if a command with the given name is currently bound.

Example:

import GCT

if GCT.IsCommandExist("my_command1"):
    GCT.UnBindCommand("my_command1")

Input

Prototype:

GCT.Input(prompt: str) -> str

Description: Displays a prompt and waits for user text input.

Example:

import GCT

name = GCT.Input("Enter your name: ")
print("Hello, " + name)

InputFromList

Prototype:

GCT.InputFromList(prompt: str, options: list[str]) -> int

Description: Displays a prompt and a list of options, returns the selected index.

Example:

import GCT

options = ["Apple", "Banana", "Orange", "Lime"]

GCT.printColoured(
    "aqua",
    "User choice is ", 
    options[GCT.InputFromList(
        "Choose what you want: ",
        options
    )])

SetColor

Prototype:

GCT.SetColor(color: str) -> None

Description: Sets the console text color. Example values: "red", "dark yellow".


ResetColor

Prototype:

GCT.ResetColor() -> None

Description: Resets the console color to default.


printColoured

Prototype:

GCT.printColoured(color: str, message: str) -> None

Parameters:

  • color (str): The color name to set the text to. Supported colors are:
    • "dark blue"
    • "dark green"
    • "dark aqua"
    • "dark red"
    • "dark purple"
    • "dark yellow"
    • "light gray"
    • "dark gray"
    • "blue"
    • "green"
    • "aqua"
    • "red"
    • "purple"
    • "yellow"
    • "white"

Description: Prints text in the specified color.

Example:

import GCT

for i in range(10**16):
    GCT.printColoured("green", "Hello world!")

GCTOut

Prototype:

GCT.GCTOut(text: str) -> None

Description: Outputs text to the internal and external GCT console.

Example:

import GCT
GCT.GCTOut("""
   _____           _                 
  / ____|         | |                
 | (___     ___   | |_    ___   _ __ 
  \___ \   / _ \  | __|  / _ \ | '__|
  ____) | | (_) | | |_  |  __/ | |   
 |_____/   \___/   \__|  \___| |_|   
      
""")

ExternalOut

Prototype:

GCT.ExternalOut(*args) -> None

Description: Outputs text to the external console (can be redirected or captured).

Example:

import GCT

GCT.ExternalOut("Successfully started!\n")

help

Prototype:

GCT.help() -> None

Description: Displays a list of available Python functions in the GCT module.


Globals

register

Prototype:

GCT.Globals.register(name: str, value: Any) -> None

Description: Registers a global variable in GCTV's memory space. This global variable becomes accessible to all scripts, including those written in other programming languages supported by the environment. The function supports registering: int, float, str, list[str], list[int], list[float].

Example:

import GCT
# Register an integer
GCT.Global.register("globalInt", 42)

# Register a floating-point number
GCT.Global.register("globalFloat", 3.14159)

# Register a string
GCT.Global.register("globalString", "Hello world")

# Register an array of integers
GCT.Global.register("globalIntArray", [1, 2, 3, 4])

# Register an array of strings
GCT.Global.register("globalStringArray", ["foo", "bar", "baz"])

Get

Prototype:

GCT.Globals.get(name: str) -> Any

Description: Retrieves the value of a global variable previously registered in GCTV's shared memory. The returned value matches the original type of the global variable

Example:

import GCT

int_value : int = GCT.Global.get("globalInt")
str_value : str = GCT.Global.get("globalString")
list_value : list[int] = GCT.Global.get("globalIntArray")

Set

Prototype:

GCT.Globals.set(name: str, value: Any) -> None

Description: Sets the value of an existing global variable.


Exists

Prototype:

GCT.Globals.exists(name: str) -> bool

Description: Checks whether a global variable with the given name exists.


Game

ReadInt

Prototype:

Game.ReadInt(address: int) -> int

Description: Reads a 32-bit integer from memory.


ReadFloat

Prototype:

Game.ReadFloat(address: int) -> float

Description:

Reads a float value from memory.


WriteInt

Prototype:

Game.WriteInt(address: int, value: int) -> None

Description:

Writes a 32-bit integer to memory.


WriteFloat

Prototype:

Game.WriteFloat(address: int, value: float) -> None

Description:

Writes a float value to memory.


ReadByte

Prototype:

Game.ReadByte(address: int) -> int

Description:

Reads a byte (8-bit unsigned int) from memory.


ReadDouble

Prototype:

Game.ReadDouble(address: int) -> float

Description:

Reads a double-precision float from memory.


WriteByte

Prototype:

Game.WriteByte(address: int, value: int) -> None

Description:

Writes a byte to memory.


WriteDouble

Prototype:

Game.WriteDouble(address: int, value: float) -> None

Description:

Writes a double-precision float to memory.


ReadInt64

Prototype:

Game.ReadInt64(address: int) -> int

Description:

Reads a 64-bit integer from memory.


WriteInt64

Prototype:

Game.WriteInt64(address: int, value: int) -> None

Description:

Writes a 64-bit integer to memory.


ReadShort

Prototype:

Game.ReadShort(address: int) -> int

Description:

Reads a 16-bit short from memory.


WriteShort

Prototype:

Game.WriteShort(address: int, value: int) -> None

Description:

Writes a 16-bit short to memory.


ReadBytes

Prototype:

Game.ReadBytes(address: int, count: int) -> list

Description:

Reads multiple bytes from memory.

Example:

import Game

offset = 0x11ADE6 address = Game.GetBaseAddress() + offset

print(Game.ReadBytes(address, 15))

WriteBytes

Prototype:

Game.WriteBytes(address: int, data: list) -> None

Description:

Writes multiple bytes to memory.


WriteString

Prototype:

Game.WriteString(address: int, text: str) -> None

Description:

Writes a null-terminated string to memory.


ReadString

Prototype:

Game.ReadString(address: int, maxLength: int) -> str

Description:

Reads a null-terminated string from memory.


FindValue

Prototype:

Game.FindValue(start: int, end: int, value: int) -> Optional[int]

Description:

Scans memory and returns a list of addresses where the given value is found.


FindPattern

Prototype:

Game.FindPattern(start: int, end: int, pattern: str, mask: str) -> int

Description:

Scans memory for a pattern/signature and returns the first matching address.


GetBaseAddress

Prototype:

Game.GetBaseAddress() -> int

Description:

Returns the base memory address of a loaded module.


Gamepad

select_controller

Prototype:

Gamepad.Gamepad.select_controller(index: int) -> None

Description:

Selects a game controller by index.

get_selected_controller

Prototype:

Gamepad.Gamepad.get_selected_controller() -> int

Description:

Returns the index of the currently selected controller.


get_pressed_key

Prototype:

Gamepad.Gamepad.get_pressed_key() -> int

Description:

Returns the last key/button pressed.


get_pressed_keys

Prototype:

Gamepad.Gamepad.get_pressed_keys() -> list[int]

Description:

Returns a list of currently pressed keys/buttons.


get_left_stick_state

Prototype:

Gamepad.Gamepad.get_left_stick_state() -> tuple[float, float]

Description:

Returns the X and Y axis values of the left analog stick.


get_right_stick_state

Prototype:

Gamepad.Gamepad.get_right_stick_state() -> tuple[float, float]

Description:

Returns the X and Y axis values of the right analog stick.


get_triggers_state

Prototype:

Gamepad.Gamepad.get_triggers_state() -> tuple[float, float]

Description:

Returns the current values of the left and right triggers.


send_vibration

Prototype:

Gamepad.Gamepad.send_vibration(left: float, right: float) -> None

Description:

Sends vibration feedback to the controller.