CreateBuilding: Difference between revisions
Jump to navigation
Jump to search
Fernando187 (talk | contribs) m (new note) |
Fernando187 (talk | contribs) mNo edit summary |
||
(7 intermediate revisions by the same user not shown) | |||
Line 2: | Line 2: | ||
{{Client function}} | {{Client function}} | ||
{{New feature/item|3.0161|1.6.0|22410|Creates a [[building]] [[element]] at a given position and rotation.}} | {{New feature/item|3.0161|1.6.0|22410|Creates a [[building]] [[element]] at a given position and rotation.}} | ||
{{ | {{BuildingInfo}} | ||
==Syntax== | ==Syntax== | ||
Line 27: | Line 26: | ||
==Example== | ==Example== | ||
<section name=" | <section name="How to automatically determine object/building creation" class="client" show="true"> | ||
This example shows you how to easily verify if any object model ID is non-dynamic, so it can be used with the createBuilding function: | This 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: | ||
<syntaxhighlight lang="lua"> | <syntaxhighlight lang="lua"> | ||
-- Dynamic object models will always have a physical properties group different than -1. | function createObjectOrBuilding(modelID, x, y, z, rx, ry, rz, interior, dimension) | ||
local isNonDynamic = | -- Dynamic object models will always have a physical properties group different than -1. | ||
if isNonDynamic then | local isNonDynamic = engineGetModelPhysicalPropertiesGroup(modelID) == -1 | ||
-- Buildings can't be placed outside dimension 0 | |||
else | 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) | |||
setElementDimension(obj, dimension) | |||
end | |||
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) | |||
iprint(element) | |||
</syntaxhighlight> | </syntaxhighlight> | ||
</section> | </section> | ||
Line 46: | Line 67: | ||
createBuilding(4550, 1985, -2544, 94, 0,0,0) -- Maze Bank Tower in LS airport | createBuilding(4550, 1985, -2544, 94, 0,0,0) -- Maze Bank Tower in LS airport | ||
end | end | ||
addEventHandler("onClientResourceStart", resourceRoot, loadMap) | addEventHandler("onClientResourceStart", resourceRoot, loadMap, false) | ||
</syntaxhighlight> | </syntaxhighlight> | ||
</section> | </section> |
Revision as of 10:20, 14 October 2024
Important information about buildings:
- There is a distinction in GTA: San Andreas between static and dynamic models (these use a separate streaming system). Examples of buildings include building models, roads, and terrain. Objects created as Buildings can contain glass and shadows, unlike those created as Objects(which can be created in any dimension).
- Using buildings for exterior mapping is more optimized than using objects. Gains in FPS can be noticed in areas where a lot of objects were replaced with buildings of this new system.
- Buildings cannot be created with dynamic object model IDs (like a door that opens when you push it), they are meant to be used for static objects, mainly buildings as the name suggests. For example, object ID 1502 (Gen_doorINT04) is a dynamic object model, which can be spawned using createObject. On the other hand, object ID 3556 (compmedhos3_LAe) is non-dynamic, you can use it with createBuilding.
- Buildings can only be created inside regular GTA:SA Map Boundaries (X between -3000 and 3000; Y between -3000 and 3000). Use createObject to spawn objects outside these normal limits.
- Created buildings can have LOD models, which is possible using createBuilding to spawn the LOD building, then setLowLODElement to associate it with a non-LOD building element created beforehand. LOD model distance changed with engineSetModelLODDistance affects buildings too.
- Buildings cannot be created outside dimension 0. Function setElementDimension will return false on any building.
Syntax
building createBuilding ( int modelId, float x, float y, float z [, float rx, float ry, float rz, int interior = 0 ] )
OOP Syntax Help! I don't understand this!
- Method: Building(...)
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.
- interior: The interior you want to set the building to. Valid values are 0 to 255.
Returns
- Returns the building element if the creation was successful, throws an error otherwise.
Example
Click to collapse [-]
How to automatically determine 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) 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) iprint(element)
Click to collapse [-]
Simple exampleThis example creates a building when the resource starts:
function loadMap() -- create a *building* at a specified position with a specified rotation createBuilding(4550, 1985, -2544, 94, 0,0,0) -- Maze Bank Tower in LS airport end addEventHandler("onClientResourceStart", resourceRoot, loadMap, false)
See Also