WorldClass
A script class that is instanced for every World in the game.
When entering a warehouse floor, the player is entering a new world.
The class can receive events sent with sm.event.sendToWorld.
The fields below are accessed using self.fieldName
in the WorldClass script:
Type | Name | Description |
---|---|---|
World | world | The World game object belonging to this class instance. |
Network | network | A Network object that can be used to send data between client and server. |
Storage | storage | A server-side Storage object that can be used to save and load data to/from the world database. |
any | data | Parameters passed to sm.world.createWorld |
cellMaxX
cellMaxY
cellMinX
cellMinY
enableAssets
enableClutter
enableCreations
enableHarvestables
enableKinematics
enableNodes
enableSurface
groundMaterialSet
isIndoor
renderMode
terrainScript
worldBorder
Server + Client
onCollision
function WorldClass.server_onCollision( self, objectA, objectB, position, pointVelocityA, pointVelocityB, normal )
end
function WorldClass.client_onCollision( self, objectA, objectB, position, pointVelocityA, pointVelocityB, normal )
end
Called when a collision occurs in this world.
Arguments:self
[ table ]: The class instance.objectA
[ Shape / Character / Harvestable / Lift / nil ]: The first colliding object. Nil if terrain.objectB
[ Shape / Character / Harvestable / Lift / nil ]: The second colliding object. Nil if terrain.position
[ Vec3 ]: The position in world space where the collision occurred.pointVelocityA
[ Vec3 ]: The velocity that that the first object had at the point of collision.pointVelocityB
[ Vec3 ]: The velocity that that the second object had at the point of collision.normal
[ Vec3 ]: The collision normal from objectA to objectB.
Server-only
onCellCreated
function WorldClass.server_onCellCreated( self, x, y )
end
Called when a world cell is loaded and feature complete for the first time.
Interactables created by terrain scripts should be processed here using sm.cell.getInteractablesByTag and sm.cell.getInteractablesByUuid, as they are only accessible for 1 tick after being created.
self
[ table ]: The class instance.x
[ int ]: The cell's X position.y
[ int ]: The cell's Y position.
onCellLoaded
function WorldClass.server_onCellLoaded( self, x, y )
end
Called when a world cell is loaded and feature complete, but has been before.
Arguments:self
[ table ]: The class instance.x
[ int ]: The cell's X position.y
[ int ]: The cell's Y position.
onCellUnloaded
function WorldClass.server_onCellUnloaded( self, x, y )
end
Called when a world cell is no longer feature complete.
Arguments:self
[ table ]: The class instance.x
[ int ]: The cell's X position.y
[ int ]: The cell's Y position.
onInteractableCreated
function WorldClass.server_onInteractableCreated( self, interactable )
end
Called when an Interactable Shape is built in the world.
Arguments:self
[ table ]: The class instance.interactable
[ Interactable ]: The interactable of the built shape.
onInteractableDestroyed
function WorldClass.server_onInteractableDestroyed( self, interactable )
end
Called when an Interactable Shape is removed from the world.
Arguments:self
[ table ]: The class instance.interactable
[ Interactable ]: The interactable of the removed shape.
onProjectile
function WorldClass.server_onProjectile( self, position, airTime, velocity, projectileName, shooter, damage, customData, normal, target, uuid )
end
Called when a projectile hits something in this world.
If the shooter is destroyed before the projectile hits, the shooter value will be nil.
self
[ table ]: The class instance.position
[ Vec3 ]: The position in world space where the projectile hit.airTime
[ number ]: The time, in seconds, that the projectile spent flying before the hit.velocity
[ Vec3 ]: The velocity of the projectile at impact.projectileName
[ string ]: The name of the projectile. (Legacy, use uuid instead)shooter
[ Player / Unit / Shape / Harvestable / nil ]: The shooter. Can be a Player, Unit, Shape, Harvestable or nil if unknown.damage
[ int ]: The damage value of the projectile.customData
[ any ]: A Lua object that can be defined at shoot time usingsm.projectile.customProjectileAttack
or any other custom version.target
[ Character / Shape / Harvestable / Lift / nil ]: The hit target. Can be a Character, Shape, Harvestable, Lift or nil if terrain or unknown.normal
[ Vec3 ]: The normal at the point of impact.uuid
[ Uuid ]: The uuid of the projectile.
onExplosion
function WorldClass.server_onExplosion( self, center, destructionLevel )
end
Called when an explosion occurs in this world.
Arguments:self
[ table ]: The class instance.center
[ Vec3 ]: The center of the explosion.destructionLevel
[ int ]: The level of destruction done by this explosion. Corresponds to thedurability
rating of a Shape.
onMelee
function WorldClass.server_onMelee( self, position, attacker, target, damage, power, direction, normal )
end
Called when a melee attack hits something in this world.
If the attacker is destroyed before the hit lands, the attacker value will be nil.
self
[ table ]: The class instance.position
[ Vec3 ]: The position in world space where the attack hit.attacker
[ Player / nil ]: The attacker. Can be a Player, Unit or nil if unknown.target
[ Character / Shape / Harvestable / Lift / nil ]: The hit target. Can be a Character, Shape, Harvestable, Lift or nil if terrain or unknown.damage
[ int ]: The damage value of the melee hit.power
[ number ]: The physical impact of the hit.direction
[ Vec3 ]: The direction of the melee attack.normal
[ Vec3 ]: The normal at the point of impact.
onProjectileFire
function WorldClass.server_onProjectileFire( self, position, velocity, projectileName, shooter, uuid )
end
Called when a projectile is fired in this world.
If the shooter is destroyed before the projectile hits, the shooter value will be nil.
self
[ table ]: The class instance.position
[ Vec3 ]: The position in world space where projectile was fired from.velocity
[ Vec3 ]: The fire velocity of the projectile.projectileName
[ string ]: The name of the projectile. (Legacy, use uuid instead)shooter
[ Player / Unit / Shape / Harvestable / nil ]: The shooter. Can be a Player, Unit, Shape, Harvestable or nil if unknown.uuid
[ Uuid ]: The uuid of the projectile.
Client-only
onCellLoaded
function WorldClass.client_onCellLoaded( self, x, y )
end
Called when a world cell is considered feature complete for a client (has nodes).
Arguments:self
[ table ]: The class instance.x
[ int ]: The cell's X position.y
[ int ]: The cell's Y position.
onCellUnloaded
function WorldClass.client_onCellUnloaded( self, x, y )
end
Called when a world cell is no longer considered feature complete for a client (no longer has nodes).
Arguments:self
[ table ]: The class instance.x
[ int ]: The cell's X position.y
[ int ]: The cell's Y position.