Browse Source

tostring

main
Hendrik Langer 5 years ago
parent
commit
c8e104ab96
  1. 35
      init.lua

35
init.lua

@ -34,7 +34,7 @@ function switch_creative:save_areas()
end end
function switch_creative:set_area_privs(id, privs_string) function switch_creative:set_area_privs(id, privs_string)
switch_creative.area_privs[id] = privs_string switch_creative.area_privs[tostring(id)] = privs_string
end end
minetest.register_chatcommand("creative_area", { minetest.register_chatcommand("creative_area", {
@ -55,10 +55,14 @@ minetest.register_chatcommand("creative_area", {
local edge2 = { x=tonumber(x2), y=tonumber(y2), z=tonumber(z2) } local edge2 = { x=tonumber(x2), y=tonumber(y2), z=tonumber(z2) }
local data = area_name local data = area_name
local astore_id = switch_creative.astore:insert_area(edge1, edge2, tostring(data)) local astore_id = switch_creative.astore:insert_area(edge1, edge2, tostring(data))
switch_creative:set_area_privs(astore_id, nil) if astore_id then
switch_creative:set_area_privs(tostring(astore_id), nil)
minetest.chat_send_player(name, "[creative_area] New area set. ID: " .. astore_id) minetest.chat_send_player(name, "[creative_area] New area set. ID: " .. astore_id)
switch_creative:save_areas() switch_creative:save_areas()
return true, "Done." return true, "Done"
else
return false, "Failed"
end
end, end,
}) })
@ -75,14 +79,13 @@ minetest.register_chatcommand("creative_area_privs", {
if not found then if not found then
return false, "Syntax error" return false, "Syntax error"
end end
area_id = tostring(area_id)
if privstring and area_id then if privstring and area_id then
switch_creative:set_area_privs(area_id, privstring) switch_creative:set_area_privs(tostring(area_id), privstring)
minetest.chat_send_player(name, "[creative_area] Privstring set for area " .. area_id .. ": " .. privstring) minetest.chat_send_player(name, "[creative_area] Privstring set for area " .. area_id .. ": " .. privstring)
switch_creative:save_areas() switch_creative:save_areas()
return true, "Done." return true, "Done"
else else
return false, "Failed." return false, "Failed"
end end
end, end,
}) })
@ -100,11 +103,10 @@ minetest.register_chatcommand("creative_area_rm", {
if not found then if not found then
return false, "Syntax error" return false, "Syntax error"
end end
area_id = tonumber(area_id) local success = switch_creative.astore:remove_area(tonumber(area_id))
local success = switch_creative.astore:remove_area(area_id)
if success then if success then
minetest.chat_send_player(name, "[creative_area] Area " .. area_id .. "removed") minetest.chat_send_player(name, "[creative_area] Area " .. area_id .. "removed")
switch_creative:set_area_privs(area_id, nil) switch_creative:set_area_privs(tostring(area_id), nil)
else else
minetest.chat_send_player(name, "[creative_area] Error removing area " .. area_id) minetest.chat_send_player(name, "[creative_area] Error removing area " .. area_id)
end end
@ -135,6 +137,7 @@ function switch_creative:decode_privs_string(str)
end end
function switch_creative:is_areas_mod(area_id) function switch_creative:is_areas_mod(area_id)
area_id = tostring(area_id)
local is_areas_id = string.sub(id, 1, 2) == "a" local is_areas_id = string.sub(id, 1, 2) == "a"
local a_id = tonumber( string.sub(id, 2) ) local a_id = tonumber( string.sub(id, 2) )
return is_areas_id, a_id return is_areas_id, a_id
@ -269,7 +272,7 @@ function switch_creative:update_player(player)
for astore_id, astore_area in pairs( current_areas ) do for astore_id, astore_area in pairs( current_areas ) do
local areasize = switch_creative:get_area_size(astore_area) local areasize = switch_creative:get_area_size(astore_area)
if not smallest_area.size or areasize < smallest_area.size then if not smallest_area.size or areasize < smallest_area.size then
smallest_area.id = astore_id smallest_area.id = tostring(astore_id)
smallest_area.size = areasize smallest_area.size = areasize
end end
end end
@ -284,7 +287,7 @@ function switch_creative:update_player(player)
for a_id, a_area in pairs( a_current_areas ) do for a_id, a_area in pairs( a_current_areas ) do
local areasize = switch_creative:get_areas_area_size(a_area) local areasize = switch_creative:get_areas_area_size(a_area)
if not smallest_areas_area.size or areasize < smallest_areas_area.size then if not smallest_areas_area.size or areasize < smallest_areas_area.size then
smallest_areas_area.id = a_id smallest_areas_area.id = tostring(a_id)
smallest_areas_area.size = areasize smallest_areas_area.size = areasize
end end
player_active_areas = player_active_areas .. ", a"..a_id player_active_areas = player_active_areas .. ", a"..a_id
@ -302,9 +305,9 @@ function switch_creative:update_player(player)
end end
local privstring = noarea_privs local privstring = noarea_privs
if smallest_area.id and switch_creative.area_privs[smallest_area.id] then if smallest_area.id then
if switch_creative.area_privs[smallest_area.id] then if switch_creative.area_privs[tostring(smallest_area.id)] then
privstring = switch_creative.area_privs[smallest_area.id] privstring = switch_creative.area_privs[tostring(smallest_area.id)]
else else
privstring = default_privs privstring = default_privs
end end
@ -323,7 +326,7 @@ function switch_creative:update_player(player)
end end
if smallest_areas_area.size and smallest_area.size then if smallest_areas_area.size and smallest_area.size then
if smallest_area.size <= smallest_areas_area.size then if smallest_area.size <= smallest_areas_area.size then
privstring = privstring .. ", " .. switch_creative.area_privs[smallest_area.id] privstring = privstring .. ", " .. switch_creative.area_privs[tostring(smallest_area.id)]
end end
end end
end end

Loading…
Cancel
Save