Skip to content

Ready-to-Use Script Examples

Here are 5 beginner-friendly Lua scripts you can directly copy, modify, and use in your mods.


1. Heal & Armor on Key Press (F4)

Restores the player's health and armor to 100% whenever F4 is pressed.

-- File: main.lua
local HEAL_KEY = 0x73 -- F4 Key

function onTick()
    if is_key_down(HEAL_KEY) then
        local playerPed = GET_PLAYER_CHAR(GET_PLAYER_ID())

        SET_CHAR_HEALTH(playerPed, 200)   -- Full health
        ADD_ARMOUR_TO_CHAR(playerPed, 100) -- Full armor

        log("Player healed!")
    end
end

2. Never Wanted (Disable Police)

Automatically resets the player's police wanted stars to 0.

-- File: main.lua
function onTick()
    local playerId = GET_PLAYER_ID()
    local playerPed = GET_PLAYER_CHAR(playerId)

    -- Clear wanted level continuously
    CLEAR_CHAR_LAST_DAMAGE_ENTITY(playerPed)
    ALTER_WANTED_LEVEL(playerId, 0)
    APPLY_WANTED_LEVEL_CHANGE_NOW(playerId)
end

3. Teleport 10 Meters Up (Unstuck / Jump)

Press Z (0x5A) to teleport your character 10 meters upward (useful if stuck in walls or geometry).

-- File: main.lua
local TELEPORT_KEY = 0x5A -- Z Key

function onTick()
    if is_key_down(TELEPORT_KEY) then
        local playerPed = GET_PLAYER_CHAR(GET_PLAYER_ID())

        -- Get current position
        local _, rawX, rawY, rawZ = call_native_out("GET_CHAR_COORDINATES", 3, playerPed)
        local x = string.unpack("f", rawX)
        local y = string.unpack("f", rawY)
        local z = string.unpack("f", rawZ)

        -- Teleport 10m higher
        SET_CHAR_COORDINATES(playerPed, x, y, z + 10.0)
        log("Teleported up!")
    end
end

4. Simple Car Speedometer & Nitro Boost (Shift)

Draws an on-screen HUD speedometer in km/h and boosts car speed with Shift:

-- File: main.lua
local NITRO_KEY = 0x10 -- Shift Key

function onTick()
    local playerPed = GET_PLAYER_CHAR(GET_PLAYER_ID())

    -- Check if inside a vehicle
    if IS_CHAR_IN_ANY_CAR(playerPed) then
        local veh = GET_CAR_CHAR_IS_USING(playerPed)
        local speedMps = GET_CAR_SPEED(veh)
        local speedKmh = speedMps * 3.6

        -- Draw HUD box and speed text
        draw_rect(20, 700, 200, 50, 0xAA000000)
        draw_text(30, 715, string.format("SPEED: %3.0f KM/H", speedKmh), 0xFFFFFFFF)

        -- Press Shift for Nitro
        if is_key_down(NITRO_KEY) then
            SET_CAR_FORWARD_SPEED(veh, speedMps * 1.3)
            draw_text(30, 735, ">> NITRO <<", 0xFFFF0000)
        end
    end
end

5. Invincibility Toggle (Godmode on F3)

Toggles God Mode on and off when pressing F3:

-- File: main.lua
local TOGGLE_KEY = 0x72 -- F3 Key
local godmode = false
local wasPressed = false

function onTick()
    local isPressed = is_key_down(TOGGLE_KEY)

    -- Trigger only on key down (not hold)
    if isPressed and not wasPressed then
        godmode = not godmode
        local playerPed = GET_PLAYER_CHAR(GET_PLAYER_ID())

        SET_CHAR_INVINCIBLE(playerPed, godmode)
        SET_CHAR_PROOFS(playerPed, godmode, godmode, godmode, godmode, godmode)

        if godmode then
            msgbox("God Mode: ENABLED")
        else
            msgbox("God Mode: DISABLED")
        end
    end
    wasPressed = isPressed
end