Script v1.7.1.0
- AI
- Animals
- Contracts
- Debug
- Economy
- Effects
- Events
- Farms
- GUI
- Handtools
- I3d
- Materials
- Misc
- Objects
- AnimatedMapObject
- AnimatedObject
- AnimatedObjectEvent
- Bale
- Basketball
- Bga
- BgaSellStation
- BunkerSilo
- BuyingStation
- DigitalDisplay
- DogBall
- HelpIcons
- LoadingStation
- NightIllumination
- Nightlight2
- NightlightFlicker
- PhysicsObject
- Rotator
- SellingStation
- SimParticleSystem
- Storage
- StorageSystem
- SunAdmirer
- TourIcons
- UnloadingStation
- VehicleSellingPoint
- WildlifeSpawner
- 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
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 |
68 | function DogBall:createNode(i3dFilename) |
69 | self.i3dFilename = i3dFilename |
70 | self.customEnvironment, self.baseDirectory = Utils.getModNameAndBaseDirectory(i3dFilename) |
71 | local dogBallRoot = g_i3DManager:loadSharedI3DFile(i3dFilename) |
72 | |
73 | local dogBallId = getChildAt(dogBallRoot, 0) |
74 | link(getRootNode(), dogBallId) |
75 | delete(dogBallRoot) |
76 | |
77 | self:setNodeId(dogBallId) |
78 | end |
delete
DescriptionDeleting DogBall objectDefinition
delete()Code
28 | function DogBall:delete() |
29 | self.isDeleted = true -- mark as deleted so we can track it in Doghouse |
30 | if self.i3dFilename ~= nil then |
31 | g_i3DManager:releaseSharedI3DFile(self.i3dFilename, nil, true) |
32 | end |
33 | unregisterObjectClassName(self) |
34 | DogBall:superClass().delete(self) |
35 | end |
getTerrainHeightWithProps
DescriptionDefinitiongetTerrainHeightWithProps()Code
82 | function DogBall:getTerrainHeightWithProps(x, z) |
83 | local terrainY = getTerrainHeightAtWorldPos(g_currentMission.terrainRootNode, x, 0, z) |
84 | local offset = 1.0 |
85 | local distance = 20.0 |
86 | local collisionMask = 63 |
87 | |
88 | self.groundY = -1.0 |
89 | raycastClosest(x, terrainY + offset, z, 0.0, -1.0, 0.0, "groundRaycastCallback", 5.0, self, collisionMask) |
90 | return math.max(terrainY, self.groundY) |
91 | end |
groundRaycastCallback
DescriptionDefinitiongroundRaycastCallback()Code
95 | function DogBall:groundRaycastCallback(hitObjectId, x, y, z, distance) |
96 | if hitObjectId ~= nil then |
97 | local objectType = getRigidBodyType(hitObjectId) |
98 | if objectType ~= "Dynamic" and objectType ~= "Kinematic" then |
99 | self.groundY = y |
100 | return false |
101 | end |
102 | end |
103 | return true |
104 | 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 |
146 | function DogBall:load(i3dFilename, x,y,z, rx,ry,rz) |
147 | self:createNode(i3dFilename) |
148 | setTranslation(self.nodeId, x, y, z) |
149 | setRotation(self.nodeId, rx, ry, rz) |
150 | |
151 | if self.isServer then |
152 | self.spawnPos = {x,y,z} |
153 | self.throwPos = {x,y,z} |
154 | self.startRot = {rx,ry,rz} |
155 | end |
156 | return true |
157 | 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 | |
23 | return self |
24 | end |
readStream
DescriptionCalled on client side on joinDefinition
readStream(integer streamId, table connection)Arguments
integer | streamId | stream ID |
table | connection | connection |
41 | function DogBall:readStream(streamId, connection) |
42 | if connection:getIsServer() then |
43 | local i3dFilename = NetworkUtil.convertFromNetworkFilename(streamReadString(streamId)) |
44 | |
45 | local isNew = self.i3dFilename == nil |
46 | if isNew then |
47 | self:load(i3dFilename, 0,0,0, 0,0,0) |
48 | -- The pose will be set by PhysicsObject, and we don't care about spawnPos/startRot on clients |
49 | end |
50 | end |
51 | DogBall:superClass().readStream(self, streamId, connection) |
52 | end |
reset
DescriptionDefinitionreset()Code
161 | function DogBall:reset() |
162 | if self.isServer then |
163 | removeFromPhysics(self.nodeId) |
164 | setTranslation(self.nodeId, unpack(self.spawnPos)) |
165 | setRotation(self.nodeId, unpack(self.startRot)) |
166 | addToPhysics(self.nodeId) |
167 | end |
168 | end |
updateTick
DescriptionLoad node from i3d fileDefinition
updateTick(string i3dFilename)Arguments
string | i3dFilename | i3d file name |
110 | function DogBall:updateTick(dt) |
111 | if self.isServer then |
112 | |
113 | -- Reset when fallen through the terrain; |
114 | local x,y,z = getWorldTranslation(self.nodeId) |
115 | if self:getTerrainHeightWithProps(x, z) > (y + 1.0) then |
116 | self:reset() |
117 | end |
118 | |
119 | local parentNode = getParent(self.nodeId) |
120 | if parentNode ~= nil and (parentNode == getRootNode() or parentNode == g_currentMission.terrainRootNode) then |
121 | local distSq = MathUtil.vector3LengthSq(x - self.spawnPos[1], y - self.spawnPos[2], z - self.spawnPos[3]) |
122 | -- Reset when too far away from spawn pos |
123 | if distSq > (DogBall.RESET_DISTANCE * DogBall.RESET_DISTANCE) then |
124 | self:reset() |
125 | end |
126 | else |
127 | local distSq = MathUtil.vector3LengthSq(x - self.throwPos[1], y - self.throwPos[2], z - self.throwPos[3]) |
128 | -- Reset when too far away from thrown pos |
129 | if distSq > (DogBall.RESET_DISTANCE * DogBall.RESET_DISTANCE) then |
130 | self:reset() |
131 | end |
132 | end |
133 | end |
134 | DogBall:superClass().updateTick(self, dt) |
135 | end |
writeStream
DescriptionCalled on server side on joinDefinition
writeStream(integer streamId, table connection)Arguments
integer | streamId | stream ID |
table | connection | connection |
58 | function DogBall:writeStream(streamId, connection) |
59 | if not connection:getIsServer() then |
60 | streamWriteString(streamId, NetworkUtil.convertToNetworkFilename(self.i3dFilename)) |
61 | end |
62 | DogBall:superClass().writeStream(self, streamId, connection) |
63 | end |