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

I'm working on a fivem script where when you aim your gun in a car your character leans…

  1. User

    I'm working on a fivem script where when you aim your gun in a car your character leans out of the vehicle

  2. Assistant

    To create a FiveM script where your character leans out of the vehicle when aiming a gun, you will need to use FiveM's native functions and events.

    First, create a new folder in your resources folder named lean_out_vehicle. Inside this folder, create a folder named client and a file named __resource.lua. In the __resource.lua file, add the following code:

    resource_manifest_version '44febabe-d386-4d18-afbe-5e627f4af937'
    
    client_script 'client/main.lua'
    

    Next, create a file inside the client folder named main.lua. This file will contain the main script that will handle checking if the player is in a vehicle and aiming a gun while making the player lean out when aiming. Add the following code to main.lua:

    Citizen.CreateThread(function()
    	while true do
            -- Wait for 0 milliseconds before the next iteration.
            Citizen.Wait(0)
    
            local playerPed = PlayerPedId()
            local vehicle = GetVehiclePedIsIn(playerPed, false)
    
            if vehicle ~= nil and vehicle ~= 0 then
                if IsPlayerFreeAiming(PlayerId()) then
                    TaskPlayAnim(playerPed, "move_ped_strafing", "roll_l", 8.0, -8.0, -1, 48, 0, false, false, false)
                end
            end
    	end
    end)
    

    This script continually checks if the player is in a vehicle and if they're aiming a gun. If both conditions are true, it will play the "roll_l" animation from the "move_ped_strafing" animation set, making the character lean out of the vehicle.

    Finally, add the resource to your server.cfg file:

    start lean_out_vehicle
    

    Now, when you aim your gun in a vehicle, your character should lean out of the vehicle. Note that this script does not distinguish between different vehicle types, so the character may lean out of the vehicle even if it doesn't have a window to lean out of. You may need to add additional checks in the script for different vehicle types if you want more specific behavior.

  3. User

    thats not a valid animation

  4. Assistant

    I apologize for the confusion. It appears that I provided an incorrect animation. I've revised the script below to use a more suitable animation for leaning out of the vehicle while aiming. The updated script is as follows:

    Citizen.CreateThread(function()
        while true do
            -- Wait for 0 milliseconds before the next iteration.
            Citizen.Wait(0)
    
            local playerPed = PlayerPedId()
            local vehicle = GetVehiclePedIsIn(playerPed, false)
    
                if vehicle ~= nil and vehicle ~= 0 and GetPedInVehicleSeat(vehicle, -1) == playerPed then
    
                    if IsPlayerFreeAiming(PlayerId()) then
    					-- If player is in front passenger or driver seat.
    				    if GetPedInVehicleSeat(vehicle, 0) == playerPed or GetPedInVehicleSeat(vehicle, -1) == playerPed then
                            RequestAnimDict("combat@aim_variants@1h@coordinatedentry")
                            if HasAnimDictLoaded("combat@aim_variants@1h@coordinatedentry") then
                                TaskPlayAnim(playerPed, "combat@aim_variants@1h@coordinatedentry", "static_panic_1h_front_cower", 8.0, -8.0, -1, 49, 0, false, false, false)
                            end
                        end
                    end
                else
                    if IsEntityPlayingAnim(playerPed, "combat@aim_variants@1h@coordinatedentry", "static_panic_1h_front_cower", 3) then
                        ClearPedTasks(playerPed)
                    end
                end
        end
    end)
    

    Now, when you aim your gun in a vehicle, your character should lean out of the vehicle.

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