Last active
July 24, 2023 19:32
-
-
Save DemmyDemon/7931a8d0788d8ffd84499cb32ab2df4c to your computer and use it in GitHub Desktop.
Just helping a donkey entertain their kid!
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- Here we list our ped models we want to cycle through. | |
local pedCycle = { | |
"s_m_y_fireman_01", | |
"s_m_y_hwaycop_01", | |
"s_m_y_marine_03", | |
"s_m_y_swat_01", | |
"s_m_m_fibsec_01", | |
"s_m_m_paramedic_01", | |
"s_f_y_scrubs_01", | |
"g_m_m_chicold_01", | |
} | |
local currentPed = 0 -- This will hold our place in the cycle. | |
-- It is initialized at 0 so the first time we increment it, it will go to the first element in the table. | |
local function LoadModel(model) | |
-- First we check if it's even worth attempting | |
if not IsModelValid(model) then | |
print('Model ' .. model .. ' is invalid') | |
return false | |
end | |
-- Then we make the initial request | |
RequestModel(model) | |
-- Let's store when we started waiting, so we know when it has timed out | |
local begin = GetGameTimer() | |
while not HasModelLoaded(model) do | |
if GetGameTimer() > begin + 1000 then -- That is, if it has been over a second since we started loading | |
print('Failed to load model ' .. model) | |
return false -- Bail out, and report failure | |
end | |
-- Or keep waiting a little longer | |
Citizen.Wait(0) | |
end | |
-- If we got here, that means it loaded! | |
return true | |
end | |
local function VehicleIAmIn() | |
if IsPedInAnyVehicle(PlayerPedId(), false) then -- Because if we're not in a car, we don't care, right? | |
local vehicle = GetVehiclePedIsIn(PlayerPedId(), false) -- Set the vehicle | |
-- Just in case we're not the driver, we'll cycle through all the seats to find the one we're in | |
for seat = -1, GetVehicleNumberOfPassengers(vehicle) do | |
if GetPedInVehicleSeat(vehicle, seat) == PlayerPedId() then | |
return vehicle, seat | |
end | |
end | |
-- If we're somehow *not* in any of the seats, it will fall off the end of the function, returning nothing. | |
-- This is the same as not being in a vehicle at all. | |
end | |
end | |
local function SwapModel(model) | |
-- Swap out the player model! | |
SetPlayerModel(PlayerId(), model) | |
-- To avoid leaving lots of ped models loaded when we don't really need them, we mark it as "GTAV can forget about it when it doesn't use it anymore" | |
SetModelAsNoLongerNeeded(model) | |
-- Most peds have some props they can use, like the firemen have helmets and smoke masks, the cops have mirrored glasses, etc | |
SetPedRandomProps(PlayerPedId()) | |
-- Components are the bits and pieces a ped is built from. This can vary just about anything, like skin color and uniform details. | |
SetPedRandomComponentVariation(PlayerPedId(), 0) | |
end | |
local function NextPedPlease() | |
-- First we increment the place in the cycle | |
currentPed += 1 | |
-- Then we check if it's out of bounds, and wrap around if it is. | |
if currentPed > #pedCycle then | |
currentPed = 1 | |
end | |
-- Now we have the index we want, and can look up the model | |
local model = pedCycle[currentPed] | |
-- To become this ped, we'll have to load the model. | |
if not LoadModel(model) then return end -- If it doesn't report success, then it's meaningless to continue the process. | |
-- Let's store the position of the camera, as switching player model resets the camera to be right behind the player ped. | |
local camHeading = GetGameplayCamRelativeHeading() | |
local camPitch = GetGameplayCamRelativePitch() | |
-- Figure out what vehicle and seat we're in, if any | |
local vehicle, seat = VehicleIAmIn() | |
-- Swap out the model | |
SwapModel(model) | |
if vehicle then -- That is, we were in a vehicle before | |
SetPedIntoVehicle(PlayerPedId(), vehicle, seat) | |
end | |
-- After the ped is loaded and set up, we put the camera back where it was. | |
-- This happens in a single frame, so the user won't see the camera move unless they're pressed up against a wall, or sat in a vehicle. | |
SetGameplayCamRelativeHeading(camHeading) | |
SetGameplayCamRelativePitch(camPitch, 1.0) | |
end | |
Citizen.CreateThread(function() | |
while true do -- Infinite loop. | |
-- An infinite loop will stall the client unless we yield the thread every now and then. | |
-- We should yield it as short as possible to not miss any keypresses. | |
Citizen.Wait(0) | |
-- If the key we want is pressed... | |
if IsControlJustPressed(1, 174) then -- Controls are listed at https://docs.fivem.net/docs/game-references/controls/#controls -- 174 is INPUT_CELLPHONE_LEFT, usually bound to Left arrow and DPad Left | |
NextPedPlease() | |
end | |
end | |
end) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
EEEEEEAAAAAAAAWWWWWWWW this is one happy donkey !