forked from nalc/awards
Refactor awards.unlock
This commit is contained in:
parent
79818c1355
commit
56d08f2f49
75
api.lua
75
api.lua
|
@ -29,6 +29,11 @@ function awards.save()
|
|||
end
|
||||
end
|
||||
|
||||
local S = function(s) return s end
|
||||
function awards.set_intllib(locale)
|
||||
S = locale
|
||||
end
|
||||
|
||||
function awards.init()
|
||||
awards.players = awards.load()
|
||||
awards.def = {}
|
||||
|
@ -79,26 +84,10 @@ function awards.register_achievement(name, def)
|
|||
end
|
||||
end
|
||||
|
||||
-- check icon, background and custom_announce data
|
||||
if not def.icon or def.icon == "" then
|
||||
def.icon = "unknown.png"
|
||||
end
|
||||
if not def.background or def.background == "" then
|
||||
def.background = "bg_default.png"
|
||||
end
|
||||
if not def.custom_announce or def.custom_announce == "" then
|
||||
def.custom_announce = "Achievement Unlocked:"
|
||||
end
|
||||
|
||||
-- add the achievement to the definition table
|
||||
-- Add Award
|
||||
awards.def[name] = def
|
||||
end
|
||||
|
||||
-- run a function when an item is crafted
|
||||
function awards.register_onCraft(func)
|
||||
table.insert(awards.onCraft,func)
|
||||
end
|
||||
|
||||
-- This function is called whenever a target condition is met.
|
||||
-- It checks if a player already has that achievement, and if they do not,
|
||||
-- it gives it to them
|
||||
|
@ -106,7 +95,7 @@ end
|
|||
--awards.give_achievement(name, award)
|
||||
-- name - the name of the player
|
||||
-- award - the name of the award to give
|
||||
function awards.give_achievement(name, award)
|
||||
function awards.unlock(name, award)
|
||||
-- Access Player Data
|
||||
local data = awards.players[name]
|
||||
local awdef = awards.def[award]
|
||||
|
@ -116,7 +105,7 @@ function awards.give_achievement(name, award)
|
|||
return
|
||||
end
|
||||
if not awdef then
|
||||
return
|
||||
return
|
||||
end
|
||||
awards.tbv(data,"unlocked")
|
||||
|
||||
|
@ -125,8 +114,10 @@ function awards.give_achievement(name, award)
|
|||
return
|
||||
end
|
||||
|
||||
-- Set award flag
|
||||
-- Unlock Award
|
||||
minetest.log("action", name.." has unlocked award "..name)
|
||||
data.unlocked[award] = award
|
||||
awards.save()
|
||||
|
||||
-- Give Prizes
|
||||
if awdef and awdef.prizes then
|
||||
|
@ -143,34 +134,6 @@ function awards.give_achievement(name, award)
|
|||
end
|
||||
end
|
||||
|
||||
-- Get data from definition tables
|
||||
local title = award
|
||||
local desc = ""
|
||||
local background = ""
|
||||
local icon = ""
|
||||
local custom_announce = ""
|
||||
if awdef.title then
|
||||
title = awdef.title
|
||||
end
|
||||
if awdef.custom_announce then
|
||||
custom_announce = awdef.custom_announce
|
||||
end
|
||||
if awdef.background then
|
||||
background = awdef.background
|
||||
end
|
||||
if awdef.icon then
|
||||
icon = awdef.icon
|
||||
end
|
||||
if awdef and awdef.description then
|
||||
desc = awdef.description
|
||||
end
|
||||
|
||||
-- Record this in the log
|
||||
minetest.log("action", name.." has unlocked award "..title)
|
||||
|
||||
-- Save playertable
|
||||
awards.save()
|
||||
|
||||
-- Run callbacks
|
||||
if awdef.on_unlock and awdef.on_unlock(name, awdef) then
|
||||
return
|
||||
|
@ -181,7 +144,14 @@ function awards.give_achievement(name, award)
|
|||
end
|
||||
end
|
||||
|
||||
-- send the won award message to the player
|
||||
-- Get Notification Settings
|
||||
local title = awdef.title or award
|
||||
local desc = awdef.description or ""
|
||||
local background = awdef.background or "bg_default.png"
|
||||
local icon = awdef.icon or "unknown.png"
|
||||
local custom_announce = awdef.custom_announce or S("Achievement Unlocked:")
|
||||
|
||||
-- Do Notification
|
||||
if awards.show_mode == "formspec" then
|
||||
-- use a formspec to send it
|
||||
minetest.show_formspec(name, "achievements:unlocked", "size[4,2]"..
|
||||
|
@ -191,7 +161,7 @@ function awards.give_achievement(name, award)
|
|||
"label[0.3,0.1;"..custom_announce.."]")
|
||||
elseif awards.show_mode == "chat" then
|
||||
-- use the chat console to send it
|
||||
minetest.chat_send_player(name, "Achievement Unlocked: "..title)
|
||||
minetest.chat_send_player(name, S("Achievement Unlocked:")..title)
|
||||
if desc~="" then
|
||||
minetest.chat_send_player(name, desc)
|
||||
end
|
||||
|
@ -244,11 +214,14 @@ function awards.give_achievement(name, award)
|
|||
end
|
||||
end
|
||||
|
||||
-- Backwards compatibility
|
||||
awards.give_achievement = awards.unlock
|
||||
|
||||
--[[minetest.register_chatcommand("gawd", {
|
||||
params = "award name",
|
||||
description = "gawd: give award to self",
|
||||
func = function(name, param)
|
||||
awards.give_achievement(name,param)
|
||||
awards.unlock(name,param)
|
||||
end
|
||||
})]]--
|
||||
|
||||
|
|
1
init.lua
1
init.lua
|
@ -26,6 +26,7 @@ end
|
|||
dofile(minetest.get_modpath("awards").."/api.lua")
|
||||
dofile(minetest.get_modpath("awards").."/chat_commands.lua")
|
||||
dofile(minetest.get_modpath("awards").."/triggers.lua")
|
||||
awards.set_intllib(S)
|
||||
|
||||
-- Light it up
|
||||
awards.register_achievement("award_lightitup",{
|
||||
|
|
|
@ -1,58 +1,59 @@
|
|||
Light It Up =
|
||||
Place 100 torches. =
|
||||
Light ALL The Things! =
|
||||
Place 1,000 torches. =
|
||||
Saint-Maclou =
|
||||
Place 20 coal checkers. =
|
||||
Castorama =
|
||||
Place 20 iron checkers. =
|
||||
Sam the Trapper =
|
||||
Place 2 trap stones. =
|
||||
Obsessed with Obsidian =
|
||||
Mine 50 obsidian. =
|
||||
On The Way =
|
||||
Place 100 rails. =
|
||||
Lumberjack =
|
||||
Dig 100 tree blocks. =
|
||||
Semi-pro Lumberjack =
|
||||
Dig 1,000 tree blocks. =
|
||||
Professional Lumberjack =
|
||||
Dig 10,000 tree blocks. =
|
||||
L33T Lumberjack =
|
||||
Dig 100,000 tree blocks. =
|
||||
Junglebaby =
|
||||
Dig 100 jungle tree blocks. =
|
||||
Jungleman =
|
||||
Dig 1,000 jungle tree blocks. =
|
||||
First Mese Find =
|
||||
Find some Mese. =
|
||||
You're a copper =
|
||||
Dig 1,000 copper ores. =
|
||||
YOU'RE A WINNER! =
|
||||
Dig 1 mossy cobblestone. =
|
||||
OMG, Nyan Cat! =
|
||||
Find a nyan cat. =
|
||||
Mini Miner =
|
||||
Dig 100 stone blocks. =
|
||||
Hardened Miner =
|
||||
Dig 1,000 stone blocks =
|
||||
Master Miner =
|
||||
Dig 10,000 stone blocks. =
|
||||
Marchand De Sable =
|
||||
Dig 1,000 sand. =
|
||||
Frequent Visitor =
|
||||
Connect to the server 50 times. =
|
||||
Dying Spree =
|
||||
Die 5 times. =
|
||||
Bot-like =
|
||||
Die 10 times. =
|
||||
You Suck! =
|
||||
Die 100 times. =
|
||||
You're a witch! =
|
||||
Burn to death in a fire. =
|
||||
In the Flow =
|
||||
Die in flowing lava. =
|
||||
This is Sad =
|
||||
Die near diamond ore. =
|
||||
The Stack =
|
||||
Die near bones. =
|
||||
Achievement Unlocked: =
|
||||
Light It Up =
|
||||
Place 100 torches. =
|
||||
Light ALL The Things! =
|
||||
Place 1,000 torches. =
|
||||
Saint-Maclou =
|
||||
Place 20 coal checkers. =
|
||||
Castorama =
|
||||
Place 20 iron checkers. =
|
||||
Sam the Trapper =
|
||||
Place 2 trap stones. =
|
||||
Obsessed with Obsidian =
|
||||
Mine 50 obsidian. =
|
||||
On The Way =
|
||||
Place 100 rails. =
|
||||
Lumberjack =
|
||||
Dig 100 tree blocks. =
|
||||
Semi-pro Lumberjack =
|
||||
Dig 1,000 tree blocks. =
|
||||
Professional Lumberjack =
|
||||
Dig 10,000 tree blocks. =
|
||||
L33T Lumberjack =
|
||||
Dig 100,000 tree blocks. =
|
||||
Junglebaby =
|
||||
Dig 100 jungle tree blocks. =
|
||||
Jungleman =
|
||||
Dig 1,000 jungle tree blocks. =
|
||||
First Mese Find =
|
||||
Find some Mese. =
|
||||
You're a copper =
|
||||
Dig 1,000 copper ores. =
|
||||
YOU'RE A WINNER! =
|
||||
Dig 1 mossy cobblestone. =
|
||||
OMG, Nyan Cat! =
|
||||
Find a nyan cat. =
|
||||
Mini Miner =
|
||||
Dig 100 stone blocks. =
|
||||
Hardened Miner =
|
||||
Dig 1,000 stone blocks =
|
||||
Master Miner =
|
||||
Dig 10,000 stone blocks. =
|
||||
Marchand De Sable =
|
||||
Dig 1,000 sand. =
|
||||
Frequent Visitor =
|
||||
Connect to the server 50 times. =
|
||||
Dying Spree =
|
||||
Die 5 times. =
|
||||
Bot-like =
|
||||
Die 10 times. =
|
||||
You Suck! =
|
||||
Die 100 times. =
|
||||
You're a witch! =
|
||||
Burn to death in a fire. =
|
||||
In the Flow =
|
||||
Die in flowing lava. =
|
||||
This is Sad =
|
||||
Die near diamond ore. =
|
||||
The Stack =
|
||||
Die near bones. =
|
||||
|
|
|
@ -32,7 +32,7 @@ old fork in Carbone, under same license.
|
|||
* name is the player name
|
||||
* def is the award def.
|
||||
* return true to cancel HUD
|
||||
* awards.give_achievement(name, award)
|
||||
* awards.unlock(name, award)
|
||||
* gives an award to a player
|
||||
* name is the player name
|
||||
|
||||
|
|
10
triggers.lua
10
triggers.lua
|
@ -113,7 +113,7 @@ minetest.register_on_dignode(function(pos, oldnode, digger)
|
|||
end
|
||||
|
||||
if res then
|
||||
awards.give_achievement(playern,res)
|
||||
awards.unlock(playern,res)
|
||||
end
|
||||
end
|
||||
end)
|
||||
|
@ -167,7 +167,7 @@ minetest.register_on_placenode(function(pos, node, digger)
|
|||
end
|
||||
|
||||
if res then
|
||||
awards.give_achievement(playern,res)
|
||||
awards.unlock(playern,res)
|
||||
end
|
||||
end
|
||||
end)
|
||||
|
@ -253,7 +253,7 @@ minetest.register_on_dieplayer(function(player)
|
|||
end
|
||||
end
|
||||
if res ~= nil then
|
||||
awards.give_achievement(name,res)
|
||||
awards.unlock(name,res)
|
||||
end
|
||||
end
|
||||
end)
|
||||
|
@ -285,7 +285,7 @@ minetest.register_on_joinplayer(function(player)
|
|||
end
|
||||
end
|
||||
if res ~= nil then
|
||||
awards.give_achievement(name,res)
|
||||
awards.unlock(name,res)
|
||||
end
|
||||
end
|
||||
end)
|
||||
|
@ -318,7 +318,7 @@ minetest.register_on_chat_message(function(name, message)
|
|||
end
|
||||
end
|
||||
if res ~= nil then
|
||||
awards.give_achievement(name,res)
|
||||
awards.unlock(name,res)
|
||||
end
|
||||
end
|
||||
end)
|
||||
|
|
Loading…
Reference in New Issue
Block a user