mirror of
https://git.minetest.land/Mineclonia/Mineclonia.git
synced 2024-11-24 08:55:12 +00:00
Add achievement chat command
This commit is contained in:
parent
e81b5ef58a
commit
d8cb7a7164
5 changed files with 73 additions and 1 deletions
|
@ -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
|
||||
|
|
|
@ -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
|
||||
})
|
||||
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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.=
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
Loading…
Reference in a new issue