Peds::new

From RAGE Multiplayer Wiki
Revision as of 07:41, 30 May 2019 by MCtheBoss (talk | contribs) (Updated the page to represent the change in syntax, as well as provide the function for legacy syntax support.)

Syntax

mp.peds.new(model, position, heading, dimension);

Required Arguments

  • modelHash: Model hash
  • position: Vector3 position
  • heading: float
  • dimension: int

Return value

  • Ped handle or object

This function relies on the 'entityStreamIn' event to handle the Ped's streamInEvent. If you do not have this event in your script, you can find it below.

Example

Client-Side
let Ped = mp.peds.new(mp.game.joaat('MP_F_Freemode_01'), new mp.Vector3( 100.0, -100.0, 25.0), 270.0, mp.players.local.dimension);

Legacy Syntax Variation

If you would like to use the legacy syntax for mp.peds.new(), refer to the following function:

Client-Side
mp.peds.newLegacy = (hash, position, heading, streamIn, dimension) =>
{
    let ped = mp.peds.new(hash, position, heading, dimension);
    ped.streamInHandler = streamIn;
    return ped;
};

For the above function to work, you must add the following 'entityStreamIn' event to your script:

Client-Side
mp.events.add("entityStreamIn", (entity) =>    
{
   if(entity.streamInHandler)
   {
       entity.streamInHandler(entity);
   }
});

Example

Client-Side
let Ped = mp.peds.newLegacy(mp.game.joaat(model), location, 0, (streamPed) => {
        // Ped Streamed
    streamPed.setAlpha(255);
    streamPed.freezePosition(false);
    streamPed.setInvincible(false);
    streamPed.setProofs(false, false, false, false, false, false, false, false); 
}, 0);


See also