mirror of
https://gitlab.com/rubenwardy/awards.git
synced 2025-06-28 14:16:12 +02:00
Compare commits
9 Commits
Author | SHA1 | Date | |
---|---|---|---|
8c0bb00b1a | |||
237525b518 | |||
21e1ce6675 | |||
0ae58ad0c3 | |||
7d462c6aa5 | |||
f0052386c8 | |||
08f654cf94 | |||
3fc12eb689 | |||
98fca7914b |
318
README.md
318
README.md
@ -7,96 +7,223 @@ 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 Awards
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
# Introduction
|
||||
|
||||
## Awards and Triggers
|
||||
|
||||
An award is a single unlockable unit, registered like so:
|
||||
|
||||
```lua
|
||||
awards.register_award("mymod:myaward", {
|
||||
description = "The title of the award",
|
||||
awards.register_award("mymod:award", {
|
||||
description = "My Example Award",
|
||||
})
|
||||
```
|
||||
|
||||
-- Optional:
|
||||
Awards are unlocked either using `awards.unlock()` or by a trigger being
|
||||
fullfilled. A trigger is a condition which unlocks an award. Triggers are
|
||||
registered at the same time as an award is registered:
|
||||
|
||||
requires = { "amod:an_award" }, -- don't show this award or allow it to be unlocked
|
||||
-- until required awards are unlocked
|
||||
|
||||
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
|
||||
```lua
|
||||
awards.register_award("mymod:award", {
|
||||
description = "My Example Award",
|
||||
trigger = {
|
||||
type = "dig",
|
||||
node = "default:stone",
|
||||
target = 10,
|
||||
},
|
||||
})
|
||||
```
|
||||
|
||||
## Registering Trigger Types
|
||||
The above trigger type is an example of a counted_key trigger:
|
||||
rather than a single counter there's a counter per key - in this
|
||||
case the key is the value of the `node` field. If you leave out
|
||||
the key in a `counted_key` trigger, then the total will be used
|
||||
instead. For example, here is an award which unlocks after you've
|
||||
placed 10 nodes of any type:
|
||||
|
||||
```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,
|
||||
awards.register_award("mymod:award", {
|
||||
description = "Place 10 nodes!",
|
||||
trigger = {
|
||||
type = "place",
|
||||
target = 10,
|
||||
},
|
||||
})
|
||||
```
|
||||
|
||||
Types:
|
||||
You can also register an *Unlock Function*, which can return the name of an
|
||||
award to unlock it:
|
||||
|
||||
* "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,
|
||||
```lua
|
||||
awards.register_award("mymod:award", {
|
||||
title = "Lava Miner",
|
||||
description = "Mine any block while being very close to lava.",
|
||||
})
|
||||
|
||||
awards.register_on_dig(function(player, data)
|
||||
local pos = player:get_pos()
|
||||
if pos and (minetest.find_node_near(pos, 1, "default:lava_source") or
|
||||
minetest.find_node_near(pos, 1, "default:lava_flowing")) then
|
||||
return "mymod:award"
|
||||
end
|
||||
return nil
|
||||
end)
|
||||
```
|
||||
|
||||
The above is a bad example as you don't actually need the stats data given.
|
||||
It would be better to register a `dignode` callback and call `awards.unlock()`
|
||||
if the condition is met.
|
||||
|
||||
## Trigger Types
|
||||
|
||||
The trigger type is used to determine which event will cause the trigger will be
|
||||
fulfilled. The awards mod comes with a number of predefined types, documented
|
||||
in [Builtin Trigger Types](#builtin-trigger-types).
|
||||
|
||||
Trigger types are registered like so:
|
||||
|
||||
```lua
|
||||
awards.register_trigger("chat", {
|
||||
type = "counted",
|
||||
progress = "@1/@2 chat messages",
|
||||
auto_description = { "Send a chat message", "Chat @1 times" },
|
||||
})
|
||||
|
||||
minetest.register_on_chat_message(function(name, message)
|
||||
local player = minetest.get_player_by_name(name)
|
||||
if not player or string.find(message, "/") then
|
||||
return
|
||||
end
|
||||
awards.notify_chat(player)
|
||||
end)
|
||||
```
|
||||
|
||||
A trigger type has a type as well, which determines how the data is stored and
|
||||
also how the trigger is fulfilled.
|
||||
|
||||
**Trigger Type Types:**
|
||||
|
||||
* **custom** requires you handle the calling of awards.unlock() yourself. You also
|
||||
need to implement on_register() yourself. You'll also probably want to implement
|
||||
`on_register()` to catch awards registered with your trigger type.
|
||||
* **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
|
||||
* **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
|
||||
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.
|
||||
If `key` is an item, then you should also add `key_is_item = true` to the
|
||||
trigger type definition.
|
||||
|
||||
As said, you could use a custom trigger if none of the other ones match your needs.
|
||||
Here's an example.
|
||||
|
||||
```lua
|
||||
awards.register_trigger("foo", {
|
||||
type = "counted",
|
||||
progress = "@1/@2 foos",
|
||||
auto_description = { "Do a foo", "Foo @1 times" },
|
||||
})
|
||||
|
||||
minetest.register_on_foo(function()
|
||||
for _, trigger in pairs(awards.on.foo) do
|
||||
-- trigger is either a trigger tables or
|
||||
-- or an unlock function.
|
||||
|
||||
-- some complex logic
|
||||
if condition then
|
||||
awards.unlock(trigger)
|
||||
end
|
||||
end
|
||||
end)
|
||||
|
||||
```
|
||||
|
||||
## Award Difficulty
|
||||
|
||||
Difficulty is used to determine how awards are sorted in awards lists.
|
||||
|
||||
If the award trigger is counted, ie: the trigger requires a `target` property,
|
||||
then the difficulty multipler is timesd by `target` to get the overall difficulty.
|
||||
If the award isn't a counted type then the difficulty multiplier is used as the
|
||||
overal difficulty. Award difficulty affects how awards are sorted in a list -
|
||||
more difficult awards are further down the list.
|
||||
|
||||
In real terms, `difficulty` is a relative difficulty to do one unit of the trigger
|
||||
if its counted, otherwise it's the relative difficulty of completely doing the
|
||||
award (if not-counted). For the `dig` trigger type, 1 unit would be 1 node dug.
|
||||
|
||||
|
||||
## Helper Functions
|
||||
Actual code used to calculate award difficulty:
|
||||
|
||||
```lua
|
||||
local difficulty = def.difficulty or 1
|
||||
if def.trigger and def.trigger.target then
|
||||
difficulty = difficulty * def.trigger.target
|
||||
end
|
||||
```
|
||||
|
||||
|
||||
# API
|
||||
|
||||
* awards.register_award(name, def), the def table has the following fields:
|
||||
* `description` - the title of the award. Required.
|
||||
* `difficulty` - see [Award Difficulty](#award-difficulty).
|
||||
* `requires` - list of awards that need to be unlocked before this one
|
||||
is visible.
|
||||
* `sound` - `SimpleSoundSpec` table to play on unlock.
|
||||
`false` to disable unlock sound.
|
||||
* `image` - the icon image, use default otherwise.
|
||||
* `background` - the background image, use default otherwise.
|
||||
* `trigger` - trigger definition, see [Builtin Trigger Types](#builtin-trigger-types).
|
||||
* `on_unlock(name, def)` - callback on unlock.
|
||||
* awards.register_trigger(name, def), the def table has the following fields:
|
||||
* `type` - see [Trigger Types](#trigger-types).
|
||||
* `progress` - used to format progress, defaults to "%1/%2".
|
||||
* `auto_description` - a table of two elements. Each element is a format string. Element 1 is singular, element 2 is plural. Used for the award description (not title) if none is given.
|
||||
* `on_register(award_def)` - called when an award registers with this type.
|
||||
* "counted_key" only:
|
||||
* `auto_description_total` - Used if the trigger is for the total.
|
||||
* `get_key(self, def)` - get key for particular award, return nil for a total.
|
||||
* `key_is_item` - true if the key is an item name. On notify(),
|
||||
any watched groups will also be notified as `group:groupname` keys.
|
||||
* 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
|
||||
## Builtin Trigger Types
|
||||
|
||||
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.
|
||||
@ -104,72 +231,81 @@ Callbacks (register a function to be run)
|
||||
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
|
||||
* eat type: Eat an item.
|
||||
* item: the eaten item type. If nil, all eaten items are counted
|
||||
|
||||
(for all types) target - how many times to dig/place/craft/etc.
|
||||
|
||||
Each type has a register function like so:
|
||||
|
||||
* awards.register_on_TRIGGERTYPE(func(player, data))
|
||||
* data is the player stats data
|
||||
* return award name or null
|
||||
|
||||
### dig
|
||||
|
||||
trigger = {
|
||||
```lua
|
||||
trigger = {
|
||||
type = "dig",
|
||||
node = "default:dirt",
|
||||
node = "default:dirt", -- item, alias, or group
|
||||
target = 50,
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### place
|
||||
|
||||
trigger = {
|
||||
```lua
|
||||
trigger = {
|
||||
type = "place",
|
||||
node = "default:dirt",
|
||||
node = "default:dirt", -- item, alias, or group
|
||||
target = 50,
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### craft
|
||||
|
||||
```lua
|
||||
trigger = {
|
||||
type = "craft",
|
||||
node = "default:dirt", -- item, alias, or group
|
||||
target = 50,
|
||||
}
|
||||
```
|
||||
|
||||
### death
|
||||
|
||||
trigger = {
|
||||
```lua
|
||||
trigger = {
|
||||
type = "death",
|
||||
reason = "fall",
|
||||
target = 5,
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### chat
|
||||
|
||||
trigger = {
|
||||
```lua
|
||||
trigger = {
|
||||
type = "chat",
|
||||
target = 100,
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### join
|
||||
|
||||
trigger = {
|
||||
```lua
|
||||
trigger = {
|
||||
type = "join",
|
||||
target = 100,
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### eat
|
||||
|
||||
trigger = {
|
||||
```lua
|
||||
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
|
||||
}
|
||||
```
|
||||
|
33
api.lua
33
api.lua
@ -51,6 +51,7 @@ local function convert_data()
|
||||
local ret = {}
|
||||
|
||||
local count = 0
|
||||
if data[from] then
|
||||
for modname, items in pairs(data[from]) do
|
||||
for itemname, value in pairs(items) do
|
||||
itemname = modname .. ":" .. itemname
|
||||
@ -59,6 +60,7 @@ local function convert_data()
|
||||
count = count + value
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
ret.__total = count
|
||||
data[from] = nil
|
||||
@ -67,8 +69,6 @@ local function convert_data()
|
||||
|
||||
awards.players[name] = data
|
||||
end
|
||||
|
||||
print(dump(awards.players))
|
||||
end
|
||||
|
||||
function awards.load()
|
||||
@ -162,7 +162,6 @@ function awards.register_trigger(tname, tdef)
|
||||
assert(player and player.is_player and player:is_player())
|
||||
local name = player:get_player_name()
|
||||
local data = awards.player(name)
|
||||
print(dump(data))
|
||||
|
||||
-- Increment counter
|
||||
local currentVal = (data[tname] or 0) + 1
|
||||
@ -179,8 +178,14 @@ function awards.register_trigger(tname, tdef)
|
||||
awards["notify_" .. tname] = tdef.notify
|
||||
|
||||
elseif tdef.type == "counted_key" then
|
||||
if tdef.key_is_item then
|
||||
tdef.watched_groups = {}
|
||||
end
|
||||
|
||||
-- On award register
|
||||
local old_reg = tdef.on_register
|
||||
function tdef:on_register(def)
|
||||
-- Register trigger
|
||||
local tmp = {
|
||||
award = def.name,
|
||||
key = tdef:get_key(def),
|
||||
@ -188,6 +193,12 @@ function awards.register_trigger(tname, tdef)
|
||||
}
|
||||
tdef.register(tmp)
|
||||
|
||||
-- If group, add it to watch list
|
||||
if tdef.key_is_item and tmp.key and tmp.key:sub(1, 6) == "group:" then
|
||||
tdef.watched_groups[tmp.key:sub(7, #tmp.key)] = true
|
||||
end
|
||||
|
||||
-- Called to get progress values and labels
|
||||
function def.getProgress(_, data)
|
||||
local done
|
||||
data[tname] = data[tname] or {}
|
||||
@ -202,6 +213,7 @@ function awards.register_trigger(tname, tdef)
|
||||
}
|
||||
end
|
||||
|
||||
-- Build description if none is specificed by the award
|
||||
function def.getDefaultDescription(_)
|
||||
local n = def.trigger.target
|
||||
if tmp.key then
|
||||
@ -214,6 +226,7 @@ function awards.register_trigger(tname, tdef)
|
||||
end
|
||||
end
|
||||
|
||||
-- Call on_register in trigger type definition
|
||||
if old_reg then
|
||||
return old_reg(tdef, def)
|
||||
end
|
||||
@ -222,16 +235,28 @@ function awards.register_trigger(tname, tdef)
|
||||
function tdef.notify(player, key, n)
|
||||
n = n or 1
|
||||
|
||||
if tdef.key_is_item and key:sub(1, 6) ~= "group:" then
|
||||
local itemdef = minetest.registered_items[key]
|
||||
if itemdef then
|
||||
for groupname, _ in pairs(itemdef.groups or {}) do
|
||||
if tdef.watched_groups[groupname] then
|
||||
tdef.notify(player, "group:" .. groupname, n)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
assert(player and player.is_player and player:is_player() and key)
|
||||
local name = player:get_player_name()
|
||||
local data = awards.player(name)
|
||||
print(dump(data))
|
||||
|
||||
-- Increment counter
|
||||
data[tname] = data[tname] or {}
|
||||
local currentVal = (data[tname][key] or 0) + n
|
||||
data[tname][key] = currentVal
|
||||
if key:sub(1, 6) ~= "group:" then
|
||||
data[tname].__total = (data[tname].__total or 0) + n
|
||||
end
|
||||
|
||||
tdef:run_callbacks(player, data, function(entry)
|
||||
local current
|
||||
|
51
awards.lua
51
awards.lua
@ -87,6 +87,7 @@ if minetest.get_modpath("default") then
|
||||
title = S("Light It Up"),
|
||||
description = S("Place 100 torches."),
|
||||
icon = "awards_novicebuilder.png^awards_level1.png",
|
||||
difficulty = 0.01,
|
||||
trigger = {
|
||||
type = "place",
|
||||
node = "default:torch",
|
||||
@ -97,8 +98,9 @@ if minetest.get_modpath("default") then
|
||||
-- Light ALL the things!
|
||||
awards.register_award("award_well_lit",{
|
||||
title = S("Well Lit"),
|
||||
description = S("Place 1,000 torches."),
|
||||
icon = "awards_novicebuilder.png^awards_level2.png",
|
||||
description = S("Place 1,000 torches."),
|
||||
difficulty = 0.01,
|
||||
trigger = {
|
||||
type = "place",
|
||||
node = "default:torch",
|
||||
@ -110,6 +112,7 @@ if minetest.get_modpath("default") then
|
||||
title = S("Really Well Lit"),
|
||||
description = S("Craft 10 mese lamps."),
|
||||
icon = "default_meselamp.png",
|
||||
difficulty = 0.2,
|
||||
trigger = {
|
||||
type = "craft",
|
||||
item = "default:meselamp",
|
||||
@ -121,6 +124,7 @@ if minetest.get_modpath("default") then
|
||||
title = S("Outpost"),
|
||||
description = S("Craft 200 stone bricks."),
|
||||
icon = "default_stone_brick.png^awards_level1.png",
|
||||
difficulty = 0.08,
|
||||
trigger = {
|
||||
type = "craft",
|
||||
item = "default:stonebrick",
|
||||
@ -132,6 +136,7 @@ if minetest.get_modpath("default") then
|
||||
title = S("Watchtower"),
|
||||
description = S("Craft 800 stone bricks."),
|
||||
icon = "default_stone_brick.png^awards_level2.png",
|
||||
difficulty = 0.08,
|
||||
trigger = {
|
||||
type = "craft",
|
||||
item = "default:stonebrick",
|
||||
@ -143,6 +148,7 @@ if minetest.get_modpath("default") then
|
||||
title = S("Fortress"),
|
||||
description = S("Craft 3,200 stone bricks."),
|
||||
icon = "default_stone_brick.png^awards_level3.png",
|
||||
difficulty = 0.08,
|
||||
trigger = {
|
||||
type = "craft",
|
||||
item = "default:stonebrick",
|
||||
@ -154,6 +160,7 @@ if minetest.get_modpath("default") then
|
||||
title = S("Desert Dweller"),
|
||||
description = S("Craft 400 desert stone bricks."),
|
||||
icon = "default_desert_stone_brick.png",
|
||||
difficulty = 0.09,
|
||||
trigger = {
|
||||
type = "craft",
|
||||
item = "default:desert_stonebrick",
|
||||
@ -165,6 +172,7 @@ if minetest.get_modpath("default") then
|
||||
title = S("Pharaoh"),
|
||||
description = S("Craft 100 sandstone bricks."),
|
||||
icon = "default_sandstone_brick.png",
|
||||
difficulty = 0.09,
|
||||
trigger = {
|
||||
type = "craft",
|
||||
item = "default:sandstonebrick",
|
||||
@ -176,6 +184,7 @@ if minetest.get_modpath("default") then
|
||||
title = S("Little Library"),
|
||||
description = S("Craft 7 bookshelves."),
|
||||
icon = "default_bookshelf.png",
|
||||
difficulty = 0.2,
|
||||
trigger = {
|
||||
type = "craft",
|
||||
item = "default:bookshelf",
|
||||
@ -188,6 +197,7 @@ if minetest.get_modpath("default") then
|
||||
description = S("Mine your first obsidian."),
|
||||
icon = "default_obsidian.png^awards_level1.png",
|
||||
background = "awards_bg_mining.png",
|
||||
difficulty = 1.5,
|
||||
trigger = {
|
||||
type = "dig",
|
||||
node = "default:obsidian",
|
||||
@ -201,6 +211,7 @@ if minetest.get_modpath("default") then
|
||||
description = S("Mine 50 obsidian."),
|
||||
icon = "default_obsidian.png^awards_level2.png",
|
||||
background = "awards_bg_mining.png",
|
||||
difficulty = 1.5,
|
||||
trigger = {
|
||||
type = "dig",
|
||||
node = "default:obsidian",
|
||||
@ -214,6 +225,7 @@ if minetest.get_modpath("default") then
|
||||
description = S("Mine any block while being very close to lava."),
|
||||
background = "awards_bg_mining.png",
|
||||
icon = "default_lava.png",
|
||||
difficulty = 1,
|
||||
})
|
||||
awards.register_on_dig(function(player,data)
|
||||
local pos = player:get_pos()
|
||||
@ -229,6 +241,7 @@ if minetest.get_modpath("default") then
|
||||
title = S("On The Way"),
|
||||
description = S("Place 100 rails."),
|
||||
icon = "carts_rail_straight.png",
|
||||
difficulty = 0.1,
|
||||
trigger = {
|
||||
type = "place",
|
||||
node = "default:rail",
|
||||
@ -240,6 +253,7 @@ if minetest.get_modpath("default") then
|
||||
title = S("First Day in the Woods"),
|
||||
description = S("Dig 6 tree blocks."),
|
||||
icon = "default_tree.png^awards_level1.png",
|
||||
difficulty = 0.03,
|
||||
trigger = {
|
||||
type = "dig",
|
||||
node = "default:tree",
|
||||
@ -252,6 +266,7 @@ if minetest.get_modpath("default") then
|
||||
title = S("Lumberjack"),
|
||||
description = S("Dig 36 tree blocks."),
|
||||
icon = "default_tree.png^awards_level2.png",
|
||||
difficulty = 0.03,
|
||||
trigger = {
|
||||
type = "dig",
|
||||
node = "default:tree",
|
||||
@ -264,6 +279,7 @@ if minetest.get_modpath("default") then
|
||||
title = S("Semi-pro Lumberjack"),
|
||||
description = S("Dig 216 tree blocks."),
|
||||
icon = "default_tree.png^awards_level3.png",
|
||||
difficulty = 0.03,
|
||||
trigger = {
|
||||
type = "dig",
|
||||
node = "default:tree",
|
||||
@ -276,6 +292,7 @@ if minetest.get_modpath("default") then
|
||||
title = S("Professional Lumberjack"),
|
||||
description = S("Dig 1,296 tree blocks."),
|
||||
icon = "default_tree.png^awards_level4.png",
|
||||
difficulty = 0.03,
|
||||
trigger = {
|
||||
type = "dig",
|
||||
node = "default:tree",
|
||||
@ -288,6 +305,7 @@ if minetest.get_modpath("default") then
|
||||
title = S("Junglebaby"),
|
||||
description = S("Dig 100 jungle tree blocks."),
|
||||
icon = "default_jungletree.png^awards_level1.png",
|
||||
difficulty = 0.05,
|
||||
trigger = {
|
||||
type = "dig",
|
||||
node = "default:jungletree",
|
||||
@ -300,6 +318,7 @@ if minetest.get_modpath("default") then
|
||||
title = S("Jungleman"),
|
||||
description = S("Dig 1,000 jungle tree blocks."),
|
||||
icon = "default_jungletree.png^awards_level2.png",
|
||||
difficulty = 0.05,
|
||||
trigger = {
|
||||
type = "dig",
|
||||
node = "default:jungletree",
|
||||
@ -313,6 +332,7 @@ if minetest.get_modpath("default") then
|
||||
description = S("Mine your first mese ore."),
|
||||
icon = "default_stone.png^default_mineral_mese.png",
|
||||
background = "awards_bg_mining.png",
|
||||
difficulty = 1,
|
||||
trigger = {
|
||||
type = "dig",
|
||||
node = "default:stone_with_mese",
|
||||
@ -327,6 +347,7 @@ if minetest.get_modpath("default") then
|
||||
description = S("Mine a mese block."),
|
||||
icon = "default_mese_block.png",
|
||||
background = "awards_bg_mining.png",
|
||||
difficulty = 1.1,
|
||||
trigger = {
|
||||
type = "dig",
|
||||
node = "default:mese",
|
||||
@ -340,6 +361,7 @@ if minetest.get_modpath("default") then
|
||||
description = S("Dig 1,000 copper ores."),
|
||||
icon = "default_stone.png^default_mineral_copper.png",
|
||||
background = "awards_bg_mining.png",
|
||||
difficulty = 0.2,
|
||||
trigger = {
|
||||
type = "dig",
|
||||
node = "default:stone_with_copper",
|
||||
@ -353,6 +375,7 @@ if minetest.get_modpath("default") then
|
||||
description = S("Dig 100 stone blocks."),
|
||||
icon = "awards_miniminer.png^awards_level1.png",
|
||||
background = "awards_bg_mining.png",
|
||||
difficulty = 0.02,
|
||||
trigger = {
|
||||
type = "dig",
|
||||
node = "default:stone",
|
||||
@ -366,6 +389,7 @@ if minetest.get_modpath("default") then
|
||||
description = S("Dig 1,000 stone blocks."),
|
||||
icon = "awards_miniminer.png^awards_level2.png",
|
||||
background = "awards_bg_mining.png",
|
||||
difficulty = 0.02,
|
||||
trigger = {
|
||||
type = "dig",
|
||||
node = "default:stone",
|
||||
@ -379,6 +403,7 @@ if minetest.get_modpath("default") then
|
||||
description = S("Dig 10,000 stone blocks."),
|
||||
icon = "awards_miniminer.png^awards_level3.png",
|
||||
background = "awards_bg_mining.png",
|
||||
difficulty = 0.02,
|
||||
trigger = {
|
||||
type = "dig",
|
||||
node = "default:stone",
|
||||
@ -392,6 +417,7 @@ if minetest.get_modpath("default") then
|
||||
description = S("Dig 1,000 sand."),
|
||||
icon = "default_sand.png",
|
||||
background = "awards_bg_mining.png",
|
||||
difficulty = 0.05,
|
||||
trigger = {
|
||||
type = "dig",
|
||||
node = "default:sand",
|
||||
@ -403,6 +429,7 @@ if minetest.get_modpath("default") then
|
||||
title = S("Crafter of Sticks"),
|
||||
description = S("Craft 100 sticks."),
|
||||
icon = "default_stick.png",
|
||||
difficulty = 0.01,
|
||||
trigger = {
|
||||
type = "craft",
|
||||
item = "default:stick",
|
||||
@ -414,6 +441,7 @@ if minetest.get_modpath("default") then
|
||||
title = S("Jungle Discoverer"),
|
||||
description = S("Mine your first jungle grass."),
|
||||
icon = "default_junglegrass.png",
|
||||
difficulty = 0.009,
|
||||
trigger = {
|
||||
type = "dig",
|
||||
node = "default:junglegrass",
|
||||
@ -425,6 +453,7 @@ if minetest.get_modpath("default") then
|
||||
title = S("Grasslands Discoverer"),
|
||||
description = S("Mine some grass."),
|
||||
icon = "default_grass_3.png",
|
||||
difficulty = 0.009,
|
||||
trigger = {
|
||||
type = "dig",
|
||||
node = "default:grass_1",
|
||||
@ -436,6 +465,7 @@ if minetest.get_modpath("default") then
|
||||
title = S("Savannah Discoverer"),
|
||||
description = S("Mine some dry grass."),
|
||||
icon = "default_dry_grass_3.png",
|
||||
difficulty = 0.009,
|
||||
trigger = {
|
||||
type = "dig",
|
||||
node = "default:dry_grass_3",
|
||||
@ -447,6 +477,7 @@ if minetest.get_modpath("default") then
|
||||
title = S("Desert Discoverer"),
|
||||
description = S("Mine your first cactus."),
|
||||
icon = "default_cactus_side.png",
|
||||
difficulty = 0.03,
|
||||
trigger = {
|
||||
type = "dig",
|
||||
node = "default:cactus",
|
||||
@ -458,6 +489,7 @@ if minetest.get_modpath("default") then
|
||||
title = S("Far Lands"),
|
||||
description = S("Mine your first dry shrub."),
|
||||
icon = "default_dry_shrub.png",
|
||||
difficulty = 0.009,
|
||||
trigger = {
|
||||
type = "dig",
|
||||
node = "default:dry_shrub",
|
||||
@ -469,6 +501,7 @@ if minetest.get_modpath("default") then
|
||||
title = S("Glacier Discoverer"),
|
||||
description = S("Mine your first ice."),
|
||||
icon = "default_ice.png",
|
||||
difficulty = 0.02,
|
||||
trigger = {
|
||||
type = "dig",
|
||||
node = "default:ice",
|
||||
@ -481,6 +514,7 @@ if minetest.get_modpath("default") then
|
||||
title = S("Very Simple Snow Man"),
|
||||
description = S("Place two snow blocks."),
|
||||
icon = "default_snow.png",
|
||||
difficulty = 0.02,
|
||||
trigger = {
|
||||
type = "place",
|
||||
node = "default:snowblock",
|
||||
@ -493,6 +527,7 @@ if minetest.get_modpath("default") then
|
||||
description = S("Mine your first gold ore."),
|
||||
icon = "default_stone.png^default_mineral_gold.png^awards_level1.png",
|
||||
background = "awards_bg_mining.png",
|
||||
difficulty = 0.9,
|
||||
trigger = {
|
||||
type = "dig",
|
||||
node = "default:stone_with_gold",
|
||||
@ -505,6 +540,7 @@ if minetest.get_modpath("default") then
|
||||
description = S("Mine 45 gold ores."),
|
||||
icon = "default_stone.png^default_mineral_gold.png^awards_level2.png",
|
||||
background = "awards_bg_mining.png",
|
||||
difficulty = 0.9,
|
||||
trigger = {
|
||||
type = "dig",
|
||||
node = "default:stone_with_gold",
|
||||
@ -516,6 +552,7 @@ if minetest.get_modpath("default") then
|
||||
title = S("Wow, I am Diamonds!"),
|
||||
description = S("Mine your first diamond ore."),
|
||||
icon = "default_stone.png^default_mineral_diamond.png^awards_level1.png",
|
||||
difficulty = 1,
|
||||
trigger = {
|
||||
type = "dig",
|
||||
node = "default:stone_with_diamond",
|
||||
@ -528,6 +565,7 @@ if minetest.get_modpath("default") then
|
||||
description = S("Mine 18 diamond ores."),
|
||||
icon = "default_stone.png^default_mineral_diamond.png^awards_level2.png",
|
||||
background = "awards_bg_mining.png",
|
||||
difficulty = 1,
|
||||
trigger = {
|
||||
type = "dig",
|
||||
node = "default:stone_with_diamond",
|
||||
@ -539,6 +577,7 @@ if minetest.get_modpath("default") then
|
||||
title = S("Hardest Block on Earth"),
|
||||
description = S("Craft a diamond block."),
|
||||
icon = "default_diamond_block.png",
|
||||
difficulty = 1.1,
|
||||
trigger = {
|
||||
type = "craft",
|
||||
item = "default:diamondblock",
|
||||
@ -550,6 +589,7 @@ if minetest.get_modpath("default") then
|
||||
title = S("In the Dungeon"),
|
||||
description = S("Mine a mossy cobblestone."),
|
||||
icon = "default_mossycobble.png",
|
||||
difficulty = 0.9,
|
||||
trigger = {
|
||||
type = "dig",
|
||||
node = "default:mossycobble",
|
||||
@ -561,6 +601,7 @@ if minetest.get_modpath("default") then
|
||||
title = S("Smelter"),
|
||||
description = S("Craft 10 furnaces."),
|
||||
icon = "default_furnace_front.png",
|
||||
difficulty = 0.08,
|
||||
trigger = {
|
||||
type = "craft",
|
||||
item= "default:furnace",
|
||||
@ -572,6 +613,7 @@ if minetest.get_modpath("default") then
|
||||
title = S("Treasurer"),
|
||||
description = S("Craft 15 chests."),
|
||||
icon = "default_chest_front.png",
|
||||
difficulty = 0.08,
|
||||
trigger = {
|
||||
type = "craft",
|
||||
item= "default:chest",
|
||||
@ -583,6 +625,7 @@ if minetest.get_modpath("default") then
|
||||
title = S("Bankier"),
|
||||
description = S("Craft 30 locked chests."),
|
||||
icon = "default_chest_lock.png",
|
||||
difficulty = 0.08,
|
||||
trigger = {
|
||||
type = "craft",
|
||||
item= "default:chest_locked",
|
||||
@ -594,6 +637,7 @@ if minetest.get_modpath("default") then
|
||||
title = S("Bricker"),
|
||||
description = S("Craft 200 brick blocks."),
|
||||
icon = "default_brick.png",
|
||||
difficulty = 0.03,
|
||||
trigger = {
|
||||
type = "craft",
|
||||
item= "default:brick",
|
||||
@ -605,6 +649,7 @@ if minetest.get_modpath("default") then
|
||||
title = S("House of Obsidian"),
|
||||
description = S("Craft 100 obsidian bricks."),
|
||||
icon = "default_obsidian_brick.png",
|
||||
difficulty = 0.4,
|
||||
trigger = {
|
||||
type = "craft",
|
||||
item= "default:obsidianbrick",
|
||||
@ -616,6 +661,7 @@ if minetest.get_modpath("default") then
|
||||
title = S("Build a Cave"),
|
||||
description = S("Place 100 stone."),
|
||||
icon = "default_stone.png",
|
||||
difficulty = 0.1,
|
||||
trigger = {
|
||||
type = "place",
|
||||
node = "default:stone",
|
||||
@ -627,6 +673,7 @@ if minetest.get_modpath("default") then
|
||||
title = S("Long Ladder"),
|
||||
description = S("Place 400 wooden ladders."),
|
||||
icon = "default_ladder_wood.png",
|
||||
difficulty = 0.1,
|
||||
trigger = {
|
||||
type = "place",
|
||||
node = "default:ladder_wood",
|
||||
@ -638,6 +685,7 @@ if minetest.get_modpath("default") then
|
||||
title = S("Industrial Age"),
|
||||
description = S("Place 40 steel ladders."),
|
||||
icon = "default_ladder_steel.png",
|
||||
difficulty = 1,
|
||||
trigger = {
|
||||
type = "place",
|
||||
node = "default:ladder_steel",
|
||||
@ -649,6 +697,7 @@ if minetest.get_modpath("default") then
|
||||
title = S("Yummy!"),
|
||||
description = S("Eat 80 apples."),
|
||||
icon = "default_apple.png",
|
||||
difficulty = 0.1,
|
||||
trigger = {
|
||||
type = "eat",
|
||||
item = "default:apple",
|
||||
|
10
gui.lua
10
gui.lua
@ -13,9 +13,13 @@ local function order_awards(name)
|
||||
if def then
|
||||
hash_is_unlocked[awardname] = true
|
||||
local score = -100000
|
||||
|
||||
local difficulty = def.difficulty or 1
|
||||
if def.trigger and def.trigger.target then
|
||||
score = score + def.trigger.target
|
||||
difficulty = difficulty * def.trigger.target
|
||||
end
|
||||
score = score + difficulty
|
||||
|
||||
retval[#retval + 1] = {
|
||||
name = awardname,
|
||||
def = def,
|
||||
@ -30,12 +34,12 @@ local function order_awards(name)
|
||||
for _, def in pairs(awards.registered_awards) do
|
||||
if not hash_is_unlocked[def.name] and def:can_unlock(data) then
|
||||
local started = false
|
||||
local score
|
||||
local score = def.difficulty or 1
|
||||
if def.secret then
|
||||
score = 1000000
|
||||
elseif def.trigger and def.trigger.target and def.getProgress then
|
||||
local progress = def:getProgress(data).perc
|
||||
score = (1 - progress) * def.trigger.target
|
||||
score = score * (1 - progress) * def.trigger.target
|
||||
if progress < 0.001 then
|
||||
score = score + 100
|
||||
else
|
||||
|
12
triggers.lua
12
triggers.lua
@ -64,7 +64,8 @@ awards.register_trigger("dig", {
|
||||
auto_description_total = { "Mine @1 block.", "Mine @1 blocks." },
|
||||
get_key = function(self, def)
|
||||
return minetest.registered_aliases[def.trigger.node] or def.trigger.node
|
||||
end
|
||||
end,
|
||||
key_is_item = true,
|
||||
})
|
||||
minetest.register_on_dignode(function(pos, node, player)
|
||||
if not player or not pos or not node then
|
||||
@ -84,7 +85,8 @@ awards.register_trigger("place", {
|
||||
auto_description_total = { "Place @1 block.", "Place @1 blocks." },
|
||||
get_key = function(self, def)
|
||||
return minetest.registered_aliases[def.trigger.node] or def.trigger.node
|
||||
end
|
||||
end,
|
||||
key_is_item = true,
|
||||
})
|
||||
minetest.register_on_placenode(function(pos, node, player)
|
||||
if not player or not pos or not node then
|
||||
@ -104,7 +106,8 @@ awards.register_trigger("craft", {
|
||||
auto_description_total = { "Craft @1 item", "Craft @1 items." },
|
||||
get_key = function(self, def)
|
||||
return minetest.registered_aliases[def.trigger.item] or def.trigger.item
|
||||
end
|
||||
end,
|
||||
key_is_item = true,
|
||||
})
|
||||
minetest.register_on_craft(function(itemstack, player, old_craft_grid, craft_inv)
|
||||
if not player or itemstack:is_empty() then
|
||||
@ -124,7 +127,8 @@ awards.register_trigger("eat", {
|
||||
auto_description_total = { "Eat @1 item", "Eat @1 items." },
|
||||
get_key = function(self, def)
|
||||
return minetest.registered_aliases[def.trigger.item] or def.trigger.item
|
||||
end
|
||||
end,
|
||||
key_is_item = true,
|
||||
})
|
||||
minetest.register_on_item_eat(function(_, _, itemstack, player, _)
|
||||
if not player or itemstack:is_empty() then
|
||||
|
Reference in New Issue
Block a user