Skip to content
TheChatArchiveThe Chat Archive
gpt-4-0314· OpenAIAi2 WildChat-4.8M (AI2)

Fivem Scripting lua how do i enable gta 5 stock police and set a wanted level so the…

  1. User

    Fivem Scripting lua how do i enable gta 5 stock police and set a wanted level so the police chase me

  2. Assistant

    To enable GTA 5 stock police and set a wanted level, you can use the SetPlayerWantedLevel() native function in a script written in FiveM with LUA programming. Here's an example of a simple script that sets your wanted level to 3, causing police to chase you.

    1. First, create a new folder in your FiveM server's resources directory, and name it policeChase (or any other name you prefer).
    2. Inside the policeChase folder, create a new file named __resource.lua and add the following code:
    -- Resource Metadata
    fx_version 'cerulean'
    games { 'gta5' }
    
    author 'Your_Name'
    description 'Police Chase Script'
    version '1.0.0'
    
    client_scripts {
        'client.lua'
    }
    
    1. Next, create another file in the policeChase folder called client.lua, and add the following code for setting your wanted level:
    -- Create a command to set the player's wanted level
    RegisterCommand('wantedlevel', function(source, args)
        -- Get the wanted level from the command argument
        local wantedLevel = tonumber(args[1])
    
        -- Check if the specified wanted level is valid (between 0 and 5)
        if wantedLevel >= 0 and wantedLevel <= 5 then
            -- Set the player's wanted level
            SetPlayerWantedLevel(PlayerId(), wantedLevel, false)
            SetPlayerWantedLevelNow(PlayerId(), false)
    
            -- Notify the player about the new wanted level
            TriggerEvent('chat:addMessage', {
                color = {255, 0, 0},
                multiline = true,
                args = {'^1New wanted level:', '^2' .. wantedLevel}
            })
        else
            TriggerEvent('chat:addMessage', {
                color = {255, 0, 0},
                multiline = true,
                args = {'^1Error:', '^2Invalid wanted level'}
            })
        end
    end, false)
    
    1. After saving the files, go to your server's server.cfg file, and add the following line to enable the policeChase script:
    ensure policeChase
    
    1. Start your FiveM server and, once connected, you can use the /wantedlevel command followed by a number between 0 and 5 to set your wanted level. For example, enter /wantedlevel 3 to set a wanted level of 3 and have the stock police chase you.

Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.