Peds::new: Difference between revisions

From RAGE Multiplayer Wiki
mNo edit summary
(Updated the page to represent the change in syntax, as well as provide the function for legacy syntax support.)
Line 1: Line 1:
==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 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==
==Example==
{{ClientSide}}
{{ClientSide}}
<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(mp.game.joaat('MP_F_Freemode_01'), new mp.Vector3( 100.0, -100.0, 25.0), 270.0, mp.players.local.dimension);
     // Ped Streamed
</syntaxhighlight>
     streamPed.setAlpha(0);
== ==
}, player.dimension);
 
==Legacy Syntax Variation==
 
If you would like to use the legacy syntax for mp.peds.new(), refer to the following function:
{{ClientSide}}
<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;
};
</syntaxhighlight>
</syntaxhighlight>
For the above function to work, you must add the following 'entityStreamIn' event to your script:
{{ClientSide}}
<syntaxhighlight lang="javascript">
mp.events.add("entityStreamIn", (entity) =>   
{
  if(entity.streamInHandler)
  {
      entity.streamInHandler(entity);
  }
});
</syntaxhighlight>
===Example===
{{ClientSide}}
<syntaxhighlight lang="javascript">
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);
</syntaxhighlight>


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

Revision as of 07:41, 30 May 2019

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