Skip to content

Instantly share code, notes, and snippets.

@aduermael
Last active March 30, 2023 19:10
Show Gist options
  • Save aduermael/6adbfe7e37da71534c89ec0ae2d3304c to your computer and use it in GitHub Desktop.
Save aduermael/6adbfe7e37da71534c89ec0ae2d3304c to your computer and use it in GitHub Desktop.
discord-help-1.lua
Config = {
Map = "aduermael.lovely_castle"
}
Client.OnStart = function()
multi = require("multi")
-- Client.OnStart is the first function called on each player device
-- It's a good place to build a user interface, setup things that you
-- need when the game starts.
TimeCycle.On = false
local t = Text()
-- change text properties
t.Text = "Hello world!"
t.Type = TextType.Screen
t.IsUnlit = true
t.Tail = true
-- use it as a normal object in the scene
t:SetParent(Player)
t.LocalPosition = { 0, 34, 0 }
-- Dev:SetGameThumbnail()
-- Defines a function to drop a player above the map.
dropPlayer = function(player)
player.Position = Number3(Map.Width * 0.5, Map.Height + 10, Map.Depth * 0.5) * Map.Scale
player.Rotation = { 0, 0, 0 }
player.Velocity = { 0, 0, 0 }
end
multi:registerPlayerAction("test", function(sender, data)
print("received: " .. data.test .. "(from " .. sender.Username .. ")")
end)
end
Client.Tick = function(dt)
-- Game loop, executed ~30 times per second on each client.
multi:tick(dt)
-- Detect if Player (local player) is falling,
-- drop it above the map when it happens.
if Player.Position.Y < -100 then
dropPlayer(Player)
Player:TextBubble("💀 you died!")
end
end
-- jump function, triggered with Action1
Client.Action1 = function()
if Player.IsOnGround then
Player.Velocity.Y = 100
end
end
-- jump function, triggered with Action1
Client.Action2 = function()
multi:playerAction("test", { test="🙂" })
end
Client.OnPlayerJoin = function(p)
multi:initPlayer(p)
World:AddChild(p)
dropPlayer(p)
end
Client.OnPlayerLeave = function(p)
multi:removePlayer(p)
end
Client.DidReceiveEvent = function(e)
multi:receive(e)
end
--
-- Server code
--
Server.Tick = function(dt)
-- Server game loop, executed ~30 times per second on the server.
end
Server.OnPlayerJoin = function(newPlayer)
print("welcome", newPlayer.Username)
end
Server.OnPlayerLeave = function(leavingPlayer)
print(leavingPlayer.Username, "has left :(")
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment