summaryrefslogtreecommitdiff
path: root/README.md
blob: c780aea297a991dc5c48b681b194d15ffb806bab (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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
# Awards

Adds achievements to Minetest (plus a very good API).

by [rubenwardy](https://rubenwardy.com),
with thanks to Wuzzy, kaeza, and MrIbby.

Majority of awards are back ported from Calinou's old fork in Carbone, under same license.

# API

## Registering Achievements

```lua
awards.register_achievement(name, {
	description = "The title of the award",

	-- Optional:

	sound = {}, -- SimpleSoundSpec or false to play no sound
	            -- if not provided, uses default sound
	image = "icon_image.png", -- uses default icon otherwise
	background = "background_image.png", -- uses default background otherwise

	trigger = { -- is only unlocked by direct calls to awards.unlock() otherwise
		type = "trigger_type",
		-- see specific docs on the trigger to see what else goes here
	}
})
```

## Registering Trigger Types

```lua
local trigger = awards.register_trigger(name, {
	type = "", -- type of trigger, defaults to custom

	progress = "%2/%2"
	auto_description = { "Mine: @2", "Mine: @1×@2" },

	on_register = function(self, def) end

	-- "counted_key" only, when no key is given (ie: a total)
	auto_description_total = { "Mine @1 block.", "Mine @1 blocks." },

	-- "counted_key" only, get key for particular award - return nil for a total
	get_key = function(self, def)
		return minetest.registered_aliases[def.trigger.node] or def.trigger.node
	end
})
```

Types:

* "custom" requires you handle the calling of awards.unlock() yourself. You also
  need to implement on_register() yourself.
* "counted" stores a single counter for each player which is incremented by calling
  trigger:notify(player). Good for homogenous actions like number of chat messages,
  joins, and the like.
* "counted_key" stores a table of counters each indexed by a key. There is also
  a total field (`__total`) which stores the sum of all counters. A counter is
  incremented by calling trigger:notify(player, key). This is good for things like
  placing nodes or crafting items, where the key will be the item or node name.


## Helper Functions

* awards.register_on_unlock(func(name, def))
	* name is the player name
	* def is the award def.
	* return true to cancel HUD

* awards.unlock(name, award)
	* gives an award to a player
	* name is the player name

# Included in the Mod

The API, above, allows you to register awards
and triggers (things that look for events and unlock awards, they need
to be registered in order to get details from award_def.trigger).

However, all awards and triggers are separate from the API.
They can be found in init.lua and triggers.lua

## Triggers

Callbacks (register a function to be run)

"dig", "place", "craft", "death", "chat", "join" or "eat"
* dig type: Dig a node.
	* node: the dug node type. If nil, all dug nodes are counted
* place type: Place a node.
	* node: the placed node type. If nil, all placed nodes are counted
* eat type: Eat an item.
	* item: the eaten item type. If nil, all eaten items are counted
* craft type: Craft something.
	* item: the crafted item type. If nil, all crafted items are counted
* death type: Die.
	* reason: the death reason, one of the types in PlayerHPChangeReason (see lua_api.txt)
				or nil for total deaths.
* chat type: Write a chat message.
* join type: Join the server.
* (for all types) target - how many times to dig/place/craft/etc.
* See Triggers

### dig

	trigger = {
		type = "dig",
		node = "default:dirt",
		target = 50
	}

### place

	trigger = {
		type = "place",
		node = "default:dirt",
		target = 50
	}

### death

	trigger = {
		type = "death",
		target = 5
	}

### chat

	trigger = {
		type = "chat",
		target = 100
	}

### join

	trigger = {
		type = "join",
		target = 100
	}

### eat

	trigger = {
		type = "eat",
		item = "default:apple",
		target = 100
	}

## Callbacks relating to triggers

* awards.register_on_dig(func(player, data))
	* data is player data (see below)
	* return award name or null
* awards.register_on_place(func(player, data))
	* data is player data (see below)
	* return award name or null
* awards.register_on_eat(func(player, data))
	* data is player data (see below)
	* return award name or null
* awards.register_on_death(func(player, data))
	* data is player data (see below)
	* return award name or null
* awards.register_on_chat(func(player, data))
	* data is player data (see below)
	* return award name or null
* awards.register_on_join(func(player, data)
	* data is player data (see below)
	* return award name or null