mirror of
https://gitlab.com/rubenwardy/awards.git
synced 2024-11-26 17:23:49 +01:00
Finish award formspec
This commit is contained in:
parent
6e9be37ed7
commit
bff6c91fc2
44
api.lua
44
api.lua
@ -43,13 +43,13 @@ function awards.tbv(tb,value,default)
|
|||||||
if not value then
|
if not value then
|
||||||
value = "[NULL]"
|
value = "[NULL]"
|
||||||
end
|
end
|
||||||
print("[ERROR] awards.tbv - table '"..value.."' is null, or not a table! Dump: "..dump(tb))
|
minetest.log("error", "awards.tbv - table '"..value.."' is null, or not a table! Dump: "..dump(tb))
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
if not value then
|
if not value then
|
||||||
print("[ERROR] awards.tbv was not used correctly!")
|
error("[ERROR] awards.tbv was not used correctly!\n"..
|
||||||
print("Value: '"..dump(value).."'")
|
"Value: '"..dump(value).."'\n"..
|
||||||
print("Dump:"..dump(tb))
|
"Dump:"..dump(tb))
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
if not tb[value] then
|
if not tb[value] then
|
||||||
@ -192,7 +192,7 @@ function awards.give_achievement(name,award)
|
|||||||
end
|
end
|
||||||
|
|
||||||
-- record this in the log
|
-- record this in the log
|
||||||
print(name.." Has unlocked"..title..".")
|
minetest.log("action", name.." has unlocked award "..title..".")
|
||||||
|
|
||||||
-- save playertable
|
-- save playertable
|
||||||
awards.save()
|
awards.save()
|
||||||
@ -215,6 +215,13 @@ minetest.register_chatcommand("awards", {
|
|||||||
awards.showto(name, name, nil, false)
|
awards.showto(name, name, nil, false)
|
||||||
end
|
end
|
||||||
})
|
})
|
||||||
|
minetest.register_chatcommand("cawards", {
|
||||||
|
params = "Empty params for your awards, player name for someone else's awards",
|
||||||
|
description = "awards: list awards",
|
||||||
|
func = function(name, param)
|
||||||
|
awards.showto(name, name, nil, true)
|
||||||
|
end
|
||||||
|
})
|
||||||
minetest.register_chatcommand("awd", {
|
minetest.register_chatcommand("awd", {
|
||||||
params = "award name",
|
params = "award name",
|
||||||
description = "awd: Details of awd gotten",
|
description = "awd: Details of awd gotten",
|
||||||
@ -227,13 +234,13 @@ minetest.register_chatcommand("awd", {
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
})
|
})
|
||||||
minetest.register_chatcommand("gawd", {
|
--[[minetest.register_chatcommand("gawd", {
|
||||||
params = "award name",
|
params = "award name",
|
||||||
description = "gawd: give award to self",
|
description = "gawd: give award to self",
|
||||||
func = function(name, param)
|
func = function(name, param)
|
||||||
awards.give_achievement(name,param)
|
awards.give_achievement(name,param)
|
||||||
end
|
end
|
||||||
})
|
})]]--
|
||||||
|
|
||||||
function awards._order_awards(name)
|
function awards._order_awards(name)
|
||||||
local done = {}
|
local done = {}
|
||||||
@ -246,7 +253,6 @@ function awards._order_awards(name)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
for _,def in pairs(awards.def) do
|
for _,def in pairs(awards.def) do
|
||||||
print("Award "..def.name)
|
|
||||||
if not done[def.name] then
|
if not done[def.name] then
|
||||||
table.insert(retval,{name=def.name,got=false})
|
table.insert(retval,{name=def.name,got=false})
|
||||||
end
|
end
|
||||||
@ -260,17 +266,16 @@ function awards.showto(name, to, sid, text)
|
|||||||
minetest.chat_send_player(name, "You do not have any awards")
|
minetest.chat_send_player(name, "You do not have any awards")
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
minetest.chat_send_player(name, name.."'s awards:")
|
minetest.chat_send_player(to, name.."'s awards:")
|
||||||
|
|
||||||
for _, str in pairs(awards.players[name].unlocked) do
|
for _, str in pairs(awards.players[name].unlocked) do
|
||||||
minetest.chat_send_player(name, str)
|
minetest.chat_send_player(to, str)
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
if sid == nil or sid < 1 then
|
if sid == nil or sid < 1 then
|
||||||
sid = 1
|
sid = 1
|
||||||
end
|
end
|
||||||
print("SID: "..dump(sid))
|
local formspec = "size[11,5]"
|
||||||
local formspec = "size[9,5]"
|
|
||||||
local listofawards = awards._order_awards(name)
|
local listofawards = awards._order_awards(name)
|
||||||
|
|
||||||
-- Sidebar
|
-- Sidebar
|
||||||
@ -288,17 +293,15 @@ function awards.showto(name, to, sid, text)
|
|||||||
if def and def.icon then
|
if def and def.icon then
|
||||||
icon = def.icon
|
icon = def.icon
|
||||||
end
|
end
|
||||||
formspec = formspec .. "label[0,2.75;"..title..status.."]"..
|
formspec = formspec .. "label[1,2.75;"..title..status.."]"..
|
||||||
"image[0,0;3,3;"..icon.."]"
|
"image[1,0;3,3;"..icon.."]"
|
||||||
if def and def.description then
|
if def and def.description then
|
||||||
formspec = formspec .. "label[0,3.25;/awd "..item.name.."\nfor more info]"
|
formspec = formspec .. "label[0,3.25;"..def.description.."]"
|
||||||
--formspec = formspec .. "label[0,3.25;"..def.description.."]"
|
|
||||||
--formspec = formspec .. "textarea[0.25,3.25;2.5,2;name;;"..def.description.."]"
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Create list box
|
-- Create list box
|
||||||
formspec = formspec .. "textlist[2.75,0;6,5;awards;"
|
formspec = formspec .. "textlist[4.75,0;6,5;awards;"
|
||||||
local first = true
|
local first = true
|
||||||
for _,award in pairs(listofawards) do
|
for _,award in pairs(listofawards) do
|
||||||
if not first then
|
if not first then
|
||||||
@ -318,9 +321,10 @@ function awards.showto(name, to, sid, text)
|
|||||||
formspec = formspec .. "#ACACAC".. minetest.formspec_escape(title)
|
formspec = formspec .. "#ACACAC".. minetest.formspec_escape(title)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
formspec = formspec .. "]"
|
formspec = formspec .. ";"..sid.."]"
|
||||||
|
|
||||||
minetest.show_formspec(name,"awards:awards",formspec)
|
-- Show formspec to user
|
||||||
|
minetest.show_formspec(to,"awards:awards",formspec)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
2
init.lua
2
init.lua
@ -108,7 +108,7 @@ awards.register_achievement("award_mine4",{
|
|||||||
-- First Death
|
-- First Death
|
||||||
awards.register_achievement("award_death1",{
|
awards.register_achievement("award_death1",{
|
||||||
title = "First Death",
|
title = "First Death",
|
||||||
description = "Oh well, it does not matter you have more lives than a cat",
|
description = "Oh well, it does not matter\nyou have more lives than a cat",
|
||||||
trigger={
|
trigger={
|
||||||
type="death",
|
type="death",
|
||||||
target=1,
|
target=1,
|
||||||
|
Loading…
Reference in New Issue
Block a user