Skip to content
Yr@Dead edited this page Apr 25, 2026 · 1 revision

MoonLoader III Opcode Reference

This page documents all available opcodes (Lua functions) exposed by MoonLoader III for GTA III scripting.


Table of Contents


Script Metadata

These functions are called at the top of your script to set metadata. They are optional — if script_name is not used, the filename (without .lua) is used for logging.

script_name(name)

Sets the display name of the script used in logs.

script_name("My Cool Mod")

script_author(author)

Sets the author name.

script_author("YourName")

script_description(description)

Sets a short description.

script_description("Spawns cars when you type a cheat")

script_version(version)

Sets the version string.

script_version("1.0")

Built-in Globals

Global Type Description
script_path string Full filesystem path to the running script
print(...) function Prints to moonloader.log with the script's display name as prefix

Core / Flow Control

wait(ms)

Yields the script for ms milliseconds. Must be called inside while true do loops to prevent freezing the game.

wait(1000)  -- wait 1 second

Input & Camera

test_cheat(string)boolean

Returns true if the player has typed the cheat string (A-Z, 0-9, space). The cheat is consumed after detection so it won't trigger again until retyped.

if test_cheat("NOC") then
    print("No Clip activated!")
end

is_key_pressed(vk)boolean

Returns true if the Windows virtual-key code is currently held down. Uses GetAsyncKeyState.

if is_key_pressed(87) then  -- VK_W
    -- W is held
end

get_frame_delta_time()float

Returns the current frame delta time multiplier (CTimer::ms_fTimeStep). Multiply by your speed value for frame-rate-independent movement.

local speedDt = SPEED * get_frame_delta_time()

get_camera_position()x, y, z

Returns the current camera position in world space.

local cx, cy, cz = get_camera_position()

get_camera_target()x, y, z

Returns a point in world space that the camera is looking at (camera position + forward vector).

local tx, ty, tz = get_camera_target()

Player

get_player_ped(id)handle

Returns the ped handle for player slot id (0 for player 1).

local ped = get_player_ped(0)

is_player_playing(id)boolean

Returns true if the player slot is active.

if is_player_playing(0) then ... end

is_char_in_any_car(handle)boolean

Returns true if the ped is currently inside any vehicle.

if is_char_in_any_car(ped) then ... end

get_player_car(id)handle

Returns the vehicle handle the player is driving, or 0 if on foot.

local car = get_player_car(0)

get_player_coords(id)x, y, z

Returns the player's current position.

local x, y, z = get_player_coords(0)

set_player_coords(id, x, y, z)

Teleports the player to the given coordinates.

set_player_coords(0, 100.0, -50.0, 10.0)

set_player_can_enter_exit_vehicles(id, enable)

Allows or blocks the player from entering/exiting vehicles.

set_player_can_enter_exit_vehicles(0, false)  -- lock player in/out

Peds

create_ped(type, model, x, y, z)handle

Spawns a pedestrian at the given coordinates. type is the ePedType (e.g., 4 for civilian male). Returns a handle or 0 on failure.

local ped = create_ped(4, 7, x, y, z)

delete_ped(handle)

Removes the ped from the world and frees memory.

delete_ped(ped)

set_ped_coords(handle, x, y, z)

Teleports the ped.

set_ped_coords(ped, x, y, z)

get_ped_coords(handle)x, y, z

Returns the ped's position.

local x, y, z = get_ped_coords(ped)

is_ped_in_car(handle)boolean

Returns true if the ped is inside a vehicle.

if is_ped_in_car(ped) then ... end

set_ped_collision(handle, enable)

Enables or disables collision for the ped.

set_ped_collision(ped, false)  -- noclip for ped

Vehicles

create_car(model, x, y, z)handle

Spawns a vehicle. You must request_model + load_all_models_now beforehand. Returns handle or 0.

request_model(111)
load_all_models_now()
local car = create_car(111, x, y, z)

delete_car(handle)

Removes the vehicle from the world.

delete_car(car)

set_car_coords(handle, x, y, z)

Teleports the vehicle.

set_car_coords(car, x, y, z)

get_car_coords(handle)x, y, z

Returns the vehicle's position.

local x, y, z = get_car_coords(car)

set_car_health(handle, health)

Sets vehicle health.

set_car_health(car, 1500)

get_car_health(handle)int

Returns vehicle health.

local hp = get_car_health(car)

set_car_collision(handle, enable)

Enables or disables collision for the vehicle.

set_car_collision(car, false)

does_car_exist(handle)boolean

Returns true if the handle is still valid (vehicle not destroyed).

if does_car_exist(car) then ... end

Models & Streaming

request_model(id)

Requests a model to be loaded into memory.

request_model(111)

load_model(id)

Alias for request_model.

load_model(111)

has_model_loaded(id)boolean

Returns true if the model is fully loaded. Important: In GTA III you must call load_all_models_now() after requesting, or this will stay false.

if has_model_loaded(111) then ... end

load_all_models_now()

Forces all requested models to load immediately. Call this after request_model.

request_model(111)
load_all_models_now()

mark_model_as_no_longer_needed(id)

Tells the streaming system it can unload this model to free memory.

mark_model_as_no_longer_needed(111)

Game World

get_game_timer()int

Returns the current game time in milliseconds.

local t = get_game_timer()

Memory

read_memory(address, size)int

Reads memory at the given address. size must be 1, 2, or 4.

local wanted = read_memory(0x9412BC, 1)

write_memory(address, size, value)

Writes memory at the given address. size must be 1, 2, or 4.

write_memory(0x9412BC, 1, 0)  -- clear wanted level

call_function(address, ...)int

Stub for calling game functions. Currently returns 0 and logs a warning.

local result = call_function(0x123456)

Debug / HUD

print_string(text)

Draws text on screen using CFont. Call inside a while true do wait(0) end loop to keep it visible.

while true do
    wait(0)
    print_string("Hello Liberty City!")
end

print_big(text)

Draws large heading-style text on screen.

print_big("BIG TEXT")

Complete Example

script_name("Vehicle Spawner")
script_author("YourName")
script_description("Spawn a Kuruma with TESTLUA cheat")
script_version("1.0")

while true do
    wait(0)

    if test_cheat("TESTLUA") then
        local px, py, pz = get_player_coords(0)
        local model = 111  -- kuruma

        request_model(model)
        load_all_models_now()

        if has_model_loaded(model) then
            local car = create_car(model, px, py + 4.0, pz)
            if car ~= 0 then
                print_string("Kuruma spawned!")
            end
            mark_model_as_no_longer_needed(model)
        end
    end
end

Clone this wiki locally