SCP Secret Laboratory\LabAPI\dependencies\global
SCP Secret Laboratory\LabAPI\plugins\7777
(or global
if you want)SCP Secret Laboratory\LabAPI
directory. If everything worked, you should see a new SCriPt
folder. This is where you will place your Lua scripts.Let’s start with a simple script that prints “Hello, World!” to the console.
Create a new file in the SCP Secret Laboratory\LabAPI\SCriPt
folder called HelloWorld.lua
and put the following code in it:
print("Hello, World!")
When you launch the server, you should see [Info] [Lua-HelloWorld] Hello, World!
in the console. If you see this, you’ve written your first script.
This is the most important note when getting started. SCriPt works on a similar paradigm as C#, using events to execute code when it is needed. Let’s create a basic script that greets players when they join the server. We’ll go over what’s happening in a moment.
Create a new file in the SCP Secret Laboratory\LabAPI\SCriPt
folder called HelloUser.lua
and put the following code in it:
hello_user = SCriPt.Module("hello_user")
function hello_user:load()
Events.Player.Joined:add(hello_user.onPlayerJoined)
end
function hello_user:unload()
Events.Player.Joined:remove(hello_user.onPlayerJoined)
end
function hello_user:onPlayerJoined(args)
Server:Broadcast("Welcome to the server, " .. args.Player.Nickname .. "!")
print("Player " .. args.Player.Nickname .. " has joined the server.")
end
hello_user = SCriPt.Module("hello_user")
: This creates a new module named hello_user
. Modules are used to organize your code and can be loaded and unloaded independently.function hello_user:load()
: This function is called when the script is loaded. Here, we add an event listener for when a player joins the server.Events.Player.Joined:add(hello_user.onPlayerJoined)
: This line registers the onPlayerJoined
function to be called whenever a player joins the server.function hello_user:unload()
: This function is called when the script is unloaded. It removes the event listener to prevent memory leaks.Events.Player.Joined:remove(hello_user.onPlayerJoined)
: This line unregisters the onPlayerJoined
function when the script is unloaded.function hello_user:onPlayerJoined(args)
: This function is called when a player joins the server. It takes an args
parameter that contains information about the player.Server:Broadcast("Welcome to the server, " .. args.Player.Nickname .. "!")
: This line sends a message to all players on the server welcoming the new player.print("Player " .. args.Player.Nickname .. " has joined the server.")
: This line prints a message to the console indicating that a player has joined.Now that you have a basic understanding of how SCriPt works, you can start creating more complex scripts. The rest of the documentation will cover more advanced topics.