Client

Client is not creatable, there's only one instance of it. It can only be accessed through its globally exposed variable.

Client is available on each client (each user device). It contains everything needed for the local simulation.

Client is nil in the Server execution context.

Functions

Opens the chat input.

Shows the game menu.

From there, players can exit or resume the game.

Properties

function APad coming soon

Shortcut to AnalogPad.

Triggered when pressing action 1 button. (space bar by default with a keyboard)

Client.Action1 = function()
  print("action1")
end

Triggered when releasing action 1 button. (space bar by default with a keyboard)

Client.Action1Release = function()
  print("action1 released")
end

Triggered when pressing action 2 button. (left click by default when using a mouse)

Client.Action2 = function()
  print("action2")
end

Triggered when releasing action 2 button. (left click by default when using a mouse)

Client.Action2Release = function()
  print("action2 released")
end

Triggered when pressing action 3 button. (right click by default when using a mouse)

Client.Action3 = function()
  print("action3")
end

Triggered when releasing action 3 button. (left click by default when using a mouse)

Client.Action3Release = function()
  print("action3 released")
end

Triggered when what we call the "analog pad" or "A-pad" is activated.

The A-pad maps to the mouse mouvements when using a mouse.

When using a touch screen, the A-pad is activated when moving the finger after a touch down from anywhere outside the DirectionalPad.

The function receives 2 arguments dx & dy to represent the delta compared to the previous position. When both dx & dy are equal to 0.0, it means the pad is back to idle state.

-- DEFAULT IMPLEMENTATION
-- (those functions can be redefined)

Client.AnalogPad = function(dx, dy)
    Player.LocalRotation.Y = Player.LocalRotation.Y + dx * 0.01
    Player.LocalRotation.X = Player.LocalRotation.X + -dy * 0.01

    if dpadX ~= nil and dpadY ~= nil then
        Player.Motion = (Player.Forward * dpadY + Player.Right * dpadX) * 10
    end
end

Client.DirectionalPad = function(x, y)
    -- storing globals here for AnalogPad
    -- to update Player.Motion
    dpadX = x dpadY = y
    Player.Motion = (Player.Forward * y + Player.Right * x) * 10
end

Triggered when what we call the "directional pad" or "D-pad" is activated.

The D-pad maps to the direction keys when using a keyboard (WASD by default).

When using a touch screen, the D-pad is by default represented by the virtual pad that's on the left side of the screen.

The function receives 2 arguments x & y to represent 8 possible directions or the idle state:

0,0 -> IDLE
0,1 -> UP, 1,0 -> RIGHT, 0,-1 -> DOWN, -1,0 -> LEFT
√2,√2 -> UP/RIGHT, √2,-√2 -> DOWN/RIGHT, -√2,-√2 -> DOWN/LEFT, -√2,√2 -> UP/LEFT

The norm (or length) of the (x,y) vector is always 1.0, or 0.0 when idle.

-- DEFAULT IMPLEMENTATION
-- (those functions can be redefined)

Client.DirectionalPad = function(x, y)
    -- storing globals here for AnalogPad
    -- to update Player.Motion
    dpadX = x dpadY = y
    Player.Motion = (Player.Forward * y + Player.Right * x) * 10
end

Client.AnalogPad = function(dx, dy)
    Player.LocalRotation.Y = Player.LocalRotation.Y + dx * 0.01
    Player.LocalRotation.X = Player.LocalRotation.X + -dy * 0.01

    if dpadX ~= nil and dpadY ~= nil then
        Player.Motion = (Player.Forward * dpadY + Player.Right * dpadX) * 10
    end
end

See Fog.

Inputs Inputs

See Inputs.

Triggered when a player joins the game.

It doens't mean the Player has spawned, just that there's a new connection.

Client.OnPlayerJoin = function(player)
  print(player.Username .. " joined the game!")
end

Triggered when a player leaves the game.

Client.OnPlayerLeave = function(player)
  print("So long " .. player.Username .. "!")
end

Triggered when the game starts.

This is the very first Lua function to be called, a good place to initialize variables.

Client.OnStart = function()
  -- place player above the top center of the map
  Player.Position = {Map.Width / 2, Map.Height + 10, Map.Depth / 2}
  -- make it spawn!
  Player:Spawn()
end

Executed ~30 times per second. Provides the elapsed time in seconds as parameter.

-- executed ~30 times per second on each user device
Client.Tick = function(dt)
  print("elapsed:", dt, "seconds")
end
UI UI

See UI.