Commit e19f21ac authored by Reedych Coyote's avatar Reedych Coyote

first commit

parents
area_pos1 = {x = 31, y = 63, z = -31}
area_pos2 = {x = -31, y = 0, z = 31}
\ No newline at end of file
banned_blocks = {
"default:chest_locked",
"default:aspen_sapling",
"default:aspen_tree"
}
function search_table(table, string) -- search for "string" in "table"
-- for i = 0, table[i] ~= nil, 1 do -- not working
-- if string == table[i] then
-- return i
-- end
-- end
local i = 1
while table[i] ~= nil do
if string == table[i] then
return i
end
i=i+1
end
return false
end
\ No newline at end of file
-- THIS CODE IS ONLY FOR 0.4 COMPATIBILITY, will be removed when 0.5 be released
if not minetest.translate then
function minetest.translate(textdomain, str, ...)
local arg = {n=select('#', ...), ...}
return str:gsub("@(.)", function(matched)
local c = string.byte(matched)
if string.byte("1") <= c and c <= string.byte("9") then
return arg[c - string.byte("0")]
else
return matched
end
end)
end
function minetest.get_translator(textdomain)
return function(str, ...) return minetest.translate(textdomain or "", str, ...) end
end
end
-- END
local S = minetest.get_translator("cubewar")
local modname = minetest.get_current_modname()
dofile(minetest.get_modpath(modname).."/banned_blocks.lua") -- load a table with banned blocks
-- it also has function "search_table"
--configs
local wait_time = minetest.settings:get("cubewar_wait_time")
--minetest.register_privilege("cubewar_noobey", {S("Don't obey of timer and permittedplacecontroller"), false})
local timer = {} -- when a player placed/removed a block lastly, used for timer
-- as "when" we use an output of minetest.get_gametime()
-- if timer[playername] is >0, player can't build
-- if 0, player can build
local function timercheck(playername) -- check that player's timer is 0
if timer[playername] ~= nil and (timer[playername] + wait_time) > minetest.get_gametime() then
return false
else
return true
end
end
local function is_block_permitted(nodename) -- check that block is permitted
if search_table(banned_blocks, nodename) ~= false then
return false
end
return true
end
minetest.register_on_placenode(function(pos, newnode, player, oldnode, itemstack, pointed_thing)
local playername = player:get_player_name() -- playername
if playername == nil then -- not a player
return true -- will not control it
end
if minetest.check_player_privs(playername, "cubewar_noobey") == true then -- if player has "cubewar_noobey" privilege, can build anywhere/anywhen
elseif is_block_permitted(minetest.get_node(pos).name) == false then -- this block is permitted
minetest.chat_send_player(playername, S("The block is not permitted"))
minetest.remove_node(pos)
return false, "the block is unpermitted"
elseif timercheck(playername) == false then -- player's timer is not 0
minetest.chat_send_player(playername, S("You can't build now"))
minetest.remove_node(pos)
return false, "can't build now"
else
timer[playername] = minetest.get_gametime() -- reload timer
end
end)
minetest.register_on_dignode(function(pos, oldnode, player)
local playername = player:get_player_name() -- playername
if playername == nil then -- not a player
return true -- will not control it
end
if minetest.check_player_privs(playername, "cubewar_noobey") == true then -- if player has "cubewar_noobey" privilege, can build anywhere/anywhen
elseif timercheck(playername) == false then -- player's timer is not 0
minetest.chat_send_player(playername, S("You can't build now"))
minetest.set_node(pos, oldnode)
return false, "can't build now"
else
timer[playername] = minetest.get_gametime() -- reload timer
end
end)
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment