update code
parent
551866c7f0
commit
f1d455a061
|
@ -0,0 +1,87 @@
|
|||
--[[
|
||||
Mod Cidades for Minetest
|
||||
Copyright (C) 2020 BrunoMine (https://github.com/BrunoMine)
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>5.
|
||||
|
||||
City Builder
|
||||
]]
|
||||
|
||||
|
||||
-- Registered cities
|
||||
cidades.registered_cities = {}
|
||||
|
||||
-- Register city
|
||||
cidades.register_city = function(city_id, def)
|
||||
cidades.registered_cities[city_id] = def
|
||||
end
|
||||
|
||||
-- Active cities
|
||||
cidades.active_cities = cidades.db.ms:get_string("active_cities")
|
||||
if cidades.active_cities == "" then
|
||||
cidades.active_cities = {}
|
||||
else
|
||||
cidades.active_cities = minetest.deserialize(cidades.active_cities)
|
||||
end
|
||||
|
||||
-- Insert active city
|
||||
cidades.insert_active_city = function(city_id, def)
|
||||
|
||||
cidades.active_cities[city_id] = def
|
||||
cidades.db.ms:set_string("active_cities", minetest.serialize(cidades.active_cities))
|
||||
end
|
||||
|
||||
-- Remove active city
|
||||
cidades.remove_active_city = function(city_id, def)
|
||||
cidades.active_cities[city_id] = nil
|
||||
cidades.db.ms:set_string("active_cities", minetest.serialize(cidades.active_cities))
|
||||
end
|
||||
|
||||
-- Create city
|
||||
cidades.create_city = function(city_id, pos)
|
||||
|
||||
local city = cidades.registered_cities[city_id]
|
||||
|
||||
-- Minp & Maxp
|
||||
local minp = {
|
||||
x = pos.x - city.radius,
|
||||
y = pos.y - city.depth,
|
||||
z = pos.z - city.radius,
|
||||
}
|
||||
local maxp = {
|
||||
x = pos.x + city.radius,
|
||||
y = pos.y + city.height,
|
||||
z = pos.z + city.radius,
|
||||
}
|
||||
|
||||
-- Place schem
|
||||
minetest.place_schematic(minp, city.schem_path)
|
||||
|
||||
-- Protect area
|
||||
local area_id = cidades.protect_area("Server city", city.name, minp, maxp)
|
||||
|
||||
-- Insert active city
|
||||
cidades.insert_active_city(city_id, {
|
||||
name = city.name,
|
||||
minp = minp,
|
||||
maxp = maxp,
|
||||
spawn = {x=pos.x, y=pos.y+6, z=pos.z},
|
||||
area_id = area_id,
|
||||
})
|
||||
|
||||
end
|
||||
|
||||
minetest.register_chatcommand("create_city", {
|
||||
params = "City ID",
|
||||
description = "Create an active city",
|
||||
func = function(name, param)
|
||||
if not param or param == "" or not cidades.registered_cities[param] then
|
||||
minetest.chat_send_player(name, "Invalid City ID")
|
||||
return
|
||||
end
|
||||
|
||||
cidades.create_city(param, minetest.get_player_by_name(name):get_pos())
|
||||
minetest.chat_send_player(name, cidades.registered_cities[param].name.." created.")
|
||||
end,
|
||||
})
|
|
@ -8,7 +8,7 @@
|
|||
City Builder
|
||||
]]
|
||||
|
||||
|
||||
-- Area mark node
|
||||
minetest.register_node("cidades:area_mark", {
|
||||
description = "Area Mark",
|
||||
tiles = {"cidades_area_mark.png"},
|
||||
|
@ -51,7 +51,7 @@ local mark_area = function(pos)
|
|||
end
|
||||
end
|
||||
|
||||
-- Create Schematic
|
||||
-- Export Schematic
|
||||
local export_city = function(pos)
|
||||
local meta = minetest.get_meta(pos)
|
||||
local radius = meta:get_float("radius")
|
||||
|
@ -80,7 +80,7 @@ local export_city = function(pos)
|
|||
minetest.chat_send_all("Schematic successfully exported. Restart the world to import it. "..filename.." file is in the world directory ('cities in work' folder).")
|
||||
end
|
||||
|
||||
-- Load Schematic
|
||||
-- Import Schematic
|
||||
local import_city = function(pos)
|
||||
local meta = minetest.get_meta(pos)
|
||||
local radius = meta:get_float("radius")
|
||||
|
|
|
@ -3,48 +3,48 @@
|
|||
Copyright (C) 2020 BrunoMine (https://github.com/BrunoMine)
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>5.
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
Data Base
|
||||
]]
|
||||
|
||||
local mod_storage = minetest.get_mod_storage()
|
||||
|
||||
cidades.db = {}
|
||||
|
||||
cidades.db.ms = minetest.get_mod_storage()
|
||||
|
||||
-- Set City def
|
||||
cidades.db.set_city = function(city_name, def)
|
||||
mod_storage:set_string("city_"..city_name, minetest.serialize(def))
|
||||
cidades.db.set_city = function(city_name, data)
|
||||
cidades.db.ms:set_string("city_"..city_name, minetest.serialize(data))
|
||||
end
|
||||
|
||||
-- Get City def
|
||||
cidades.db.get_city = function(city_name)
|
||||
return minetest.deserialize(mod_storage:get_string("city_"..city_name))
|
||||
return minetest.deserialize(cidades.db.ms:get_string("city_"..city_name))
|
||||
end
|
||||
|
||||
|
||||
-- Set Property def
|
||||
cidades.db.set_property = function(owner, def)
|
||||
mod_storage:set_string("property_"..owner, minetest.serialize(def))
|
||||
-- Set Property data
|
||||
cidades.db.set_property = function(owner, data)
|
||||
cidades.db.ms:set_string("property_"..owner, minetest.serialize(data))
|
||||
end
|
||||
|
||||
-- Get Property def
|
||||
-- Remove Property data
|
||||
cidades.db.reset_property = function(owner)
|
||||
cidades.db.ms:set_string("property_"..owner, "")
|
||||
end
|
||||
|
||||
-- Get Property data
|
||||
cidades.db.get_property = function(owner)
|
||||
return minetest.deserialize(mod_storage:get_string("property_"..owner))
|
||||
return minetest.deserialize(cidades.db.ms:get_string("property_"..owner))
|
||||
end
|
||||
|
||||
-- Check Property
|
||||
cidades.db.check_property = function(owner)
|
||||
if mod_storage:get_string("property_"..owner) ~= "" then
|
||||
if cidades.db.ms:get_string("property_"..owner) ~= "" then
|
||||
return true
|
||||
end
|
||||
return false
|
||||
end
|
||||
|
||||
|
||||
-- Active cities
|
||||
cidades.update_active_cities = function(city_name, status)
|
||||
cidades.active_cities[city_name] = status
|
||||
mod_storage:set_string("active_cities", minetest.serialize(cidades.active_cities))
|
||||
end
|
||||
|
||||
|
|
|
@ -1 +1,2 @@
|
|||
default
|
||||
areas
|
||||
|
|
8
init.lua
8
init.lua
|
@ -3,7 +3,7 @@
|
|||
Copyright (C) 2020 BrunoMine (https://github.com/BrunoMine)
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>5.
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
]]
|
||||
|
||||
|
@ -15,9 +15,11 @@ local modpath = minetest.get_modpath("cidades")
|
|||
|
||||
dofile(modpath.."/data_base.lua")
|
||||
|
||||
dofile(modpath.."/protected_area.lua")
|
||||
dofile(modpath.."/number_nodes.lua")
|
||||
dofile(modpath.."/land.lua")
|
||||
|
||||
--dofile(modpath.."/city.lua")
|
||||
dofile(modpath.."/city.lua")
|
||||
dofile(modpath.."/city_builder.lua")
|
||||
--dofile(modpath.."/city_stone.lua")
|
||||
|
||||
|
@ -25,7 +27,7 @@ dofile(modpath.."/property.lua")
|
|||
dofile(modpath.."/property_builder.lua")
|
||||
dofile(modpath.."/property_stone.lua")
|
||||
|
||||
--dofile(modpath.."/teleporter.lua")
|
||||
dofile(modpath.."/teleporter.lua")
|
||||
|
||||
dofile(modpath.."/seller_node.lua")
|
||||
|
||||
|
|
|
@ -0,0 +1,54 @@
|
|||
--[[
|
||||
Mod Cidades for Minetest
|
||||
Copyright (C) 2020 BrunoMine (https://github.com/BrunoMine)
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
Land
|
||||
]]
|
||||
|
||||
|
||||
-- Place poles
|
||||
cidades.place_poles = function(pos, radius)
|
||||
minetest.set_node({x=pos.x+radius, y=pos.y+2, z=pos.z+radius}, {name="default:fence_wood"})
|
||||
minetest.set_node({x=pos.x+radius, y=pos.y+2, z=pos.z-radius}, {name="default:fence_wood"})
|
||||
minetest.set_node({x=pos.x-radius, y=pos.y+2, z=pos.z+radius}, {name="default:fence_wood"})
|
||||
minetest.set_node({x=pos.x-radius, y=pos.y+2, z=pos.z-radius}, {name="default:fence_wood"})
|
||||
end
|
||||
|
||||
-- Retore land
|
||||
cidades.restore_land = function(pos, data)
|
||||
|
||||
local c_air = minetest.get_content_id("air")
|
||||
local c_soil = minetest.get_content_id(data.soil_node)
|
||||
|
||||
-- Get the vmanip mapgen object and the nodes and VoxelArea
|
||||
local vm = minetest.get_voxel_manip()
|
||||
local emin, emax = vm:read_from_map(data.minp, data.maxp)
|
||||
local vm_data = vm:get_data()
|
||||
local area = VoxelArea:new{MinEdge=emin, MaxEdge=emax}
|
||||
|
||||
-- Clear area
|
||||
for i in area:iter(
|
||||
data.minp.x, data.minp.y+1, data.minp.z,
|
||||
data.maxp.x, data.maxp.y, data.maxp.z
|
||||
) do
|
||||
vm_data[i] = c_air
|
||||
end
|
||||
|
||||
-- Set soil
|
||||
for i in area:iter(
|
||||
data.minp.x, data.minp.y, data.minp.z,
|
||||
data.maxp.x, data.minp.y, data.maxp.z
|
||||
) do
|
||||
vm_data[i] = c_soil
|
||||
end
|
||||
|
||||
-- Return the changed nodes data, fix light and change map
|
||||
vm:set_data(vm_data)
|
||||
vm:write_to_map()
|
||||
|
||||
end
|
||||
|
||||
|
|
@ -3,7 +3,7 @@
|
|||
Copyright (C) 2020 BrunoMine (https://github.com/BrunoMine)
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>5.
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
-- Number nodes
|
||||
]]
|
||||
|
|
78
property.lua
78
property.lua
|
@ -3,7 +3,7 @@
|
|||
Copyright (C) 2020 BrunoMine (https://github.com/BrunoMine)
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>5.
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
Property
|
||||
]]
|
||||
|
@ -107,6 +107,7 @@ cidades.property.get_data_pos = function(pos, data_type, def)
|
|||
end
|
||||
end
|
||||
|
||||
|
||||
-- Get property data
|
||||
cidades.property.get_data = function(pos)
|
||||
local height = cidades.property.height[tostring(cidades.number_node[minetest.get_node(cidades.property.get_data_pos(pos, "height")).name])]
|
||||
|
@ -124,3 +125,78 @@ cidades.property.get_data = function(pos)
|
|||
end
|
||||
|
||||
|
||||
-- Set owner
|
||||
cidades.set_owner = function(player, pos, data)
|
||||
|
||||
-- Update property stone
|
||||
minetest.set_node(pos, {name="cidades:property_stone_purchased"})
|
||||
|
||||
-- Minp & Maxp
|
||||
local minp = {
|
||||
x=pos.x-data.radius,
|
||||
y=pos.y+1,
|
||||
z=pos.z-data.radius
|
||||
}
|
||||
local maxp = {
|
||||
x=pos.x+data.radius,
|
||||
y=pos.y+1+data.height,
|
||||
z=pos.z+data.radius
|
||||
}
|
||||
|
||||
-- Protect area
|
||||
local area_id = cidades.protect_area(player:get_player_name(), "Property", minp, maxp)
|
||||
|
||||
-- Update metadata
|
||||
data.pos = pos
|
||||
data.width = (data.radius * 2) + 1
|
||||
data.minp = minp
|
||||
data.maxp = maxp
|
||||
data.soil_node = minetest.get_node({x=pos.x, y=pos.y+1, z=pos.z}).name
|
||||
data.owner = player:get_player_name()
|
||||
data.area_id = area_id
|
||||
|
||||
-- Update data base
|
||||
cidades.db.set_property(data.owner, data)
|
||||
|
||||
minetest.get_meta(pos):set_string("stone_data", minetest.serialize(data))
|
||||
end
|
||||
|
||||
|
||||
-- Reset owner
|
||||
cidades.reset_property = function(pos, data)
|
||||
|
||||
-- Update property stone
|
||||
minetest.set_node({x=pos.x, y=pos.y-3, z=pos.z}, {name="cidades:property_stone_for_sale"})
|
||||
|
||||
-- Update data base
|
||||
cidades.db.reset_property(data.owner)
|
||||
|
||||
-- Restore land
|
||||
cidades.restore_land(pos, data)
|
||||
|
||||
-- Unprotect area
|
||||
cidades.unprotect_area(data.area_id)
|
||||
|
||||
-- Place poles
|
||||
cidades.place_poles(pos, data.radius)
|
||||
|
||||
-- Place seller
|
||||
minetest.set_node({x=pos.x, y=pos.y+3, z=pos.z}, {name="cidades:seller"})
|
||||
|
||||
-- Update metadata
|
||||
data.owner = nil
|
||||
end
|
||||
|
||||
|
||||
minetest.register_chatcommand("reset_property", {
|
||||
params = "None",
|
||||
description = "Reset self property",
|
||||
func = function(name, param)
|
||||
if cidades.db.check_property(name) == false then
|
||||
return false, "No property"
|
||||
end
|
||||
|
||||
-- Remove registry
|
||||
cidades.db.reset_property(name)
|
||||
end,
|
||||
})
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
Copyright (C) 2020 BrunoMine (https://github.com/BrunoMine)
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>5.
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
Property Builder
|
||||
]]
|
||||
|
@ -39,8 +39,11 @@ local create_property = function(pos)
|
|||
-- Set seller
|
||||
minetest.set_node({x=pos.x, y=pos.y+1, z=pos.z}, {name = "cidades:seller"})
|
||||
|
||||
-- Place poles
|
||||
cidades.place_poles({x=pos.x, y=pos.y-2, z=pos.z}, radius)
|
||||
|
||||
-- Remove property builder
|
||||
--minetest.remove_node(pos)
|
||||
minetest.remove_node(pos)
|
||||
|
||||
minetest.chat_send_all("Property created")
|
||||
end
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
Copyright (C) 2020 BrunoMine (https://github.com/BrunoMine)
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>5.
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
Property Stone
|
||||
]]
|
||||
|
@ -31,3 +31,27 @@ minetest.register_node("cidades:property_stone_purchased", {
|
|||
groups = {choppy = 2, oddly_breakable_by_hand = 2, stone = 1},
|
||||
sounds = default.node_sound_stone_defaults(),
|
||||
})
|
||||
|
||||
|
||||
-- Check property stone
|
||||
cidades.check_property_stone = function(pos)
|
||||
local meta = minetest.get_meta(pos)
|
||||
local data = minetest.deserialize(meta:get_string("stone_data"))
|
||||
|
||||
-- Check data base registry
|
||||
if cidades.db.check_property(data.owner) == false then
|
||||
cidades.reset_property(pos, data)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
-- Check property stones
|
||||
minetest.register_abm{
|
||||
label = "check purchased property",
|
||||
nodenames = {"cidades:property_stone_purchased"},
|
||||
interval = 300,
|
||||
chance = 1,
|
||||
action = function(pos)
|
||||
cidades.check_property_stone(pos)
|
||||
end,
|
||||
}
|
||||
|
|
|
@ -0,0 +1,39 @@
|
|||
--[[
|
||||
Mod Cidades for Minetest
|
||||
Copyright (C) 2020 BrunoMine (https://github.com/BrunoMine)
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>5.
|
||||
|
||||
Protected area
|
||||
]]
|
||||
|
||||
|
||||
-- Protect area
|
||||
cidades.protect_area = function(ownername, areaname, pos1, pos2)
|
||||
|
||||
if pos1 and pos2 then
|
||||
pos1, pos2 = areas:sortPos(pos1, pos2)
|
||||
else
|
||||
return false
|
||||
end
|
||||
|
||||
minetest.log("action", "Protected area by buy land. Owner = "..ownername..
|
||||
" AreaName = "..areaname..
|
||||
" StartPos = "..minetest.pos_to_string(pos1)..
|
||||
" EndPos = " ..minetest.pos_to_string(pos2))
|
||||
|
||||
local id = areas:add(ownername, areaname, pos1, pos2, nil)
|
||||
areas:save()
|
||||
|
||||
return id
|
||||
end
|
||||
|
||||
-- Unprotect area
|
||||
cidades.unprotect_area = function(id)
|
||||
local id = tonumber(id)
|
||||
|
||||
areas:remove(id)
|
||||
areas:save()
|
||||
return true
|
||||
end
|
|
@ -3,7 +3,7 @@
|
|||
Copyright (C) 2020 BrunoMine (https://github.com/BrunoMine)
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>5.
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
Seller node
|
||||
]]
|
||||
|
@ -20,10 +20,9 @@ local seller_access = function(player, pos)
|
|||
local width = (data.radius * 2) + 1
|
||||
|
||||
-- Button status
|
||||
local status = "button[0,2.35;5,1;buy;Buy]"
|
||||
if cidades.db.check_property(name) ~= true then
|
||||
status = "label[0,2.35;"..minetest.colorize("#ff0707", "You already own land.")
|
||||
.."\n"..minetest.colorize("#ff0707", "Sell it to buy that one.").."]"
|
||||
local text = "Make sure you can pay."
|
||||
if cidades.db.check_property(name) == true then
|
||||
text = minetest.colorize("#ff0707", "You already own land. Sell it to buy that one.")
|
||||
end
|
||||
|
||||
minetest.show_formspec(name, "cidades:seller",
|
||||
|
@ -32,14 +31,42 @@ local seller_access = function(player, pos)
|
|||
.."\nHeight: "..data.height
|
||||
.."\nWidth: "..width
|
||||
.."\nTotal buildable area: "..(width*width*(data.height)).." blocks"
|
||||
.."\nCost: "..data.cost.."]"
|
||||
..status
|
||||
.."\nCost: "..data.cost
|
||||
.."\n"..text.."]"
|
||||
.."button_exit[0,2.35;5,1;buy;Buy]"
|
||||
)
|
||||
|
||||
|
||||
end
|
||||
|
||||
|
||||
minetest.register_on_player_receive_fields(function(player, formname, fields)
|
||||
if formname == "cidades:seller" then
|
||||
local name = player:get_player_name()
|
||||
local pos = minetest.deserialize(player:get_attribute("cidades:seller_pos"))
|
||||
local data = cidades.property.get_data({x=pos.x, y=pos.y-3, z=pos.z})
|
||||
|
||||
if fields.buy then
|
||||
-- Check property
|
||||
if cidades.db.check_property(name) == true then
|
||||
return minetest.chat_send_player(name, "You already own land. Sell it to buy that one.")
|
||||
end
|
||||
|
||||
if player:get_inventory():contains_item("main", cidades.money_item.." "..data.cost) == false then
|
||||
return minetest.chat_send_player(name, "You can not pay that.")
|
||||
end
|
||||
|
||||
-- Get payment
|
||||
player:get_inventory():remove_item("main", cidades.money_item.." "..data.cost)
|
||||
minetest.remove_node(pos)
|
||||
|
||||
cidades.set_owner(player, {x=pos.x, y=pos.y-3, z=pos.z}, data)
|
||||
|
||||
minetest.chat_send_player(name, "Land purchased.")
|
||||
end
|
||||
end
|
||||
end)
|
||||
|
||||
|
||||
-- Seller node
|
||||
minetest.register_node("cidades:seller", {
|
||||
description = "Seller",
|
||||
|
|
|
@ -0,0 +1,120 @@
|
|||
--[[
|
||||
Mod Cidades for Minetest
|
||||
Copyright (C) 2020 BrunoMine (https://github.com/BrunoMine)
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
Teleporter
|
||||
]]
|
||||
|
||||
|
||||
-- Cities
|
||||
local cities_string_list = ""
|
||||
local cities_list = {}
|
||||
|
||||
-- Fosmpec padrao
|
||||
local formspec = "size[6,5]"
|
||||
..default.gui_bg
|
||||
..default.gui_bg_img
|
||||
.."label[0.5,0;Choose a city]"
|
||||
.."label[0.5,0;Choose a city]"
|
||||
|
||||
-- Atualizar lista de vilas
|
||||
local update_list = function()
|
||||
|
||||
cities_string_list = ""
|
||||
cities_list = {}
|
||||
|
||||
for city_id, city_data in pairs(cidades.active_cities) do
|
||||
|
||||
-- Add ','
|
||||
if cities_string_list ~= "" then cities_string_list = cities_string_list .. "," end
|
||||
|
||||
-- Add city name
|
||||
cities_string_list = cities_string_list .. city_data.name
|
||||
|
||||
-- Add spawn pos
|
||||
table.insert(cities_list, {
|
||||
name = city_data.name,
|
||||
pos = city_data.spawn,
|
||||
})
|
||||
end
|
||||
|
||||
if cities_string_list ~= "" then
|
||||
|
||||
-- Update formspec
|
||||
formspec = "size[6,5]"
|
||||
..default.gui_bg
|
||||
..default.gui_bg_img
|
||||
.."label[0.5,0;Choose a city]"
|
||||
.."textlist[0.5,0.8;4.8,3;city;"..cities_string_list.."]"
|
||||
|
||||
end
|
||||
end
|
||||
update_list()
|
||||
|
||||
local show_formspec = function(player)
|
||||
local name = player:get_player_name()
|
||||
if player:get_attribute("cidades:teleporter_choose") ~= nil then
|
||||
minetest.show_formspec(name, "cidades:teleporter", formspec.."button_exit[1,4.2;4,1;teleport;Go]")
|
||||
else
|
||||
minetest.show_formspec(name, "cidades:teleporter", formspec)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
|
||||
minetest.register_on_player_receive_fields(function(player, formname, fields)
|
||||
|
||||
if formname == "cidades:teleporter" then
|
||||
|
||||
if fields.city then
|
||||
local n = string.split(fields.city, ":")
|
||||
|
||||
player:set_attribute("cidades:teleporter_choose", n[2])
|
||||
|
||||
if n[1] == "DCL" then
|
||||
fields.teleport = true
|
||||
else
|
||||
show_formspec(player, n[2])
|
||||
return
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
if fields.teleport then
|
||||
local name = player:get_player_name()
|
||||
local id = tonumber(player:get_attribute("cidades:teleporter_choose"))
|
||||
|
||||
player:set_attribute("cidades:teleporter_choose", nil)
|
||||
player:set_pos(cities_list[id].pos)
|
||||
|
||||
minetest.close_formspec(name, "cidades:teleporter")
|
||||
minetest.chat_send_player(name, "Welcome to "..cities_list[id].name)
|
||||
end
|
||||
|
||||
if fields.quit then
|
||||
player:set_attribute("cidades:teleporter_choose", nil)
|
||||
end
|
||||
end
|
||||
end)
|
||||
|
||||
|
||||
-- Teleporter
|
||||
minetest.register_node("cidades:teleporter", {
|
||||
description = "Teleporter",
|
||||
paramtype2 = "facedir",
|
||||
place_param2 = 0,
|
||||
tiles = {"default_wood.png^default_diamond.png"},
|
||||
is_ground_content = false,
|
||||
groups = {choppy = 2, oddly_breakable_by_hand = 2},
|
||||
|
||||
on_rightclick = function(pos, node, clicker, itemstack, pointed_thing)
|
||||
if cities_list[1] then
|
||||
show_formspec(clicker)
|
||||
else
|
||||
minetest.chat_send_player(clicker:get_player_name(), "No cities avaliable"..dump(cidades.active_cities))
|
||||
end
|
||||
end,
|
||||
})
|
Loading…
Reference in New Issue