Script v1.7.1.0
- AI
- Animals
- Contracts
- Debug
- Economy
- Effects
- Events
- Farms
- GUI
- Handtools
- I3d
- Materials
- Misc
- Objects
- Placeables
- Player
- Shop
- Sounds
- Specializations
- Triggers
- Utils
- Vehicles
- Weather
Engine v1.7.1.0
- AI
- Animation
- Camera
- Entity
- Fillplanes
- General
- I3D
- Input
- Lighting
- Math
- Network
- Node
- Overlays
- Particle System
- Physics
- Rendering
- Scenegraph
- Shape
- Sound
- Spline
- String
- Terrain Detail
- Text Rendering
- Tire Track
- XML
- general
Foundation Reference
MapDataGrid
DescriptionA map data grid that splits a map in multiple sectionsParent
DataGridFunctions
getRowColumnFromWorldPos
DescriptionGets clamped row and column at given world positionDefinition
getRowColumnFromWorldPos(float worldX, float worldZ)Arguments
float | worldX | world position x |
float | worldZ | world position z |
integer | row | row |
integer | column | column |
55 | function MapDataGrid:getRowColumnFromWorldPos(worldX, worldZ) |
56 | local mapSize = self.mapSize |
57 | local blocksPerRowColumn = self.blocksPerRowColumn |
58 | |
59 | local x = (worldX + mapSize*0.5) / mapSize |
60 | local z = (worldZ + mapSize*0.5) / mapSize |
61 | |
62 | local row = MathUtil.clamp(math.ceil(blocksPerRowColumn*z), 1, blocksPerRowColumn) |
63 | local column = MathUtil.clamp(math.ceil(blocksPerRowColumn*x), 1, blocksPerRowColumn) |
64 | |
65 | -- log(worldX, worldZ, " -> ", (worldX + self.mapSize*0.5), (worldZ + self.mapSize*0.5), z, x, row, column) |
66 | |
67 | return row, column |
68 | end |
getValueAtWorldPos
DescriptionGet value at world positionDefinition
getValueAtWorldPos(float worldX, float worldZ)Arguments
float | worldX | world position x |
float | worldZ | world position z |
table | value | value at the given position |
34 | function MapDataGrid:getValueAtWorldPos(worldX, worldZ) |
35 | local rowIndex, colIndex = self:getRowColumnFromWorldPos(worldX, worldZ) |
36 | return self:getValue(rowIndex, colIndex), rowIndex, colIndex |
37 | end |
new
DescriptionCreating data gridDefinition
new(integer mapSize, integer blocksPerRowColumn, table customMt)Arguments
integer | mapSize | map size |
integer | blocksPerRowColumn | blocks per row and column |
table | customMt | custom metatable |
table | instance | instance of object |
19 | function MapDataGrid:new(mapSize, blocksPerRowColumn, customMt) |
20 | local self = DataGrid:new(blocksPerRowColumn, blocksPerRowColumn, customMt or MapDataGrid_mt) |
21 | |
22 | self.blocksPerRowColumn = blocksPerRowColumn |
23 | self.mapSize = mapSize |
24 | self.blockSize = self.mapSize/self.blocksPerRowColumn |
25 | |
26 | return self |
27 | end |
setValueAtWorldPos
DescriptionSet value at world positionDefinition
setValueAtWorldPos(float worldX, float worldZ, table value)Arguments
float | worldX | world position x |
float | worldZ | world position z |
table | value | value at the given position |
44 | function MapDataGrid:setValueAtWorldPos(worldX, worldZ, value) |
45 | local rowIndex, colIndex = self:getRowColumnFromWorldPos(worldX, worldZ) |
46 | self:setValue(rowIndex, colIndex, value) |
47 | end |