Ped::Ped: Difference between revisions
(serverside mp.peds.new) |
(unify with clientside syntax) |
||
| Line 1: | Line 1: | ||
__TOC__ | __TOC__ | ||
{{ClientsideJsFunction}} | |||
Creates a new clientside ped. | |||
Use [[Client-side_functions#Player|Player API]] to control peds actions. | |||
{{JSContainer| | |||
<pre> | |||
mp.peds.new(model, position, heading, dimension); | |||
</pre> | |||
}} | |||
==Parameters== | |||
*'''model''': {{RageType|Hash}} ([[Peds|Ped Models]]) | |||
*'''position''': {{RageType|Vector3}} | |||
*'''heading''': {{RageType|Float}} | |||
*'''dimension''': {{RageType|Integer}} | |||
==Example== | |||
{{ClientsideCode| | |||
<pre> | |||
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 | |||
); | |||
</pre>}} | |||
==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: | |||
{{ClientsideCode| | |||
<pre> | |||
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); | |||
} | |||
}); | |||
</pre>}} | |||
{{ServersideJsFunction}} | {{ServersideJsFunction}} | ||
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 | To control dynamic ped actions, use clientside [[Client-side_functions#Player|Player API]] to control peds actions. | ||
{{JSContainer| | {{JSContainer| | ||
Revision as of 12:08, 14 November 2021
Client-Side Function
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
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 to control peds actions.
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
- Functions
- Properties