Enter Lua Trigger

Processed Lua Code

Macho API Features

Macho API provides advanced security and error handling for your Lua triggers. Here are the key features:

Security Enhancement

MachoSetLoggerState(0)

Disables logging during execution for enhanced security and performance.

Error Handling

pcall(function() ... end)

Wraps your code in protected calls to prevent crashes and handle errors gracefully.

Notifications

MachoMenuNotification("SUCCESS", "Message")

Provides user-friendly notifications for success and error states.

Timing Control

Citizen.Wait(100)

Ensures proper timing and prevents blocking operations.

Complete Macho API Documentation

Comprehensive guide to all Macho API functions for FiveM Lua development:

Window Management

MachoMenuWindow(PositionX, PositionY, EndPositionX, EndPositionY)

Creates a new menu window and returns a handle reference.

MachoMenuTabbedWindow(Name, PosX, PosY, SizeX, SizeY, TabSectionWidth)

Creates a tabbed window interface.

MachoMenuDestroy(WindowReference)

Destroys the specified menu window.

MachoMenuSetAccent(WindowReference, r, g, b)

Sets the accent color for the menu window.

MachoMenuSetKeybind(WindowReference, Keybind)

Sets the keybind for menu toggle (use virtual key codes).

MachoMenuIsOpen(WindowReference)

Returns true if the menu window is currently open.

Widget Management

MachoMenuGroup(WindowReference, Name, PositionX, PositionY, EndPositionX, EndPositionY)

Creates a group section within a window.

MachoMenuAddTab(WindowReference, Name)

Adds a tab to the window and returns a tab reference.

MachoMenuSmallText(WindowReference, Text)

Adds small text to the window.

Interactive Widgets

MachoMenuButton(GroupReference, Name, Callback)

Creates a clickable button with callback function.

MachoMenuCheckbox(GroupReference, Name, CallbackEnabled, CallbackDisabled)

Creates a checkbox with enable/disable callbacks.

MachoMenuSlider(GroupReference, Name, DefaultValue, Minimum, Maximum, Unit, DecimalPrecision, Callback)

Creates a slider with value range and callback.

MachoMenuText(GroupReference, Text)

Adds static text to a group.

MachoMenuInputbox(GroupReference, Text, Placeholder)

Creates an input box for text entry.

MachoMenuGetInputbox(WidgetReference)

Gets the current value from an input box.

MachoMenuSetText(WidgetReference, Text)

Updates the text of any widget.

MachoMenuDropDown(GroupReference, Name, Callback, Selectable1, Selectable2...)

Creates a dropdown menu with options.

MachoMenuKeybind(GroupReference, Name, DefaultKey, Callback)

Creates a keybind selector with callback.

Security & Logging

MachoGetLoggerState()

Returns the current logger state (enabled/disabled bits).

MachoSetLoggerState(state)

Sets the logger state (0 = all disabled, 3 = all enabled).

MachoLockLogger()

Completely locks the event logger (irreversible until reload).

Resource Management

MachoInjectResource(Resource, Code)

Injects Lua code into a specific resource.

MachoHijackResource(ResourceName)

Injects the complete script into a resource (use at file start).

MachoResourceStop(Resource)

Stops a specific resource.

MachoResourceStart(Resource)

Starts a specific resource.

Authentication

MachoAuthenticationKey()

Returns the user's current authentication key.

MachoWebRequest(URL)

Makes a web request and returns the response body.

Notifications

MachoMenuNotification(Title, Description)

Displays a Macho-style notification to the user.

API Usage Examples

Complete Menu Example:

-- Create main window
local mainWindow = MachoMenuWindow(100, 100, 400, 600)
MachoMenuSetKeybind(mainWindow, 0x2E) -- DELETE key

-- Create tabs
local tab1 = MachoMenuAddTab(mainWindow, "Main")
local tab2 = MachoMenuAddTab(mainWindow, "Settings")

-- Create groups
local group1 = MachoMenuGroup(tab1, "Actions", 10, 50, 380, 200)
local group2 = MachoMenuGroup(tab2, "Configuration", 10, 50, 380, 300)

-- Add widgets to group1
MachoMenuButton(group1, "Execute Trigger", function()
    -- Your trigger code here
    TriggerEvent('esx:getSharedObject')
    MachoMenuNotification("SUCCESS", "Trigger executed!")
end)

MachoMenuCheckbox(group1, "Enable Feature", 
    function() print("Feature enabled") end,
    function() print("Feature disabled") end
)

local slider = MachoMenuSlider(group1, "Speed", 50, 0, 100, "km/h", 0, function(value)
    print("Speed set to: " .. value)
end)

-- Add widgets to group2
local inputBox = MachoMenuInputbox(group2, "Player Name", "Enter name...")
MachoMenuButton(group2, "Get Name", function()
    local name = MachoMenuGetInputbox(inputBox)
    print("Player name: " .. name)
end)

MachoMenuDropDown(group2, "Vehicle Type", function(selection)
    print("Selected: " .. selection)
end, "Car", "Bike", "Plane", "Boat")

MachoMenuKeybind(group2, "Teleport Key", 0, function(key, toggle)
    print("Key pressed: " .. key .. ", Toggle: " .. tostring(toggle))
end)

Advanced Menu Layout with Multiple Sections:

-- Advanced menu layout with calculated sections
local MenuSize = vec2(600, 350)
local MenuStartCoords = vec2(500, 500) 

local TabsBarWidth = 0 -- The width of the tabs bar, height is assumed to be MenuHeight as it goes top to bottom

local SectionChildWidth = MenuSize.x - TabsBarWidth -- The total size for sections on the left hand side
local SectionsCount = 3 
local SectionsPadding = 10 -- pixels between each section (that makes SetionCount + 1 = total padding areas)
local MachoPaneGap = 10 -- Hard coded gap of accent at the top.

-- Therefore each section width must be:
local EachSectionWidth = (SectionChildWidth - (SectionsPadding * (SectionsCount + 1))) / SectionsCount

-- Now you have each sections absolute width, you can calculate their X coordinate and Y coordinate
local SectionOneStart = vec2(TabsBarWidth + (SectionsPadding * 1) + (EachSectionWidth * 0), SectionsPadding + MachoPaneGap)
local SectionOneEnd = vec2(SectionOneStart.x + EachSectionWidth, MenuSize.y - SectionsPadding)

local SectionTwoStart = vec2(TabsBarWidth + (SectionsPadding * 2) + (EachSectionWidth * 1), SectionsPadding + MachoPaneGap)
local SectionTwoEnd = vec2(SectionTwoStart.x + EachSectionWidth, MenuSize.y - SectionsPadding)

local SectionThreeStart = vec2(TabsBarWidth + (SectionsPadding * 3) + (EachSectionWidth * 2), SectionsPadding + MachoPaneGap)
local SectionThreeEnd = vec2(SectionThreeStart.x + EachSectionWidth, MenuSize.y - SectionsPadding)

-- Create our window, MenuStartCoords is where the menu starts
MenuWindow = MachoMenuWindow(MenuStartCoords.x, MenuStartCoords.y, MenuSize.x, MenuSize.y)

MachoMenuSetAccent(MenuWindow, 137, 52, 235)

-- First section
FirstSection = MachoMenuGroup(MenuWindow, "Section One", SectionOneStart.x, SectionOneStart.y, SectionOneEnd.x, SectionOneEnd.y)

MachoMenuButton(FirstSection, "Close", function()
    MachoMenuDestroy(MenuWindow)
end)

-- Second section
SecondSection = MachoMenuGroup(MenuWindow, "Section Two", SectionTwoStart.x, SectionTwoStart.y, SectionTwoEnd.x, SectionTwoEnd.y)

MenuSliderHandle = MachoMenuSlider(SecondSection, "Slider", 10, 0, 100, "%", 0, function(Value)
    print("Slider updated with value ".. Value)
end)

MachoMenuCheckbox(SecondSection, "Checkbox", 
    function()
        print("Enabled")
    end,
    function()
        print("Disabled")
    end
)

TextHandle = MachoMenuText(SecondSection, "SomeText")

MachoMenuButton(SecondSection, "Change Text Example", function()
    MachoMenuSetText(TextHandle, "ChangedText")
end)

-- Third section
ThirdSection = MachoMenuGroup(MenuWindow, "Section Three", SectionThreeStart.x, SectionThreeStart.y, SectionThreeEnd.x, SectionThreeEnd.y)

InputBoxHandle = MachoMenuInputbox(ThirdSection, "Input", "...")
MachoMenuButton(ThirdSection, "Print Input", function()
    local LocatedText = MachoMenuGetInputbox(InputBoxHandle)
    print(LocatedText)
end)

DropDownHandle = MachoMenuDropDown(ThirdSection, "Drop Down", 
    function(Index)
        print("New Value is " .. Index)
    end, 
    "Selectable 1",
    "Selectable 2",
    "Selectable 3"
)

Basic Menu Layout Example:

-- Basic menu layout with 3 sections
local MenuSize = vec2(500, 300)
local MenuStartCoords = vec2(500, 500) 

local TabsBarWidth = 0 -- The width of the tabs bar, height is assumed to be MenuHeight as it goes top to bottom

local SectionChildWidth = MenuSize.x - TabsBarWidth -- The total size for sections on the left hand side
local SectionsCount = 3 
local SectionsPadding = 10 -- pixels between each section (that makes SetionCount + 1 = total padding areas)
local MachoPaneGap = 10 -- Hard coded gap of accent at the top.

-- Therefore each section width must be:
local EachSectionWidth = (SectionChildWidth - (SectionsPadding * (SectionsCount + 1))) / SectionsCount

-- Now you have each sections absolute width, you can calculate their X coordinate and Y coordinate
local SectionOneStart = vec2(TabsBarWidth + (SectionsPadding * 1) + (EachSectionWidth * 0), SectionsPadding + MachoPaneGap)
local SectionOneEnd = vec2(SectionOneStart.x + EachSectionWidth, MenuSize.y - SectionsPadding)

local SectionTwoStart = vec2(TabsBarWidth + (SectionsPadding * 2) + (EachSectionWidth * 1), SectionsPadding + MachoPaneGap)
local SectionTwoEnd = vec2(SectionTwoStart.x + EachSectionWidth, MenuSize.y - SectionsPadding)

local SectionThreeStart = vec2(TabsBarWidth + (SectionsPadding * 3) + (EachSectionWidth * 2), SectionsPadding + MachoPaneGap)
local SectionThreeEnd = vec2(SectionThreeStart.x + EachSectionWidth, MenuSize.y - SectionsPadding)

-- Create our window, MenuStartCoords is where the menu starts
MenuWindow = MachoMenuWindow(MenuStartCoords.x, MenuStartCoords.y, MenuSize.x, MenuSize.y)

MachoMenuSetAccent(MenuWindow, 137, 52, 235)

-- First tab
FirstSection = MachoMenuGroup(MenuWindow, "Section One", SectionOneStart.x, SectionOneStart.y, SectionOneEnd.x, SectionOneEnd.y)

MachoMenuButton(FirstSection, "Close", function()
    MachoMenuDestroy(MenuWindow)
end)

-- Second tab
SecondSection = MachoMenuGroup(MenuWindow, "Section Two", SectionTwoStart.x, SectionTwoStart.y, SectionTwoEnd.x, SectionTwoEnd.y)
MachoMenuButton(SecondSection, "Close", function()
    MachoMenuDestroy(MenuWindow)
end)

-- Third tab
ThirdSection = MachoMenuGroup(MenuWindow, "Section Three", SectionThreeStart.x, SectionThreeStart.y, SectionThreeEnd.x, SectionThreeEnd.y)
MachoMenuButton(ThirdSection, "Close", function()
    MachoMenuDestroy(MenuWindow)
end)

Authentication Example:

-- Paid script authentication
local KeysBin = MachoWebRequest("https://your-website.com/keys.txt")
local CurrentKey = MachoAuthenticationKey()

local KeyPresent = string.find(KeysBin, CurrentKey)
if KeyPresent ~= nil then
    print("Key is authenticated [" .. CurrentKey .. "]")
    MachoMenuNotification("SUCCESS", "Authentication successful!")
else
    print("Key is not in the list [" .. CurrentKey .. "]")
    MachoMenuNotification("ERROR", "Invalid authentication key!")
end

Resource Injection Example:

-- Inject code into a resource
MachoInjectResource('es_extended', [[
    print("Injected into es_extended!")
    -- Your injected code here
]])

-- Or hijack entire resource
-- [MachoHijackResource('es_extended')]
-- Your complete script here

-- Resource management
MachoResourceStop('es_extended')
Citizen.Wait(1000)
MachoResourceStart('es_extended')

Security & Logging Example:

-- Secure trigger execution
local function executeSecureTrigger()
    -- Disable logger before execution
    local loggerState = MachoGetLoggerState()
    MachoSetLoggerState(0)
    
    -- Execute your trigger
    local success, result = pcall(function()
        TriggerEvent('esx:getSharedObject')
        -- Your sensitive code here
    end)
    
    -- Restore logger state
    Citizen.Wait(100)
    MachoSetLoggerState(loggerState)
    
    if success then
        MachoMenuNotification("SUCCESS", "Trigger executed securely")
    else
        MachoMenuNotification("ERROR", "Trigger failed: " .. tostring(result))
    end
end

-- Completely lock logger (use with caution)
-- MachoLockLogger()

Basic Trigger Example

Basic Trigger Example:

-- Your original code
TriggerEvent('esx:getSharedObject')
local xPlayer = ESX.GetPlayerData()
print('Player data loaded successfully')

-- Gets processed to:
-- Macho API Support
local function executeSafely()
    local loggerState = MachoGetLoggerState()
    MachoSetLoggerState(0)
    
    local success, result = pcall(function()
        TriggerEvent('esx:getSharedObject')
        local xPlayer = ESX.GetPlayerData()
        print('Player data loaded successfully')
    end)
    
    Citizen.Wait(100)
    MachoSetLoggerState(loggerState)
    
    if success then
        MachoMenuNotification("SUCCESS", "Trigger executed successfully")
        print("^2[SUCCESS]^7 Trigger executed successfully")
        return true
    else
        MachoMenuNotification("ERROR", "Failed to execute trigger: " .. tostring(result))
        print("^1[ERROR]^7 Failed to execute trigger: " .. tostring(result))
        return false
    end
end

local result = executeSafely()
if result then
    print("^3[INFO]^7 Trigger execution completed")
else
    print("^1[INFO]^7 Trigger execution failed")
end