CreateObject: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
No edit summary
m (Reverted edits by Marcin778 (talk) to last revision by Ccw)
Line 1: Line 1:
Extrem liże hazowi dupsko a Barcioo liże cipsko Trinowi
__NOTOC__
Extrem liże hazowi dupsko a Barcioo liże cipsko Trinowi
{{Server client function}}
Extrem liże hazowi dupsko a Barcioo liże cipsko Trinowi
{{Note|Dynamic objects do not automatically have physics applied to them. Use setElementVelocity(object, 0, 0, 0) to fix this.}}
Extrem liże hazowi dupsko a Barcioo liże cipsko Trinowi
Creates an object in the GTA world.
Extrem liże hazowi dupsko a Barcioo liże cipsko Trinowi
 
Extrem liże hazowi dupsko a Barcioo liże cipsko Trinowi
==Syntax==
Extrem liże hazowi dupsko a Barcioo liże cipsko Trinowi
<syntaxhighlight lang="lua">object createObject ( int modelid, float x, float y, float z, [ float rx, float ry, float rz, bool isLowLOD = false ] )</syntaxhighlight>
Extrem liże hazowi dupsko a Barcioo liże cipsko Trinowi
{{OOP||Object||}}
Extrem liże hazowi dupsko a Barcioo liże cipsko Trinowi
===Required Arguments===
Extrem liże hazowi dupsko a Barcioo liże cipsko Trinowi
*'''modelid:''' a whole integer specifying the GTASA object model ID.
Extrem liże hazowi dupsko a Barcioo liże cipsko Trinowi
*'''x:''' a floating point number representing the X coordinate on the map.
Extrem liże hazowi dupsko a Barcioo liże cipsko Trinowi
*'''y:''' a floating point number representing the Y coordinate on the map.
Extrem liże hazowi dupsko a Barcioo liże cipsko Trinowi
*'''z:''' a floating point number representing the Z coordinate on the map.
Extrem liże hazowi dupsko a Barcioo liże cipsko Trinowi
 
Extrem liże hazowi dupsko a Barcioo liże cipsko Trinowi
===Optional Arguments===
Extrem liże hazowi dupsko a Barcioo liże cipsko Trinowi
{{OptionalArg}}
Extrem liże hazowi dupsko a Barcioo liże cipsko Trinowi
*'''rx:''' a floating point number representing the rotation about the X axis in degrees.
Extrem liże hazowi dupsko a Barcioo liże cipsko Trinowi
*'''ry:''' a floating point number representing the rotation about the Y axis in degrees.
Extrem liże hazowi dupsko a Barcioo liże cipsko Trinowi
*'''rz:''' a floating point number representing the rotation about the Z axis in degrees.
Extrem liże hazowi dupsko a Barcioo liże cipsko Trinowi
{{New items|3.0120|1.2|
Extrem liże hazowi dupsko a Barcioo liże cipsko Trinowi
*'''isLowLOD:''' a bool value specifying if the object will be low LOD. A low LOD object has no collision and a longer draw distance.
Extrem liże hazowi dupsko a Barcioo liże cipsko Trinowi
}}
Extrem liże hazowi dupsko a Barcioo liże cipsko Trinowi
===Returns===
Extrem liże hazowi dupsko a Barcioo liże cipsko Trinowi
* The [[object]] element if creation was successful.
Extrem liże hazowi dupsko a Barcioo liże cipsko Trinowi
* ''false'' otherwise.
Extrem liże hazowi dupsko a Barcioo liże cipsko Trinowi
 
Extrem liże hazowi dupsko a Barcioo liże cipsko Trinowi
==Example==
Extrem liże hazowi dupsko a Barcioo liże cipsko Trinowi
 
Extrem liże hazowi dupsko a Barcioo liże cipsko Trinowi
<section name="Example1" class="server" show="true">
Extrem liże hazowi dupsko a Barcioo liże cipsko Trinowi
This example creates an object when the resource starts:
Extrem liże hazowi dupsko a Barcioo liże cipsko Trinowi
<syntaxhighlight lang="lua">
Extrem liże hazowi dupsko a Barcioo liże cipsko Trinowi
function mapLoad ( name )
Extrem liże hazowi dupsko a Barcioo liże cipsko Trinowi
  -- create an object at a specified position with a specified rotation
Extrem liże hazowi dupsko a Barcioo liże cipsko Trinowi
  createObject ( 1337, 5540.6654, 1020.55122, 1240.545, 90, 0, 0 )
Extrem liże hazowi dupsko a Barcioo liże cipsko Trinowi
end
Extrem liże hazowi dupsko a Barcioo liże cipsko Trinowi
addEventHandler ( "onResourceStart", resourceRoot, mapLoad )
Extrem liże hazowi dupsko a Barcioo liże cipsko Trinowi
</syntaxhighlight>
Extrem liże hazowi dupsko a Barcioo liże cipsko Trinowi
</section>
Extrem liże hazowi dupsko a Barcioo liże cipsko Trinowi
 
 
 
<section name="Example2" class="server" show="true">
This example creates an object near player who write createObject:
<syntaxhighlight lang="lua">
-- this function is called whenever someone types 'createObject' in the console:
function consoleCreateObject ( thePlayer, commandName )
  if ( thePlayer ) then
      local x, y, z = getElementPosition ( thePlayer ) -- get the player's position
      -- create a Object next to the player:
      local theObject = createObject ( 980, x + 2, y + 2, z, 0, 0, 0 )
      if ( theObject ) then -- check if the Obeject was created successfully
        outputConsole ( "Object created successfully", thePlayer )
      else
        outputConsole ( "Failed to create Object", thePlayer )
      end
  end
end
addCommandHandler ( "createObject", consoleCreateObject )
</syntaxhighlight>
</section>
 
==See Also==
{{Object functions}}
 
[[de:createObject]]

Revision as of 18:42, 1 January 2017

[[{{{image}}}|link=|]] Note: Dynamic objects do not automatically have physics applied to them. Use setElementVelocity(object, 0, 0, 0) to fix this.

Creates an object in the GTA world.

Syntax

object createObject ( int modelid, float x, float y, float z, [ float rx, float ry, float rz, bool isLowLOD = false ] )

OOP Syntax Help! I don't understand this!

Method: Object(...)


Required Arguments

  • modelid: a whole integer specifying the GTASA object model ID.
  • x: a floating point number representing the X coordinate on the map.
  • y: a floating point number representing the Y coordinate on the map.
  • z: a floating point number representing the Z coordinate on the map.

Optional Arguments

NOTE: When using optional arguments, you might need to supply all arguments before the one you wish to use. For more information on optional arguments, see optional arguments.

  • rx: a floating point number representing the rotation about the X axis in degrees.
  • ry: a floating point number representing the rotation about the Y axis in degrees.
  • rz: a floating point number representing the rotation about the Z axis in degrees.
  • isLowLOD: a bool value specifying if the object will be low LOD. A low LOD object has no collision and a longer draw distance.

Returns

  • The object element if creation was successful.
  • false otherwise.

Example

Click to collapse [-]
Example1

This example creates an object when the resource starts:

function mapLoad ( name )
   -- create an object at a specified position with a specified rotation
   createObject ( 1337, 5540.6654, 1020.55122, 1240.545, 90, 0, 0 )
end
addEventHandler ( "onResourceStart", resourceRoot, mapLoad )


Click to collapse [-]
Example2

This example creates an object near player who write createObject:

-- this function is called whenever someone types 'createObject' in the console:
function consoleCreateObject ( thePlayer, commandName )
   if ( thePlayer ) then
      local x, y, z = getElementPosition ( thePlayer ) -- get the player's position
      -- create a Object next to the player:
      local theObject = createObject ( 980, x + 2, y + 2, z, 0, 0, 0 )
      if ( theObject ) then -- check if the Obeject was created successfully
         outputConsole ( "Object created successfully", thePlayer )
      else
         outputConsole ( "Failed to create Object", thePlayer )
      end
   end
end
addCommandHandler ( "createObject", consoleCreateObject )

See Also