Melhorias gerais
parent
4f2aff65bd
commit
ca289dc4e3
|
@ -63,6 +63,12 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
|
|||
return
|
||||
end
|
||||
|
||||
-- Verifica se possui o item ainda
|
||||
if urbos.tror.trocar_plus(player, {"urbos:alvara_cidade 1"}, nil) == false then
|
||||
minetest.chat_send_player(name, "Precisa do alvará para fundar a cidade")
|
||||
return
|
||||
end
|
||||
|
||||
-- Cria cidade
|
||||
urbos.criar_cidade(player, fields.nome_cidade)
|
||||
|
||||
|
@ -74,7 +80,7 @@ end)
|
|||
-- Alvara
|
||||
minetest.register_craftitem("urbos:alvara_cidade", {
|
||||
description = "Alvara para Fundar Cidade",
|
||||
inventory_image = "default_paper.png",
|
||||
inventory_image = "urbos_alvara_cidade.png",
|
||||
stack_max = 1,
|
||||
on_use = function(itemstack, user, pointed_thing)
|
||||
exibir_interface_alvara(user:get_player_name())
|
||||
|
|
12
cidade.lua
12
cidade.lua
|
@ -69,6 +69,18 @@ urbos.criar_cidade = function(player, nome_cidade)
|
|||
end
|
||||
player:setpos(pos_spawn)
|
||||
|
||||
-- Encontra nodes de teleportador
|
||||
do
|
||||
local nodes = minetest.find_nodes_in_area(
|
||||
{x=minp.x, y=pos_spawn.y-4, z=minp.z},
|
||||
{x=maxp.x, y=pos_spawn.y+10, z=maxp.z},
|
||||
{"urbos:teleportador"}
|
||||
)
|
||||
for _,p in ipairs(nodes) do
|
||||
minetest.registered_nodes["urbos:teleportador"].on_construct(p)
|
||||
end
|
||||
end
|
||||
|
||||
-- Registra no banco de dados
|
||||
urbos.nova_cidade(nome_cidade, pos_spawn)
|
||||
|
||||
|
|
3
init.lua
3
init.lua
|
@ -27,6 +27,9 @@ notificar("Carregando scripts...")
|
|||
-- Criação do banco de dados
|
||||
urbos.bd = dofile(modpath.."/lib/memor.lua")
|
||||
|
||||
-- Lib tror
|
||||
urbos.tror = dofile(modpath.."/lib/tror.lua")
|
||||
|
||||
-- Variaveis personalizaveis
|
||||
urbos.var = {}
|
||||
|
||||
|
|
|
@ -0,0 +1,148 @@
|
|||
--[[
|
||||
Lib Tror para Minetest
|
||||
Copyright (C) 2017 BrunoMine (https://github.com/BrunoMine)
|
||||
|
||||
Recebeste uma cópia da GNU Lesser General
|
||||
Public License junto com esse software,
|
||||
se não, veja em <http://www.gnu.org/licenses/>.
|
||||
|
||||
Operações de troca de itens
|
||||
]]
|
||||
|
||||
local tror = {}
|
||||
|
||||
-- Verificar viabilidade de uma troca
|
||||
tror.verificar = function(player, item_rem, item_add)
|
||||
|
||||
if not player or not item_add or not item_rem then
|
||||
minetest.log("error", "[Tror] Faltou dados em (em tror.verificar)")
|
||||
return false
|
||||
end
|
||||
|
||||
local inv = player:get_inventory()
|
||||
|
||||
-- Verificar jogador
|
||||
if not inv:contains_item("main", item_rem) then
|
||||
return 1 -- Jogador nao pode pagar
|
||||
elseif not inv:room_for_item("main", item_add) then
|
||||
return 2 -- Jogador com inventario lotado
|
||||
end
|
||||
|
||||
return true
|
||||
end
|
||||
|
||||
-- Realizar uma troca entre com um jogador
|
||||
tror.trocar = function(player, item_rem, item_add, msg)
|
||||
|
||||
if not player or not item_add or not item_rem then
|
||||
minetest.log("error", "[Tror] Faltou dados em (em tror.trocar)")
|
||||
return false
|
||||
end
|
||||
|
||||
|
||||
local v = tror.verificar(player, item_rem, item_add)
|
||||
if v ~= true then
|
||||
if v == 1 then
|
||||
if msg and msg.ins then
|
||||
minetest.chat_send_player(player:get_player_name(), msg.ins)
|
||||
end
|
||||
return 1
|
||||
elseif v == 2 then
|
||||
if msg and msg.lot then
|
||||
minetest.chat_send_player(player:get_player_name(), msg.lot)
|
||||
end
|
||||
return 2
|
||||
else
|
||||
minetest.log("error", "[Tror] Resultado inesperado em tror.trocar (v = "..dump(v)..")")
|
||||
return false
|
||||
end
|
||||
end
|
||||
|
||||
local inv = player:get_inventory()
|
||||
|
||||
-- Retirar itens do inventario
|
||||
local i = string.split(item_rem, " ")
|
||||
local n = i[2] or 1
|
||||
i = i[1]
|
||||
for r=1, tonumber(n) do -- 1 eh o tanto que quero tirar
|
||||
inv:remove_item("main", i) -- tira 1 por vez
|
||||
end
|
||||
|
||||
inv:add_item("main", item_add)
|
||||
|
||||
|
||||
if msg and msg.ok then
|
||||
minetest.chat_send_player(player:get_player_name(), msg.ok)
|
||||
end
|
||||
return true
|
||||
|
||||
end
|
||||
|
||||
-- Realizar uma troca com um jogador
|
||||
--[[
|
||||
Retorna false caso o jogador nao tenha os itens requisitados
|
||||
e dropa no local todos os itens que não couberem no inventario
|
||||
]]
|
||||
tror.trocar_plus = function(player, item_rem, item_add)
|
||||
|
||||
if not player then
|
||||
minetest.log("error", "[Tror] Faltou player (em tror.trocar_plus)")
|
||||
return false
|
||||
end
|
||||
|
||||
if item_rem and not item_rem[1] then
|
||||
minetest.log("error", "[Tror] argumento item_rem invalido (em tror.trocar_plus)")
|
||||
return false
|
||||
end
|
||||
|
||||
if item_add and not item_add[1] then
|
||||
minetest.log("error", "[Tror] argumento item_add invalido (em tror.trocar_plus)")
|
||||
return false
|
||||
end
|
||||
|
||||
local pos = player:getpos()
|
||||
|
||||
local inv = player:get_inventory()
|
||||
|
||||
-- Verificar se o jogador possui os itens requisitados
|
||||
local possui = true
|
||||
for _,item in ipairs(item_rem) do
|
||||
if not inv:contains_item("main", item) then
|
||||
possui = false
|
||||
break
|
||||
end
|
||||
end
|
||||
|
||||
-- Retorna false por jogador não ter os itens requisitados
|
||||
if possui == false then
|
||||
return false
|
||||
end
|
||||
|
||||
-- Retira itens do jogador
|
||||
for _,item in ipairs(item_rem) do
|
||||
local i = string.split(item, " ")
|
||||
local n = i[2] or 1
|
||||
i = i[1]
|
||||
for r=1, tonumber(n) do -- 1 eh o tanto que quero tirar
|
||||
inv:remove_item("main", i) -- tira 1 por vez
|
||||
end
|
||||
end
|
||||
|
||||
-- Transfere todos os itens ao jogador (e dropa os que nao couberem no inventario)
|
||||
local dropou = false
|
||||
if item_add ~= nil then
|
||||
for _,item in ipairs(item_add) do
|
||||
if inv:room_for_item("main", item) then
|
||||
inv:add_item("main", item)
|
||||
else
|
||||
dropou = true
|
||||
minetest.env:add_item({x = pos.x + math.random() * 2 - 1, y = pos.y+1, z = pos.z + math.random() * 2 - 1}, item)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
return true
|
||||
|
||||
end
|
||||
|
||||
return tror
|
|
@ -126,18 +126,37 @@ end)
|
|||
minetest.register_node("urbos:teleportador", {
|
||||
description = "Teleportador de Cidades",
|
||||
tiles = {
|
||||
"default_chest_top.png^urbos_teleportador_cima.png", -- Cima
|
||||
"urbos_teleportador_cima.png", -- Cima
|
||||
"default_chest_top.png", -- Baixo
|
||||
"default_chest_side.png", -- Direita
|
||||
"default_chest_side.png", -- Esquerda
|
||||
"default_chest_side.png", -- Fundo
|
||||
"default_chest_front.png" -- Frente
|
||||
"default_chest_side.png^urbos_teleportador_lado.png", -- Direita
|
||||
"default_chest_side.png^urbos_teleportador_lado.png", -- Esquerda
|
||||
"default_chest_side.png^urbos_teleportador_lado.png", -- Fundo
|
||||
"default_chest_side.png^urbos_teleportador_lado.png" -- Frente
|
||||
},
|
||||
paramtype2 = "facedir",
|
||||
groups = {choppy = 2, oddly_breakable_by_hand = 2},
|
||||
sounds = default.node_sound_wood_defaults(),
|
||||
drop = "",
|
||||
|
||||
on_construct = function(pos)
|
||||
local meta = minetest.get_meta(pos)
|
||||
meta:set_string("infotext", "Viajar para outra cidade")
|
||||
|
||||
minetest.add_entity({x=pos.x, y=pos.y+0.85, z=pos.z}, "urbos:mapinha")
|
||||
local timer = minetest.get_node_timer(pos)
|
||||
timer:start(0.5)
|
||||
end,
|
||||
|
||||
on_destruct = function(pos)
|
||||
for _, obj in pairs(minetest.get_objects_inside_radius(pos, 0.9)) do
|
||||
if obj and obj:get_luaentity() and
|
||||
obj:get_luaentity().name == "urbos:mapinha" then
|
||||
obj:remove()
|
||||
break
|
||||
end
|
||||
end
|
||||
end,
|
||||
|
||||
on_rightclick = function(pos, node, player)
|
||||
exibir_interface_teleportador(player:get_player_name())
|
||||
end,
|
||||
|
@ -148,4 +167,21 @@ minetest.register_node("urbos:teleportador", {
|
|||
end,
|
||||
})
|
||||
|
||||
-- Entidade
|
||||
minetest.register_entity("urbos:mapinha", {
|
||||
visual = "sprite",
|
||||
visual_size = {x=0.55, y=0.55},
|
||||
collisionbox = {0},
|
||||
physical = false,
|
||||
textures = {"urbos_mapinha.png"},
|
||||
|
||||
on_activate = function(self)
|
||||
local pos = self.object:getpos()
|
||||
|
||||
if minetest.get_node({x=pos.x, y=pos.y-1, z=pos.z}).name ~= "urbos:teleportador" then
|
||||
self.object:remove()
|
||||
end
|
||||
end
|
||||
})
|
||||
|
||||
|
||||
|
|
Binary file not shown.
After Width: | Height: | Size: 356 B |
Binary file not shown.
After Width: | Height: | Size: 376 B |
Binary file not shown.
Before Width: | Height: | Size: 1.1 KiB After Width: | Height: | Size: 399 B |
Binary file not shown.
After Width: | Height: | Size: 508 B |
Loading…
Reference in New Issue