DropletManager
The DropletManager is the main entry point for the DropletSystem API. The DropletSystem is a system for creating, managing, and collecting droplets in your game. It aims to handle all the annoying parts of droplets for you, such as physics, collection, and replication. Once you create a new droplet type, spawning them is extremely easy.
To get started look at DropletServerManager's methods :RegisterResourceType
and :Spawn
.
For more info on how to create a new droplet type, you can take a look at the included
'ExampleResourceTypeData' file, which will show you an example of a working ResourceType
data table.
In order for the DropletSystem to work, you must have a Server and Client DropletManager, accessing them through this file on both server and client should initialize them so that replication can be established.
This file in particular exposes access to the Server and Client DropletManagers, Enums, and several common public types.
EXAMPLE USAGE:
[ExampleData.lua]
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local DropletManager = require(ReplicatedStorage.DropletManager)
type Droplet = DropletManager.Droplet
return {
Defaults = {
LifeTime = NumberRange.new(20, 30);
};
SetupDroplet = function(droplet: Droplet): table?
local Model = Instance.new("Model")
Model.Name = "ExampleDroplet"
local Part = Instance.new("Part")
Part.Size = Vector3.one
-- All attached parts should typically have these properties set to these values
Part.Anchored = false
Part.CanCollide = false
Part.CanTouch = false
Part.CanQuery = false
Part.Massless = true
Part.Parent = Model
Model.PrimaryPart = Part
droplet:AttachModel(Model)
local SetupData = {
Direction = if math.random() > 0.5 then 1 else -1 end;
}
return CustomData
end;
-- Ran when the droplet is within render range of the LocalPlayer's Camera
OnRenderUpdate = function(droplet: Droplet, rendertimeElapsed: number): CFrame?
local SetupData = droplet:GetSetupData()
local OffsetCFrame = CFrame.new()
local tPi = rendertimeElapsed * math.pi
do -- Bobbing
local AMPLITUDE = 1 -- Studs of vertical movement (+- half of this)
local FREQUENCY = 0.25 -- Cycles per second
local Y = (AMPLITUDE * 0.5) * -math.cos(tPi * (FREQUENCY))
OffsetCFrame *= CFrame.new(0, AMPLITUDE + Y, 0)
end
do -- Rotating
local TimeToMakeOneRotation = 4
local RotationsPerSecond = 1/TimeToMakeOneRotation
OffsetCFrame *= CFrame.Angles(0, tPi * RotationsPerSecond * SetupData.SpinDirection, 0)
end
return OffsetCFrame
end;
OnClientCollect = function(playerWhoCollected: Player, droplet: Droplet)
print(playerWhoCollected, "collected droplet worth", droplet:GetValue())
end;
OnServerCollect = function(playerWhoCollected: Player, value: any)
print(playerWhoCollected, "collected droplet worth", value)
end;
}
Some Server Script:
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local DropletManager = require(ReplicatedStorage.DropletManager)
local ExampleData = require(ReplicatedStorage.ExampleData)
Droplets.Server:RegisterResourceType("Example", ExampleData) -- Register the Example ResourceType on the Server
while true do
Droplets.Server:Spawn({
ResourceType = "Example";
Value = NumberRange.new(1, 5);
Count = NumberRange.new(5, 10);
SpawnPosition = Vector3.new(
math.random(0, 10),
5,
math.random(0, 10)
);
})
task.wait(1)
end
Some Client Script:
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local DropletManager = require(ReplicatedStorage.DropletManager)
local ExampleData = require(ReplicatedStorage.ExampleData)
DropletManager.Client:RegisterResourceType("Example", ExampleData) -- Register the Example ResourceType on the Client
Types
Droplet
ResourceTypeData
ResourceSpawnData
Properties
Server
This item only works when running on the server. ServerDropletManager.Server:
DropletServerManager
Accessing this will automatically create a new DropletServerManager if one does not exist.
Client
This item only works when running on the client. ClientDropletManager.Client:
DropletClientManager
Accessing this will automatically create a new DropletClientManager if one does not exist.
Util
DropletManager.Util:
DropletUtil