Перейти к содержанию

Peds::new

Материал из RAGE MP Wiki Archive
Версия от 12:12, 14 ноября 2021; imported>Brzys
(разн.) ← Предыдущая версия | Текущая версия (разн.) | Следующая версия → (разн.)

Syntax

<syntaxhighlight lang="javascript">mp.peds.new(model, position, heading, dimension);</syntaxhighlight>

Required Arguments

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

Return value

  • Ped object

Example

<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,
   mp.players.local.dimension

); </syntaxhighlight>

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