AI-Assisted Development Guide

Learn how to use AI to help you with FiveM scripting and development.

Introduction to AI-Assisted Development

Artificial Intelligence (AI) can be a powerful tool for FiveM development. It can help you write code, debug problems, and learn new things. This guide will teach you how to use AI effectively, even if you don't have much experience with programming.

Choosing an AI Tool

There are many AI tools available, but for our purposes, we recommend using a large language model (LLM) like Gemini, Claude, or ChatGPT. These models are designed to understand and generate human-like text, which makes them great for programming tasks.

How to Prompt the AI

The key to getting good results from an AI is to write good prompts. A prompt is the instruction you give to the AI. Here are some tips for writing effective prompts:

  • Be specific: The more specific you are, the better the AI will understand what you want. Instead of saying "make a script," say "create a FiveM script in Lua that gives players a welcome message when they join the server."
  • Provide context: Give the AI as much information as you can about what you're trying to do. This includes the programming language you're using (e.g., Lua), the FiveM framework you're using (e.g., QP-core), and any other relevant details.
  • Provide examples: If you have an example of what you're trying to achieve, show it to the AI. This can be a code snippet, a screenshot, or a description of the desired outcome.
  • Ask for explanations: If you don't understand the code the AI gives you, ask it to explain it. This is a great way to learn and improve your own skills.

Using AI for Script Configuration

Configuring scripts can be tricky, especially when you're new to FiveM development. AI can help you with this by generating the configuration code for you.

Here's an example of how you could use AI to configure a script:

Prompt

                        I need to configure the qp-policejob script for my FiveM server. I want to add a new police car to the garage. The car's spawn name is "police4" and its display name is "Marked Cruiser". Can you show me how to add this to the config file?
                                                

The AI might respond with something like this:

Lua

                        Sure, here's how you can add the new police car to your `config.lua` file:
                        
                        -- In your qp-policejob/config.lua file
                        
                        Config.Vehicles = {
                            -- ... other vehicles
                            ["police4"] = {
                                name = "Marked Cruiser",
                                spawn = "police4",
                                -- ... other options
                            },
                            -- ... other vehicles
                        }
                                                

The AI has not only provided the code, but also told you which file to put it in. This is a great example of how AI can save you time and effort.

Using AI for Debugging

Debugging is the process of finding and fixing errors in your code. AI can be a huge help with this, especially when you're new to programming.

If you're getting an error in your FiveM server console, you can copy and paste the error message into the AI and ask it to explain what's wrong.

Here's an example:

Error Log

                        I'm getting this error in my FiveM server console:
                        
                        [script:qp-policejob] error during NuiMessageCallback: citizenid is nil
                        [script:qp-policejob] citizenid = nil
                        
                        Can you help me figure out what's wrong?
                                                

The AI might respond with something like this:

Lua

                        This error means that the `citizenid` variable is `nil` (meaning it has no value) when it's being used. This usually happens when the script is trying to get the player's character ID before it has been loaded.
                        
                        To fix this, you need to make sure that the player's data is loaded before you try to use it. You can do this by adding a check to see if the player's data is loaded before running the code that uses the `citizenid`.
                        
                        Here's an example of how you could do this:
                        
                        -- In your qp-policejob script
                        
                        RegisterNUICallback("get_player_info", function(data, cb) 
                            local PlayerData = QBCore.Functions.GetPlayerData()
                            if PlayerData then
                                -- The player's data is loaded, so we can send it to the NUI
                                cb({
                                    citizenid = PlayerData.citizenid,
                                    -- ... other data
                                })
                            else
                                -- The player's data is not loaded yet, so we'll wait and try again
                                Wait(1000)
                                -- ... try again
                            end
                        end)
                                                

The AI has not only explained the error, but also provided a possible solution. This is a great way to learn how to debug your own code.

More Prompt Examples

Creating a New Resource

Prompt

                        
                                                                Create a new FiveM resource that adds a "taco" item to the game. The item should be usable and should give the player a small amount of health when used. The script should use the QBCore framework.
                        
                                                                                        

Debugging a Specific Error

Prompt

                        
                                                                I'm getting the following error in my FiveM server console when I try to use the "/cuff" command:
                        
                                                                
                        
                                                                [script:my-script] error during NuiMessageCallback: attempt to index a nil value (local 'target')
                        
                                                                
                        
                                                                Here is the relevant code from my script:
                        
                                                                
                        
                                                                RegisterCommand('cuff', function(source, args, rawCommand)
                        
                                                                    local target = GetPlayerFromServerId(tonumber(args[1]))
                        
                                                                    TriggerClientEvent('my-script:cuff', target)
                        
                                                                end, false)
                        
                                                                
                        
                                                                Can you help me figure out what's wrong?
                        
                                                                                        

Optimizing a Script

Prompt

                        
                                                                I have a script that loops through all the players on the server every frame to check if they are in a certain area. This is causing performance issues on my server. Can you show me a more efficient way to do this?
                        
                                                                                        

Limitations of AI

While AI can be a powerful tool, it's important to remember that it has its limitations. Here are a few things to keep in mind:

  • AI is not always right: AI models are trained on vast amounts of data, but they can still make mistakes. Always double-check the code that the AI gives you to make sure it's correct.
  • AI is not a replacement for learning: AI can help you learn, but it's not a replacement for learning how to code. The more you learn about programming, the better you'll be at using AI to help you.
  • AI is not creative: AI is good at following instructions, but it's not very creative. If you want to create something truly unique, you'll need to use your own creativity.

Conclusion

AI can be a powerful tool for FiveM development, but it's important to remember that it's just a tool. It's not a replacement for learning how to code. The more you learn about programming, the better you'll be at using AI to help you.