PickupScheduler: using the Official Package

PickupScheduler: using the Offiical Package

Requirements:

  • Inventory Tutorial for pickupSpawnerScript
  • Basic scripting

Installed Packages

  • Pickup Scheduler (crayta)
  • Inventory (crayta)

Overview

PickupSchedulerScript is used in the Collection Starter Game to control the number of pickups during each game period.

This tutorial will apply this script to chests and/or crates to limit the number of spawned items in a world.


Starting Out

The Collection Starter Game starts the scheduler each game round. The Adventure Game Starter does not have this function. An onInitEventScript is needed to start the scheduler when the game is started.

The pickupSpawnerScript calls HidePickup on start by default. When using the pickupScheduler, StartScheduler needs to start after pickupSpawnerScript.

The gameController is used to start the scheduler after a short wait using the onInitEventScript. This is accomplished by using onInitEventScript for StartScheduler and a wait time of 1.

The default is to use all entities in the world with the pickupSpawnerScript. If unchecked, an array of entities maybe specified for a more customizable approach.


Setting up the world

  1. Place a chest or crate in the world.
    • add PickupSpawnerScript and configure
    • make template
    • place templates
  2. Place a locator in the world and call it gameController
    • add pickupSchedulerScript
  3. Create onInitEventScript
    • add to gameController
    • code is provided below
    • add event StartScheduler

PickupSpawnerScript

Only changes are listed below

Name Setting
pickupSound
useOnCollision true
rotateTime
respawning false … (if true, will break scheduler)
spawnTimeMin 5 … (1 works too)
spawnTimeMax 10 … (5 works too)
useSelfAsTemplate false
pickupTemplate
pickupCount
EnableCollisionOnChildern
showOnInit
onPickup
promptMsg

PickupSchedulerScript

Only changes are listed below

Name Setting
numberOfConcurrentPickups
spawnNewPicksOnCollect
useRespawnTimerForFirstSpawn
useResapwnTimerForReplacementSpawn true
useAllPickups
pickups

OnInitEventScript

Only changes are listed below

Name Setting
onInitEvent add
- Entity gameController
- Script pickupSchedulerScript
- Event StartScheduler
waitTime

Summary

On previewing the game, only the number of chests and/or crates will appear in the game determined by the pickupScheduler.

The respawn time will depend on whether the pickupScheduler is instantly spawning another item or using the respawn timer in the pickupSpawnerScript.

After a working model is established, feel free to play around and work onward from there.


Screenshots and Scripts

Screenshots
PickupSpawnerScript PickupSchedulerScript
OnInitEventScript
local OnInitEventScript = {}

OnInitEventScript.Properties = {
	{ name = "onInitEvent", type = "event", tooltip = "", },
	{ name = "waitTime", type = "number", default = 1, 
		tooltip = "time to wait before kicking off event", },
}

function OnInitEventScript:Init()
	self:Schedule(function()
		Wait(self.properties.waitTime)
		self.properties.onInitEvent:Send()
	end)
end

return OnInitEventScript
1 Like