Script v1_7_1_0
- AI
- Animals
- Collections
- Contracts
- Debug
- Economy
- Elements
- EnvironmentalScore
- Errors
- Events
- GUI
- Handtools
- Hud
- I3d
- Input
- Jobs
- Maps
- Materials
- Misc
- Objects
- AnimatedMapObject
- AnimatedObject
- Bale
- Basketball
- BgaSellStation
- BunkerSilo
- BuyingStation
- DigitalDisplay
- DogBall
- HelpIcons
- InlineBale
- InlineBaleSingle
- LoadingStation
- MountableObject
- NightIllumination
- Nightlight2
- NightlightFlicker
- PackedBale
- PhysicsObject
- ProductionPoint
- Rotator
- SellingStation
- SimParticleSystem
- Storage
- SunAdmirer
- TourIconsMobile
- UnloadingStation
- VehicleSellingPoint
- WildlifeSpawner
- Parameters
- Placeables
- Placement
- Player
- Shop
- Sounds
- Specialization
- Specializations
- StateMachine
- Statistics
- Tasks
- Triggers
- Utils
- Vehicles
Engine v1_7_1_0
- AI
- Animation
- Camera
- Entity
- Fillplanes
- general
- General
- I3D
- Input
- Lighting
- Math
- Network
- Node
- NoteNode
- Overlays
- Particle System
- Physics
- Rendering
- Scenegraph
- Shape
- Sound
- Spline
- String
- Terrain Detail
- Text Rendering
- Tire Track
- VoiceChat
- XML
Foundation Reference
DogBall
DescriptionClass for DogBallsParent
PhysicsObjectFunctions
- createNode
- delete
- getTerrainHeightWithProps
- groundRaycastCallback
- load
- new
- readStream
- reset
- updateTick
- writeStream
createNode
DescriptionLoad node from i3d fileDefinition
createNode(string i3dFilename)Arguments
string | i3dFilename | i3d file name |
69 | function DogBall:createNode(i3dFilename) |
70 | self.i3dFilename = i3dFilename |
71 | self.customEnvironment, self.baseDirectory = Utils.getModNameAndBaseDirectory(i3dFilename) |
72 | local dogBallRoot, sharedLoadRequestId = g_i3DManager:loadSharedI3DFile(i3dFilename, false, false) |
73 | self.sharedLoadRequestId = sharedLoadRequestId |
74 | |
75 | local dogBallId = getChildAt(dogBallRoot, 0) |
76 | link(getRootNode(), dogBallId) |
77 | delete(dogBallRoot) |
78 | |
79 | self:setNodeId(dogBallId) |
80 | end |
delete
DescriptionDeleting DogBall objectDefinition
delete()Code
29 | function DogBall:delete() |
30 | self.isDeleted = true -- mark as deleted so we can track it in Doghouse |
31 | if self.sharedLoadRequestId ~= nil then |
32 | g_i3DManager:releaseSharedI3DFile(self.sharedLoadRequestId) |
33 | end |
34 | unregisterObjectClassName(self) |
35 | DogBall:superClass().delete(self) |
36 | end |
getTerrainHeightWithProps
DescriptionDefinitiongetTerrainHeightWithProps()Code
84 | function DogBall:getTerrainHeightWithProps(x, z) |
85 | local terrainY = getTerrainHeightAtWorldPos(g_currentMission.terrainRootNode, x, 0, z) |
86 | local offset = 1.0 |
87 | local distance = 20.0 |
88 | local collisionMask = 63 |
89 | |
90 | self.groundY = -1.0 |
91 | raycastClosest(x, terrainY + offset, z, 0.0, -1.0, 0.0, "groundRaycastCallback", 5.0, self, collisionMask) |
92 | return math.max(terrainY, self.groundY) |
93 | end |
groundRaycastCallback
DescriptionDefinitiongroundRaycastCallback()Code
97 | function DogBall:groundRaycastCallback(hitObjectId, x, y, z, distance) |
98 | if hitObjectId ~= nil then |
99 | local objectType = getRigidBodyType(hitObjectId) |
100 | if objectType ~= RigidBodyType.DYNAMIC and objectType ~= RigidBodyType.KINEMATIC then |
101 | self.groundY = y |
102 | return false |
103 | end |
104 | end |
105 | return true |
106 | end |
load
DescriptionLoad DogBallDefinition
load(string i3dFilename, float x, float y, float z, float rx, float ry, float rz)Arguments
string | i3dFilename | i3d file name |
float | x | x world position |
float | y | z world position |
float | z | z world position |
float | rx | rx world rotation |
float | ry | ry world rotation |
float | rz | rz world rotation |
148 | function DogBall:load(i3dFilename, x,y,z, rx,ry,rz) |
149 | self:createNode(i3dFilename) |
150 | setTranslation(self.nodeId, x, y, z) |
151 | setRotation(self.nodeId, rx, ry, rz) |
152 | |
153 | if self.isServer then |
154 | self.spawnPos = {x,y,z} |
155 | self.throwPos = {x,y,z} |
156 | self.startRot = {rx,ry,rz} |
157 | end |
158 | return true |
159 | end |
new
DescriptionCreating DogBall objectDefinition
new(boolean isServer, boolean isClient, table customMt)Arguments
boolean | isServer | is server |
boolean | isClient | is client |
table | customMt | customMt |
table | instance | Instance of object |
17 | function DogBall.new(isServer, isClient, customMt) |
18 | local self = PhysicsObject.new(isServer, isClient, customMt or DogBall_mt) |
19 | |
20 | self.forcedClipDistance = 150 |
21 | registerObjectClassName(self, "DogBall") |
22 | self.sharedLoadRequestId = nil |
23 | |
24 | return self |
25 | end |
readStream
DescriptionCalled on client side on joinDefinition
readStream(integer streamId, table connection)Arguments
integer | streamId | stream ID |
table | connection | connection |
42 | function DogBall:readStream(streamId, connection) |
43 | if connection:getIsServer() then |
44 | local i3dFilename = NetworkUtil.convertFromNetworkFilename(streamReadString(streamId)) |
45 | |
46 | local isNew = self.i3dFilename == nil |
47 | if isNew then |
48 | self:load(i3dFilename, 0,0,0, 0,0,0) |
49 | -- The pose will be set by PhysicsObject, and we don't care about spawnPos/startRot on clients |
50 | end |
51 | end |
52 | DogBall:superClass().readStream(self, streamId, connection) |
53 | end |
reset
DescriptionDefinitionreset()Code
163 | function DogBall:reset() |
164 | if self.isServer then |
165 | removeFromPhysics(self.nodeId) |
166 | setTranslation(self.nodeId, unpack(self.spawnPos)) |
167 | setRotation(self.nodeId, unpack(self.startRot)) |
168 | addToPhysics(self.nodeId) |
169 | end |
170 | end |
updateTick
DescriptionLoad node from i3d fileDefinition
updateTick(string i3dFilename)Arguments
string | i3dFilename | i3d file name |
112 | function DogBall:updateTick(dt) |
113 | if self.isServer then |
114 | |
115 | -- Reset when fallen through the terrain |
116 | local x,y,z = getWorldTranslation(self.nodeId) |
117 | if self:getTerrainHeightWithProps(x, z) > (y + 1.0) then |
118 | self:reset() |
119 | end |
120 | |
121 | local parentNode = getParent(self.nodeId) |
122 | if parentNode ~= 0 and (parentNode == getRootNode() or parentNode == g_currentMission.terrainRootNode) then |
123 | local distSq = MathUtil.vector3LengthSq(x - self.spawnPos[1], y - self.spawnPos[2], z - self.spawnPos[3]) |
124 | -- Reset when too far away from spawn pos |
125 | if distSq > (DogBall.RESET_DISTANCE * DogBall.RESET_DISTANCE) then |
126 | self:reset() |
127 | end |
128 | else |
129 | local distSq = MathUtil.vector3LengthSq(x - self.throwPos[1], y - self.throwPos[2], z - self.throwPos[3]) |
130 | -- Reset when too far away from thrown pos |
131 | if distSq > (DogBall.RESET_DISTANCE * DogBall.RESET_DISTANCE) then |
132 | self:reset() |
133 | end |
134 | end |
135 | end |
136 | DogBall:superClass().updateTick(self, dt) |
137 | end |
writeStream
DescriptionCalled on server side on joinDefinition
writeStream(integer streamId, table connection)Arguments
integer | streamId | stream ID |
table | connection | connection |
59 | function DogBall:writeStream(streamId, connection) |
60 | if not connection:getIsServer() then |
61 | streamWriteString(streamId, NetworkUtil.convertToNetworkFilename(self.i3dFilename)) |
62 | end |
63 | DogBall:superClass().writeStream(self, streamId, connection) |
64 | end |