World | CraytaKit
Skip to main content

World

Functions

Function NameReturn TypeDescriptionTags
RevertClientProperty(string propertyName)NoneRevert a property that's been changed on the client back to the server's value for itClient Only
Raycast(Vector start, Vector end, Entity entityToIgnore, function callback)NoneSend a ray (line) from start position to end position, and call the collisionCallback with the entity that was hit and a HitResult structure if any Entity is hit along the way. Pass an entityToIgnore to tell it not to hit that one (for example ignore the player when doing a ray from a gun the player is holding)None
Raycast(Vector start, Vector end, table<Entity> entitiesToIgnore, function callback)NoneSend a ray (line) from start position to end position, and call the collisionCallback with the entity that was hit and a HitResult structure if any Entity is hit along the way. Pass an array of entities to ignoreNone
Raycast(Vector start, Vector end, Entity entityToIgnore, boolean highFidelityCollision, function callback)NoneSend a ray (line) from start position to end position, and call the collisionCallback with the entity that was hit and a HitResult structure if any Entity is hit along the way. Pass an entityToIgnore to tell it not to hit that one (for example ignore the player when doing a ray from a gun the player is holding). High fidelity collisions will ignore any collision with an entity's bounding box if it would not also collide with it's more complex inner collisionNone
Raycast(Vector start, Vector end, table<Entity> entitiesToIgnore, boolean highFidelityCollision, function callback)NoneSend a ray (line) from start position to end position, and call the collisionCallback with the entity that was hit and a HitResult structure if any Entity is hit along the way. Pass an array of entities to ignore. High fidelity collisions will ignore any collision with an entity's bounding box if it would not also collide with it's more complex inner collisionNone
Find(string name)EntityFind a named Entity within the world. Generally an entity type property which is filled in in the editor is a better optionNone
FindAll()table<Entity>Return all entities in the world. Can be very slowNone
FindAll(table derivedType)table<Entity>Return all entities in the world of the given type (Light, Mesh, etc). Can be very slowNone
FindAllScripts(string scriptName)table<Script>Find all scripts named scriptName recursively in the world. Most often used where multiple scripts are used to simulate an array of structuresNone
FindAllScripts(ScriptAsset scriptAsset)table<Script>Find all scripts matching the script asset recursively in the world. Most often used where multiple scripts are used to simulate an array of structuresNone
FindScript(string scriptName)ScriptFind any entity with a script named scriptName recursively in the world, returns the script if foundNone
FindScript(ScriptAsset scriptAsset)ScriptFind any entity with a script matching the script asset recursively in the world, returns the script if foundNone
FindTemplate(string name)TemplateFind a Template in the world by name. Returns nil if not foundNone
GetLocalUser()UserGet the User that this client is owned byClient Only
GetUsers()table<User>Get a table containing all the User entities within the current world. This works on the server or the client however the client version of the table might lag behind the server versionNone
ForEachUser(function callback)NoneCall the given callback for each User with the User as the argumentNone
ApplyPointDamage(number baseDamage, Vector rayStart, Vector direction, Entity fromEntity)NoneApplies point damage to the first Entity that intersects the given rayServer Only
ApplyPointDamage(number baseDamage, Vector rayStart, Vector direction, Entity fromEntity, table damageModifiers)NoneApplies point damage to the first Entity that intersects the given rayServer Only
ApplyRadialDamage(number baseDamage, Vector origin, number radius, number falloff, Entity fromEntity)NoneApplies radial damage to all Entities within a radius of an originServer Only
ApplyRadialDamage(number baseDamage, Vector origin, number radius, number falloff, Entity fromEntity, table damageModifiers)NoneApplies radial damage to all Entities within a radius of an originServer Only
SetVoxelProperties(table properties)NoneSet the voxel properties of the worldServer Only
SetVoxelProperties(table properties, number defaultMaxHealth, number defaultHealTime)NoneSet the voxel properties of the worldNone
GetTimeOfDay()numberGet the time of day as a value between 0 and 1None
Spawn(Template template, Vector position, Rotation rotation)EntitySpawn a new Entity from the template pointed at by templateAsset, at the given position and rotationServer Only
Spawn(Template template, Locator locator)Spawn a new Entity from the template pointed at by templateAsset, at the given locator's position and rotationServer Only
BroadcastToScripts(string eventName, ...)NoneTry calling eventName on all scripts of all Entities within the World. When called on the server it sends to server scripts only, if called on the client it will send to client scripts onlyNone
GetServerTime()numberGet server up time in seconds (can be called on client or server)None
GetUTCTime()numberGets unit time (number of seconds that have elapsed since Jan 1 1970). This has an issue that it will start to overflow 32-bits in 2038None
GetGames(string railName, function callback)NoneGet all games from a specified railNone
GetGames(table<string> railNames, function callback)NoneGet all games from the specified railsNone
GetActiveChallenges()tableGets the current active challengesNone
PlayCameraShakeEffectAtLocation(CameraShakeAsset cameraShake, number scale, Vector location, number innerRadius, number outerRadius, number falloff, boolean orientToDirection)NonePlay a camera shake effect at this location in the world with a scale multiplierNone
PlayCameraShakeEffectAtLocation(CameraShakeAsset cameraShake, Vector location, number innerRadius, number outerRadius, number falloff, boolean orientToDirection)NonePlay a camera shake effect at this location in the worldNone
GetWorldAsset()WorldAssetReturns the WorldAsset that's currently loadedNone

Properties

Property NameReturn TypeDescriptionTags
startTimenumberStart time of day from 0.0 (midnight) - 0.5 (midday) - 1.0 (next midnight)Read-Write
dayLengthnumberLength of virtual 'day' in real-time secondsRead-Write
sunDirectionnumberAngle of sun in degrees. Controls whether the sun rises from west to east, north to south, etc.Read-Write
sunColorColorColor of the sunRead-Write
sunIntensitynumberIntensity of the sunRead-Write
heightFogStartDistancenumberHeight fog start distanceDeprecated
heightFogFalloffnumberHeight fog falloffDeprecated
heightFogDensitynumberHeight fog densityDeprecated
heightFogColorColorColor of the height fogDeprecated
skyLightIntensitynumberIntensity of the ambient lightRead-Write
skyLightColorColorColor of the ambient lightDeprecated
postProcessPostProcessAssetPost Process effectRead-Write
colorGradingColorGradingAssetColor Grading effectRead-Write
skydomeSkydomeAssetSkydome assetDeprecated
innerHorizonHorizonAssetInner Horizon assetRead-Write
outerHorizonHorizonAssetOuter Horizon assetRead-Write
skyMeshSkyMeshAssetSky Mesh assetRead-Write
enableShadowsbooleanEnable/Disable ShadowsRead-Write
fogStartDistancenumberFog start distanceRead-Write
fogDensitynumberFog densityRead-Write
fogFalloffnumberFog falloffRead-Write
fogColorColorColor of the fogRead-Write
fogAffectedByAtmospherebooleanFog Affected by AtmosphereRead-Write
cloudDensitynumberCloud DensityRead-Write
cloudCoveragenumberCloud CoverageRead-Write
cloudAltitudenumberCloud altitudeRead-Write
cloudLayerThicknessnumberCloud Layer ThicknessRead-Write
atmosphereThicknessnumberSet the thickness of the atmosphere. 1 = None, 2 = Thin, 3 = Earth-LikeRead-Write
atmosphericScatteringColorColorAtmospheric Scattering ColorRead-Write
atmosphereTintColorAtmosphere TintRead-Write
deathPlaneActivebooleanSet whether the death plane is active or notRead-Write
deathPlaneZnumberHeight of the death plane, when active the game will send OnFellToDeath to any Player who falls below this, automatically putting the Player back to where they spawned if the event is not responded to by any scriptsRead-Write
windDirectionRotation rotationDirection of global wind. This affects all Effects in the world.Read-Write
windSpeednumber windSpeedSpeed of global wind, in centimeters per second (cm/s). This affects all Effects in the world.Read-Write

Examples

ApplyPointDamage

DamageModifiers is a table of

{ 
voxel = [VoxelAsset](voxelAsset),
damageMultiplier = number
}

tables, and/or scripts that have voxel and damageMultiplier properties: { name = "voxel", type = "voxelasset" } and { name = "damageMultiplier", type = "number" }:

damageModifiers = { 
{ voxel = [VoxelAsset](voxel_asset), damageMultiplier = number },
{ voxel = [VoxelAsset](voxel_asset), damageMultiplier = number },
[Script](script),
[Script](script)
}

SetVoxelProperties

VoxelProperties is a table of { voxel = <voxelasset>, health = <number>, healTime = <number> } tables, and/or scripts that have voxel, and optionally health and healTime properties: { name = "voxel", type = "voxelasset" }, { name = "health", type = "number", default = 100 }, { name = "healTime", type = "number", editor = "seconds", default = 3 }. voxelProperties = { { voxel = <voxelasset>, health = <number>, healTime = <number> }, { voxel = <voxelasset>, health = <number> }, { voxel = <voxelasset>, healTime = <number> }, <script>, <script> } Defaults are 100 for health, 3.0 for heal time.

GetActiveChallenges

Example result table:

result = {} 
result[1] = {id = <ChallengeId>, name = <LocalisedName>, icon = <IconUrl>, count = <TotalCountToComplete>} result[2] = {id...

ForEachUser

function ExampleScript:DespawnAllPlayers()
GetWorld():ForEachUser(function(userEntity)
userEntity:DespawnPlayerWithEffect()
end)
end
© 2024 CraytaKit