Ped::Ped

From RAGE Multiplayer Wiki
Revision as of 12:13, 14 November 2021 by Brzys (talk | contribs) (typo)

Client-Side
Function

 JavaScript



Creates a new clientside ped. Use Player API to control peds actions.

JavaScript Syntax

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


Parameters

  • model: Hash (Ped Models)
  • position: Vector3
  • heading: Float
  • dimension: Integer

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

The previous syntax for this function allowed you to specify a "streamedIn" callback. This has been removed in favor of the EntityStreamIn event, but you can add this polyfill to your client script to enable the previous syntax:

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

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


Server-Side
Function

 JavaScript



Creates a new serverside static or dynamic ped.
Dynamic peds are synchronised/controlled by the player that your gamemode manually assigns and can be reassigned at any moment.
To control dynamic ped actions, use clientside Player API on a controller.

JavaScript Syntax

mp.peds.new(model, position,
{    
      dynamic: dynamic, 
      frozen: frozen,
      invincible: invincible
});


Parameters

  • model: Hash (Ped Models)
  • position: Vector3
  • dynamic: Boolean: true - synced by controller, false - static
  • frozen: Boolean
  • invincible: Boolean

Example

Server-Side
let dynamicPed = mp.peds.new(mp.joaat('mp_m_freemode_01'), mp.players.at(0).position, {dynamic:true});
dynamicPed.controller = mp.players.at(0);

let staticPed = mp.peds.new(mp.joaat('player_zero'), mp.players.at(0).position,
{    
      dynamic: false, // still server-side but not sync'ed anymore
      frozen: true,
      invincible: true
});


See Also