Getting Started with Lua Modding¶
Welcome to GTA IV modding with LuaModLoader! This guide is designed for beginners. You don't need any prior C++ or reverse engineering experience.
How Does a Lua Mod Work?¶
A mod is simply a .lua text file placed inside your game directory. LuaModLoader reads this file and executes its code directly inside GTA IV.
π Grand Theft Auto IV/ (Game Root Folder)
βββ π mods/
β βββ π MyFirstMod/
β βββ π manifest.lua <-- declares the mod (required)
β βββ π main.lua <-- Your mod's code goes here!
βββ π dinput8.dll
βββ π LuaModLoader.dll
The editor can do steps 1 to 3 for you
With the game running, press F6, right-click in the mod list and pick
New mod. You get the folder, a commented manifest.lua and a main.lua
ready to fill in. The steps below are the same thing done by hand.
Step 1: Create Your First Mod¶
- Open your GTA IV installation folder (where
GTAIV.exeis located). - Open or create the
mods/folder. - Inside
mods/, create a new folder namedMyFirstMod. - Inside
MyFirstMod, create a new text file namedmain.lua.
Step 2: Write Your First Code¶
Open main.lua with Notepad, VS Code, or any text editor and paste the following:
-- When the game loads, show a welcome message
Console.MsgBox("Hello from LuaModLoader!")
-- This function runs automatically every frame
Thread.Create(function()
while true do
-- Check if the player presses the F4 key (0x73)
if Input.IsKeyDown(0x73) then
local playerPed = GetPlayerChar(GetPlayerId())
-- Restore player health to 200 (max)
SetCharHealth(playerPed, 200)
-- Give body armour
AddArmourToChar(playerPed, 100)
Log.Print("Health and armor restored!")
end
Thread.Wait(0)
end
end)
Step 3: Declare the Mod (manifest.lua)¶
The manifest is what makes the folder a mod: without it the loader walks past
the folder and your script never shows up. Put a manifest.lua next to
main.lua:
name 'My First Mod'
author 'You'
description 'Heals the player on F4.'
version '1.0.0'
autostart = true
client_scripts {
'main.lua',
}
Each line is a plain Lua call, which is why the strings need no =. The
exception is autostart, a boolean, and f true is not valid Lua: write
autostart = true or autostart(true). It defaults to false, so this is
the line that decides whether the mod starts by itself.
The Mod structure page carries the full manifest
reference, covering multi-file mods, MOD_DIR and the legacy formats.
Step 4: Test and Edit Live in Game (F6 Key)¶
You don't need to restart GTA IV every time you modify your code!
- Start GTA IV.
- Press F6 at any time to open the In-Game Code Editor.
- You can edit your code live or test small snippets immediately.
- Close the editor with F6 or Escape to return to gameplay.
π‘ Naming: natives are PascalCase¶
Every GTA IV native is a global function under its PascalCase name:
These are the same names ScriptHookDotNet scripts and classic trainers use, so ported code needs no renaming.
The canonical SNAKE_CASE name is not a global function. It stays reachable
in two places:
- the
nativestable, as innatives.SET_CHAR_HEALTH(ped, 200). Native.Call("SET_CHAR_HEALTH", ped, 200). There the name must beSNAKE_CASE, since the lookup is an exact match on the canonical name.
Everything the loader itself provides lives in a namespace instead:
Thread, Console, Log, Draw, Color, Input, Gamepad, Native,
Memory, Vehicle, Script. See the API reference.