Shared core of the Doors plugin: the access levels of characters to owned doors, the
registries of door properties and title types, and what both realms know about the
ownership of a door. Plugins add properties with Doors:register_property from the
RegisterDoorProperties hook and title types with Doors:register_title_type from
RegisterDoorTitleTypes.
Summary
Hooks
Doors.use_distance.Methods
Doors:clear_owner and tells the owner about it if they are playing that character.Doors.use_distance of it.Doors:get_menu_info returns for a door, so that their door management menu shows the current state.Hooks
Implements hook LanguageChanged
Makes every door work its status text out again when the language changes.
Implements hook LoadData
Loads the saved doors when the framework loads its data.
Implements hook NetVarChanged
Makes a door work its status text out again when one of its ownership variables ('fl_door_ownable', 'fl_door_price', 'fl_door_owner' or 'fl_door_text') has changed.
Parameters
- entity Entity the entity whose variable has changed
- key String variable name
Implements hook OnCharacterDelete
Releases the doors of a character that is about to be deleted and takes away the access it had to the doors of others.
Parameters
- _actor Player the player who deletes the character
- id Number ID of the character
- _character Character the character that is about to be deleted
Implements hook OnConfigReceived
Makes every door work its status text out again when the door_price config changes.
Parameters
- key String config key
Implements hook OnPluginsLoaded
Runs the RegisterDoorProperties and RegisterDoorTitleTypes hooks so that plugins can register their door properties and title types.
Implements hook PlayerCanLockDoor
Allows the player to lock and unlock the door if they satisfy its conditions, or if their character owns the door or has been given access to it.
Parameters
- actor Player
- entity Entity the door
Returns
- Boolean true if the player passes the door's conditions or has access to the door, nil otherwise
Throttles the use of doors and toggles the lock of a door when a player who is allowed to lock it uses it while sprinting. If locking or unlocking takes time (the door_lock_time and door_unlock_time configs), the use starts the timed action instead and is blocked. Runs the PlayerUseDoor hook for every use of a door that is not blocked.
Parameters
- activator Player
- entity Entity the entity that is being used
Returns
- Boolean false if the door is on cooldown, has just been locked or is about to be locked or unlocked by a timed action, nil otherwise
Draws the titles of the doors within 256 units of the camera on both sides
of the door, using the title type that is set on each door. A door that is ownable or
owned and has never been given a title type is drawn with Doors.default_title_type, so
that its status shows; choosing the disabled title type for it turns that off.
Parameters
- depth Boolean whether the depth pass is being drawn
- skybox Boolean whether the skybox is being drawn
Implements hook RegisterPermissions
Registers the 'manage_doors' level design permission.
Implements hook SaveData
Saves the doors when the framework saves its data.
Opens the door menu for the player if they are looking at a door within
Doors.use_distance. Along with the conditions of the door the client is sent what the
player may know about its ownership (see Doors:get_menu_info).
Parameters
- actor Player
Methods
Puts a door, along with the doors linked to it, under the main door of a group, where
they share its ownership state. Nothing is checked, networked or saved here; Doors:link
is what the Door Link tool goes through and Doors:restore_links what the loading of the
doors goes through.
Parameters
- entity Entity the door to link
- root Entity the main door of the group
Makes the active character of a player buy a door and the doors linked with it: checks that the door is for sale, the door limit of the character and their money, asks the PlayerCanBuyDoor hook, takes the price and makes the character the owner. The player is told about a purchase; a refusal is returned for the caller to tell.
local success, reason, arguments = Doors:buy(actor, entity)
if !success then
actor:notify(reason, arguments)
end
Parameters
- actor Player
- entity Entity the door
Returns
- Boolean whether the door was bought
- String error phrase if it was not
- Map arguments of the phrase
Doors:change_access(actor, entity, character_id, level)
server plugins/doors/plugin/lib/sv_access.lua:128Makes a player give a character access to a door, change the access it has or take it away. The player has to manage the door (DOOR_ACCESS_MANAGE); only the owner gives and takes the DOOR_ACCESS_MANAGE level. A character that is not on the access list yet has to be the active character of a player on the server. The PlayerCanChangeDoorAccess hook can refuse the change. Both players are told about a change; a refusal is returned for the caller to tell.
Parameters
- actor Player
- entity Entity the door
- character_id Number ID of the character
- level Number DOOR_ACCESS_USE or DOOR_ACCESS_MANAGE; DOOR_ACCESS_NONE takes the access away
Returns
- Boolean whether the character now has that level
- String error phrase if it does not
- Map arguments of the phrase
Makes a player put a text on a door that they manage (DOOR_ACCESS_MANAGE). Line breaks and other control characters become spaces and the text is cut to the length that the door_text_length config allows; an empty text removes the text. A refusal is returned for the caller to tell.
Parameters
- actor Player
- entity Entity the door
- text String
Returns
- Boolean whether the text was set
- String error phrase if it was not
Takes a door and the doors linked with it away from their owner: the access list and the text are cleared and the doors are unlocked. Nothing is refunded here.
Parameters
- entity Entity the door
Returns
- Boolean true if the door had an owner
- Map the owner it had
Counts the doors that a character owns. A group of linked doors counts as one.
Parameters
- character_id Number ID of the character
Returns
- Number
Takes a door away from its owner like Doors:clear_owner and tells the owner about it
if they are playing that character.
Parameters
- entity Entity the door
Returns
- Boolean true if the door had an owner
Finds the player whose active character has the given ID.
Parameters
- character_id Number
Returns
- Player the player, or nil if nobody is playing that character
Formats a price for display.
Parameters
- price Number the price
- currency String ID of the currency of the price
Returns
- String the amount followed by the name of the currency; nil if the price is not above 0 or the currency is not known, which is when a door is free
Returns the access level of the active character of a player to a door.
Parameters
- actor Player
- entity Entity the door
Returns
- Number DOOR_ACCESS_OWNER
- DOOR_ACCESS_MANAGE
- DOOR_ACCESS_USE or DOOR_ACCESS_NONE
Returns the access level of a character to a door.
Parameters
- entity Entity the door
- character_id Number ID of the character
Returns
- Number DOOR_ACCESS_OWNER
- DOOR_ACCESS_MANAGE
- DOOR_ACCESS_USE or DOOR_ACCESS_NONE
Returns the ID of the active character of a player, which is what owns doors and holds access to them.
Parameters
- actor Player
Returns
- Number character ID; nil for bots, for players without an active character and when the Characters plugin is not loaded
Returns every door of the group that a door is linked into.
Parameters
- entity Entity the door
Returns
- List<Entity> the main door followed by the doors linked to it; only the door itself if it is not linked
Returns how long it takes a player to lock or to unlock a door.
Parameters
- lock Boolean true for locking, false for unlocking
Returns
- Number seconds from the door_lock_time or the door_unlock_time config; 0 means that it happens at once
Returns the owner of a door.
Parameters
- entity Entity the door
Returns
- Map the owner: id (Number character ID), name (String character name), paid (Number what the door was bought for) and currency (String currency ID, nil if it was free); nil if the door has no owner
Returns the ID of the character that owns a door.
Parameters
- entity Entity the door
Returns
- Number character ID, or nil if nobody owns the door
Returns the ownership of a door in the form it is saved in.
Parameters
- entity Entity the door
Returns
- Map
parent(the map creation ID of the main door) for a door that is linked to another, orowner,access(a List of Maps with id, name and level) andtextfor a door that has an owner; nil if there is nothing to save
Returns what a door costs: its own price if staff have set one, the door_price config otherwise, rounded to the decimals of the default currency of the Currencies plugin. A group of linked doors has one price for all of its doors. Doors are free while the Currencies plugin is not loaded or has no default currency.
Parameters
- entity Entity the door
Returns
- Number the price, 0 if the door is free
- String ID of the currency the price is in, nil if there is no currency to pay with
Returns what the owner of a door gets back for selling it: the door_sell_share percent of what the door was bought for.
Parameters
- entity Entity the door
Returns
- Number the refund, 0 if there is none
- String ID of the currency of the refund, nil if there is none
Returns the main door of the group that a door is linked into.
Parameters
- entity Entity the door
Returns
- Entity the main door, which is the door itself if it is not linked to another
Returns the ownership state of a door, creating it if the door has none yet. The doors of a group share one table. Do not change it directly: use the setters, which also network the change.
Parameters
- entity Entity the door
Returns
- Map the state: ownable (Boolean), price (Number, nil for the default price), owner (Map with the id and name of the character, the paid price and its currency; nil if the door has no owner), access (Map of character IDs to Maps with level and name) and text (String, nil if there is none)
Returns the status line of a door, which title types draw below its name: the text of the owner or a note that the door is owned, or for an ownable door without an owner that it is for sale and for how much. The line is kept on the door and only worked out again once one of its 'fl_door_*' variables, the language or the door_price config changes.
Doors:register_title_type('plain', {
name = 'door.title_type.plain',
draw = function(entity, w, h, alpha)
local status = Doors:get_status_text(entity)
if status then
draw.SimpleText(status, Theme.get_font('text_3d2d'), 0, 0, color_white:alpha(alpha))
end
end
})
Parameters
- entity Entity the door
Returns
- String the status, or nil if the door is neither owned nor ownable
Returns the text that the owner of a door has put on it.
Parameters
- entity Entity the door
Returns
- String the text, or an empty string if there is none
Checks whether the active character of a player owns a door or has been given access to it.
if Doors:has_access(actor, entity, DOOR_ACCESS_MANAGE) then
Doors:set_text(entity, 'Closed')
end
Parameters
- actor Player
- entity Entity the door
- level Number optional, defaults to
DOOR_ACCESS_USEthe least access level that counts
Returns
- Boolean
Makes a door work its status text out again, for when one of its ownership variables has changed.
Parameters
- entity Entity the door
Makes every door work its status text out again, for when something that every status depends on has changed: the language or the door_price config.
Checks whether a player is close enough to a door to use its menu, lock it, trade it,
manage it or edit it: within Doors.use_distance of it.
Parameters
- actor Player
- entity Entity the door
Returns
- Boolean
Checks whether staff have marked a door, or the group it is linked into, as ownable.
Parameters
- entity Entity the door
Returns
- Boolean
Checks whether a door has an owner.
Parameters
- entity Entity the door
Returns
- Boolean
Checks whether the active character of a player owns a door.
Parameters
- actor Player
- entity Entity the door
Returns
- Boolean
Links a door into the group of another door, so that the two are owned, shared and labeled together. The door takes over the ownership state of the group. A door that already leads a group brings its doors along; a door of another group leaves that group. The doors are saved.
Parameters
- entity Entity the door to link
- parent Entity a door of the group to link it into
Returns
- Boolean whether the door was linked
- String error phrase if it was not: either is not a door, they are in one group already, or the door to link has an owner
Applies the saved properties, conditions and ownership to the doors of the map, skipping the saved doors that the map no longer has. Runs the InitialDoorsLoad hook instead if nothing has been saved yet.
Locks or unlocks the door and plays the latch sound.
Parameters
- entity Entity the door
- lock Boolean true to lock, false to unlock
Makes a player lock or unlock a door. It happens at once unless the door_lock_time or the door_unlock_time config is above 0: then the player starts a timed action ('lock_door' or 'unlock_door') that lasts as long as they keep looking at the door from nearby, and the door is locked or unlocked when it completes, provided that the player still passes PlayerCanLockDoor. Whether the player may lock the door at all is up to the caller.
Parameters
- actor Player
- entity Entity the door
- lock Boolean true to lock, false to unlock
- move Boolean optional, defaults to
falsealso close the door when it is locked and open it when it is unlocked
Returns
- Boolean true if the door has been locked or unlocked or the timed action has started, false if the player is busy with something else
Registers a door property that is saved together with the door and can optionally be edited in the door menu.
Doors:register_property('name', {
-- Returns the value to save. Also provides the value displayed in the door menu.
get_save_data = function(entity)
return entity:get_nv('fl_name', '')
end,
-- Serverside. Applies a value that was loaded or changed in the door menu.
on_load = function(entity, data)
entity:set_nv('fl_name', data)
end,
-- Optional, clientside. Creates and returns the row for the door menu.
create_panel = function(entity, panel)
local name = panel.properties:CreateRow(t'door.categories.general', t'door.properties.name')
name:Setup('Generic')
return name
end
})
Parameters
- id String unique property id, also the key the value is saved under
- data Map property definition: get_save_data(entity), on_load(entity, data) and the optional create_panel(entity, panel)
Registers a way to draw the title of a door, selectable in the door menu.
Doors:register_title_type('plain', {
name = 'door.title_type.plain',
-- Called in a 3D2D context that is centered on a face of the door.
draw = function(entity, w, h, alpha)
local text = entity:get_nv('fl_name')
local font = Theme.get_font('text_3d2d')
local text_w, text_h = util.text_size(text, font)
draw.SimpleText(text, font, -text_w / 2, -h / 4 - text_h / 2, color_white:alpha(alpha))
end
-- An optional draw_back function with the same arguments draws the back face.
})
Parameters
- id String unique title type id
- data Map title type definition: name (phrase), draw(entity, w, h, alpha) and the optional draw_back(entity, w, h, alpha)
Releases every door that a character owns, without a refund, and takes away the access it has to the doors of others. Used when the character is deleted.
Parameters
- character_id Number ID of the character
Returns
- Number how many doors and groups of doors were released
Links the loaded doors to their main doors again and networks the ownership state of every loaded door. Nothing is saved, since the doors are as they were saved.
Parameters
- doors List<Entity> the doors that were loaded
Writes the registered properties, the conditions and the ownership of every door on the map to the plugin data storage.
Makes a player sell a door that their active character owns, together with the doors linked with it: asks the PlayerCanSellDoor hook, pays the refund and releases the door. Nothing changes if the AdjustReceivedMoney hook refuses the refund. The player is told about a sale, with the refund they have actually received; a refusal is returned for the caller to tell.
Parameters
- actor Player
- entity Entity the door
Returns
- Boolean whether the door was sold
- String error phrase if it was not
- Map arguments of the phrase
Sends a player what Doors:get_menu_info returns for a door, so that their door
management menu shows the current state.
Parameters
- actor Player
- entity Entity the door
Doors:set_access(entity, character_id, level, name)
server plugins/doors/plugin/lib/sv_access.lua:64Gives a character access to an owned door and to the doors linked with it, changes the
access it has or takes it away. Nothing is checked here; Doors:change_access is what
players go through.
Parameters
- entity Entity the door
- character_id Number ID of the character, which may not be the owner
- level Number DOOR_ACCESS_USE or DOOR_ACCESS_MANAGE; DOOR_ACCESS_NONE takes the access away
- name String optional, defaults to
nilname to list the character under; the name it is already listed under is kept if omitted
Returns
- Boolean false if the door has no owner, the character is its owner or an argument is not valid
Sets whether a door and the doors linked with it can be owned. The owner of a door that stops being ownable is evicted.
Parameters
- entity Entity the door
- ownable Boolean
Doors:set_owner(entity, character_id, name, paid, currency)
server plugins/doors/plugin/lib/sv_ownership.lua:165Makes a character the owner of a door and of the doors linked with it, in place of the
owner it had. The access list and the text of the door are cleared. Nothing is checked
or paid here, and the door does not have to be ownable; Doors:buy is what players go
through.
Doors:set_owner(entity, target:get_character_id(), target:name(true))
Parameters
- entity Entity the door
- character_id Number ID of the character
- name String optional, defaults to
''name of the character, shown to staff and to those who manage the door - paid Number optional, defaults to
0what was paid for the door; the refund is a share of it - currency String optional, defaults to
nilID of the currency it was paid in
Returns
- Boolean false if the character ID is not a number
Applies saved ownership to a door. The link of a door to its main door is only
remembered here; Doors:restore_links makes it once every door has been loaded.
Parameters
- entity Entity the door
- data Map what
Doors:get_ownership_datareturned for the door; anything else is ignored
Sets the price of a door and of the doors linked with it.
Parameters
- entity Entity the door
- price Number optional, defaults to
nilthe price, 0 makes the door free; nil, or a number that is not finite, makes it cost what the door_price config says
Sets the text of the owner on a door and on the doors linked with it. The text is not
checked here; Doors:change_text is what players go through.
Parameters
- entity Entity the door
- text String optional, defaults to
nilthe text; nil or an empty string removes it
Networks the ownership state of a door to the clients, for every door of its group: the 'fl_door_ownable', 'fl_door_price', 'fl_door_owner' and 'fl_door_text' variables.
Parameters
- entity Entity the door
Takes a door out of the group it is linked into. The door keeps the price and the ownable flag of the group but not its owner. Unlinking the main door of a group breaks the whole group up, and the main door keeps the owner. The doors are saved.
Parameters
- entity Entity the door
Returns
- Boolean whether anything was unlinked
- String error phrase if the door is not linked to any other
Defined in
- plugins/doors/plugin/cl_hooks.lua
- plugins/doors/plugin/cl_plugin.lua
- plugins/doors/plugin/lib/sh_doors.lua
- plugins/doors/plugin/lib/sv_access.lua
- plugins/doors/plugin/lib/sv_ownership.lua
- plugins/doors/plugin/lib/sv_persistence.lua
- plugins/doors/plugin/lib/sv_trade.lua
- plugins/doors/plugin/sh_plugin.lua
- plugins/doors/plugin/sv_hooks.lua
- plugins/doors/plugin/sv_plugin.lua