perks: Fix undefined variable access
Instead of ANAND's suggestion to put this function in the `player` API, I feel it belongs in the `boxes` API instead, other than that it's mostly similar to his MR#18.
This commit is contained in:
parent
7ea209215c
commit
cd3c598f25
@ -48,6 +48,28 @@ dofile(modpath .. "/score.lua")
|
|||||||
|
|
||||||
local areas = AreaStore("insidethebox")
|
local areas = AreaStore("insidethebox")
|
||||||
|
|
||||||
|
function boxes.get_player_boxes(name)
|
||||||
|
local is_admin = minetest.check_player_privs(name, "server")
|
||||||
|
local boxes = {}
|
||||||
|
for id = 0, db.get_last_box_id() do
|
||||||
|
local meta = db.box_get_meta(id)
|
||||||
|
if (meta.type == db.BOX_TYPE and meta.meta and
|
||||||
|
meta.meta.builder and meta.meta.builder == name) or
|
||||||
|
(is_admin and meta.type == db.BOX_TYPE) then
|
||||||
|
table.insert(boxes, {id = id,
|
||||||
|
name = meta.meta.box_name or "[Unnamed]",
|
||||||
|
status = meta.meta.status,
|
||||||
|
builder = meta.meta.builder})
|
||||||
|
end
|
||||||
|
end
|
||||||
|
table.sort(boxes, function(box1, box2)
|
||||||
|
return box1.status < box2.status or
|
||||||
|
(box1.status == box2.status and box1.id > box2.id)
|
||||||
|
end)
|
||||||
|
|
||||||
|
return boxes
|
||||||
|
end
|
||||||
|
|
||||||
function boxes.find_box(pos)
|
function boxes.find_box(pos)
|
||||||
local count = 0
|
local count = 0
|
||||||
local name = nil
|
local name = nil
|
||||||
|
@ -368,28 +368,6 @@ register_teleport("boxes:lobby_teleport", {
|
|||||||
end,
|
end,
|
||||||
})
|
})
|
||||||
|
|
||||||
local get_boxes = function(name)
|
|
||||||
local is_admin = minetest.check_player_privs(name, "server")
|
|
||||||
local boxes = {}
|
|
||||||
for id = 0, db.get_last_box_id() do
|
|
||||||
local meta = db.box_get_meta(id)
|
|
||||||
if (meta.type == db.BOX_TYPE and meta.meta and
|
|
||||||
meta.meta.builder and meta.meta.builder == name) or
|
|
||||||
(is_admin and meta.type == db.BOX_TYPE) then
|
|
||||||
table.insert(boxes, {id = id,
|
|
||||||
name = meta.meta.box_name or "[Unnamed]",
|
|
||||||
status = meta.meta.status,
|
|
||||||
builder = meta.meta.builder})
|
|
||||||
end
|
|
||||||
end
|
|
||||||
table.sort(boxes, function(box1, box2)
|
|
||||||
return box1.status < box2.status or
|
|
||||||
(box1.status == box2.status and box1.id > box2.id)
|
|
||||||
end)
|
|
||||||
|
|
||||||
return boxes
|
|
||||||
end
|
|
||||||
|
|
||||||
local get_sizes = function(player)
|
local get_sizes = function(player)
|
||||||
--FIXME link to scoring and limit box sizes for novice builders
|
--FIXME link to scoring and limit box sizes for novice builders
|
||||||
return {20, 25, 30, 35, 40}
|
return {20, 25, 30, 35, 40}
|
||||||
@ -608,7 +586,7 @@ end
|
|||||||
do_creator_if = function(player, context)
|
do_creator_if = function(player, context)
|
||||||
local name = player:get_player_name()
|
local name = player:get_player_name()
|
||||||
if not context.boxes or not context.sizes then
|
if not context.boxes or not context.sizes then
|
||||||
context.boxes = get_boxes(name)
|
context.boxes = boxes.get_player_boxes(name)
|
||||||
context.sizes = get_sizes(name)
|
context.sizes = get_sizes(name)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -42,7 +42,7 @@ function perks.grant(name_or_player)
|
|||||||
|
|
||||||
-- count all boxes built by name
|
-- count all boxes built by name
|
||||||
local accepted = 0
|
local accepted = 0
|
||||||
for k, v in pairs(boxes) do
|
for k, v in pairs(boxes.get_player_boxes(name)) do
|
||||||
if v.status == db.STATUS_ACCEPTED and v.builder == name then
|
if v.status == db.STATUS_ACCEPTED and v.builder == name then
|
||||||
accepted = accepted + 1
|
accepted = accepted + 1
|
||||||
end
|
end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user