GetObjectProperty: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
m (Fixed argument list)
 
(2 intermediate revisions by 2 users not shown)
Line 4: Line 4:


==Syntax==  
==Syntax==  
<syntaxhighlight lang="lua">mixed getObjectProperty ( object theObject, string property [ , var value1, ... ] )</syntaxhighlight>  
<syntaxhighlight lang="lua">mixed getObjectProperty ( object theObject, string property )</syntaxhighlight>  
{{OOP||[[object]]:getProperty||setProperty}}
{{OOP||[[object]]:getProperty||setProperty}}
===Required Arguments===
===Required Arguments===
*'''theObject''': the [[object]] you wish to get a property of.
*'''theObject:''' the [[object]] you wish to get a property of.
*'''property:''': the property you want to get the value of:
*'''property:''' the property you want to get the value of:
<div style="padding-left:20px">
<div style="padding-left:20px">
* "all" - ''table'' with values of all properties below (OOP method: ''getProperties'')
* "all" - ''table'' with values of all properties below (OOP method: ''getProperties'')
Line 25: Line 25:
local theObject = createObject(980, 0, 0, 0) -- create an object
local theObject = createObject(980, 0, 0, 0) -- create an object
if theObject then
if theObject then
setObjectProperty(theObject, "center_of_mass", 0, -1, 0) -- set it's center of mass
setObjectProperty(theObject, "center_of_mass", 0, -1, 0) -- set its center of mass


local x, y, z = getObjectProperty(theObject, "center_of_mass") -- get it's center of mass
local x, y, z = getObjectProperty(theObject, "center_of_mass") -- get its center of mass
outputChatBox("Object's center of mass: "..tostring(x)..", "..tostring(y)..", "..tostring(z))
outputChatBox("Object's center of mass: "..tostring(x)..", "..tostring(y)..", "..tostring(z))
end
end

Latest revision as of 07:50, 28 October 2021

This function gets a property of the specified object.

Syntax

mixed getObjectProperty ( object theObject, string property )

OOP Syntax Help! I don't understand this!

Method: object:getProperty(...)
Counterpart: setProperty


Required Arguments

  • theObject: the object you wish to get a property of.
  • property: the property you want to get the value of:
  • "all" - table with values of all properties below (OOP method: getProperties)
  • "mass" - float
  • "turn_mass" - float
  • "air_resistance" - float
  • "elasticity" - float
  • "center_of_mass" - Vector3D - (x, y, z)
  • "buoyancy" - float

Returns

On success: table for all, 3 floats for center_of_mass or float for other properties

On failure: false

Example

Click to collapse [-]
Client
addEventHandler("onClientResourceStart", resourceRoot, function()
	local theObject = createObject(980, 0, 0, 0) -- create an object
	if theObject then
		setObjectProperty(theObject, "center_of_mass", 0, -1, 0) -- set its center of mass

		local x, y, z = getObjectProperty(theObject, "center_of_mass") -- get its center of mass
		outputChatBox("Object's center of mass: "..tostring(x)..", "..tostring(y)..", "..tostring(z))
	end
end)

See Also