Peds::new: Difference between revisions

From RAGE Multiplayer Wiki
No edit summary
No edit summary
 
(4 intermediate revisions by 3 users not shown)
Line 1: Line 1:
{{Note|Updated docs on creating peds: [[Ped::Ped]].}}
==Syntax==
==Syntax==
<syntaxhighlight lang="javascript">mp.peds.new(model, position, heading, streamInEventHandler, dimension);</syntaxhighlight>
<syntaxhighlight lang="javascript">mp.peds.new(model, position, heading, dimension);</syntaxhighlight>
=== Required Arguments ===
=== Required Arguments ===
*'''modelHash:''' Model hash
*'''modelHash:''' Model hash
*'''position:''' Vector3 position
*'''position:''' Vector3 position
*'''heading:''' float
*'''heading:''' float
*'''streamInEventHandler:''' function (called when the ped is streamed)
*'''dimension:''' int
*'''dimension:''' int
===Return value===
===Return value===
*'''Ped handle or object'''
*'''Ped object'''


==Example==
==Example==
<div class="header" style="background-color: #AE4040; color: #FFFFFF; border: 2px solid #AE4040;">
<div style="margin: 10px 10px 10px 10px;"><b>Client-Side</b></div>
<syntaxhighlight lang="javascript">
<syntaxhighlight lang="javascript">
let Ped = mp.peds.new(mp.game.joaat('MP_F_Freemode_01'), new mp.Vector3( 100.0, -100.0, 25.0), 270.0, (streamPed) => {
let ped = mp.peds.new(
     // Ped Streamed
    mp.game.joaat('MP_F_Freemode_01'),  
    streamPed.setAlpha(0);
    new mp.Vector3(100.0, -100.0, 25.0),
}, player.dimension);
    270.0,
     mp.players.local.dimension
);
</syntaxhighlight>
</syntaxhighlight>
</div>
 
==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:
 
<syntaxhighlight lang="javascript">
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);
  }
});
</syntaxhighlight>
 
===Example===
<syntaxhighlight lang="javascript">
let ped = mp.peds.newLegacy(mp.game.joaat('mp_m_freemode_01'), new mp.Vector3(1000, 100, 10), 0, ped => {
    // Called when the ped is streamed in
    ped.setAlpha(255);
    ped.freezePosition(false);
    ped.setInvincible(false);
    ped.setProofs(false, false, false, false, false, false, false, false);
}, 0);
</syntaxhighlight>
 


==See also==
==See also==
{{Ped_s_function_c}}
{{Ped_functions_c}}
[[Category:Clientside API]]
[[Category:Clientside API]]

Latest revision as of 12:12, 14 November 2021

Updated docs on creating peds: Ped::Ped.

Syntax

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

Required Arguments

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

Return value

  • Ped object

Example

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:

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);
   }
});

Example

let ped = mp.peds.newLegacy(mp.game.joaat('mp_m_freemode_01'), new mp.Vector3(1000, 100, 10), 0, ped => {
    // Called when the ped is streamed in
    ped.setAlpha(255);
    ped.freezePosition(false);
    ped.setInvincible(false);
    ped.setProofs(false, false, false, false, false, false, false, false); 
}, 0);


See also