Skip to content

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

  1. Open your GTA IV installation folder (where GTAIV.exe is located).
  2. Open or create the mods/ folder.
  3. Inside mods/, create a new folder named MyFirstMod.
  4. Inside MyFirstMod, create a new text file named main.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!

  1. Start GTA IV.
  2. Press F6 at any time to open the In-Game Code Editor.
  3. You can edit your code live or test small snippets immediately.
  4. 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!