{"id":193197,"date":"2025-08-17T20:57:54","date_gmt":"2025-08-17T18:57:54","guid":{"rendered":"https:\/\/fivemx.com\/?p=193197"},"modified":"2025-12-23T16:43:20","modified_gmt":"2025-12-23T15:43:20","slug":"escrever-scripts-fivem-usando-ia","status":"publish","type":"post","link":"https:\/\/fivemx.com\/pt\/write-fivem-scripts-using-ai\/","title":{"rendered":"Como escrever scripts para FiveM usando IA: Guia completo para desenvolvedores\u2026"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">Writing FiveM scripts has traditionally required deep knowledge of Lua, JavaScript, and the FiveM API. Today, AI tools like Claude Code, GitHub Copilot, and ChatGPT are revolutionizing how developers create everything from <a href=\"https:\/\/fivemx.com\/esx-scripts\">ESX scripts<\/a> to complex <a href=\"https:\/\/fivemx.com\/standalone-scripts\">standalone systems<\/a>. This comprehensive guide shows you exactly how to leverage AI for FiveM development, with concrete examples and proven workflows.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Why AI-Assisted FiveM Development Changes Everything<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Traditional FiveM script development requires mastering multiple technologies simultaneously: Lua for server-side logic, JavaScript for NUI interfaces, SQL for database operations, and the extensive <a href=\"https:\/\/docs.fivem.net\/natives\/\" target=\"_blank\" data-type=\"link\" data-id=\"https:\/\/docs.fivem.net\/natives\/\" rel=\"noreferrer noopener\">FiveM native functions library<\/a>. AI tools compress months of learning into hours of productive coding.<\/p>\n\n\n\n<div class=\"wp-block-buttons is-layout-flex wp-block-buttons-is-layout-flex\">\n<div class=\"wp-block-button is-style-fill\"><a class=\"wp-block-button__link has-white-color has-black-background-color has-text-color has-background has-link-color wp-element-button\" href=\"https:\/\/fivemx.com\/awesome-tools-for-fivem-development\/\">Awesome Tools for FiveM Development<\/a><\/div>\n<\/div>\n\n\n\n<div style=\"height:32px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Real Impact for Server Owners:<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Reduce custom script development time by 60-80%<\/li>\n\n\n\n<li>Generate boilerplate code instantly for common patterns<\/li>\n\n\n\n<li>Debug complex synchronization issues between client and server<\/li>\n\n\n\n<li>Convert ideas directly into working prototypes<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">Essential AI Tools for FiveM Development<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\"><a href=\"https:\/\/www.anthropic.com\/claude-code\" data-type=\"link\" data-id=\"https:\/\/www.anthropic.com\/claude-code\" target=\"_blank\" rel=\"noopener\">Claude Code (Anthropic)<\/a><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Claude Code excels at FiveM development because it understands context across multiple files and can generate complete resource structures. Install via command line:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">pip install claude-code\nclaude-code init --project fivem-resource\n<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>FiveM-Specific Advantages:<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Generates complete fxmanifest.lua configurations<\/li>\n\n\n\n<li>Understands ESX, QBCore, and VRP frameworks<\/li>\n\n\n\n<li>Creates matching client\/server event handlers automatically<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\"><a href=\"https:\/\/github.com\/features\/copilot\" target=\"_blank\" rel=\"noopener\">GitHub Copilot<\/a><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Integrates directly into VS Code, providing real-time suggestions as you type. Particularly effective for:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Completing native function calls<\/li>\n\n\n\n<li>Generating event handler patterns<\/li>\n\n\n\n<li>Auto-completing database queries<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">ChatGPT with Custom Instructions<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Configure ChatGPT specifically for FiveM by setting custom instructions:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">You are a FiveM script developer. Always use:\n- Lua 5.4 syntax for server scripts\n- Modern JavaScript for client scripts\n- FiveM natives from the latest game build\n- Proper event security with server-side validation\n<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Step-by-Step: Creating Your First AI-Generated Script<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Let&#8217;s build a complete vehicle shop script using Claude Code, demonstrating the entire workflow from concept to deployment.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Step 1: Define Clear Requirements<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Create a <code>requirements.md<\/code> file:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">## Vehicle Shop Script Requirements\n- Framework: ESX Legacy 1.9.0+\n- Database: MySQL with oxmysql\n- Features:\n  - Browse vehicles by category\n  - Test drive system with time limit\n  - Finance options with weekly payments\n  - Admin commands for adding vehicles\n- UI: Modern NUI with React\n<\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Step 2: Generate the Resource Structure<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Command to Claude Code:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">claude-code generate \"Create a complete FiveM vehicle shop resource based on requirements.md\"\n<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">This generates:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">vehicle_shop\/\n\u251c\u2500\u2500 fxmanifest.lua\n\u251c\u2500\u2500 config.lua\n\u251c\u2500\u2500 server\/\n\u2502   \u251c\u2500\u2500 main.lua\n\u2502   \u251c\u2500\u2500 database.lua\n\u2502   \u2514\u2500\u2500 commands.lua\n\u251c\u2500\u2500 client\/\n\u2502   \u251c\u2500\u2500 main.lua\n\u2502   \u251c\u2500\u2500 showroom.lua\n\u2502   \u2514\u2500\u2500 testdrive.lua\n\u251c\u2500\u2500 ui\/\n\u2502   \u251c\u2500\u2500 index.html\n\u2502   \u251c\u2500\u2500 style.css\n\u2502   \u2514\u2500\u2500 script.js\n\u2514\u2500\u2500 sql\/\n    \u2514\u2500\u2500 vehicle_shop.sql\n<\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Step 3: AI-Generated fxmanifest.lua<\/h3>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">fx_version 'cerulean'\ngame 'gta5'\n\nauthor 'YourName'\ndescription 'AI-Generated Vehicle Shop'\nversion '1.0.0'\n\nshared_scripts {\n    '@es_extended\/imports.lua',\n    '@ox_lib\/init.lua',\n    'config.lua'\n}\n\nclient_scripts {\n    'client\/*.lua'\n}\n\nserver_scripts {\n    '@oxmysql\/lib\/MySQL.lua',\n    'server\/*.lua'\n}\n\nui_page 'ui\/index.html'\n\nfiles {\n    'ui\/index.html',\n    'ui\/style.css',\n    'ui\/script.js'\n}\n\ndependencies {\n    'es_extended',\n    'oxmysql',\n    'ox_lib'\n}\n<\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Step 4: Implement Core Functionality with AI<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Prompt for Server-Side Vehicle Loading:<\/strong><\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">-- AI-Generated: server\/database.lua\nlocal vehicles = {}\n\nCreateThread(function()\n    local result = MySQL.query.await('SELECT * FROM vehicle_shop WHERE stock &gt; 0')\n    \n    for i = 1, #result do\n        local vehicle = result[i]\n        vehicles[vehicle.model] = {\n            model = vehicle.model,\n            name = vehicle.name,\n            price = vehicle.price,\n            category = vehicle.category,\n            stock = vehicle.stock\n        }\n    end\n    \n    print(('[^2INFO^7] Loaded %d vehicles from database'):format(#result))\nend)\n\n-- Secure server event for purchasing\nRegisterNetEvent('vehicle_shop:server:purchaseVehicle', function(vehicleModel, paymentMethod)\n    local src = source\n    local xPlayer = ESX.GetPlayerFromId(src)\n    \n    -- Security check\n    if not vehicles[vehicleModel] then\n        return TriggerClientEvent('ox_lib:notify', src, {\n            title = 'Error',\n            description = 'Invalid vehicle model',\n            type = 'error'\n        })\n    end\n    \n    local vehicleData = vehicles[vehicleModel]\n    \n    -- Payment processing\n    if paymentMethod == 'cash' then\n        if xPlayer.getMoney() &gt;= vehicleData.price then\n            xPlayer.removeMoney(vehicleData.price)\n            -- Generate plate and spawn vehicle\n            local plate = GeneratePlate()\n            \n            MySQL.insert('INSERT INTO owned_vehicles (owner, plate, vehicle) VALUES (?, ?, ?)', {\n                xPlayer.identifier,\n                plate,\n                json.encode({model = vehicleModel, plate = plate})\n            })\n            \n            TriggerClientEvent('vehicle_shop:client:spawnVehicle', src, vehicleModel, plate)\n        else\n            TriggerClientEvent('ox_lib:notify', src, {\n                title = 'Insufficient Funds',\n                description = ('You need $%d'):format(vehicleData.price),\n                type = 'error'\n            })\n        end\n    end\nend)\n<\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Step 5: Client-Side Implementation<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>AI Prompt:<\/strong> &#8220;Create client-side showroom with camera controls and vehicle preview&#8221;<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">-- AI-Generated: client\/showroom.lua\nlocal currentVehicle = nil\nlocal cam = nil\nlocal inShowroom = false\n\nlocal showroomCoords = vector3(-42.34, -1097.35, 26.42)\nlocal vehicleSpawnCoords = vector4(-47.52, -1097.29, 26.42, 340.0)\n\nfunction OpenShowroom(category)\n    inShowroom = true\n    DoScreenFadeOut(500)\n    Wait(500)\n    \n    -- Setup camera\n    cam = CreateCam('DEFAULT_SCRIPTED_CAMERA', true)\n    SetCamCoord(cam, -54.31, -1097.29, 28.42)\n    PointCamAtCoord(cam, vehicleSpawnCoords.x, vehicleSpawnCoords.y, vehicleSpawnCoords.z)\n    SetCamActive(cam, true)\n    RenderScriptCams(true, false, 0, true, false)\n    \n    -- Request vehicles from server\n    ESX.TriggerServerCallback('vehicle_shop:getVehicles', function(vehicles)\n        SendNUIMessage({\n            action = 'showVehicles',\n            vehicles = vehicles,\n            category = category\n        })\n        SetNuiFocus(true, true)\n    end, category)\n    \n    DoScreenFadeIn(500)\nend\n\nRegisterNUICallback('previewVehicle', function(data, cb)\n    if currentVehicle then\n        DeleteEntity(currentVehicle)\n    end\n    \n    local model = GetHashKey(data.model)\n    RequestModel(model)\n    \n    while not HasModelLoaded(model) do\n        Wait(10)\n    end\n    \n    currentVehicle = CreateVehicle(model, vehicleSpawnCoords.x, vehicleSpawnCoords.y, \n                                   vehicleSpawnCoords.z, vehicleSpawnCoords.w, false, false)\n    SetEntityAsMissionEntity(currentVehicle, true, true)\n    SetVehicleOnGroundProperly(currentVehicle)\n    SetVehicleDoorsLocked(currentVehicle, 2)\n    \n    cb('ok')\nend)\n<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Advanced AI Techniques for Complex Systems<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">Multi-File Context Management<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">When developing interconnected systems like <a href=\"https:\/\/fivemx.com\/phone-scripts\">phone scripts<\/a>, provide AI with complete context:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\"># Feed multiple files to Claude Code\nclaude-code analyze --files \"server\/*.lua,client\/*.lua,config.lua\" \\\n  --prompt \"Add a garage system that integrates with the existing vehicle shop\"\n<\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Framework-Specific Prompting<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Different frameworks require different approaches. Here&#8217;s how to optimize AI prompts for each:<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>For ESX:<\/strong><\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">Generate an ESX job script with:\n- Grades\/ranks system using ESX.Jobs\n- Salary payments via ESX.GetJobs()\n- Boss menu with society funds\n- Use esx_society patterns\n<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>For QBCore:<\/strong><\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">Create a QBCore gang system with:\n- Gang territories using PolyZone\n- Reputation system with QB.Shared.Gangs\n- Stash\/storage using qb-inventory\n- Gang management via qb-gangmenu patterns\n<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>For <a href=\"https:\/\/fivemx.com\/vrp-scripts\">VRP Scripts<\/a>:<\/strong><\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">Build a VRP business system using:\n- vRP.getUserId for player identification\n- vRP permissions system\n- vRP money methods (giveMoney, tryPayment)\n- vRPclient tunnel for client callbacks\n<\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Database Schema Generation<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">AI excels at creating optimized database structures:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">-- AI Prompt: \"Create MySQL schema for advanced vehicle shop with financing\"\n-- Generated Result:\n\nCREATE TABLE IF NOT EXISTS `vehicle_shop_catalog` (\n    `id` int(11) NOT NULL AUTO_INCREMENT,\n    `model` varchar(60) NOT NULL,\n    `name` varchar(60) NOT NULL,\n    `manufacturer` varchar(60) DEFAULT NULL,\n    `category` varchar(60) DEFAULT NULL,\n    `price` int(11) NOT NULL,\n    `stock` int(11) DEFAULT 10,\n    `max_speed` int(11) DEFAULT NULL,\n    `acceleration` float DEFAULT NULL,\n    `braking` float DEFAULT NULL,\n    `handling` float DEFAULT NULL,\n    PRIMARY KEY (`id`),\n    UNIQUE KEY `model` (`model`),\n    KEY `idx_category` (`category`),\n    KEY `idx_price` (`price`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;\n\nCREATE TABLE IF NOT EXISTS `vehicle_financing` (\n    `id` int(11) NOT NULL AUTO_INCREMENT,\n    `identifier` varchar(60) NOT NULL,\n    `vehicle_id` int(11) NOT NULL,\n    `down_payment` int(11) NOT NULL,\n    `weekly_payment` int(11) NOT NULL,\n    `weeks_remaining` int(11) NOT NULL,\n    `last_payment` timestamp DEFAULT CURRENT_TIMESTAMP,\n    `repo_warning_sent` boolean DEFAULT FALSE,\n    PRIMARY KEY (`id`),\n    KEY `idx_identifier` (`identifier`),\n    FOREIGN KEY (`vehicle_id`) REFERENCES `owned_vehicles`(`id`) ON DELETE CASCADE\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;\n<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Debugging and Optimization with AI<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">Performance Profiling Prompts<\/h3>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">-- Prompt: \"Add performance monitoring to this resource\"\n-- AI generates:\n\nlocal performanceStats = {\n    events = {},\n    queries = {}\n}\n\nlocal function profileEvent(eventName, func)\n    return function(...)\n        local startTime = GetGameTimer()\n        local result = {func(...)}\n        local executionTime = GetGameTimer() - startTime\n        \n        performanceStats.events[eventName] = performanceStats.events[eventName] or {}\n        table.insert(performanceStats.events[eventName], executionTime)\n        \n        if executionTime &gt; 50 then\n            print(('[^3WARNING^7] Event %s took %dms'):format(eventName, executionTime))\n        end\n        \n        return table.unpack(result)\n    end\nend\n\n-- Wrap existing events\nRegisterNetEvent('vehicle_shop:server:purchaseVehicle', \n                profileEvent('purchaseVehicle', purchaseVehicleHandler))\n<\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Security Validation<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">AI can identify and fix security vulnerabilities:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">-- Prompt: \"Add security validation to this client-to-server event\"\n-- Before (vulnerable):\nRegisterNetEvent('giveWeapon', function(weapon)\n    local src = source\n    GiveWeaponToPed(GetPlayerPed(src), weapon, 250, false, true)\nend)\n\n-- After (AI-secured):\nlocal allowedWeapons = {\n    ['WEAPON_PISTOL'] = true,\n    ['WEAPON_COMBATPISTOL'] = true\n}\n\nRegisterNetEvent('giveWeapon', function(weapon)\n    local src = source\n    local xPlayer = ESX.GetPlayerFromId(src)\n    \n    -- Multiple validation layers\n    if not xPlayer then return end\n    if not allowedWeapons[weapon] then\n        return DropPlayer(src, 'Attempted to spawn invalid weapon')\n    end\n    if not xPlayer.hasPermission('weapons.spawn') then\n        return TriggerClientEvent('ox_lib:notify', src, {\n            title = 'Access Denied',\n            type = 'error'\n        })\n    end\n    \n    -- Log the action\n    print(('[^3WEAPON^7] %s spawned %s'):format(xPlayer.getName(), weapon))\n    \n    xPlayer.addWeapon(weapon, 250)\nend)\n<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">NUI Development with AI<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Creating modern interfaces for FiveM requires HTML\/CSS\/JavaScript expertise. AI streamlines this process:<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">React Component Generation<\/h3>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">\/\/ Prompt: \"Create a React vehicle shop UI with category filtering\"\n\/\/ AI generates:\n\nimport React, { useState, useEffect } from 'react';\nimport '.\/VehicleShop.css';\n\nconst VehicleShop = () =&gt; {\n    const [vehicles, setVehicles] = useState([]);\n    const [selectedCategory, setSelectedCategory] = useState('all');\n    const [selectedVehicle, setSelectedVehicle] = useState(null);\n    const [searchTerm, setSearchTerm] = useState('');\n\n    useEffect(() =&gt; {\n        window.addEventListener('message', handleMessage);\n        return () =&gt; window.removeEventListener('message', handleMessage);\n    }, []);\n\n    const handleMessage = (event) =&gt; {\n        const { action, data } = event.data;\n        \n        switch(action) {\n            case 'showVehicles':\n                setVehicles(data.vehicles);\n                break;\n            case 'updateStock':\n                updateVehicleStock(data.model, data.stock);\n                break;\n        }\n    };\n\n    const filteredVehicles = vehicles.filter(vehicle =&gt; {\n        const matchesCategory = selectedCategory === 'all' || \n                               vehicle.category === selectedCategory;\n        const matchesSearch = vehicle.name.toLowerCase()\n                                    .includes(searchTerm.toLowerCase());\n        return matchesCategory &amp;&amp; matchesSearch;\n    });\n\n    const purchaseVehicle = (vehicle, paymentMethod) =&gt; {\n        fetch(`https:\/\/${GetParentResourceName()}\/purchaseVehicle`, {\n            method: 'POST',\n            headers: { 'Content-Type': 'application\/json' },\n            body: JSON.stringify({\n                model: vehicle.model,\n                paymentMethod: paymentMethod\n            })\n        });\n    };\n\n    return (\n        &lt;div className=\"vehicle-shop-container\"&gt;\n            &lt;div className=\"shop-header\"&gt;\n                &lt;h1&gt;Premium Deluxe Motorsport&lt;\/h1&gt;\n                &lt;input \n                    type=\"text\"\n                    placeholder=\"Search vehicles...\"\n                    value={searchTerm}\n                    onChange={(e) =&gt; setSearchTerm(e.target.value)}\n                    className=\"search-input\"\n                \/&gt;\n            &lt;\/div&gt;\n\n            &lt;div className=\"category-filters\"&gt;\n                {['all', 'sports', 'super', 'sedan', 'suv', 'motorcycle'].map(cat =&gt; (\n                    &lt;button\n                        key={cat}\n                        className={`category-btn ${selectedCategory === cat ? 'active' : ''}`}\n                        onClick={() =&gt; setSelectedCategory(cat)}\n                    &gt;\n                        {cat.toUpperCase()}\n                    &lt;\/button&gt;\n                ))}\n            &lt;\/div&gt;\n\n            &lt;div className=\"vehicles-grid\"&gt;\n                {filteredVehicles.map(vehicle =&gt; (\n                    &lt;VehicleCard \n                        key={vehicle.model}\n                        vehicle={vehicle}\n                        onSelect={() =&gt; setSelectedVehicle(vehicle)}\n                    \/&gt;\n                ))}\n            &lt;\/div&gt;\n\n            {selectedVehicle &amp;&amp; (\n                &lt;VehicleDetails \n                    vehicle={selectedVehicle}\n                    onPurchase={purchaseVehicle}\n                    onClose={() =&gt; setSelectedVehicle(null)}\n                \/&gt;\n            )}\n        &lt;\/div&gt;\n    );\n};\n<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Common AI Pitfalls and Solutions<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">Problem 1: Outdated Native Functions<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Issue:<\/strong> AI suggests deprecated FiveM natives <strong>Solution:<\/strong> Always specify the game build in your prompt:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">Use only FiveM natives compatible with game build 3095+\nReplace deprecated natives like GetPlayerPed(-1) with PlayerPedId()\n<\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Problem 2: Memory Leaks in Loops<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Issue:<\/strong> AI creates infinite loops without proper cleanup <strong>Solution:<\/strong> Request garbage collection patterns:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">-- AI-improved version with cleanup\nlocal activeThreads = {}\n\nlocal function createManagedThread(id, func)\n    if activeThreads[id] then\n        -- Kill existing thread\n        activeThreads[id] = false\n    end\n    \n    activeThreads[id] = true\n    \n    CreateThread(function()\n        while activeThreads[id] do\n            func()\n            Wait(0)\n        end\n    end)\nend\n\n-- Cleanup on resource stop\nAddEventHandler('onResourceStop', function(resourceName)\n    if GetCurrentResourceName() == resourceName then\n        for id, _ in pairs(activeThreads) do\n            activeThreads[id] = false\n        end\n    end\nend)\n<\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Problem 3: Synchronization Issues<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Issue:<\/strong> Client-server state mismatches <strong>Solution:<\/strong> Use AI to generate state management:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">-- Prompt: \"Create a synchronized state manager for client-server data\"\n-- AI generates:\n\n-- Server-side state manager\nlocal StateManager = {}\nStateManager.states = {}\n\nfunction StateManager:set(key, value)\n    self.states[key] = value\n    TriggerClientEvent('stateManager:sync', -1, key, value)\nend\n\nfunction StateManager:get(key)\n    return self.states[key]\nend\n\nRegisterNetEvent('stateManager:requestSync', function()\n    local src = source\n    TriggerClientEvent('stateManager:fullSync', src, StateManager.states)\nend)\n\n-- Client-side state manager\nlocal ClientState = {}\n\nRegisterNetEvent('stateManager:sync', function(key, value)\n    ClientState[key] = value\nend)\n\nRegisterNetEvent('stateManager:fullSync', function(states)\n    ClientState = states\nend)\n\n-- Request initial sync\nCreateThread(function()\n    Wait(1000)\n    TriggerServerEvent('stateManager:requestSync')\nend)\n<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Testing and Deployment Strategies<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">Automated Testing with AI<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Generate comprehensive test suites:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">-- Prompt: \"Create unit tests for the vehicle shop purchase function\"\n-- AI generates:\n\nlocal function runTests()\n    local testResults = {\n        passed = 0,\n        failed = 0,\n        tests = {}\n    }\n\n    -- Test 1: Valid purchase with sufficient funds\n    local function testValidPurchase()\n        local mockPlayer = {\n            identifier = 'test_player_1',\n            money = 50000,\n            getMoney = function() return 50000 end,\n            removeMoney = function(amount) \n                mockPlayer.money = mockPlayer.money - amount\n                return true\n            end\n        }\n        \n        local result = attemptPurchase(mockPlayer, 'adder', 45000)\n        assert(result.success == true, 'Valid purchase should succeed')\n        assert(mockPlayer.money == 5000, 'Money should be deducted correctly')\n        \n        return true\n    end\n\n    -- Test 2: Purchase with insufficient funds\n    local function testInsufficientFunds()\n        local mockPlayer = {\n            identifier = 'test_player_2',\n            money = 1000,\n            getMoney = function() return 1000 end\n        }\n        \n        local result = attemptPurchase(mockPlayer, 'adder', 45000)\n        assert(result.success == false, 'Purchase should fail with insufficient funds')\n        assert(result.error == 'insufficient_funds', 'Should return correct error code')\n        \n        return true\n    end\n\n    -- Run all tests\n    local tests = {\n        {name = 'Valid Purchase', func = testValidPurchase},\n        {name = 'Insufficient Funds', func = testInsufficientFunds}\n    }\n\n    for _, test in ipairs(tests) do\n        local success, error = pcall(test.func)\n        if success then\n            testResults.passed = testResults.passed + 1\n            print(('[^2\u2713^7] %s passed'):format(test.name))\n        else\n            testResults.failed = testResults.failed + 1\n            print(('[^1\u2717^7] %s failed: %s'):format(test.name, error))\n        end\n        \n        table.insert(testResults.tests, {\n            name = test.name,\n            passed = success,\n            error = error\n        })\n    end\n\n    return testResults\nend\n\n-- Run tests on resource start in development mode\nif Config.Debug then\n    CreateThread(function()\n        Wait(1000)\n        local results = runTests()\n        print(('Tests completed: %d passed, %d failed'):format(\n            results.passed, results.failed\n        ))\n    end)\nend\n<\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Performance Monitoring<\/h3>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">-- Prompt: \"Add performance monitoring for production deployment\"\n-- AI generates:\n\nlocal Monitor = {\n    metrics = {\n        eventCalls = {},\n        dbQueries = {},\n        memoryUsage = {}\n    }\n}\n\nfunction Monitor:trackEvent(eventName)\n    self.metrics.eventCalls[eventName] = (self.metrics.eventCalls[eventName] or 0) + 1\nend\n\nfunction Monitor:trackQuery(queryType, duration)\n    table.insert(self.metrics.dbQueries, {\n        type = queryType,\n        duration = duration,\n        timestamp = os.time()\n    })\nend\n\nfunction Monitor:getReport()\n    local report = {\n        uptime = GetGameTimer() \/ 1000,\n        totalEvents = 0,\n        averageQueryTime = 0,\n        memoryUsage = collectgarbage('count')\n    }\n    \n    for _, count in pairs(self.metrics.eventCalls) do\n        report.totalEvents = report.totalEvents + count\n    end\n    \n    if #self.metrics.dbQueries &gt; 0 then\n        local totalTime = 0\n        for _, query in ipairs(self.metrics.dbQueries) do\n            totalTime = totalTime + query.duration\n        end\n        report.averageQueryTime = totalTime \/ #self.metrics.dbQueries\n    end\n    \n    return report\nend\n\n-- Export metrics endpoint\nRegisterCommand('metrics', function(source)\n    if source == 0 or IsPlayerAceAllowed(source, 'admin.metrics') then\n        print(json.encode(Monitor:getReport(), {indent = true}))\n    end\nend, true)\n<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Integration with Existing Resources<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">When adding AI-generated scripts to existing servers with <a href=\"https:\/\/fivemx.com\/esx-scripts\">ESX scripts<\/a> or <a href=\"https:\/\/fivemx.com\/standalone-scripts\">standalone scripts<\/a>, follow these integration patterns:<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Resource Dependencies<\/h3>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">-- config.lua - AI-generated configuration for compatibility\nConfig = {}\n\n-- Framework detection\nConfig.Framework = nil\n\nCreateThread(function()\n    if GetResourceState('es_extended') == 'started' then\n        Config.Framework = 'esx'\n        ESX = exports['es_extended']:getSharedObject()\n    elseif GetResourceState('qb-core') == 'started' then\n        Config.Framework = 'qbcore'\n        QBCore = exports['qb-core']:GetCoreObject()\n    else\n        Config.Framework = 'standalone'\n    end\n    \n    print(('[^2INFO^7] Detected framework: %s'):format(Config.Framework))\nend)\n\n-- Framework-agnostic money functions\nfunction GetPlayerMoney(source)\n    if Config.Framework == 'esx' then\n        local xPlayer = ESX.GetPlayerFromId(source)\n        return xPlayer.getMoney()\n    elseif Config.Framework == 'qbcore' then\n        local Player = QBCore.Functions.GetPlayer(source)\n        return Player.PlayerData.money.cash\n    else\n        -- Standalone implementation\n        return exports['your_economy']:GetMoney(source)\n    end\nend\n<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Best Practices Checklist<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Before deploying AI-generated scripts:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>[ ] <strong>Security Validation<\/strong>: All client-to-server events validated<\/li>\n\n\n\n<li>[ ] <strong>Performance Testing<\/strong>: No loops without Wait()<\/li>\n\n\n\n<li>[ ] <strong>Memory Management<\/strong>: Proper cleanup on resource stop<\/li>\n\n\n\n<li>[ ] <strong>Database Indexes<\/strong>: Indexes on frequently queried columns<\/li>\n\n\n\n<li>[ ] <strong>Error <a class=\"wpil_keyword_link\" href=\"https:\/\/fivemx.com\/fivem-vehicle-handling-editor\/\" title=\"FiveM Vehicle Handling Editor\" data-wpil-keyword-link=\"linked\" data-wpil-monitor-id=\"1820\">Handling<\/a><\/strong>: Try-catch blocks around critical operations<\/li>\n\n\n\n<li>[ ] <strong>Logging<\/strong>: Structured logging for debugging<\/li>\n\n\n\n<li>[ ] <strong>Configuration<\/strong>: Externalized config values<\/li>\n\n\n\n<li>[ ] <strong>Documentation<\/strong>: README with installation steps<\/li>\n\n\n\n<li>[ ] <strong>Version Control<\/strong>: Semantic versioning in fxmanifest<\/li>\n\n\n\n<li>[ ] <strong>License<\/strong>: Appropriate license file included<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">Optimized Prompt for a FiveM Developer Agent<\/h2>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">You are an expert FiveM developer with 5+ years of production experience managing high-population servers. Your expertise spans all major frameworks and you prioritize secure, performant code.<\/pre>\n\n\n\n<div class=\"wp-block-buttons is-layout-flex wp-block-buttons-is-layout-flex\"><\/div>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\" \/>\n\n\n\n<h2 class=\"wp-block-heading\">Conclusion<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">AI tools like Claude Code transform FiveM development from a months-long learning process into productive scripting within hours, enabling rapid prototyping and complex system development while maintaining security and performance standards.<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\" \/>\n\n\n\n<p class=\"wp-block-paragraph\"><em>Ready to enhance your FiveM server? Explore our curated collection of <a href=\"https:\/\/fivemx.com\/esx-scripts\">premium scripts<\/a> or dive into <a href=\"https:\/\/fivemx.com\/standalone-scripts\">standalone solutions<\/a> that complement your AI-generated resources.<\/em><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Writing FiveM scripts has traditionally required deep knowledge of Lua, JavaScript, and the FiveM API. Today, AI tools like Claude Code, GitHub Copilot, and ChatGPT are revolutionizing how developers create everything from ESX scripts to complex standalone systems. This comprehensive guide shows you exactly how to leverage AI for FiveM development, with concrete examples and [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":193198,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2340],"tags":[],"class_list":["post-193197","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-lua-scripting"],"blocksy_meta":[],"_links":{"self":[{"href":"https:\/\/fivemx.com\/pt\/wp-json\/wp\/v2\/posts\/193197","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fivemx.com\/pt\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fivemx.com\/pt\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fivemx.com\/pt\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fivemx.com\/pt\/wp-json\/wp\/v2\/comments?post=193197"}],"version-history":[{"count":0,"href":"https:\/\/fivemx.com\/pt\/wp-json\/wp\/v2\/posts\/193197\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/fivemx.com\/pt\/wp-json\/wp\/v2\/media\/193198"}],"wp:attachment":[{"href":"https:\/\/fivemx.com\/pt\/wp-json\/wp\/v2\/media?parent=193197"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fivemx.com\/pt\/wp-json\/wp\/v2\/categories?post=193197"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fivemx.com\/pt\/wp-json\/wp\/v2\/tags?post=193197"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}