success/fail stats
This commit is contained in:
parent
038f74fbec
commit
4759e05872
10
executor.lua
10
executor.lua
@ -18,9 +18,11 @@ missions.start = function(pos, player)
|
||||
end
|
||||
|
||||
local meta = minetest.get_meta(pos)
|
||||
local pos_str = minetest.pos_to_string(pos)
|
||||
|
||||
mission = {
|
||||
version = missions.CURRENT_MISSION_SPEC_VERSION,
|
||||
pos = pos_str,
|
||||
steps = steps,
|
||||
currentstep = 1,
|
||||
start = os.time(os.date("!*t")),
|
||||
@ -40,12 +42,17 @@ local update_mission = function(mission, player)
|
||||
local playername = player:get_player_name()
|
||||
local step = mission.steps[mission.currentstep]
|
||||
local abort = missions.has_aborted(playername)
|
||||
local block_pos = minetest.string_to_pos(mission.pos)
|
||||
local block_meta = minetest.get_meta(block_pos)
|
||||
|
||||
if not step then
|
||||
-- no more steps
|
||||
minetest.chat_send_player(playername, "Mission completed: '" .. mission.name .. "'")
|
||||
missions.set_current_mission(player, nil)
|
||||
missions.show_banner(player, "Mission completed", mission.name)
|
||||
|
||||
-- increment counter
|
||||
block_meta:set_int("successcount", block_meta:get_int("successcount") + 1)
|
||||
return
|
||||
end
|
||||
|
||||
@ -71,6 +78,9 @@ local update_mission = function(mission, player)
|
||||
player=player
|
||||
})
|
||||
end
|
||||
|
||||
-- increment counter
|
||||
block_meta:set_int("failcount", block_meta:get_int("failcount") + 1)
|
||||
end
|
||||
|
||||
if abort then
|
||||
|
@ -21,7 +21,8 @@ missions.form.missionblock_main = function(pos, node, player)
|
||||
"label[0,0;Mission block]" ..
|
||||
"button_exit[0,1;8,1;stepeditor;Step editor]" ..
|
||||
"button_exit[0,2;8,1;user;User view]" ..
|
||||
"button_exit[0,3;8,1;help;Help]" ..
|
||||
"button_exit[0,3;8,1;stats;Statistics]" ..
|
||||
"button_exit[0,4;8,1;help;Help]" ..
|
||||
"button_exit[0,7;8,1;exit;Exit]"
|
||||
|
||||
minetest.show_formspec(player:get_player_name(),
|
||||
@ -62,6 +63,13 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
|
||||
return true
|
||||
end
|
||||
|
||||
if fields.stats then
|
||||
minetest.after(0.1, function()
|
||||
missions.form.missionblock_stats(pos, node, player)
|
||||
end)
|
||||
return true
|
||||
end
|
||||
|
||||
if fields.help then
|
||||
minetest.after(0.1, function()
|
||||
missions.form.missionblock_help(pos, node, player)
|
||||
|
25
form.missionblock_stats.lua
Normal file
25
form.missionblock_stats.lua
Normal file
@ -0,0 +1,25 @@
|
||||
|
||||
local FORMNAME = "mission_block_stats"
|
||||
|
||||
missions.form.missionblock_stats = function(pos, node, player)
|
||||
|
||||
local meta = minetest.get_meta(pos)
|
||||
local successcount = meta:get_int("successcount")
|
||||
local failcount = meta:get_int("failcount")
|
||||
|
||||
local formspec = "size[8,8;]" ..
|
||||
--left
|
||||
"label[0,0;Mission block]" ..
|
||||
"label[0,2;Success-count: " .. successcount .. "]" ..
|
||||
"label[0,3;Fail-count: " .. failcount .. "]" ..
|
||||
"button_exit[0,7;8,1;exit;Exit]"
|
||||
|
||||
minetest.show_formspec(player:get_player_name(),
|
||||
FORMNAME .. ";" .. minetest.pos_to_string(pos),
|
||||
formspec
|
||||
)
|
||||
|
||||
end
|
||||
|
||||
|
||||
|
@ -17,10 +17,6 @@ missions.get_owner_from_pos = function(pos)
|
||||
end
|
||||
|
||||
|
||||
|
||||
missions.MISSION_ATTRIBUTE_NAME = "currentmission"
|
||||
missions.CURRENT_MISSION_SPEC_VERSION = 1
|
||||
|
||||
local playermissions = {}
|
||||
local playerabort = {}
|
||||
|
||||
|
5
init.lua
5
init.lua
@ -9,13 +9,16 @@ missions = {
|
||||
hud = {
|
||||
posx = tonumber(minetest.settings:get("missions.hud.offsetx") or 0.7),
|
||||
posy = tonumber(minetest.settings:get("missions.hud.offsety") or 0.2)
|
||||
}
|
||||
},
|
||||
MISSION_ATTRIBUTE_NAME = "currentmission",
|
||||
CURRENT_MISSION_SPEC_VERSION = 2 -- see executor.lua:missions.start()
|
||||
}
|
||||
|
||||
-- forms
|
||||
dofile(MP.."/form.missionblock_main.lua")
|
||||
dofile(MP.."/form.missionblock_stepeditor.lua")
|
||||
dofile(MP.."/form.missionblock_user.lua")
|
||||
dofile(MP.."/form.missionblock_stats.lua")
|
||||
dofile(MP.."/form.missionblock_help.lua")
|
||||
dofile(MP.."/form.newstep.lua")
|
||||
dofile(MP.."/form.wand.lua")
|
||||
|
@ -6,4 +6,13 @@ missions.migrate_mission_block = function(pos, meta)
|
||||
minetest.log("info", "[missions] Migrated mission-block inventory (v1) at pos: " .. minetest.pos_to_string(pos))
|
||||
inv:set_size("main", 8)
|
||||
end
|
||||
|
||||
if meta:get_int("successcount") == nil then
|
||||
meta:set_int("successcount", 0)
|
||||
end
|
||||
|
||||
if meta:get_int("failcount") == nil then
|
||||
meta:set_int("failcount", 0)
|
||||
end
|
||||
|
||||
end
|
Loading…
x
Reference in New Issue
Block a user