To control a deer's movement in FiveM so you can ride it, you'll need to create a script that spawns the deer, sets you as the rider, and provides controls for movement. You can use the following script as a starting point. Save it as deerRider.lua and place it in your server's resource folder.
-- Variables
local deer = nil
local ridingDeer = false
-- Helper function to load a model
function LoadModel(name)
local model = GetHashKey(name)
RequestModel(model)
while not HasModelLoaded(model) do
Wait(1)
end
return model
end
-- Helper function to spawn a deer and set you as the rider
function SpawnDeer()
local deerModel = LoadModel("a_c_deer")
local playerPed = PlayerPedId()
local playerCoords = GetEntityCoords(playerPed)
deer = CreatePed(28, deerModel, playerCoords.x, playerCoords.y, playerCoords.z, 0, true, false)
SetEntityAsMissionEntity(deer, true, true)
TaskWarpPedIntoVehicle(playerPed, deer, 0)
ridingDeer = true
end
-- Controls for the deer's movement
Citizen.CreateThread(function()
while true do
Citizen.Wait(0)
if ridingDeer then
local playerPed = PlayerPedId()
local coords = GetEntityCoords(deer)
local heading = GetEntityHeading(deer)
-- Move forward
if IsControlPressed(0, 71) then
TaskAnimalInteraction(playerPed, deer, 0, -1, 0, 0)
coords = coords + GetEntityForwardVector(deer) * 0.5
SetEntityCoordsNoOffset(deer, coords.x, coords.y, coords.z, false, false, false)
end
-- Move backward
if IsControlPressed(0, 72) then
TaskAnimalInteraction(playerPed, deer, 0, -5, 0, 0)
coords = coords - GetEntityForwardVector(deer) * 0.3
SetEntityCoordsNoOffset(deer, coords.x, coords.y, coords.z, false, false, false)
end
-- Turn left
if IsControlPressed(0, 63) then
heading = heading - 2
SetEntityHeading(deer, heading)
end
-- Turn right
if IsControlPressed(0, 64) then
heading = heading + 2
SetEntityHeading(deer, heading)
end
end
end
end)
-- Command to start riding a deer
RegisterCommand("rideDeer", function(source, args, rawCommand)
if not ridingDeer then
SpawnDeer()
end
end, false)
Once you have added the script to your server, don't forget to add it to the server.cfg file:
start deerRider
After starting your server, you can use the /rideDeer command in-game to spawn a deer and ride it. The script uses the default driving control keys for moving forward, backward, and turning.