Tilted Online
  • Overview
  • Guides
    • Getting Started
    • Client setup
      • Initial setup
        • Removing the old setup
        • Installing the game
        • Launching the game
      • Overview
      • Using ModOrganizer2 (MO2)
        • Installing ModOrganizer2
          • Installating the MO2 mod manager
          • Initial MO2 setup
          • Creating a MO2 profile
          • Creating a separator in MO2
        • Disabling the included Creation Club content
        • Utilities
          • Address Library for SKSE
        • Skyrim Together Reborn
          • Downloading Skyrim Together Reborn
          • Installing Skyrim Together Reborn
          • Locating Skyrim Together Reborn through MO2
          • Making a custom launch option in MO2
          • Launching SkyrimTogether through MO2
        • Playing Skyrim Together Reborn
          • Before we begin
          • First time launch
          • Connecting to a server
      • Using Vortex Mod Manager (VMM)
        • Installing Vortex Mod Manager
          • Installing the Vortex Mod Manager
          • Initial VMM setup
          • Creating a profile in VMM
        • Disabling the included Creation Club content
        • Utilities
          • Address Library for SKSE
        • Skyrim Together Reborn
          • Download Skyrim Together Reborn
          • Making a custom launch option in VMM
          • Launching SkyrimTogether through VMM
        • Playing Skyrim Together Reborn
          • Before we begin
          • First time launch
          • Connecting to a server
    • Server setup
      • ReadMe first
      • Terminology
      • Overview
      • Windows setup
        • Regular setup
          • Locating the STServer.ini
          • Editing STServer.ini
          • Explaining bEnableModcheck
          • Locating IP addresses
          • Port forwarding
          • Launching your server
        • ZeroTier setup
          • Locating the STServer.ini
          • Editing STServer.ini
          • Explaining bEnableModcheck
          • Initial ZeroTier setup
          • Configuring ZeroTier network
          • Authorizing users in ZeroTier network
          • Connecting to your server
        • Local setup
          • Locating the STServer.ini
          • Editing STServer.ini
      • Linux setup
        • Docker setup
        • Locating your IP address
        • Locating the STServer.ini
        • Editing STServer.ini
        • Explaining bEnableModcheck
        • Port forwarding
      • Pterodactyl
      • Server configuration parameters
    • Troubleshooting
      • Address Library error
      • Closing the SkyrimTogether UI (STR UI) makes it reopen
      • Disabling the included Creation Club content
        • Using ModOrganizer2
        • Using Vortex Mod Manager
      • During server setup, my firewall didn't ask for network permission!
      • Hostile NPCs only target my friends, not me
      • How do I uninstall the mod?
        • Using ModOrganizer2
        • Using Vortex Mod Manager
      • I need help updating the Skyrim Together Reborn mod
      • I selected the wrong .exe, when first launching SkyrimTogether
      • I want to install Skyrim Script Extender (SKSE)
        • Using ModOrganizer2
        • Using Vortex Mod Manager
      • My game crashes when I open it or connect to a server
      • My game runs with very low FPS
        • Using ModOrganizer2
        • Using Vortex Mod Manager (VMM)
      • Naked NPCs / players
      • The STR UI doesn't appear when I press RIGHT CTRL or F2
      • The server list is not appearing
      • My game opens to a black screen for 2-10 seconds and then closes
      • STR UI shows my filesystem
      • Resource folder does not exist
    • Scripting
      • Core Math functions
      • Player functions
      • GameServer
      • Components
      • Services
      • World
      • Event Handlers
  • General information
    • Features
    • Playguide
    • FAQ
    • Supported games
    • Helpful Links
    • Admin
    • Commands
      • Server Console
      • In-Game Chat
    • Command line arguments
  • Technical documentation
    • Build guide
      • Build Docker server image
      • Troubleshooting
    • Overview
    • Contributing to translations
Powered by GitBook
On this page

Was this helpful?

  1. Guides
  2. Scripting

GameServer

GameServer is a singleton instance. To fetch use, use the following lua:

local gameServer = GameServer:get()

Interact with the GameServer After obtaining the game server instance, you can call methods from the GameServer class using the colon operator (:) . For example:

gameServer:Kill(playerId)
gameServer:Kick(playerId)
local serverTick = gameServer:GetTick()

Send a chat message To send a chat message from the server to a specific player, use the SendChatMessage method:

local connectionId = 1 -- Replace this with the target player's connection ID
local message = "Hello from the server!"
gameServer:SendChatMessage(connectionId, message)

Name
Description
Usage

get()

Get the GameServer instance

GameServer:get()

Kill()

Shut down server

GameServer:get():Kill()

Kick(int)

Kick the player with the given Connection Id

GameServer:get():Kick(player:GetConnectionId())

GetTick()

Get the server's current tick value

GameServer:get():GetTick()

SendChatMessage(int, string)

Send a message to the given Connection Id

GameServer:get():SendMessage(player:getConnectionId(), "This is a message")

SendGlobalChatMessage(string)

Send a message to all connected players

GameServer:get():SendGlobalChatMessage("This is a global message")

SetTime(int hours, int minutes, float timeScale)

Set the world's time to the specified hour and minutes at the given time scale (default time scale is whatever the current world time scale

GameServer:get():SetTime(11, 15, 20) -- Set time to 11:15 AM at a time scale of 20

NOTE: SendChatMessage and SendGlobalChatMessage are automatically sanitized to remove any HTML tags

Example

local gameServer = GameServer:get()

addEventHandler("onPlayerQuit", function(entityId)
  gameServer:SendGlobalChatMessage("Someone left, server sad, server close :(")
  gameServer:Kill()
end)

addEventHandler("onSetTime", function(hours, minutes, timeScale)
  gameServer:SendGlobalChatMessage("Time set to " .. hours .. ":" .. minutes .. " at time scale of " .. timeScale)
end)

addEventHandler("onChatMessage", function(entityId, message)
  local player = getPlayer(entityId)
  if not player then
    return
  end
  
  if(string.find(message, "a") then
    gameServer:SendMessage(player:GetConnectionId(), "Your message contains an a, you're kicked")
    gameServer:Kick(player:GetConnectionId())
  end
end)
PreviousPlayer functionsNextComponents

Last updated 6 months ago

Was this helpful?