CreateObject: Difference between revisions
Jump to navigation
Jump to search
(remove false note about broken object sync) |
|||
(16 intermediate revisions by 10 users not shown) | |||
Line 1: | Line 1: | ||
__NOTOC__ | __NOTOC__ | ||
{{Server client function}} | {{Server client function}} | ||
Creates an object | Creates an [[object]] [[element]] at a given position and rotation. | ||
{{Note|Dynamic objects do not automatically have physics applied to them. Use [[setElementVelocity]](object, 0, 0, 0) to fix this.}} | |||
==Syntax== | ==Syntax== | ||
<syntaxhighlight lang="lua">object createObject ( int | <syntaxhighlight lang="lua">object createObject ( int modelId, float x, float y, float z, [ float rx, float ry, float rz, bool isLowLOD = false ] )</syntaxhighlight> | ||
{{OOP||[[Object]]||}} | |||
===Required Arguments=== | ===Required Arguments=== | ||
*''' | *'''modelId:''' A whole integer specifying the GTA:SA object model ID. | ||
*'''x:''' A floating point number representing the X coordinate on the map. | *'''x:''' A floating point number representing the X coordinate on the map. | ||
*'''y:''' A floating point number representing the Y 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. | *'''z:''' A floating point number representing the Z coordinate on the map. | ||
===Optional Arguments=== | ===Optional Arguments=== | ||
{{OptionalArg}} | {{OptionalArg}} | ||
*'''rx:''' A floating point number representing the rotation about the X axis in degrees. | *'''rx:''' A floating point number representing the rotation about the X axis in degrees. | ||
Line 20: | Line 22: | ||
*'''isLowLOD:''' A bool value specifying if the object will be low LOD. A low LOD object has no collision and a longer draw distance. | *'''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=== | ===Returns=== | ||
Returns the [[object]] element if creation was successful, ''false'' otherwise. | * Returns the [[object]] element if the creation was successful, ''false'' otherwise. | ||
==Example== | ==Example== | ||
<section name="Server-only Example 1" class="server" show="true"> | |||
<section name=" | |||
This example creates an object when the resource starts: | This example creates an object when the resource starts: | ||
<syntaxhighlight lang="lua"> | <syntaxhighlight lang="lua"> | ||
function | function loadMapObjects() | ||
-- create an object at a specified position with a specified rotation | -- create an object at a specified position with a specified rotation | ||
createObject ( 1337, 5540.6654, 1020.55122, 1240.545, 90, 0, 0 ) | createObject(1337, 5540.6654, 1020.55122, 1240.545, 90, 0, 0) | ||
end | end | ||
addEventHandler ( "onResourceStart", | addEventHandler("onResourceStart", resourceRoot, loadMapObjects) | ||
</syntaxhighlight> | </syntaxhighlight> | ||
</section> | </section> | ||
<section name="Server-only Example 2" class="server" show="true"> | |||
This example creates an object near the player who write /createObject in the chat: | |||
<section name=" | |||
This example creates an object near player who write createObject: | |||
<syntaxhighlight lang="lua"> | <syntaxhighlight lang="lua"> | ||
-- this function is called whenever someone types 'createObject' in the console: | -- this function is called whenever someone types 'createObject' in the console: | ||
function | function createObjectCommand(thePlayer, commandName) | ||
if ( thePlayer ) then | if (thePlayer) then | ||
local x, y, z = getElementPosition ( thePlayer ) | local x, y, z = getElementPosition(thePlayer) | ||
-- create a | -- create a object next to the player: | ||
local theObject = createObject ( 980, x + 2, y + 2, z, 0, 0, 0 ) | local theObject = createObject(980, x + 2, y + 2, z, 0, 0, 0) | ||
if ( theObject ) then -- check if the | if (theObject) then -- check if the object was created successfully | ||
outputChatBox("Object created successfully.", thePlayer) | |||
else | else | ||
outputChatBox("Failed to create the object.", thePlayer) | |||
end | end | ||
end | end | ||
end | end | ||
addCommandHandler ( " | addCommandHandler("createobject", createObjectCommand) | ||
</syntaxhighlight> | </syntaxhighlight> | ||
</section> | </section> | ||
Line 60: | Line 60: | ||
==See Also== | ==See Also== | ||
{{Object functions}} | {{Object functions}} | ||
Latest revision as of 11:32, 31 October 2022
Creates an object element at a given position and rotation.
Note: Dynamic objects do not automatically have physics applied to them. Use setElementVelocity(object, 0, 0, 0) to fix this. |
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 GTA:SA 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
- Returns the object element if the creation was successful, false otherwise.
Example
Click to collapse [-]
Server-only Example 1This example creates an object when the resource starts:
function loadMapObjects() -- 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, loadMapObjects)
Click to collapse [-]
Server-only Example 2This example creates an object near the player who write /createObject in the chat:
-- this function is called whenever someone types 'createObject' in the console: function createObjectCommand(thePlayer, commandName) if (thePlayer) then local x, y, z = getElementPosition(thePlayer) -- 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 object was created successfully outputChatBox("Object created successfully.", thePlayer) else outputChatBox("Failed to create the object.", thePlayer) end end end addCommandHandler("createobject", createObjectCommand)
See Also
Shared