Lançamento dos primeiros scripts
parent
bb73ee0709
commit
481487b3cd
|
@ -0,0 +1,165 @@
|
|||
GNU LESSER GENERAL PUBLIC LICENSE
|
||||
Version 3, 29 June 2007
|
||||
|
||||
Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
|
||||
Everyone is permitted to copy and distribute verbatim copies
|
||||
of this license document, but changing it is not allowed.
|
||||
|
||||
|
||||
This version of the GNU Lesser General Public License incorporates
|
||||
the terms and conditions of version 3 of the GNU General Public
|
||||
License, supplemented by the additional permissions listed below.
|
||||
|
||||
0. Additional Definitions.
|
||||
|
||||
As used herein, "this License" refers to version 3 of the GNU Lesser
|
||||
General Public License, and the "GNU GPL" refers to version 3 of the GNU
|
||||
General Public License.
|
||||
|
||||
"The Library" refers to a covered work governed by this License,
|
||||
other than an Application or a Combined Work as defined below.
|
||||
|
||||
An "Application" is any work that makes use of an interface provided
|
||||
by the Library, but which is not otherwise based on the Library.
|
||||
Defining a subclass of a class defined by the Library is deemed a mode
|
||||
of using an interface provided by the Library.
|
||||
|
||||
A "Combined Work" is a work produced by combining or linking an
|
||||
Application with the Library. The particular version of the Library
|
||||
with which the Combined Work was made is also called the "Linked
|
||||
Version".
|
||||
|
||||
The "Minimal Corresponding Source" for a Combined Work means the
|
||||
Corresponding Source for the Combined Work, excluding any source code
|
||||
for portions of the Combined Work that, considered in isolation, are
|
||||
based on the Application, and not on the Linked Version.
|
||||
|
||||
The "Corresponding Application Code" for a Combined Work means the
|
||||
object code and/or source code for the Application, including any data
|
||||
and utility programs needed for reproducing the Combined Work from the
|
||||
Application, but excluding the System Libraries of the Combined Work.
|
||||
|
||||
1. Exception to Section 3 of the GNU GPL.
|
||||
|
||||
You may convey a covered work under sections 3 and 4 of this License
|
||||
without being bound by section 3 of the GNU GPL.
|
||||
|
||||
2. Conveying Modified Versions.
|
||||
|
||||
If you modify a copy of the Library, and, in your modifications, a
|
||||
facility refers to a function or data to be supplied by an Application
|
||||
that uses the facility (other than as an argument passed when the
|
||||
facility is invoked), then you may convey a copy of the modified
|
||||
version:
|
||||
|
||||
a) under this License, provided that you make a good faith effort to
|
||||
ensure that, in the event an Application does not supply the
|
||||
function or data, the facility still operates, and performs
|
||||
whatever part of its purpose remains meaningful, or
|
||||
|
||||
b) under the GNU GPL, with none of the additional permissions of
|
||||
this License applicable to that copy.
|
||||
|
||||
3. Object Code Incorporating Material from Library Header Files.
|
||||
|
||||
The object code form of an Application may incorporate material from
|
||||
a header file that is part of the Library. You may convey such object
|
||||
code under terms of your choice, provided that, if the incorporated
|
||||
material is not limited to numerical parameters, data structure
|
||||
layouts and accessors, or small macros, inline functions and templates
|
||||
(ten or fewer lines in length), you do both of the following:
|
||||
|
||||
a) Give prominent notice with each copy of the object code that the
|
||||
Library is used in it and that the Library and its use are
|
||||
covered by this License.
|
||||
|
||||
b) Accompany the object code with a copy of the GNU GPL and this license
|
||||
document.
|
||||
|
||||
4. Combined Works.
|
||||
|
||||
You may convey a Combined Work under terms of your choice that,
|
||||
taken together, effectively do not restrict modification of the
|
||||
portions of the Library contained in the Combined Work and reverse
|
||||
engineering for debugging such modifications, if you also do each of
|
||||
the following:
|
||||
|
||||
a) Give prominent notice with each copy of the Combined Work that
|
||||
the Library is used in it and that the Library and its use are
|
||||
covered by this License.
|
||||
|
||||
b) Accompany the Combined Work with a copy of the GNU GPL and this license
|
||||
document.
|
||||
|
||||
c) For a Combined Work that displays copyright notices during
|
||||
execution, include the copyright notice for the Library among
|
||||
these notices, as well as a reference directing the user to the
|
||||
copies of the GNU GPL and this license document.
|
||||
|
||||
d) Do one of the following:
|
||||
|
||||
0) Convey the Minimal Corresponding Source under the terms of this
|
||||
License, and the Corresponding Application Code in a form
|
||||
suitable for, and under terms that permit, the user to
|
||||
recombine or relink the Application with a modified version of
|
||||
the Linked Version to produce a modified Combined Work, in the
|
||||
manner specified by section 6 of the GNU GPL for conveying
|
||||
Corresponding Source.
|
||||
|
||||
1) Use a suitable shared library mechanism for linking with the
|
||||
Library. A suitable mechanism is one that (a) uses at run time
|
||||
a copy of the Library already present on the user's computer
|
||||
system, and (b) will operate properly with a modified version
|
||||
of the Library that is interface-compatible with the Linked
|
||||
Version.
|
||||
|
||||
e) Provide Installation Information, but only if you would otherwise
|
||||
be required to provide such information under section 6 of the
|
||||
GNU GPL, and only to the extent that such information is
|
||||
necessary to install and execute a modified version of the
|
||||
Combined Work produced by recombining or relinking the
|
||||
Application with a modified version of the Linked Version. (If
|
||||
you use option 4d0, the Installation Information must accompany
|
||||
the Minimal Corresponding Source and Corresponding Application
|
||||
Code. If you use option 4d1, you must provide the Installation
|
||||
Information in the manner specified by section 6 of the GNU GPL
|
||||
for conveying Corresponding Source.)
|
||||
|
||||
5. Combined Libraries.
|
||||
|
||||
You may place library facilities that are a work based on the
|
||||
Library side by side in a single library together with other library
|
||||
facilities that are not Applications and are not covered by this
|
||||
License, and convey such a combined library under terms of your
|
||||
choice, if you do both of the following:
|
||||
|
||||
a) Accompany the combined library with a copy of the same work based
|
||||
on the Library, uncombined with any other library facilities,
|
||||
conveyed under the terms of this License.
|
||||
|
||||
b) Give prominent notice with the combined library that part of it
|
||||
is a work based on the Library, and explaining where to find the
|
||||
accompanying uncombined form of the same work.
|
||||
|
||||
6. Revised Versions of the GNU Lesser General Public License.
|
||||
|
||||
The Free Software Foundation may publish revised and/or new versions
|
||||
of the GNU Lesser General Public License from time to time. Such new
|
||||
versions will be similar in spirit to the present version, but may
|
||||
differ in detail to address new problems or concerns.
|
||||
|
||||
Each version is given a distinguishing version number. If the
|
||||
Library as you received it specifies that a certain numbered version
|
||||
of the GNU Lesser General Public License "or any later version"
|
||||
applies to it, you have the option of following the terms and
|
||||
conditions either of that published version or of any later version
|
||||
published by the Free Software Foundation. If the Library as you
|
||||
received it does not specify a version number of the GNU Lesser
|
||||
General Public License, you may choose any version of the GNU Lesser
|
||||
General Public License ever published by the Free Software Foundation.
|
||||
|
||||
If the Library as you received it specifies that a proxy can decide
|
||||
whether future versions of the GNU Lesser General Public License shall
|
||||
apply, that proxy's public statement of acceptance of any version is
|
||||
permanent authorization for you to choose that version for the
|
||||
Library.
|
30
README.md
30
README.md
|
@ -1 +1,29 @@
|
|||
terrenos
|
||||
# Terrenos v1.0.0-DEV
|
||||
|
||||
[![Baixar](https://img.shields.io/badge/Baixar-v1.0.0-green.svg)](https://github.com/BrunoMine/terrenos/archive/v1.0.0.zip)
|
||||
[![Projeto](https://img.shields.io/badge/Git-Projeto-green.svg)](https://github.com/BrunoMine/terrenos)
|
||||
[![!Bower](https://img.shields.io/badge/Bower-Projeto-green.svg)](https://minetest-bower.herokuapp.com/mods/terrenos)
|
||||
[![!Fórum](https://img.shields.io/badge/Forum-Projeto-green.svg)](http://forum.minetestbrasil.com)
|
||||
[![Licença](https://img.shields.io/badge/Licença-LGPL_v3.0-blue.svg)](https://github.com/BrunoMine/terrenos/blob/master/LICENSE)
|
||||
|
||||
## Descrição
|
||||
Adiciona placas de terrenos de aluguel
|
||||
|
||||
## Recursos do projeto
|
||||
|
||||
* [Baixar](https://github.com/BrunoMine/terrenos/archive/v1.0.0.zip)
|
||||
* [Projeto](https://github.com/BrunoMine/terrenos)
|
||||
* [Bower](https://minetest-bower.herokuapp.com/mods/terrenos)
|
||||
|
||||
## Requisitos
|
||||
|
||||
* Minetest 0.4.15 ou superior
|
||||
|
||||
## Licença
|
||||
Veja LICENSE.txt para informações detalhadas da licença LGPL 3.0
|
||||
|
||||
### Autores do código fonte
|
||||
Originalmente por BrunoMine, Bruno Borges <borgesdossantosbruno@gmail.com> (LGPL 3.0)
|
||||
|
||||
### Autores de mídias (texturas, modelos and sons)
|
||||
BrunoMine, Bruno Borges <borgesdossantosbruno@gmail.com> (CC BY-SA 3.0)
|
||||
|
|
|
@ -0,0 +1,29 @@
|
|||
--[[
|
||||
Mod Terrenos 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/>.
|
||||
|
||||
Cobrar itens do jogador
|
||||
]]
|
||||
|
||||
-- Cobrar item do jogador
|
||||
terrenos.cobrar = function(player, itemstack)
|
||||
local inv = player:get_inventory()
|
||||
|
||||
-- Verificar se o jogador consegue pagar
|
||||
if not inv:contains_item("main", itemstack) then return false end
|
||||
|
||||
|
||||
-- Retira itens do jogador
|
||||
local i = itemstack.name
|
||||
local n = itemstack.count
|
||||
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
|
||||
|
||||
return true
|
||||
end
|
|
@ -0,0 +1,225 @@
|
|||
--[[
|
||||
Mod Terrenos 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/>.
|
||||
|
||||
Contador de tempo
|
||||
]]
|
||||
|
||||
-- Quantos dias tem cada mes
|
||||
local dias_meses = {
|
||||
31, -- Janeiro
|
||||
28, -- Fevereiro (29 em ano bissexto)
|
||||
31, -- Março
|
||||
30, -- Abril
|
||||
31, -- Maio
|
||||
30, -- Junho
|
||||
31, -- Julho
|
||||
31, -- Agosto
|
||||
30, -- Setembro
|
||||
31, -- Outubro
|
||||
30, -- Novembro
|
||||
31 -- Dezembro
|
||||
}
|
||||
|
||||
-- Pegar dias do mes naquele ano
|
||||
local pegar_dias_mes = function(mes, ano)
|
||||
|
||||
-- converter para valor numerico
|
||||
mes = tonumber(mes)
|
||||
ano = tonumber(ano)
|
||||
|
||||
-- ajustando para numero entre 1 e 12
|
||||
if mes > 12 then mes = mes - (math.floor(mes/12)*12) end
|
||||
|
||||
-- caso o mes de zero
|
||||
if mes == 0 then mes = 12 end
|
||||
|
||||
-- adiciona um dia em Fevereiro caso seja ano bissexto
|
||||
if mes == 2 and math.fmod(ano, 4) == 0 then
|
||||
return dias_meses[mes] + 1
|
||||
else
|
||||
return dias_meses[mes]
|
||||
end
|
||||
end
|
||||
|
||||
-- Pegar numero maior
|
||||
local pegar_maior = function(n1, n2)
|
||||
if tonumber(n1) > tonumber(n2) then
|
||||
return n1
|
||||
else
|
||||
return n2
|
||||
end
|
||||
end
|
||||
|
||||
-- Pegar numero menor
|
||||
local pegar_menor = function(n1, n2)
|
||||
if n1 < n2 then
|
||||
return n1
|
||||
else
|
||||
return n2
|
||||
end
|
||||
end
|
||||
|
||||
-- Pegar data atual
|
||||
--[[
|
||||
Esse metodo retorna os valores referentes à data atual
|
||||
Retorno:
|
||||
<ano atual>
|
||||
<mes atual>
|
||||
<dia do mes atual>
|
||||
<hora do dia atual>
|
||||
<minutos da hora do dia atual>
|
||||
]]
|
||||
terrenos.pegar_data_atual = function()
|
||||
-- Pegando data atual
|
||||
local ano = tonumber(os.date("%Y"))
|
||||
local mes = tonumber(os.date("%m"))
|
||||
local dia = tonumber(os.date("%d"))
|
||||
local hora = tonumber(os.date("%H"))
|
||||
local minuto = tonumber(os.date("%M"))
|
||||
return ano, mes, dia, hora, minuto
|
||||
end
|
||||
|
||||
-- Comparar data
|
||||
--[[
|
||||
Esse metodo recebe uma data como argumento e retorna
|
||||
as quantidades de dias, horas e minutos em relação à
|
||||
data atual
|
||||
Retorno:
|
||||
<diferença de dias>
|
||||
<diferença de horas>
|
||||
<diferença de minutos>
|
||||
Argumentos:
|
||||
<ano da data>
|
||||
<mes da data>
|
||||
<dia do mes da data>
|
||||
<hora do dia da data>
|
||||
<minutos da hora do dia da data>
|
||||
]]
|
||||
terrenos.comparar_data = function(ano, mes, dia, hora, minuto)
|
||||
if not ano or not tonumber(ano) then
|
||||
minetest.log("error", "[Terrenos] Ano invalido em especificado (em terrenos.comparar_data)")
|
||||
return false
|
||||
end
|
||||
if not mes or not tonumber(mes) then
|
||||
minetest.log("error", "[Terrenos] Mes invalido em especificado (em terrenos.comparar_data)")
|
||||
return false
|
||||
end
|
||||
if not dia or not tonumber(dia) then
|
||||
minetest.log("error", "[Terrenos] Dia invalido em especificado (em terrenos.comparar_data)")
|
||||
return false
|
||||
end
|
||||
if not hora or not tonumber(hora) then
|
||||
minetest.log("error", "[Terrenos] Hora invalido em especificado (em terrenos.comparar_data)")
|
||||
return false
|
||||
end
|
||||
if not minuto or not tonumber(minuto) then
|
||||
minetest.log("error", "[Terrenos] Minuto invalido em especificado (em terrenos.comparar_data)")
|
||||
return false
|
||||
end
|
||||
|
||||
-- Conversoes
|
||||
ano = tonumber(ano)
|
||||
mes = tonumber(mes)
|
||||
dia = tonumber(dia)
|
||||
hora = tonumber(hora)
|
||||
minuto = tonumber(minuto)
|
||||
|
||||
-- Pegando data atual
|
||||
local ano_atual, mes_atual, dia_atual, hora_atual, minuto_atual = terrenos.pegar_data_atual()
|
||||
|
||||
-- Pegar diferença de ano
|
||||
local dif_ano = ano - ano_atual
|
||||
|
||||
-- Pegar diferença de meses
|
||||
local dif_meses = mes - (mes_atual - (dif_ano*12)) -- (considerando os meses de um ano para outro)
|
||||
|
||||
-- Pegar a diferença de dias
|
||||
local dif_dias = 0
|
||||
-- Pegar dias dos meses que passaram
|
||||
if dif_meses > 0 then -- do mes atual ate o mes futuro (apenas os meses inteiros, logo o ultimo nao conta, por isso o menos 1)
|
||||
local a = ano_atual -- ano do mes contado
|
||||
local n = mes_atual -- qual mes do ano contado
|
||||
for m=mes_atual, mes_atual+dif_meses-1 do
|
||||
if n > 12 then
|
||||
n = n - 12
|
||||
a = a + 1
|
||||
end
|
||||
dif_dias = dif_dias + pegar_dias_mes(m, a)
|
||||
n = n + 1
|
||||
end
|
||||
elseif dif_meses < 0 then -- do mes passado do passado ate o mes atual
|
||||
local a = ano -- ano do mes contado
|
||||
local n = mes -- qual mes do ano contado
|
||||
for m=mes, mes+math.abs(dif_meses)-1 do
|
||||
if n > 12 then
|
||||
n = n - 12
|
||||
a = a + 1
|
||||
end
|
||||
dif_dias = dif_dias + pegar_dias_mes(m, a)
|
||||
n = n + 1
|
||||
end
|
||||
dif_dias = dif_dias * (-1) -- mantem valor negativo por estar no passado
|
||||
end
|
||||
-- Adiciona a diferença de dias conforme os dias do mes de cada data
|
||||
dif_dias = dif_dias + (dia - dia_atual)
|
||||
|
||||
-- Pegar diferença de horas
|
||||
local dif_horas = 0
|
||||
if dif_dias > 0 then
|
||||
if hora >= hora_atual then
|
||||
dif_horas = hora - hora_atual
|
||||
else
|
||||
dif_dias = dif_dias - 1
|
||||
dif_horas = (hora + 24) - hora_atual
|
||||
end
|
||||
elseif dif_dias < 0 then
|
||||
dif_dias = dif_dias + 1 -- (1 dia é tirado para ser fracionado em horas pois 1 desses dias não foi inteiro)
|
||||
dif_horas = (24-hora) + hora_atual -- (desconta as horas de 24 horas de um dia que foi descontado)
|
||||
if dif_horas >= 24 then
|
||||
dif_dias = dif_dias - 1
|
||||
dif_horas = dif_horas - 24
|
||||
end
|
||||
dif_horas = dif_horas * (-1) -- mantem valor negativo por estar no passado
|
||||
else -- A data é do mesmo dia
|
||||
dif_horas = hora - hora_atual
|
||||
end
|
||||
|
||||
-- Pegar diferença de minutos
|
||||
local dif_minutos = 0
|
||||
if dif_horas > 0 then
|
||||
if minuto >= minuto_atual then
|
||||
dif_minutos = minuto - minuto_atual
|
||||
else
|
||||
dif_horas = dif_horas - 1
|
||||
dif_minutos = (minuto + 60) - minuto_atual
|
||||
end
|
||||
elseif dif_horas < 0 then
|
||||
dif_horas = dif_horas + 1 -- (1 dia é tirado para ser fracionado em horas pois 1 desses dias não foi inteiro)
|
||||
dif_minutos = (60-minuto) + minuto_atual -- (desconta as horas de 24 horas de um dia que foi descontado)
|
||||
if dif_minutos >= 60 then
|
||||
dif_horas = dif_horas - 1
|
||||
dif_minutos = dif_minutos - 60
|
||||
end
|
||||
dif_minutos = dif_minutos * (-1) -- mantem valor negativo por estar no passado
|
||||
else -- A data é da mesma hora
|
||||
dif_minutos = minuto - minuto_atual
|
||||
end
|
||||
|
||||
-- Reajuste de valores (caso o saldo de horas esteja incompativel com saldo de dias)
|
||||
if dif_horas > 1 and dif_dias < 1 then
|
||||
dif_dias = dif_dias + 1
|
||||
dif_horas = dif_horas - 24
|
||||
end
|
||||
if dif_horas < 1 and dif_dias > 1 then
|
||||
dif_dias = dif_dias - 1
|
||||
dif_horas = dif_horas + 24
|
||||
end
|
||||
|
||||
return dif_dias, dif_horas, dif_minutos
|
||||
|
||||
end
|
|
@ -0,0 +1,74 @@
|
|||
--[[
|
||||
Mod Terrenos 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/>.
|
||||
|
||||
Manipular coordenada de posição
|
||||
]]
|
||||
|
||||
-- Pegar coordenadas de referencias
|
||||
--[[
|
||||
Esse metodo retorna as coordenadas `pos1` e `pos2`
|
||||
localizadas com base nas referencias `ref1` e `ref2`
|
||||
respectivamente.
|
||||
Argumentos:
|
||||
<pos> coordenada de onde `ref1` e `ref2` se referenciam
|
||||
<ref1> referencia 1
|
||||
<ref2> referencia 2
|
||||
Retornos
|
||||
<pos1> coordenada da referencia 1
|
||||
<pos2> coordenada da referencia 2
|
||||
]]
|
||||
terrenos.pegar_pos = function(pos, ref1, ref2)
|
||||
local pos1 = {x=pos.x+ref1.x, y=pos.y+ref1.y, z=pos.z+ref1.z}
|
||||
local pos2 = {x=pos.x+ref2.x, y=pos.y+ref2.y, z=pos.z+ref2.z}
|
||||
return pos1, pos2
|
||||
end
|
||||
|
||||
|
||||
-- Gerar referencias de cordenadas
|
||||
--[[
|
||||
Esse metodo gera duas referencias
|
||||
]]
|
||||
terrenos.gerar_ref = function(pos, pos1, pos2)
|
||||
local ref1 = {x=pos1.x-pos.x, y=pos1.y-pos.y, z=pos1.z-pos.z}
|
||||
local ref2 = {x=pos2.x-pos.x, y=pos2.y-pos.y, z=pos2.z-pos.z}
|
||||
return ref1, ref2
|
||||
end
|
||||
|
||||
|
||||
-- Ajustar coordenadas do menor ao maior
|
||||
--[[
|
||||
Esse metodo retorna as duas coordenadas informadas porem
|
||||
uma delas tera os menores valores para cada eixo e a outra
|
||||
tera os maiores
|
||||
Retornos:
|
||||
<minp>
|
||||
<maxp>
|
||||
]]
|
||||
terrenos.ajustar_pos = function(pos1, pos2)
|
||||
local p1 = minetest.deserialize(minetest.serialize(pos1))
|
||||
local p2 = minetest.deserialize(minetest.serialize(pos2))
|
||||
|
||||
if p1.x > p2.x then
|
||||
p2.x = pos1.x
|
||||
p1.x = pos2.x
|
||||
end
|
||||
|
||||
if p1.y > p2.y then
|
||||
p2.y = pos1.y
|
||||
p1.y = pos2.y
|
||||
end
|
||||
|
||||
if p1.z > p2.z then
|
||||
p2.z = pos1.z
|
||||
p1.z = pos2.z
|
||||
end
|
||||
|
||||
return p1, p2
|
||||
end
|
||||
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
default
|
||||
areas
|
|
@ -0,0 +1,30 @@
|
|||
--[[
|
||||
Mod Terrenos 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/>.
|
||||
|
||||
Desocupar placa
|
||||
]]
|
||||
|
||||
-- Desocupar placa
|
||||
terrenos.desocupar_placa = function(pos)
|
||||
|
||||
local meta = minetest.get_meta(pos)
|
||||
|
||||
local pos1, pos2 = terrenos.pegar_pos(pos, minetest.deserialize(meta:get_string("ref1")), minetest.deserialize(meta:get_string("ref2")))
|
||||
|
||||
-- Trocar placa
|
||||
terrenos.trocar_node(pos, "terrenos:livre")
|
||||
|
||||
-- Configurar placa
|
||||
local meta = minetest.get_meta(pos)
|
||||
meta:set_string("status", "livre")
|
||||
meta:set_string("infotext", "Terreno a Venda")
|
||||
meta:set_string("dono", nil)
|
||||
meta:set_string("ultimo_pagamento", nil)
|
||||
meta:set_float("area_id", nil)
|
||||
|
||||
end
|
|
@ -0,0 +1,17 @@
|
|||
--
|
||||
-- Mod placa_terreno
|
||||
--
|
||||
-- Diretrizes
|
||||
--
|
||||
|
||||
terrenos.var = {}
|
||||
|
||||
-- Node usado como pagamento
|
||||
terrenos.var.pag = "default:apple"
|
||||
terrenos.var.pag_desc = minetest.registered_items[terrenos.var.pag].description
|
||||
|
||||
-- Quantidade de nodes pago como alugal
|
||||
terrenos.var.qtd_pag_aluguel = 1
|
||||
|
||||
-- Quantidade de dias para pagar aluguel
|
||||
terrenos.var.max_dias = 3 * 30
|
|
@ -0,0 +1,71 @@
|
|||
--[[
|
||||
Mod Terrenos 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/>.
|
||||
|
||||
Formspec de datas
|
||||
]]
|
||||
local sigla_mes = {
|
||||
"Jan",
|
||||
"Fev",
|
||||
"Mar",
|
||||
"Abr",
|
||||
"Mai",
|
||||
"Jun",
|
||||
"Jul",
|
||||
"Ago",
|
||||
"Set",
|
||||
"Out",
|
||||
"Nov",
|
||||
"Dez",
|
||||
}
|
||||
|
||||
|
||||
-- Retorna formspec da data atual cor
|
||||
terrenos.formspec_data_rest = function(data_ant)
|
||||
|
||||
local data_atual = {terrenos.pegar_data_atual()}
|
||||
|
||||
-- Dias de diferença
|
||||
local max_dif = 3 * 30
|
||||
local dif = terrenos.comparar_data(data_ant[1], data_ant[2], data_ant[3], data_ant[4], data_ant[5])
|
||||
|
||||
local dias_rest = max_dif - dif
|
||||
|
||||
local st = tostring(dif)
|
||||
|
||||
-- Pagou a menos de 1 mes
|
||||
if dif < 30 then
|
||||
st = core.colorize("#00FF00", st)
|
||||
|
||||
-- Falta menos de 1 mes para expirar o terreno
|
||||
elseif dias_rest < 30 then
|
||||
st = core.colorize("#FF0000", st)
|
||||
|
||||
-- Faltam menos de 2 meses para expirar o terreno
|
||||
elseif dias_rest < 60 then
|
||||
st = core.colorize("#FFA500", st)
|
||||
|
||||
-- Faltam menos de 3 meses para expirar o terreno
|
||||
elseif dias_rest < 90 then
|
||||
st = core.colorize("#1E90FF", st)
|
||||
|
||||
end
|
||||
|
||||
return st
|
||||
|
||||
end
|
||||
|
||||
-- Retorna formspec da data atual cor
|
||||
terrenos.formspec_data_pag = function()
|
||||
|
||||
local data_atual = {terrenos.pegar_data_atual()}
|
||||
|
||||
local st = data_atual[3].."/"..sigla_mes[data_atual[2]].."/"..data_atual[1]
|
||||
|
||||
return st
|
||||
|
||||
end
|
|
@ -0,0 +1,45 @@
|
|||
--[[
|
||||
Mod Terrenos 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/>.
|
||||
|
||||
Inicializador de scripts
|
||||
]]
|
||||
|
||||
-- Variavel global
|
||||
terrenos = {}
|
||||
|
||||
-- Privilegio
|
||||
minetest.register_privilege("terrenos_admin", "Administrar terrenos")
|
||||
|
||||
-- Notificador de Inicializador
|
||||
local notificar = function(msg)
|
||||
if minetest.setting_get("log_mods") then
|
||||
minetest.debug("[TERRENOS]"..msg)
|
||||
end
|
||||
end
|
||||
|
||||
local modpath = minetest.get_modpath("terrenos")
|
||||
|
||||
-- Carregar scripts
|
||||
notificar("Carregando...")
|
||||
dofile(modpath.."/diretrizes.lua")
|
||||
dofile(modpath.."/contador_tempo.lua")
|
||||
dofile(modpath.."/coordenadas.lua")
|
||||
dofile(modpath.."/formspec_data.lua")
|
||||
dofile(modpath.."/limpar.lua")
|
||||
dofile(modpath.."/cobrar.lua")
|
||||
dofile(modpath.."/podar.lua")
|
||||
dofile(modpath.."/trocar_node.lua")
|
||||
dofile(modpath.."/proteger_area.lua")
|
||||
dofile(modpath.."/desocupar_placa.lua")
|
||||
dofile(modpath.."/interface.lua")
|
||||
dofile(modpath.."/nodes.lua")
|
||||
dofile(modpath.."/verificador_de_aluguel.lua")
|
||||
notificar("OK")
|
||||
|
||||
|
||||
|
|
@ -0,0 +1,222 @@
|
|||
--[[
|
||||
Mod Terrenos 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/>.
|
||||
|
||||
Interface
|
||||
]]
|
||||
|
||||
-- Coordenadas rapidas
|
||||
terrenos.lugar1 = {}
|
||||
terrenos.lugar2 = {}
|
||||
terrenos.ultima_placa = {}
|
||||
|
||||
-- Formspecs
|
||||
local formspec_style = default.gui_bg
|
||||
..default.gui_bg_img
|
||||
|
||||
-- Acessar uma placa
|
||||
terrenos.acessar = function(player, pos)
|
||||
local meta = minetest.get_meta(pos)
|
||||
local name = player:get_player_name()
|
||||
terrenos.ultima_placa[name] = {x=pos.x, y=pos.y, z=pos.z}
|
||||
|
||||
-- Terreno desconfigurado
|
||||
if meta:get_string("status") == "desconfigurado" then
|
||||
|
||||
-- Administrador de terrenos
|
||||
if minetest.check_player_privs(name, {terrenos_admin=true}) then
|
||||
|
||||
local pos1, pos2 = "", ""
|
||||
if terrenos.lugar1[name] then pos1 = "OK" else pos1 = "INDEFINIDO" end
|
||||
if terrenos.lugar2[name] then pos2 = "OK" else pos2 = "INDEFINIDO" end
|
||||
|
||||
local formspec = "size[5,4]"
|
||||
..formspec_style
|
||||
.."label[0,0;Terreno desconfigurado]"
|
||||
.."field[0.5,1.25;2.2,1.5;altura;Altura;10]"
|
||||
.."field[3,1.25;2.2,1.5;custo;Custo;0]"
|
||||
.."label[0,2.3;Pos1 "..pos1.." \nPos2 "..pos2.."]"
|
||||
.."button_exit[1,3.3;3,1;configurar;Configurar]"
|
||||
|
||||
minetest.show_formspec(name, "terrenos:desconfigurado", formspec)
|
||||
end
|
||||
|
||||
-- Terreno livre
|
||||
elseif meta:get_string("status") == "livre" then
|
||||
|
||||
-- Qualquer jogador
|
||||
local formspec = "size[5,4]"
|
||||
..formspec_style
|
||||
.."label[0,0;Terreno a venda]"
|
||||
.."label[0,1;Altura de "..meta:get_float("altura").." blocos]"
|
||||
.."label[0,1.5;Custo de "..meta:get_float("custo").."]"
|
||||
.."item_image_button[0,2;1,1;"..terrenos.var.pag..";item;]"
|
||||
.."button_exit[1,3.25;3,1;comprar;Comprar]"
|
||||
|
||||
minetest.show_formspec(name, "terrenos:livre", formspec)
|
||||
|
||||
-- Terreno ocupado
|
||||
elseif meta:get_string("status") == "ocupado" then
|
||||
|
||||
-- Administrador de terrenos
|
||||
if minetest.check_player_privs(name, {terrenos_admin=true}) then
|
||||
|
||||
local formspec = "size[6,4]"
|
||||
..formspec_style
|
||||
.."label[0,0;Terreno ocupado]"
|
||||
.."label[0,1;Dono "..meta:get_string("dono").."]"
|
||||
.."label[0,1.5;Custo "..meta:get_float("custo").."]"
|
||||
.."label[0,2;Aluguel pago "..terrenos.formspec_data_pag().." dias]"
|
||||
.."label[0,2.5;Faltam "..terrenos.formspec_data_rest(minetest.deserialize(meta:get_string("ultimo_pagamento"))).." dias]"
|
||||
.."button_exit[0,3.25;3,1;remover;Remover]"
|
||||
.."button_exit[3,3.25;3,1;podar;Podar]"
|
||||
|
||||
minetest.show_formspec(name, "terrenos:ocupado", formspec)
|
||||
|
||||
-- Dono do terreno
|
||||
elseif meta:get_string("dono") == name then
|
||||
|
||||
local formspec = "size[6,4]"
|
||||
..formspec_style
|
||||
.."label[0,0;Terreno ocupado]"
|
||||
.."label[0,1;Dono "..meta:get_string("dono").."]"
|
||||
.."label[0,1.5;Custo "..meta:get_float("custo").."]"
|
||||
.."label[0,2;Aluguel pago "..terrenos.formspec_data_pag().." dias]"
|
||||
.."label[0,2.5;Faltam "..terrenos.formspec_data_rest(minetest.deserialize(meta:get_string("ultimo_pagamento"))).." dias]"
|
||||
.."button_exit[0,3.25;6,1;aluguel;Pagar Aluguel]"
|
||||
|
||||
minetest.show_formspec(name, "terrenos:ocupado", formspec)
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
-- Receptor de botoes
|
||||
minetest.register_on_player_receive_fields(function(player, formname, fields)
|
||||
|
||||
-- Placa "desconfigurado"
|
||||
if formname == "terrenos:desconfigurado" then
|
||||
local name = player:get_player_name()
|
||||
|
||||
if fields.configurar then
|
||||
|
||||
-- Verificar dados
|
||||
if tonumber(fields.custo) == nil then
|
||||
return minetest.chat_send_player(name, "Custo invalido")
|
||||
elseif tonumber(fields.altura) == nil then
|
||||
return minetest.chat_send_player(name, "Altura invalida")
|
||||
elseif terrenos.lugar1[name] == nil then
|
||||
return minetest.chat_send_player(name, "Defina o primeiro ponto do terreno")
|
||||
elseif terrenos.lugar2[name] == nil then
|
||||
return minetest.chat_send_player(name, "Defina o segundo ponto do terreno")
|
||||
end
|
||||
|
||||
local pos = terrenos.ultima_placa[name]
|
||||
|
||||
-- Trocar placa
|
||||
terrenos.trocar_node(pos, "terrenos:livre")
|
||||
|
||||
-- Configurar placa
|
||||
local meta = minetest.get_meta(pos)
|
||||
meta:set_string("infotext", "Terreno a Venda")
|
||||
meta:set_string("status", "livre")
|
||||
meta:set_float("custo", tonumber(fields.custo))
|
||||
meta:set_float("altura", tonumber(fields.altura))
|
||||
terrenos.lugar2[name].y = terrenos.lugar2[name].y + fields.altura -- Ajuste de altura
|
||||
local pos1, pos2 = terrenos.ajustar_pos(terrenos.lugar1[name], terrenos.lugar2[name])
|
||||
local ref1, ref2 = terrenos.gerar_ref(pos, pos1, pos2)
|
||||
meta:set_string("ref1", minetest.serialize(ref1))
|
||||
meta:set_string("ref2", minetest.serialize(ref2))
|
||||
|
||||
-- Limpar terreno para estado inicial
|
||||
terrenos.limpar(pos1, pos2, minetest.get_node({x=pos.x, y=pos.y-1, z=pos.z}).name)
|
||||
|
||||
-- Zerar coordenadas rapidas
|
||||
terrenos.lugar1[name] = nil
|
||||
terrenos.lugar2[name] = nil
|
||||
end
|
||||
|
||||
-- Placa "livre"
|
||||
elseif formname == "terrenos:livre" then
|
||||
local name = player:get_player_name()
|
||||
|
||||
if fields.comprar then
|
||||
|
||||
local pos = terrenos.ultima_placa[name]
|
||||
local meta = minetest.get_meta(pos)
|
||||
|
||||
-- Verificar se jogador consegue comprar
|
||||
if terrenos.cobrar(player, {name=terrenos.var.pag, count=meta:get_float("custo")}) == false then
|
||||
return minetest.chat_send_player(name, "Nao consegues pagar o terreno. Precisas de mais "..terrenos.var.pag_desc)
|
||||
end
|
||||
|
||||
local pos1, pos2 = terrenos.pegar_pos(pos, minetest.deserialize(meta:get_string("ref1")), minetest.deserialize(meta:get_string("ref2")))
|
||||
|
||||
-- Trocar placa
|
||||
terrenos.trocar_node(pos, "terrenos:ocupado")
|
||||
local meta = minetest.get_meta(pos)
|
||||
meta:set_string("infotext", "Terreno de "..name)
|
||||
meta:set_string("status", "ocupado")
|
||||
meta:set_string("dono", name)
|
||||
meta:set_string("ultimo_pagamento", minetest.serialize({terrenos.pegar_data_atual()}))
|
||||
meta:set_float("area_id", terrenos.proteger_area(name, "Terreno", pos1, pos2)) -- Protege area
|
||||
|
||||
end
|
||||
|
||||
-- Placa "ocupado"
|
||||
elseif formname == "terrenos:ocupado" then
|
||||
local name = player:get_player_name()
|
||||
|
||||
if fields.remover then
|
||||
|
||||
local pos = terrenos.ultima_placa[name]
|
||||
local meta = minetest.get_meta(pos)
|
||||
|
||||
local pos1, pos2 = terrenos.pegar_pos(pos, minetest.deserialize(meta:get_string("ref1")), minetest.deserialize(meta:get_string("ref2")))
|
||||
|
||||
terrenos.desproteger_area(meta:get_string("area_id"))
|
||||
|
||||
terrenos.limpar(pos1, pos2, minetest.get_node({x=pos.x, y=pos.y-1, z=pos.z}).name)
|
||||
|
||||
terrenos.desocupar_placa(pos)
|
||||
|
||||
elseif fields.podar then
|
||||
|
||||
local pos = terrenos.ultima_placa[name]
|
||||
local meta = minetest.get_meta(pos)
|
||||
|
||||
local pos1, pos2 = terrenos.pegar_pos(pos, minetest.deserialize(meta:get_string("ref1")), minetest.deserialize(meta:get_string("ref2")))
|
||||
|
||||
terrenos.podar(pos1, pos2)
|
||||
|
||||
elseif fields.aluguel then
|
||||
|
||||
local pos = terrenos.ultima_placa[name]
|
||||
local meta = minetest.get_meta(pos)
|
||||
|
||||
-- Verificar se ja pagou hoje
|
||||
local data_pag = minetest.deserialize(meta:get_string("ultimo_pagamento"))
|
||||
if terrenos.comparar_data(data_pag[1], data_pag[2], data_pag[3], data_pag[4], data_pag[5]) < 1 then
|
||||
return minetest.chat_send_player(name, "Aluguei ja foi pago hoje")
|
||||
end
|
||||
|
||||
-- Verificar se jogador consegue pagar aluguel
|
||||
if terrenos.cobrar(player, {name=terrenos.var.pag, count=meta:get_float("custo")}) == false then
|
||||
return minetest.chat_send_player(name, "Nao consegues pagar o aluguel. Precisas de mais "..terrenos.var.pag_desc)
|
||||
end
|
||||
|
||||
-- Atualiza data de pagamento
|
||||
meta:set_string("ultimo_pagamento", minetest.serialize({terrenos.pegar_data_atual()}))
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end)
|
||||
|
||||
|
|
@ -0,0 +1,55 @@
|
|||
--[[
|
||||
Mod Terrenos 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/>.
|
||||
|
||||
Limpar terreno
|
||||
]]
|
||||
|
||||
-- Limpa o terreno
|
||||
terrenos.limpar = function(pos1, pos2, nodename)
|
||||
|
||||
if pos1.x > pos2.x then -- Mantendo pos1 com o menor x
|
||||
local aux = pos1.x
|
||||
pos1.x = pos2.x
|
||||
pos2.x = aux
|
||||
end
|
||||
if pos1.z > pos2.z then -- Mantendo pos1 com o menor z
|
||||
local aux = pos1.z
|
||||
pos1.z = pos2.z
|
||||
pos2.z = aux
|
||||
end
|
||||
if pos1.y > pos2.y then -- Mantendo pos1 com o menor z
|
||||
local aux = pos1.y
|
||||
pos1.y = pos2.y
|
||||
pos2.y = aux
|
||||
end
|
||||
|
||||
local pos = {x=pos1.x,y=pos1.y,z=pos1.z}
|
||||
while pos.y <= pos2.y do
|
||||
pos.x = pos1.x
|
||||
while pos.x <= pos2.x do
|
||||
pos.z = pos1.z
|
||||
while pos.z <= pos2.z do
|
||||
minetest.set_node(pos, {name=nodename})
|
||||
pos.z = pos.z + 1
|
||||
end
|
||||
|
||||
pos.x = pos.x + 1
|
||||
end
|
||||
|
||||
nodename = "air"
|
||||
|
||||
pos.y = pos.y + 1
|
||||
end
|
||||
|
||||
-- Colocar 4 estacas nos limites
|
||||
minetest.set_node({x=pos1.x,y=pos1.y+1,z=pos1.z}, {name="default:fence_wood"})
|
||||
minetest.set_node({x=pos2.x,y=pos1.y+1,z=pos1.z}, {name="default:fence_wood"})
|
||||
minetest.set_node({x=pos1.x,y=pos1.y+1,z=pos2.z}, {name="default:fence_wood"})
|
||||
minetest.set_node({x=pos2.x,y=pos1.y+1,z=pos2.z}, {name="default:fence_wood"})
|
||||
end
|
||||
|
|
@ -0,0 +1,92 @@
|
|||
--[[
|
||||
Mod Terrenos 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/>.
|
||||
|
||||
Nodes
|
||||
]]
|
||||
|
||||
-- Placa de Terreno
|
||||
minetest.register_node("terrenos:ocupado", {
|
||||
description = "Placa de Terreno",
|
||||
drawtype = "nodebox",
|
||||
paramtype = "light",
|
||||
paramtype2 = "facedir",
|
||||
walkable = false,
|
||||
drop = "",
|
||||
tiles = {
|
||||
"default_pine_wood.png",
|
||||
"default_pine_wood.png",
|
||||
"default_pine_wood.png",
|
||||
"default_pine_wood.png",
|
||||
"default_pine_wood.png",
|
||||
"default_pine_wood.png^terrenos_ocupado.png"
|
||||
},
|
||||
node_box = {
|
||||
type = "fixed",
|
||||
fixed = {
|
||||
{-0.375, -0.5, 0.125, 0.375, -0.4375, 0.4375}, -- Base
|
||||
{-0.3125, -0.5, 0.25, 0.3125, -0.0625, 0.3125}, -- Placa
|
||||
}
|
||||
},
|
||||
groups = {choppy=2,oddly_breakable_by_hand=2},
|
||||
sounds = default.node_sound_wood_defaults(),
|
||||
on_construct = function(pos)
|
||||
local meta = minetest.get_meta(pos)
|
||||
meta:set_string("infotext", "Placa de Terreno (desconfigurado)")
|
||||
meta:set_string("status", "desconfigurado")
|
||||
end,
|
||||
on_use = function(itemstack, user, pointed_thing)
|
||||
if pointed_thing then
|
||||
local name = user:get_player_name()
|
||||
if terrenos.lugar1[name] == nil then
|
||||
terrenos.lugar1[name] = pointed_thing.under
|
||||
minetest.chat_send_player(name, "Lugar 1 definido")
|
||||
elseif terrenos.lugar2[name] == nil then
|
||||
terrenos.lugar2[name] = pointed_thing.under
|
||||
minetest.chat_send_player(name, "Lugar 2 definido")
|
||||
else
|
||||
terrenos.lugar1[name] = nil
|
||||
terrenos.lugar2[name] = nil
|
||||
minetest.chat_send_player(name, "Lugar 1 e 2 zerados")
|
||||
end
|
||||
end
|
||||
end,
|
||||
on_rightclick = function(pos, node, clicker)
|
||||
terrenos.acessar(clicker, pos)
|
||||
end,
|
||||
})
|
||||
|
||||
-- Placa de Terreno (Livre)
|
||||
minetest.register_node("terrenos:livre", {
|
||||
description = "Placa de Terreno",
|
||||
drawtype = "nodebox",
|
||||
paramtype = "light",
|
||||
paramtype2 = "facedir",
|
||||
walkable = false,
|
||||
drop = "",
|
||||
tiles = {
|
||||
"default_pine_wood.png",
|
||||
"default_pine_wood.png",
|
||||
"default_pine_wood.png",
|
||||
"default_pine_wood.png",
|
||||
"default_pine_wood.png",
|
||||
"default_pine_wood.png^terrenos_livre.png"
|
||||
},
|
||||
node_box = {
|
||||
type = "fixed",
|
||||
fixed = {
|
||||
{-0.3125, -0.5, 0.0625, 0.3125, -0.4375, 0.4375}, -- Base
|
||||
{-0.0625, -0.5, 0.1875, 0.0625, -0.125, 0.3125}, -- Haste
|
||||
{-0.4375, -0.125, 0.1875, 0.4375, 0.5, 0.3125} -- Placa
|
||||
}
|
||||
},
|
||||
groups = {choppy=2,oddly_breakable_by_hand=2},
|
||||
sounds = default.node_sound_wood_defaults(),
|
||||
on_rightclick = function (pos, node, clicker)
|
||||
terrenos.acessar(clicker, pos)
|
||||
end,
|
||||
})
|
|
@ -0,0 +1,55 @@
|
|||
--[[
|
||||
Mod Terrenos 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/>.
|
||||
|
||||
Podar terreno : remover folhas e arvore das laterais e em cima
|
||||
]]
|
||||
|
||||
-- Nodes podáveis
|
||||
local podaveis = {
|
||||
"default:papyrus",
|
||||
"default:tree",
|
||||
"default:jungletree",
|
||||
"default:pine_tree",
|
||||
"default:acacia_tree",
|
||||
"default:apple",
|
||||
"default:cactus"
|
||||
}
|
||||
|
||||
-- Nodes extras para os lados a serem podados
|
||||
local largura_extra = 2
|
||||
local altura_extra = 10
|
||||
|
||||
-- Podar terreno (remove partes de arvores de perto cima e lados do terreno)
|
||||
terrenos.podar = function(pos1, pos2)
|
||||
if pos1.x > pos2.x then -- Mantendo pos1 com o menor x
|
||||
local aux = pos1.x
|
||||
pos1.x = pos2.x
|
||||
pos2.x = aux
|
||||
end
|
||||
if pos1.z > pos2.z then -- Mantendo pos1 com o menor z
|
||||
local aux = pos1.z
|
||||
pos1.z = pos2.z
|
||||
pos2.z = aux
|
||||
end
|
||||
if pos1.y > pos2.y then -- Mantendo pos1 com o menor z
|
||||
local aux = pos1.y
|
||||
pos1.y = pos2.y
|
||||
pos2.y = aux
|
||||
end
|
||||
-- Pega todos os nodes na area em volta do terreno
|
||||
local nodes = minetest.find_nodes_in_area(
|
||||
{x=pos1.x-largura_extra, y=pos1.y, z=pos1.z-largura_extra},
|
||||
{x=pos2.x+largura_extra, y=pos2.y+altura_extra, z=pos2.z+largura_extra},
|
||||
podaveis
|
||||
)
|
||||
|
||||
-- Remove todos os nodes pegos
|
||||
for i, pos in ipairs(nodes) do
|
||||
minetest.remove_node(pos)
|
||||
end
|
||||
end
|
|
@ -0,0 +1,44 @@
|
|||
--[[
|
||||
Mod Terrenos 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/>.
|
||||
|
||||
Proteger area
|
||||
]]
|
||||
|
||||
-- Proteger area para o jogador
|
||||
terrenos.proteger_area = function(ownername, areaname, pos1, pos2)
|
||||
|
||||
if pos1 and pos2 then
|
||||
pos1, pos2 = areas:sortPos(pos1, pos2)
|
||||
else
|
||||
return false
|
||||
end
|
||||
|
||||
if not areas:player_exists(ownername) then
|
||||
return false
|
||||
end
|
||||
|
||||
minetest.log("action", "Area registrada por compra de terreno. 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
|
||||
|
||||
-- Remover area protegida
|
||||
terrenos.desproteger_area = function(id)
|
||||
local id = tonumber(id)
|
||||
|
||||
areas:remove(id)
|
||||
areas:save()
|
||||
return true
|
||||
end
|
||||
|
Binary file not shown.
After Width: | Height: | Size: 248 B |
Binary file not shown.
After Width: | Height: | Size: 259 B |
|
@ -0,0 +1,25 @@
|
|||
--[[
|
||||
Mod Terrenos 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/>.
|
||||
|
||||
Trocar node
|
||||
]]
|
||||
|
||||
-- Trocar node
|
||||
terrenos.trocar_node = function(pos, nodename)
|
||||
-- Pegar node
|
||||
local node = minetest.get_node(pos)
|
||||
-- Pegar metadados
|
||||
local metadados = minetest.get_meta(pos):to_table()
|
||||
-- Troca o nome
|
||||
node.name = nodename
|
||||
-- Coloca novo node
|
||||
minetest.set_node(pos, node)
|
||||
-- Coloca metadados no novo node
|
||||
minetest.get_meta(pos):from_table(metadados)
|
||||
end
|
||||
|
|
@ -0,0 +1,39 @@
|
|||
--[[
|
||||
Mod Terrenos 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/>.
|
||||
|
||||
Verificador de aluguel
|
||||
]]
|
||||
|
||||
-- Abm's que atualizam as placas
|
||||
minetest.register_abm({
|
||||
label = "verificar terreno",
|
||||
nodenames = {"terrenos:ocupado"},
|
||||
interval = 2,
|
||||
chance = 1,
|
||||
action = function(pos)
|
||||
local meta = minetest.get_meta(pos)
|
||||
|
||||
if meta:get_string("status") == "ocupado" then
|
||||
|
||||
local data_ant = minetest.deserialize(meta:get_string("ultimo_pagamento"))
|
||||
local dif = terrenos.comparar_data(data_ant[1], data_ant[2], data_ant[3], data_ant[4], data_ant[5])
|
||||
|
||||
if dif > terrenos.var.max_dias then
|
||||
local pos1, pos2 = terrenos.pegar_pos(pos, minetest.deserialize(meta:get_string("ref1")), minetest.deserialize(meta:get_string("ref2")))
|
||||
|
||||
terrenos.desproteger_area(meta:get_string("area_id"))
|
||||
|
||||
terrenos.limpar(pos1, pos2, minetest.get_node({x=pos.x, y=pos.y-1, z=pos.z}).name)
|
||||
|
||||
terrenos.desocupar_placa(pos)
|
||||
end
|
||||
|
||||
minetest.chat_send_all("terreno ocupado a "..dif.." dias")
|
||||
end
|
||||
end
|
||||
})
|
Loading…
Reference in New Issue