A small request and response layer between the client and the server, loosely modeled on model-view-controller. Panels (the views) send named requests, and handlers on the server (the controllers) act on them and can answer. On the server MVC.handler registers a handler for a request name. Inside of a handler respond_to sends a response back to the player who has made the request, and MVC.push sends data under a name to any player at any time. On the client MVC.push sends a request, MVC.request sends one and calls a function with the response, and MVC.listen receives everything the server pushes under a name. Plugins usually keep their handlers in their controllers folder.

Summary

Functions

Registers a function that handles the requests clients send with MVC.push or MVC.request.
Registers a permanent callback for the data that the server pushes under the specified name.
Registers a callback for the data that the server pushes under the specified name.
Sends data to the callbacks the clients have registered with MVC.pull, MVC.request or MVC.listen.
Sends a request to the server and calls the handler once the server responds to it.

Functions

MVC.handler(name, handler)

server packages/active_ui/lib/sh_mvc.lua:114

Registers a function that handles the requests clients send with MVC.push or MVC.request. Call respond_to inside the handler to send a response back. Serverside only.

MVC.handler('fl_create_character', function(actor, data)
  local status = Characters.create(actor, data)

  respond_to { success = status == CHAR_SUCCESS, status = status }
end)

Parameters

  • name String name of the request
  • handler Function receives the player who has sent the request, followed by the request's data

MVC.listen(name, handler)

client packages/active_ui/lib/sh_mvc.lua:66

Registers a permanent callback for the data that the server pushes under the specified name.

Parameters

  • name String name of the request
  • handler Function receives the pushed values

MVC.pull(name, handler, prevent_remove)

client packages/active_ui/lib/sh_mvc.lua:34

Registers a callback for the data that the server pushes under the specified name. The callback is removed after the first response unless prevent_remove is set.

Parameters

  • name String name of the request
  • handler Function receives the pushed values
  • prevent_remove Boolean optional, defaults to false keep the callback for further responses

MVC.push(target, name, ...)

shared packages/active_ui/lib/sh_mvc.lua:128

On the server

Sends data to the callbacks the clients have registered with MVC.pull, MVC.request or MVC.listen. Serverside variant.

Parameters

  • target Player/List<Player> recipients, everyone if not a valid player
  • name String name of the request
  • ... Vararg data to pass to the callbacks

On the client

Sends a request to the server, where it is passed to the handlers registered with MVC.handler. Clientside variant.

MVC.push('SpawnMenu::GiveItem', PLAYER, item_obj.id, 1)

Parameters

  • name String name of the request
  • ... Vararg data to pass to the handlers

Defined in

MVC.request(name, handler, ...)

client packages/active_ui/lib/sh_mvc.lua:58

Sends a request to the server and calls the handler once the server responds to it.

MVC.request('fl_create_character', function(response)
  if response.success then
    print('Character created!')
  end
end, char_data)

Parameters

  • name String name of the request
  • handler Function receives the values of the response
  • ... Vararg data to send with the request

Defined in