summaryrefslogtreecommitdiff
path: root/README
blob: 71a4ca98593d8fe2c87c8443699ef595606247dc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
playersettings
==============

This mod provides a GUI (via unified_inventory) that allows players to change various per-player settings.
No settings are actually included, but other mods can provide their own.

To register a setting:

playersettings.register("yourmodname:yoursettingname",{

	type = "number",
	-- Specifies the type of the setting to register.
	-- Valid types are:
	---- "number": An integer or floating-point value.
	---- "string": A text string.
	---- "boolean": A simple yes/no checkbox.
	---- "enum": A list of possible choices.
	
	shortdesc = "Short Description",
	-- A short (human-readable) description of the setting, to be shown as the setting name in the menu.
	
	longdesc = "Long Description Goes Here",
	-- A longer desciption that is shown when the user selects your setting in the menu.
	
	default = 5,
	-- The default value of the setting.
	
	min = 0,
	-- For "number" settings: The smallest selectable value.
	
	max = 10,
	-- For "number" settings: The largest selectable value.
	
	integer = true,
	-- For "integer" settings: If true, entered numbers will be rounded down to the nearest integer.
	
	values = "some text here",
	-- For "string" settings: Text to be displayed under the entry field to assist the user in selecting valid values.
	
	values = {"Apple", "Orange", "Banana"},
	-- For "enum" settings: A list of the possible choices.
	
	onjoin = function(player_name,setting_value),
	-- A function to be called whenever a player joins the game.
	-- 'player_name' is the name of the player that just joined.
	-- 'setting_value' is the current value of the setting.
	
	onchange = function(player_name,old_value,new_value)
	-- A function to be called when a player tries to change the setting, before the setting is actually changed.
	-- Custom validation logic should go here.
	-- 'player_name' is the name of the player trying to change the setting.
	-- 'old_value' is the current value of the setting.
	-- 'new_value' is the value the player wants to change the setting to.
	-- Return true to allow the change to take place, or false (or nothing at all) to prevent the change.
	
	afterchange = function(player_name,old_value,new_value)
	-- A function to be called after the setting is changed.
	-- Code to apply the new value of the setting should go here.
	-- 'player_name' is the name of the player that changed the setting.
	-- 'old_value' is the old value of the setting, before it was changed.
	-- 'new_value' is the value that the setting was changed to.
})

To set a setting (from another mod):

playersettings.set(player_name,setting_name,new_value)
-- 'player_name' is the player to change the setting for.
-- 'setting_name' is the name of the setting to change.
-- 'new_value' is the new value of the setting.
-- Changing settings via this interface bypasses the built-in validation (such as range checking on numbers) but NOT any specified onchange or afterchange actions.

To get the value of a setting (from another mod):

playersettings.get(player_name,setting_name)
-- 'player_name' is the player to get the setting value from.
-- 'setting_name' is the name of the setting to get.