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/
β βββ π main.lua <-- Your mod's code goes here!
βββ π binkw32.dll
βββ π binkw32_orig.dll
βββ π LuaModLoader.dll
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
msgbox("Hello from LuaModLoader!")
-- This function runs automatically every frame
function onTick()
-- Check if the player presses the F4 key (0x73)
if is_key_down(0x73) then
local playerPed = GET_PLAYER_CHAR(GET_PLAYER_ID())
-- Restore player health to 200 (max)
SET_CHAR_HEALTH(playerPed, 200)
-- Give body armour
ADD_ARMOUR_TO_CHAR(playerPed, 100)
log("Health and armor restored!")
end
end
Step 3: 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 Styles: SNAKE_CASE & PascalCase
LuaModLoader natively supports both GTA native naming conventions interchangeably:
- SNAKE_CASE:
SET_CHAR_HEALTH(ped, 200) - PascalCase:
SetCharHealth(ped, 200)
Both point to the exact same native function, meaning scripts ported from ScriptHookDotNet or classic trainers work without rewriting all function names!