Native REDM CreatePedNative REDM CreatePed
CreatePed

0xD49F9B0955C367DE

-- CREATE_PED
local retval --[[ Ped ]] =
	CreatePed(
		modelHash --[[ Hash ]], 
		x --[[ number ]], 
		y --[[ number ]], 
		z --[[ number ]], 
		heading --[[ number ]], 
		isNetwork --[[ boolean ]], 
		bScriptHostPed --[[ boolean ]], 
		p7 --[[ boolean ]], 
		p8 --[[ boolean ]]
	)

 

Citizen.Invoke value:

0xD49F9B0955C367DE

Parameters:

modelHash:

The model of ped to spawn.

x, y, z coords

x:      Spawn coordinate X component.
y:      Spawn coordinate Y component.
z:      Spawn coordinate Z component. 

heading:

Heading to face towards, in degrees.

isNetwork:

Whether to create a network object for the ped. If false, the ped exists only in the local client. It’s movements will not be synced between clients.

bScriptHostPed:

Whether to register the ped as pinned to the script host in the R* network model.

Practical application. If you set this to true the client treats it as a native ped to the game and resources like onesync will manage whether or not it is deleted as part of it’s clean up routines. If you set this to false, then the client treats it as separate and your resources/script is in full control of the ped.

Returns:

A script handle (fwScriptGuid index) for the ped, also called an EntityID, or 0 if the ped failed to be created.

Summary

Creates a ped (biped character, pedestrian, actor, animals, horses, etc ) with the specified model at the specified position and heading. This ped will initially be owned by the creating script as a mission entity, and the model should be preloaded (e.g. using REQUEST_MODEL). This is the server-side RPC native equivalent of the client native CREATE_PED.

Example

--- Valentine auctions
ExtraSpawns = {  
[1] = {model="A_C_Cow", type="cow", coords = {x = -204.39, y = 591.85, z = 113.27}, min=1, max=1}
}

local YAW = 0.0
local offsetx = 2
local offsety = 2 
local X = ExtraSpawns.coords.x
local Y = ExtraSpawns.coords.y
local Z = ExtraSpawns.coords.z
local NetworkMe = false
local Scripted = false
model_hash = GetHashKey(ExtraSpawns.model) 
LoadModel(model_hash )   
AnimalEntityId = CreatePed(model_hash, X+offsetx, Y+offsety, Z, YAW, NetworkMe, Scripted ) 

-- SetRandomOutfitVariation 0x283978A15512B2FE _SET_RANDOM_OUTFIT_VARIATION 
Citizen.InvokeNative(0x283978A15512B2FE, AnimalEntityId, true) 
SetEntityVisible( AnimalEntityId, true)

--- this handles loading the model and is run before the ped is created.
function LoadModel(model) 
    RequestModel(model)
    local emergency_break = 0
    while HasModelLoaded(model) == false or 0 do 
        Citizen.Wait(100)
        emergency_break = emergency_break +1
        if emergency_break > 20 then 
            break   -- no runaway loops here.
        end 
    end
end
    


Additional natives used in this example, or natives commonly used with this native.

Common Errors or Problems

Problem: My ped is invisible. – Solution: Set Visible or Give ped an outfit.

Problem: My script makes a ped for every player. Solution: You have the ped networked, and your script generates a ped for every player. If players don’t need to interact with the exact same ped, set network to false, this allows the players client to manage the ped, and not share the data with other players.

Problem: I only generate one ped and I need all the players to see it. Solution: Set the ped to be networked.

Credits and Disclaimers

The base of this data was taken from the redm/cfx fivem/rdr docs, or from the redm natives database hosted on vespura while it was active. Side note we thought vespura was part of the redm/cfx network originally, but apparently not, since we came back from our break to find it shut down. We have been saving and making notes for two years now, and are now adding them to our site for everyone to use. We will be modifying the notes as needed, and building tutorials around the data so these pages will change as we work on it. This is a manual process, not an automated one, so updates will occur as we have time, the priority is releasing resources. Thanks for your patience.

Was the documentation useful?

0
CreatePed - Native

Do you understand the native?

You will be redirected

Related Examples or Posts

No posts found.

By MK

Dragon Codes