User | CraytaKit
Skip to main content

User

Functions

Function NameReturn TypeDescriptionTags
GetUsername()TextGet the display name of the UserNone
GetPlayerCardIcon()stringGet the player avatar URLNone
SpawnPlayer(Template playerTemplate)CharacterSpawn a player Entity for this User using the supplied template assetServer Only
SpawnPlayer(Template playerTemplate, Locator locatorEntity)CharacterSpawn a player Entity for this User using the supplied template asset, at the position and rotation of the locatorEntityServer Only
SpawnPlayer(Template playerTemplate, Vector position, Rotation rotation)CharacterSpawn a player Entity for this User using the supplied template asset, at the given position and rotationServer Only
SpawnPlayerWithEffect(Template playerTemplate, function callback)CharacterSpawn a player Entity for this User using the supplied template asset and trigger the spawn effect with callbackServer Only
SpawnPlayerWithEffect(Template playerTemplate, Locator locatorEntity, function callback)CharacterSpawn a player Entity for this User using the supplied template asset, at the position of the spawnPoint (which can be any Entity with a 'playerstart' component) and trigger the spawn effect with callbackServer Only
SpawnPlayerWithEffect(Template playerTemplate, Vector position, Rotation rotation, function callback)CharacterSpawn a player Entity for this User using the supplied template asset, at the given position and trigger the spawn effectServer Only
SpawnPlayerWithEffect(Template playerTemplate)CharacterSpawn a player Entity for this User using the supplied template asset and trigger the spawn effectServer Only
SpawnPlayerWithEffect(Template playerTemplate, Locator locatorEntitiy)CharacterSpawn a player Entity for this User using the supplied template asset, at the position of the spawnPoint (which can be any Entity with a 'playerstart' component) and trigger the spawn effectServer Only
SpawnPlayerWithEffect(Template playerTemplate, Vector position, Rotation rotation)CharacterSpawn a player Entity for this User using the supplied template asset, at the given position and trigger the spawn effectServer Only
DespawnPlayer()NoneDespawn a playerServer Only
DespawnPlayerWithEffect(function callback)NoneDespawn a player and trigger the despawn effect with callback when it finishesServer Only
DespawnPlayerWithEffect()NoneDespawn a player and trigger the despawn effectServer Only
GetPlayer()CharacterGet the Entity (if there is one) that has been spawned for the UserNone
SetCamera(Entity camera)NoneSet camera view of this User to the given cameraEntity (which can be either a Camera entity or a Character entity)Server Only
SetCamera(Entity camera, number transitionTime)NoneSet camera view of this User to the given cameraEntity (which can be either a Camera entity or a Character entity). Transitions the camera over a given time from the previous oneServer Only
GetCamera()CameraGet the camera for the userNone
GetCameraLookAtPos()VectorGet the point the camera is looking atNone
GetCameraLookAt()Vector, VectorReturn two values, the position of the camera and a point the camera is facing at (where it collides with the scene)None
GetCursorLookAt()Vector, VectorReturn two values, the position of the cursor projected to world space and the point the cursor is hovering over (where it collides with the scene).Local Only
LeaveGame()NoneLeave the gameServer Only, Local Only
LeaveGame(function callback)NoneLeave the game, calling the callback if leaving failsServer Only
GoToGame(string gameId)NoneGo to game, specified by game idServer Only
GoToGame(string gameId, function callback)Nonego to game, specified by game id, calling callback if travel failsServer Only
GoToWorld(WorldAsset world)NoneGo to worldServer Only
GoToWorld(WorldAsset world)NoneGo to world, calling callback if the travel failsServer Only
OpenStore()NoneOpen the in-game crayta storeServer Only, Local Only
OpenNews()NoneOpen the in-game crayta newsServer Only, Local Only
OpenGameHelp(string helpPageId)NoneOpen the game-specific help menu at the given pageServer Only, Local Only
OpenGameHelp()NoneOpen the game-specific help menuServer Only, Local Only
OpenGameControls(string controlSchemeId)NoneOpen the game-specific game controls, at the specified control schemeServer Only, Local Only
OpenGameControls()NoneOpen the game-specific game controlsServer Only, Local Only
ShowCursor(boolean showCursor)NoneTurn the cursor on or offDeprecated
ProjectPositionToScreen(Vector worldLocation)Vector2DConverts a position in world space to a screen space co-ordinate Returned on-screen values are in the range 0 to 1 UsageLocal Only
ProjectPositionToWidget(Widget widget, Vector worldPosition)Converts a position in world space to a widget space co-ordinate Returned on-screen values are in the range 0 to 1Local Only
PlayVibrationEffect(VibrationEffectAsset vibrationEffectAsset)NonePlay the specific vibration effectNone
PlayManualVibration(number intensity, number duration, boolean affectSmallMotors, boolean affectLargeMotors)NoneManually play a vibration using the given valuesNone
PlayCameraShakeEffect(CameraShakeAsset cameraShakeAsset, number scale)NonePlay a camera shake effect on this User with a scale multiplierNone
PlayCameraShakeEffect(CameraShakeAsset cameraShakeAsset)NonePlay a camera shake effect on this UserNone
SetMoveOverride(Vector2D scale, Vector2D add)NoneSet a scale on the user's actual move input and an addition 2D vector to add to it. Used for example to auto-walk a player forward but scaling the real input down to zero and adding an additional valueNone
SetLookOverride(Vector2D scale, Vector2D add)NoneSet a scale on the user's actual look input and an addition 2D vector to add to it. Used for example to auto-look a player at a particular point by scaling the real input down to zero and adding an additional valueNone
SetLeaderboardValue(string leaderboardId, number value, function callback)NoneSet a value in the given leaderboard with the given value. Call the given callback with the resultServer Only
SetLeaderboardValue(string leaderboardId, number value)NoneSet a value in the given leaderboard with the given valueServer Only
GetLeaderboardValue(string leaderboardId, function callback)NoneGets the highest ranking value on the specified leaderboard for this user. Results are returned as parameters to the callback function. Callback function parameters are Score & RankNone
AddToLeaderboardValue(string leaderboardId, number increment, function callback)NoneAdd a number to the leaderboard value on the specified leaderboard for this user. Results are returned as parameters to the callback function. Callback function parameter is the new scoreNone
AddToLeaderboardValue(string leaderboardId, number increment)NoneAdd a number to the leaderboard value on the specified leaderboard for this userServer Only
GetChallengeProgress(string challengeId)numberGets the current progress on an active challengeNone
SendChallengeEvent(string eventName, table eventParameters)NonePlease use SendGameEvent instead of this. SendGameEvent trigger Challenges and ActivitiesDeprecated, Server Only
SendChallengeEvent(string eventName)NonePlease use SendGameEvent instead of this. SendGameEvent trigger Challenges and ActivitiesDeprecated, Server Only
SendXPEvent(string eventName, table eventParameterTable)NoneSends an event for this user that can be used by the Challenges and Activities systems. Takes a lua table of named parameters which are checked against the conditions inside each challenge and activityServer Only
SendXPEvent(string eventName)NoneSends an event for this user that can be used by the Challenges and Activities systems. This is the same as sending an empty parameter list in the other SendXPEvent overloadServer Only
GetBattlePassInfo()tableGet whether this player has the current battlepass and what level they are onNone
IsInputAssistanceEnabled()booleanNone

Properties

Property NameReturn TypeDescriptionTags
showDefaultCrosshairbooleanShow the default crosshairNone
useHotbarbooleanUse hotbar inputs, using the next and previous item buttons on controller and the hotbar buttons on keyboardNone
hotbarMaxnumberNumber of slots in the hotbar, this is a wrap point for next and previous item buttonsNone
hotbarIndexnumberThe current (1-based) hotbar index for this userNone
voiceChannelnumberThe current voice channel for this user (1 - 32)None

Examples

SendXPEvent

Here's an example of sending an event called SomeEvent which will progress any matching challenges or trigger any activities and give the player XP. The parameter names are entirely up to you and will be compared against the conditions in the definitions.

self:GetEntity():GetUser():SendXPEvent("SomeEvent", {someParameter1 = someValue1, someParameter2 = someValue2})

GetLeaderboardValue

function UserScript:UpdateLeaderboards()
self:GetEntity():GetLeaderboardValue("my-cool-leaderboard", function(score, rank)
self:GetEntity().leaderboardsWidget.js.data.myScore = { score = score, rank = rank }
end)
end

SetMoveOverride

SetMoveOveride lets you do two things:

  1. Scale user input on the X and Y axes
  2. Add a fixed amount to user input on the X and Y axes

For example, to force the user to move only left and right:

function UserScript:Init()
self:GetEntity():SetMoveOverride(Vector2D.New(1, 0), Vector2D.Zero)
end
© 2024 CraytaKit