Template:ExampleCreateObjectOrBuilding
Jump to navigation
Jump to search
This template is used on createBuilding and createObject pages, as a unified example.
Click to collapse [-]
How to automatically perform object/building creationThis example shows you how to easily verify if any object model ID is non-dynamic, so it can be used with the createBuilding function, as long as it's outside within the map boundaries:
function createObjectOrBuilding(modelID, x, y, z, rx, ry, rz, interior, dimension)
-- Dynamic object models will always have a physical properties group different than -1.
local isNonDynamic = engineGetModelPhysicalPropertiesGroup(modelID) == -1
-- Buildings can't be placed outside dimension 0
local isNormalDimension = dimension == 0
-- Buildings can't be placed outside regular map boundaries
local isInsideMapLimits = x >= -3000 and x <= 3000 and y >= -3000 and y <= 3000
if isNonDynamic and isNormalDimension and isInsideMapLimits then
createBuilding(modelID, x, y, z, rx, ry, rz, interior)
else
local obj = createObject(modelID, x, y, z, rx, ry, rz, false)
setElementInterior(obj, interior)
setElementDimension(obj, dimension)
end
end
-- This would be your object's model ID
local modelID = 3556
-- This would be your object's position coordinates
local x, y, z = 0, 0, 69
-- This would be your object's rotation coordinates
local rx, ry, rz = 0, 0, 90
-- This would be your object's interior ID
local interior = 0
-- This would be your object's dimension ID
local dimension = 0
local element = createObjectOrBuilding(modelID, x, y, z, rx, ry, rz, interior, dimension)
-- OPTIONAL: Then you can apply additional properties, like so:
if getElementType(element) == "object" then
setObjectScale(element, 1.69)
setObjectBreakable(object, false)
end
setElementAlpha(element, 255)
setElementCollisionsEnabled(element, true)
setElementFrozen(element, false)