Ped::Ped: Difference between revisions

From RAGE Multiplayer Wiki
(typo)
No edit summary
 
Line 49: Line 49:
Creates a new serverside static or dynamic ped.<br>
Creates a new serverside static or dynamic ped.<br>
Dynamic peds are synchronised/controlled by the player that your gamemode manually assigns and can be reassigned at any moment.<br>
Dynamic peds are synchronised/controlled by the player that your gamemode manually assigns and can be reassigned at any moment.<br>
To control dynamic ped actions, use clientside [[Client-side_functions#Player|Player API]] on a controller.
Use clientside [[Client-side_functions#Player|Player API]] on peds to setup tasks. Tasks have to be executed by a player controlling ped.


{{JSContainer|  
{{JSContainer|  

Latest revision as of 12:17, 14 November 2021

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.
Use clientside Player API on peds to setup tasks. Tasks have to be executed by a player controlling ped.

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