Creating Ped / Invisible Peds

Hi All,

I recently started doing some work on RedM and I wanted to create a small function that spawns Peds. I used FiveM reference since I managed to achieve this there but on RedM I faced an issue. It seems that when you are spawning ped it is there but it is invisible even if you request model. Original code

RegisterCommand('zombie', function() 
	SpawnZombie()
end, false)

function SpawnZombie()
	--local zombieModel = GetHashKey("A_M_O_WapTownfolk_01")
	zombieModel = GetHashKey("A_C_Wolf")

	
	-- Request Model To be Loaded (IT DOESNT LOAD FOR SOME REASON)
	RequestModel(zombieModel)
	while not HasModelLoaded(zombieModel) do
		RequestModel(zombieModel)
		Wait(1)
	end
	
	local x, y, z = table.unpack(GetEntityCoords(PlayerPedId(), false))
	-- Spawn Zombie
	local zombie = CreatePed(zombieModel, x, y, z+5, 45.0, false, false, 0)
end

I tried to research it, looked through everything on cfx forum but cant seem to figure it out. Is it possible that this RequestModel or CreatePed is broken or am I missing something. Thank you all for your help!

Try to use: (before CreatePed)

void SetRandomOutfitVariation(int /* Ped */ ped, bool p1);

Hi Hayden,

Just tried to include this into the code but it does not work, it throws an error - Attempt to call nil value (Global ‘SetRandomOutfitVariantion’).

This is what I have done:

	local zombieModel = GetHashKey("A_M_O_WapTownfolk_01")
	--zombieModel = GetHashKey("A_C_Wolf")
	
	-- Request Model To be Loaded (IT DOESNT LOAD FOR SOME REASON)
	RequestModel(zombieModel)
	while not HasModelLoaded(zombieModel) do
		RequestModel(zombieModel)
		Wait(1)
	end
	
	local x, y, z = table.unpack(GetEntityCoords(PlayerPedId(), false))
	-- Spawn Zombie
	SetRandomOutfitVariation(zombieModel, true)
	local zombie = CreatePed(zombieModel, x, y, z+5, 45.0, false, false, 0)

I tried to change boolean to false as well, same result.

Don’t now much of programming in LUA but maybe you can try to call this function by HASH:

0x283978A15512B2FE

Link if you want more infos: https://vespura.com/doc/natives/#_0x283978A15512B2FE

Hi Hayden,

The HASH key is already called by using GetHashKey(string), i tried to do it manually but still the result was the same. I believe that there might be an actual glitch when it comes to creating these peds since this works perfectly on FiveM.

I had this same issue, however I’m using JavaScript rather than Lua.

My solution was to invoke the native function as opposed to the global JavaScript function. That is, rather than calling SetRandomOutfitVariation I execute Citizen.invokeNative('0x283978A15512B2FE', horsePed, false) instead.

Here is the full script:

import { Vector3 } from 'fivem-js'

const Wait = (ms): Promise<void> => new Promise(resolve => setTimeout(resolve, ms))

RegisterCommand('gibhorse', () => {
    const playerPed = PlayerPedId();

    const [x1, y1, z1] = GetEntityCoords(playerPed, true)
    const playerPos = new Vector3(x1, y1, z1)

    const [x2, y2, z2] = GetEntityForwardVector(playerPed)
    const playerForwardPos = new Vector3(x2, y2, z2)

    const horsePedSpawnPos = playerPos.add(playerForwardPos.multiply(5))
    const horseHash = 0x225752B // 'A_C_Horse_Shire_LightGrey'

    RequestModel(horseHash)

    let wait = 0
    const timer = setTick(async () => {
        wait += 100
        await Wait(100)
        if (wait >= 5000) {
            clearTick(timer)
        }

        if (HasModelLoaded(horseHash)) {
            const horsePed = CreatePed(horseHash, horsePedSpawnPos.x, horsePedSpawnPos.y, horsePedSpawnPos.z, GetEntityHeading(playerPed), false, false)
            Citizen.invokeNative('0x283978A15512B2FE', horsePed, false) // SetRandomOutfitVariation()
            Citizen.invokeNative('0x23f74c2fda6e7c61', -1230993421, horsePed) // BlipAddForEntity()
            SetModelAsNoLongerNeeded(horseHash)
            clearTick(timer)
        }
    })
}, false)

If I want to spawn a ped, I use the following code for it

Great, it works !!!
By the way, I’m following your RDX frameworks redm_extended.
When you do other modules such as horse and stable management, then you need one for the shop.
Another very important module is that of user management with the first access and creation of the avatar.
Then to follow that of work and many other activities.

I wanted to install it but I’m waiting, assuming you don’t say that other mods of the RedM version also work: RP … but then how many mods should be installed to make everything work ???

I’m waiting for you to release the mods for Your Frameworks which I see that you have done a really good job.

Hi All,

Thank you for helping me out on this, I was finally able to achieve what I desired!

This fixed everything:

Citizen.InvokeNative(0x283978A15512B2FE, ped, true)

1 Like