Object::Object: Difference between revisions

From RAGE Multiplayer Wiki
mNo edit summary
(alpha updated)
 
(17 intermediate revisions by 10 users not shown)
Line 1: Line 1:
Creates new object in to the world.
{{SharedFunctionJS}}


[http://objects.codeshock.hu/gallery.php Gallery of objects]
Creates a new Object.
*'''[https://cdn.rage.mp/public/odb/index.html Objects gallery]'''


=Syntax=
<syntaxhighlight lang="javascript">
mp.objects.new(model, Vector3 position, Vector3 rotation);
</syntaxhighlight>


== '''Required Arguments:''' ==
{{JSContainer|
==Syntax==
{{SharedCode|
<pre>
mp.objects.new(model, position,
{
    rotation: rotation,
    alpha: alpha,
    dimension: dimension
});
</pre>
}}


*'''model hash''': <code>mp.joaat('<model_name>')</code> or object id
==Required Arguments==
*'''position''': <b><font color='green'>Vector3</font></b>
*'''model''': {{RageType|Hash}}
*'''rotation''': <b><font color='green'>Vector3</font></b>
*'''position''': {{RageType|Vector3}}
*'''rotation''': {{RageType|Vector3}}
*'''alpha''': {{RageType|Number}}: The object's transparency.
*'''dimension''': {{RageType|Number}}


=Example=
==Example==


<syntaxhighlight lang="javascript">
<pre>
let pos = player.position; // Returns Vector3 object
mp.events.addCommand('flag', (player) => {
pos.y += 1
    mp.objects.new('apa_prop_flag_portugal', player.position,
pos.z -= 1
        {
            rotation: player.rotation,
            alpha: 255,
            dimension: player.dimension
        });
});


let object = mp.objects.new(mp.joaat('p_stinger_03'), pos , [0, 0, 0]); // Creates a stinger beside the player
//Following this code, you'll create a portuguese flag (apa_prop_flag_portugal) at the players position, facing the same way the player is facing, with no transparency (255 on alpha) and at the same dimension the player is.
let object = mp.objects.new(795100068, pos , [0, 0, 0]); // Alternative, mp.joaat(...) resolves the model name into this object id
</pre>
</syntaxhighlight>
}}
[[Category:Object API]]
[[Category:Shared Function]]
[[Category:TODO: Example]]

Latest revision as of 12:52, 1 February 2023

Shared
Function

 JavaScript


Creates a new Object.


JavaScript Syntax

Syntax

Shared
mp.objects.new(model, position,
{
    rotation: rotation,
    alpha: alpha,
    dimension: dimension
});

Required Arguments

  • model: Hash
  • position: Vector3
  • rotation: Vector3
  • alpha: Number: The object's transparency.
  • dimension: Number

Example

mp.events.addCommand('flag', (player) => {
    mp.objects.new('apa_prop_flag_portugal', player.position,
        {
            rotation: player.rotation,
            alpha: 255,
            dimension: player.dimension
        });
});

//Following this code, you'll create a portuguese flag (apa_prop_flag_portugal) at the players position, facing the same way the player is facing, with no transparency (255 on alpha) and at the same dimension the player is.