Auto-Respawn, Health, and Checkpoint (cliff notes) - using the official Packages

Auto-Respawn, Health, and Checkpoint (cliff notes) - using the official Packages

ref: (Andy’s Crayta Tutorial Videos)
Crayta Tutorial: Checkpoints

- Overview -

  • respawning package (mirrors Andys video as close as possible)
  • checkpoint package

- Auto-Respawn Package -

  • required for Checkpoint Package
  • follows video Tutorial for configuration

Install

  • search for respawn
  • check Crayta Packages
  • click Install
Auto-Respawn Package

Default

  • create a hole by the player
    • example hole is 10 x 10
    • mesh arrow infront of player for direction finding
  • preview
    • player falls down hole
    • player respawns at startlocation locator

User template

  • drag and drop User Spawn template onto User template
  • (optional) rename to Spawn
User Template

Spawn without configuration

  • preview
    • no player spawns
    • spawn is not configured

Spawn configuration

  • check Spawn on Login
  • preview and see the player spawn
spawnUserScript - Spawn on Login
  • add a locator in the world (example has one at the tip of the arrow)
  • in the world tab, remove the Default Spawn Locator value
  • preview
    • the player now spawns at either locator
    • the player will spawn at a random locator in the world without this configured
loctor1 at tip of arrow World Tab - Default Spawn Locator

Set Default Spawn Point

  • User Template under Spawn
  • set Spawn Point - startlocation
    • cannot drag and drop this location
    • navigate down to find in tree
  • spawnUserScript now controls player spawning
  • change Respawn Delay Time as desired
  • preview
    • player now only spawns on startlocation
    • (optional) test falling down hole
spawnUserScript - Spawn Point

- Health Package -

  • required for Checkpoint Package
  • not part of Andy’s Video Tutorial

Install

  • search for health
  • check Crayta Packages
  • click Install
Health Package

Player template

  • drag and drop Player Health template onto Player template
  • (optional) rename to Health
  • obby game uses this for OnDeathPlaneTrigger
  • no additional configuration needed
  • (optional) to hide the health bar
    • (if not wanted to be displayed)
    • uncheck Visible on the widget
Player Template healthWidget

- Checkpoint Package -

  • follows official package
  • this is the script from Obby Starter game

Install

  • search for checkpoint
  • check Crayta Packages
  • click Install
Checkpoint Package

Player template

  • add Script Folder called ObbyPlayer onto Player template
  • add obbyPlayerScript (see below for code)
    • obby game has obbyPlayerScript (same code - renamed for tutorial)
    • this script is not in the checkpoint package
    • supports AddNotification from the Notifications Package
    • supports ChallengeEvents
  • Checkpoint Start - checkpoint1
  • Checkpoint Msg - Reached checkpoint {checkpoint} (example not localized)
    • “Checkpoint {checkpoint} erreicht” [de]
    • “Reached checkpoint {checkpoint}” [en-US]
    • “Punto de control {checkpoint} alcanzado” [es]
    • “Point de contrôle {checkpoint} atteint” [fr-Ca][fr]
    • “Checkpoint {checkpoint} raggiunto” [it]
Player Template obbyPlayerScript

Setting Up Checkpoints

  • from templates drop one in front of arrow
  • from templates drop another infront of one
  • align checkpoints for easy running through
  • extrude hole past checkpoints

Checkpoint1

  • Name - Checkpoint! 1
  • Next Checkpoint - Checkpoint2
    • (can be done via drag and drop)
    • leave blank for non-liner progression

Checkpoint2

  • Name - Checkpoint! 2
Editior View checkpoint 1 checkpoint2

- Scripts -


obbyPlayerScript

local ObbyPlayerScript = {}

ObbyPlayerScript.Properties = {
	{ name = "checkpointStart", type = "entity", },
	{ name = "checkpointMsg", type = "text", },
	{ name = "checkpointCurrent", type = "entity", editable=false, },
}

function ObbyPlayerScript:Init()
	local checkpointScripts = GetWorld():FindAllScripts("checkpointScript")
	for _, checkpointScript in ipairs(checkpointScripts) do
		checkpointScript.properties.onCheckpoint:Listen(self, "OnCheckpoint")
	end
end

function ObbyPlayerScript:OnCheckpoint(checkpoint, player)
	-- check the player is us, as we've registered for *any* player
	-- going through checkpoint...
	if player == self:GetEntity() then
		self.properties.checkpointCurrent = checkpoint
		local spawnUserScript = self:GetEntity():GetUser().spawnUserScript
		local spawnPoint = checkpoint.checkpointScript.properties.spawnLocation
		if spawnUserScript and spawnPoint and spawnUserScript:GetSpawn() ~= spawnPoint then
			spawnUserScript:SetSpawn(spawnPoint)
			player:GetUser():SendToScripts("AddNotification", self.properties.checkpointMsg, {checkpoint = checkpoint.checkpointScript.properties.name})
		end
		player:GetUser():SendChallengeEvent("reached-checkpoint", {name = checkpoint:GetName()})
	end
end

return ObbyPlayerScript