1
0
Fork 0

Add achievement chat command

objects
Wuzzy 2020-03-30 21:02:13 +02:00
parent e81b5ef58a
commit d8cb7a7164
5 changed files with 73 additions and 1 deletions

View File

@ -178,6 +178,11 @@ function awards.clear_player(name)
awards.players[name] = {}
end
-- Returns true if award exists, false otherwise
function awards.exists(award)
return awards.def[award] ~= nil
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

View File

@ -38,3 +38,50 @@ minetest.register_chatcommand("awards", {
end
})
minetest.register_privilege("achievements", {
description = S("Can give achievements to any player"),
give_to_singleplayer = false,
give_to_admin = false,
})
minetest.register_chatcommand("achievement", {
params = S("(grant <player> (<achievement> | all)) | list"),
privs = { achievements = true },
description = S("Give achievement to player or list all achievements"),
func = function(name, param)
if param == "list" then
local list = {}
for k,_ in pairs(awards.def) do
table.insert(list, k)
end
table.sort(list)
for a=1, #list do
minetest.chat_send_player(name, S("@1 (@2)", awards.def[list[a]].title, list[a]))
end
return true
end
local keyword, playername, achievement = string.match(param, "([^ ]+) (.+) (.+)")
if not keyword or not playername or not achievement then
return false, S("Invalid syntax.")
end
if keyword ~= "grant" then
return false, S("Invalid action.")
end
local player = minetest.get_player_by_name(playername)
if not player then
return false, S("Player is not online.")
end
if achievement == "all" then
for k,_ in pairs(awards.def) do
awards.unlock(playername, k)
end
return true, S("Done.")
elseif awards.exists(achievement) then
awards.unlock(playername, achievement)
return true, S("Done.")
else
return false, S("Achievement “@1” does not exist.", achievement)
end
end
})

View File

@ -49,3 +49,12 @@ Place @1 block(s).=Platzieren Sie @1 Blöcke.
Dig @1 block(s).=Bauen Sie @1 Blöcke ab.
Eat @1 item(s).=Essen Sie @1 Dinge.
Craft @1 item(s).=Fertigen Sie @1 Gegenstände.
Can give achievements to any player=Kann Spielern Auszeichnungen vergeben
(grant <player> (<achievement> | all)) | list=(grant <Spieler> (<Auszeichnung> | all)) | list
Give achievement to player or list all achievements=Auszeichnung an Spieler vergeben oder alle Auszeichnungen auflisten
@1 (@2)=@1 (@2)
Invalid syntax.=Ungültige Syntax.
Invalid action.=Ungültige Aktion.
Player is not online.=Spieler ist nicht online.
Done.=Fertig.
Achievement “@1” does not exist.=Auszeichnung »@1« existiert nicht.

View File

@ -50,3 +50,12 @@ Place @1 block(s).=
Dig @1 block(s).=
Eat @1 item(s).=
Craft @1 item(s).=
Can give achievements to any player=
(grant <player> (<achievement> | all)) | list=
Give achievement to player or list all achievements=
@1 (@2)=
Invalid syntax.=
Invalid action.=
Player is not online.=
Done.=
Achievement “@1” does not exist.=

View File

@ -11,7 +11,7 @@ old fork in Carbone, under same license.
# Basic API
* awards.register_achievement(name, def)
* name
* name: Unique identifier for achievement. You can use anything except "all"
* desciption
* sound [optional] - set a custom sound (SimpleSoundSpec) or `false` to play no sound.
If not specified, a default sound is played
@ -59,6 +59,8 @@ old fork in Carbone, under same license.
* awards.unlock(name, award)
* gives an award to a player
* name is the player name
* awards.exists(award)
* returns true if award exists, false otherwise
# Included in the Mod