123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181 |
- local vector_distance = vector.distance
- local vector_round = vector.round
- local vector_add = vector.add
- local vector_equals = vector.equals
- local math_random = math.random
- local CITYBLOCK_DELAY_TIME = city_block.CITYBLOCK_DELAY_TIME
- local time_active = city_block.time_active
- function city_block.create_formspec(pos, pname, blockdata)
- local meta = minetest.get_meta(pos)
- local inv = meta:get_inventory()
- local spos = pos.x .. "," .. pos.y .. "," .. pos.z
-
- if inv:get_size("config") == 0 then
- inv:set_size("config", 1)
- end
- local pvp = "false"
- if blockdata.pvp_arena then
- pvp = "true"
- end
- local hud = "false"
- if blockdata.hud_beacon then
- hud = "true"
- end
- local formspec = "size[8.0,4.5]" ..
- default.gui_bg ..
- default.gui_bg_img ..
- default.gui_slots ..
- "real_coordinates[true]" ..
- "container[2.5,0]" ..
- "container[0,0]" ..
- "label[0.3,0.5;Enter city/area region name:]" ..
- "field[0.30,0.75;3.5,0.8;CITYNAME;;]" ..
- "button_exit[3.9,0.75;1.5,0.4;OK;Confirm]" ..
- "button_exit[3.9,1.16;1.5,0.4;CANCEL;Abort]" ..
- "field_close_on_enter[CITYNAME;true]" ..
- "container_end[]" ..
- "checkbox[0.3,3.1;pvp_arena;Mark Dueling Arena;" .. pvp .. "]" ..
- "checkbox[0.3,3.5;hud_beacon;Signal Nearby Keys;" .. hud .. "]" ..
- "container[0.4,0]" ..
- "list[nodemeta:" .. spos .. ";config;3.95,2.9;1,1;]" ..
- "image[3.95,2.9;1,1;configurator_inv.png]" ..
- "container_end[]" ..
- "container_end[]" ..
- "container[0.4,4.6]" ..
- "list[current_player;main;0,0;8,1;]" ..
- default.get_hotbar_bg(0, 0, true) ..
- "container_end[]"
- return formspec
- end
- local function check_cityname(cityname)
- return not string.match(cityname, "[^%a%s]")
- end
- function city_block.on_receive_fields(player, formname, fields)
- if formname ~= "city_block:main" then
- return
- end
- if not player or not player:is_player() then
- return
- end
- local pname = player:get_player_name()
- local pos = city_block.formspecs[pname]
-
- if not pos then
- return true
- end
- local meta = minetest.get_meta(pos)
- local owner = meta:get_string("owner")
-
- if pname ~= owner then
- return true
- end
- if fields.key_enter_field == "CITYNAME" or fields.OK then
- local area_name = (fields.CITYNAME or ""):trim()
- area_name = area_name:gsub("%s+", " ")
-
- local is_valid = true
-
-
- if #area_name > 20 then
- is_valid = false
- end
- if not check_cityname(area_name) then
- is_valid = false
- end
- if anticurse.check(pname, area_name, "foul") then
- is_valid = false
- elseif anticurse.check(pname, area_name, "curse") then
- is_valid = false
- end
- if not is_valid then
- minetest.chat_send_player(pname, "# Server: Region name not valid.")
- return
- end
- local block = city_block.get_block(pos)
-
- if not block then
- return
- end
-
- meta:set_string("cityname", area_name)
- meta:set_string("infotext", city_block.get_infotext(pos))
- if #area_name > 0 then
- block.area_name = area_name
- else
- block.area_name = nil
- end
- city_block:save()
-
- elseif fields.pvp_arena == "true" then
- local block = city_block.get_block(pos)
- if block then
- minetest.chat_send_player(pname, "# Server: Enabled dueling arena.")
- block.pvp_arena = true
- meta:set_string("infotext", city_block.get_infotext(pos))
- city_block:save()
- end
- elseif fields.pvp_arena == "false" then
- local block = city_block.get_block(pos)
- if block then
- minetest.chat_send_player(pname, "# Server: Disabled dueling arena.")
- block.pvp_arena = nil
- meta:set_string("infotext", city_block.get_infotext(pos))
- city_block:save()
- end
-
-
- elseif fields.hud_beacon == "true" then
- local block = city_block.get_block(pos)
- if block then
- minetest.chat_send_player(pname, "# Server: Activated KEY signal.")
- block.hud_beacon = true
- city_block:save()
- end
- elseif fields.hud_beacon == "false" then
- local block = city_block.get_block(pos)
- if block then
- minetest.chat_send_player(pname, "# Server: Disabled KEY signal.")
- block.hud_beacon = nil
- city_block:save()
- end
-
- end
- return true
- end
|