JavaScript API
Native functions
CLEO Redux supports all commands native to the current game. In the classic GTA 3D series they are also known as opcodes. In GTA IV they are known as native functions. You can find them in Sanny Builder Library.
Each available command has a predefined name that the game associates with a particular set of instructions running as you execute that command with arguments. To call a command by name use a built-in function native
. For example, to change the player's health run native("SET_PLAYER_HEALTH", 0, 100)
, where 0
is the player's id and 100
is the desired health.
For convenience, CLEO Redux also defines a wide set of abstractions on top of the native functions called classes. Each class represents a group of commands around some domain, e.g. commands related to the player, vehicles, or text display can be found in classes Player
, Car
, or Text
respectively. You can browse available classes and methods they provide in Sanny Builder Library.
For example, to change the player's health using classes run p.setHealth(100)
, where p
is an instance of the Player
class created with new Player()
or Player.Create
functions.
CLEO Redux Bindings
In addition to native commands CLEO Redux adds extra variables and functions.
Variables
HOST
the host name (previously available as GAME
variable). Possible values are gta3
, vc
, re3
, reVC
, sa
, gta3_unreal
, vc_unreal
, sa_unreal
, gta_iv
, bully
, unknown
.
CLEO plugins can use SDK to customize the name for their needs.
if (HOST === "gta3") {
showTextBox("This is GTA III");
}
if (HOST === "sa") {
showTextBox("This is San Andreas");
}
if (HOST === "unknown") {
showTextBox("This host is not natively supported");
}
ONMISSION
the global flag controlling whether the player is on a mission now. Not available on an unknown
host.
if (!ONMISSION) {
showTextBox("Not on a mission. Setting ONMISSION to true");
ONMISSION = true;
}
TIMERA, TIMERB
two auto-incrementing timers useful for measuring time intervals.
while (true) {
TIMERA = 0;
// wait 1000 ms
while (TIMERA < 1000) {
wait(0);
}
showTextBox("1 second passed");
}
__dirname
an absolute path to the directory with the current file
__filename
an absolute path to the current file
Functions
log
log(...values)
prints comma-separated {values}
to the cleo_redux.log
var x = 1;
log("value of x is ", x);
wait
wait(timeInMs)
pauses the script execution for at least {timeInMs}
milliseconds
while (true) {
wait(1000);
log("1 second passed");
}
showTextBox
showTextBox(text)
displays {text}
in the black rectangular box. Not available on an unknown
host.
showTextBox("Hello, world!");
exit
exit(reason?)
terminates the script immediately. exit
function accepts an optional string argument that will be added to the cleo_redux.log
.
exit("Script ended");
native
native(command_name, ...input_args)
is a low-level function to execute a command using its name {command_name}
. The command name matches name
property in a JSON file provided by Sanny Builder Library.
native("SET_TIME_OF_DAY", 12, 30); // sets the time of day to 12:30
For the commands that return a single value, the result is this value.
const progress = native("GET_PROGRESS_PERCENTAGE");
showTextBox(`Progress is ${progress}`);
For the commands that return multiple values, the result is an object where each key corresponds to a returned value. The key names match the output names given in the command definition
var pos = native("GET_CHAR_COORDINATES", char); // returns char's coordinates vector {x, y, z}
showTextBox(`Character pos: x ${pos.x} y ${pos.y} z ${pos.z}`);
For the conditional commands the result is the boolean value true
or false
if (native("HAS_MODEL_LOADED", 101)) {
// checks the condition
showTextBox("Model with id 101 has been loaded");
}
Static Objects
Memory
Memory
object allows to manipulate the process memory. See the Memory guide for more information.
Math
Math
object is a standard object available in the JS runtime that provides common mathematical operations. CLEO Redux extends it with some extra commands. See the Math object for more information.
FxtStore
FxtStore
allows to update the content of in-game texts. See the Custom Text guide for details.
CLEO
-
CLEO
object provides access to the runtime information and utilities:CLEO.debug.trace(flag)
toggles on and off command tracing in the current script. When {flag} is true all executed commands get added tocleo_redux.log
:
CLEO.debug.trace(true); wait(50); const p = new Player(0); CLEO.debug.trace(false);
CLEO.version
- a complex property providing information about current CLEO version
log(CLEO.version); // "0.9.4-dev.20220427" log(CLEO.version.major); // "0" log(CLEO.version.minor); // "9" log(CLEO.version.patch); // "4" log(CLEO.version.pre); // "dev" log(CLEO.version.build); // "20220427"
- (since 1.0.0)
CLEO.apiVersion
- a complex property providing information about current API (usingmeta.version
field in the primary definition file). Scripts can use it to check if the user has a particular API version installed.
log(CLEO.apiVersion); // "0.219" log(CLEO.apiVersion.major); // "0" log(CLEO.apiVersion.minor); // "219" log(CLEO.apiVersion.patch); // undefined log(CLEO.apiVersion.pre); // undefined log(CLEO.apiVersion.build); // undefined