-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
95 additions
and
588 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
local ReplicatedStorage = game:GetService("ReplicatedStorage") | ||
|
||
local red = require(ReplicatedStorage.Packages.red) | ||
|
||
local store: red.StoreType = red.Store.new() | ||
|
||
store:subscribe(function(action: red.Action<any>) | ||
if action.type == "PLAYER_KILL" then | ||
print(`{action.payload} was killed!`) | ||
end | ||
end) | ||
|
||
-- "get" will wait for a result | ||
local data = store:get({ type = "GET_DATA" }) | ||
|
||
if data.success then | ||
print(data.payload.data) -- Hello, world! | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
local PlayerController = {} | ||
|
||
function PlayerController.kill(player: Player): boolean? | ||
local character = player.Character :: Model? | ||
local humanoid = character | ||
and character:FindFirstChildOfClass("Humanoid") :: Humanoid? | ||
|
||
if humanoid then | ||
humanoid.Health = 0 | ||
|
||
print(player.Name .. " was killed!") | ||
|
||
return true | ||
end | ||
|
||
return false | ||
end | ||
|
||
function PlayerController.damage(player: Player, amount: number) | ||
local character = player.Character :: Model? | ||
local humanoid = character | ||
and character:FindFirstChildOfClass("Humanoid") :: Humanoid? | ||
|
||
if humanoid then | ||
humanoid.Health -= amount | ||
print(`{player.Name} took {amount} damage!`) | ||
end | ||
end | ||
|
||
return PlayerController |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
local red = require(game.ReplicatedStorage.Packages.red) | ||
|
||
return function(server: red.ServerType) | ||
server:bind("GET_DATA", function(_player: Player) | ||
print("Getting data...") | ||
task.wait(1) | ||
|
||
return { | ||
type = "DATA", | ||
payload = { data = "Hello, world!" }, | ||
} | ||
end) | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
local red = require(game.ReplicatedStorage.Packages.red) | ||
|
||
return function(server: red.ServerType) | ||
server:bind("PING", function(player: Player) | ||
server:dispatch(player, { type = "PONG" }) | ||
end) | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
local red = require(game.ReplicatedStorage.Packages.red) | ||
|
||
local PlayerController = require(script.Parent.Parent.Controllers.PlayerController) | ||
|
||
return function(server: red.ServerType) | ||
server:bind("PLAYER_KILL", function(player: Player) | ||
local success = PlayerController.kill(player) | ||
|
||
if success then | ||
server:dispatch(true, { type = "PLAYER_KILLED", payload = player.Name }) | ||
end | ||
end) | ||
|
||
server:bind( | ||
"PLAYER_DAMAGE", | ||
function(player: Player, payload: red.ActionPayload<{ amount: number }>) | ||
PlayerController.damage(player, payload.amount) | ||
end | ||
) | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
local ReplicatedStorage = game:GetService("ReplicatedStorage") | ||
|
||
local red = require(ReplicatedStorage.Packages.red) | ||
|
||
local server: red.ServerType = red.Server.new() | ||
|
||
server:useHandlers(script.Parent.Handlers) |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.