Update code
|
@ -0,0 +1,82 @@
|
||||||
|
Macromoney API de referencia sem-versão
|
||||||
|
=======================================
|
||||||
|
|
||||||
|
|
||||||
|
Summary
|
||||||
|
-------
|
||||||
|
* Introdução
|
||||||
|
* Operações gerais
|
||||||
|
* Funcionalidades
|
||||||
|
* Métodos
|
||||||
|
* Tabelas globais
|
||||||
|
* Definições de tabelas
|
||||||
|
|
||||||
|
|
||||||
|
Introdução
|
||||||
|
----------
|
||||||
|
O objetivo principal dessa documentação é tornar facil o entendimento
|
||||||
|
e a utilização dos métodos do sistema macromoney.
|
||||||
|
|
||||||
|
|
||||||
|
Operações gerais
|
||||||
|
----------------
|
||||||
|
Esse sistema é basicamente um registrador de valores em um banco de
|
||||||
|
dados separado do banco de dados do servidor. É possivel que outras
|
||||||
|
modificações registrem sua propria moeda ou outro registro semelhante.
|
||||||
|
|
||||||
|
|
||||||
|
Funcionalidades
|
||||||
|
---------------
|
||||||
|
Veja aqui algumas das coisas úteis em macromoney
|
||||||
|
|
||||||
|
#### Salvando dados das contas
|
||||||
|
As contas ficam salvas na pasta ´macronodes´ dentro da pasta do mundo
|
||||||
|
correspondente bastando apenas copiar a pasta para obter os dados e
|
||||||
|
coloca-lo no mundo onde quiser no futuro. Lembre-se de manter as mesmas
|
||||||
|
contas no mundo pois a conta no sistema macromoney corresponde aos
|
||||||
|
jogadores ativos no servidor.
|
||||||
|
|
||||||
|
#### Registrando novos valores
|
||||||
|
É possivel criar novos valores (moedas, medalahs, xp, etc).
|
||||||
|
Mas lembresse que os dados de todas os valores registrados ficarão salvos
|
||||||
|
junto, mas caso um valor será desativado futuramente não há problema em
|
||||||
|
usar o mesmo banco de dados pois os registros do valor ficaram inacessiveis
|
||||||
|
no banco de dados.
|
||||||
|
|
||||||
|
|
||||||
|
Métodos
|
||||||
|
-------
|
||||||
|
Veja os métodos de acordo com sua finalidade.
|
||||||
|
|
||||||
|
#### Registrar valores
|
||||||
|
* `macromoney.register_value(value_id, {definições de valor})`: Register value
|
||||||
|
|
||||||
|
#### Manipular valores em contas
|
||||||
|
* `macromoney.get_account(player_name, value_id)`: Pega um valor em uma conta
|
||||||
|
* `macromoney.add_account(player_name, value_id, add_value)`: Adiciona um valor em uma conta
|
||||||
|
* `macromoney.subtract_account(player_name, value_id, subtract_value)`: Subtrai um valor em uma conta
|
||||||
|
* `macromoney.exist_account(player_name)`: Verifica se uma conta existe
|
||||||
|
|
||||||
|
|
||||||
|
Tabela global
|
||||||
|
-------------
|
||||||
|
* `macromoney.registered_values`: Valores registrados, indexado pelo ID do valor
|
||||||
|
|
||||||
|
|
||||||
|
Definições de tabelas
|
||||||
|
---------------------
|
||||||
|
|
||||||
|
### Definições de valor (`register_value`)
|
||||||
|
{
|
||||||
|
description = "Macro money", -- Descrição do valor
|
||||||
|
specimen_prefix = "M¢", -- Prefixo do valor moeda (exemplo: $, £, etc)
|
||||||
|
specimen_name = "Macro", -- Nome da moeda. Não é recomendado usar 'specimen_prefix' e 'specimen_name' simultaneamente. Escolha só um deles.
|
||||||
|
value_type = "number", -- Tipo de valor. Apenas "number" para valores numéricos.
|
||||||
|
initial_value = 0, -- Valor inicial
|
||||||
|
tag = "money", -- Termo simples para ser usado em comandos de console
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
62
README.md
|
@ -1,54 +1,32 @@
|
||||||
# Macromoney v1.0.0
|
# Macromoney
|
||||||
|
|
||||||
[![Baixar](https://img.shields.io/badge/Baixar-v1.0.0-green.svg)](https://github.com/BrunoMine/macromoney/archive/v1.0.0.zip)
|
[![download](https://img.shields.io/github/tag/BrunoMine/fine_mobs.svg?style=flat-square&label=release)](https://github.com/BrunoMine/cow/archive/master.zip)
|
||||||
[![Projeto](https://img.shields.io/badge/Git-Projeto-green.svg)](https://github.com/BrunoMine/macromoney)
|
[![Git](https://img.shields.io/badge/Git-Projeto-green.svg)](https://github.com/BrunoMine/macromoney)
|
||||||
[![!Bower](https://img.shields.io/badge/Bower-Projeto-green.svg)](https://minetest-bower.herokuapp.com/mods/macromoney)
|
[![Bower](https://img.shields.io/badge/Bower-Projeto-green.svg)](https://minetest-bower.herokuapp.com/mods/macromoney)
|
||||||
[![Licença](https://img.shields.io/badge/Licença-LGPL_v3.0-blue.svg)](https://github.com/BrunoMine/macromoney/blob/master/LICENSE)
|
[![Forum](https://img.shields.io/badge/minetest-mod-green.svg?style=flat-square)](https://forum.minetest.net)
|
||||||
|
[![License](https://img.shields.io/badge/Licença-LGPL_v3.0-blue.svg)](https://github.com/BrunoMine/macromoney/blob/master/LICENSE)
|
||||||
|
|
||||||
## Descrição
|
## Description
|
||||||
Cria sistema contas de dinheiro e medalhas
|
Creates monetary system on the server
|
||||||
* Sistema dinheiro
|
|
||||||
* Sistema de medalhas
|
|
||||||
* Vinculação de contas no fórum
|
|
||||||
|
|
||||||
## Recursos do projeto
|
## Requirements
|
||||||
|
* Minetest 0.5.1 or higher
|
||||||
|
* default mod
|
||||||
|
* dye mod
|
||||||
|
|
||||||
* [Baixar](https://github.com/BrunoMine/macromoney/archive/v1.0.0.zip)
|
## License
|
||||||
* [Projeto](https://github.com/BrunoMine/macromoney)
|
See LICENSE.txt for more info about LGPL 3.0 license
|
||||||
* [Bower](https://minetest-bower.herokuapp.com/mods/macromoney)
|
|
||||||
|
|
||||||
## Requisitos
|
### Authors of the source code
|
||||||
|
Originally by BrunoMine, Bruno Borges <borgesdossantosbruno@gmail.com> (LGPL 3.0)
|
||||||
|
|
||||||
* Minetest 0.4.15 ou superior
|
### Authors of media (textures, models and sonds)
|
||||||
* Mod default
|
All that are not described here are authored by
|
||||||
* Mod dye
|
|
||||||
|
|
||||||
## Comandos
|
|
||||||
|
|
||||||
* `/forum <NickForum>` : Vincula a conta ao nick de um forum
|
|
||||||
* `/macomoney <operação>` : Manipula contas
|
|
||||||
|
|
||||||
## Banco de dados
|
|
||||||
Todos os dados do mod ficam salvos na pasta `macromoney` na pasta do mundo
|
|
||||||
|
|
||||||
## Privilégios
|
|
||||||
|
|
||||||
* `macromoney` : Administrador de contas
|
|
||||||
|
|
||||||
## Licença
|
|
||||||
Veja LICENSE.txt para informações detalhadas da licença LGPL 3.0
|
|
||||||
|
|
||||||
### Autores do código fonte
|
|
||||||
Originalmente por kotolegokot, (GPL v2)
|
|
||||||
Modificado por BrunoMine, Bruno Borges <borgesdossantosbruno@gmail.com> (LGPL 3.0)
|
|
||||||
|
|
||||||
### Autores de mídias (texturas, modelos and sons)
|
|
||||||
Todos que não estao listados aqui:
|
|
||||||
BrunoMine, Bruno Borges <borgesdossantosbruno@gmail.com> (CC BY-SA 3.0)
|
BrunoMine, Bruno Borges <borgesdossantosbruno@gmail.com> (CC BY-SA 3.0)
|
||||||
|
|
||||||
Desconhecido (C00)
|
Desconhecido (C00)
|
||||||
macromoney_erro.ogg
|
macromoney_error.ogg
|
||||||
macromoney_maquina_shop.ogg
|
macromoney_machine.ogg
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,124 @@
|
||||||
|
--[[
|
||||||
|
Mod Minemacro 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/>.
|
||||||
|
|
||||||
|
API
|
||||||
|
]]
|
||||||
|
|
||||||
|
-- Basic methods
|
||||||
|
|
||||||
|
-- Exists account
|
||||||
|
macromoney.exist_account = function(name)
|
||||||
|
return macromoney.db.exist(name)
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Exists account value
|
||||||
|
macromoney.exist_account_value = function(name, value_type)
|
||||||
|
local data = macromoney.db.get(name)
|
||||||
|
if data[value_type] ~= nil then
|
||||||
|
return true
|
||||||
|
else
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Set
|
||||||
|
macromoney.set_account = function(name, value_type, new_value)
|
||||||
|
local data = macromoney.db.get(name)
|
||||||
|
data[value_type] = new_value
|
||||||
|
return macromoney.db.set(name, data)
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Get
|
||||||
|
macromoney.get_account = function(name, value_type)
|
||||||
|
return macromoney.db.get(name)[value_type]
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Add
|
||||||
|
macromoney.add_account = function(name, value_type, add_value)
|
||||||
|
local data = macromoney.db.get(name)
|
||||||
|
data[value_type] = data[value_type] + add_value
|
||||||
|
macromoney.db.set(name, data)
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Subtract
|
||||||
|
macromoney.subtract_account = function(name, value_type, subtract_value)
|
||||||
|
local data = macromoney.db.get(name)
|
||||||
|
data[value_type] = data[value_type] - subtract_value
|
||||||
|
macromoney.db.set(name, data)
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
-- Tags
|
||||||
|
macromoney.tags = {}
|
||||||
|
|
||||||
|
|
||||||
|
-- Registered values
|
||||||
|
macromoney.registered_values = {}
|
||||||
|
|
||||||
|
-- Register value
|
||||||
|
macromoney.register_value = function(value_id, def)
|
||||||
|
macromoney.registered_values[value_id] = def
|
||||||
|
|
||||||
|
-- Tag
|
||||||
|
if def.tag then
|
||||||
|
macromoney.tags[def.tag] = value_id
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Get text value
|
||||||
|
macromoney.get_text_number_value = function(value_id, value)
|
||||||
|
local def = macromoney.registered_values[value_id]
|
||||||
|
local prefix = def.specimen_prefix or ""
|
||||||
|
local text
|
||||||
|
|
||||||
|
-- Number type
|
||||||
|
if def.value_type == "number" then
|
||||||
|
|
||||||
|
-- Positive balance
|
||||||
|
if value > 0 then
|
||||||
|
text = minetest.colorize("#07ff07", prefix .. value)
|
||||||
|
|
||||||
|
-- Negative balance
|
||||||
|
elseif value < 0 then
|
||||||
|
text = minetest.colorize("#ff0707", "-" .. prefix .. math.abs(value))
|
||||||
|
|
||||||
|
-- Zero
|
||||||
|
else
|
||||||
|
text = prefix .. value
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Text type
|
||||||
|
else
|
||||||
|
text = value
|
||||||
|
end
|
||||||
|
|
||||||
|
return text
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Check and register player accounts
|
||||||
|
minetest.register_on_joinplayer(function(player)
|
||||||
|
if not player then return end
|
||||||
|
local name = player:get_player_name()
|
||||||
|
for value_id,def in pairs(macromoney.registered_values) do
|
||||||
|
|
||||||
|
-- Check if exist account
|
||||||
|
if macromoney.exist_account(name) == false then
|
||||||
|
-- Set all registered value
|
||||||
|
local data = {}
|
||||||
|
for value_id,def in pairs(macromoney.registered_values) do
|
||||||
|
data[value_id] = def.initial_value
|
||||||
|
end
|
||||||
|
macromoney.db.set(name, data)
|
||||||
|
break
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Add remaning values
|
||||||
|
if macromoney.exist_account_value(name, value_id) == false then
|
||||||
|
macromoney.set_account(name, value_id, def.initial_value)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end)
|
|
@ -10,9 +10,9 @@
|
||||||
|
|
||||||
]]
|
]]
|
||||||
|
|
||||||
-- Caixa de Banco
|
-- Money machine
|
||||||
minetest.register_node("macromoney:caixa_de_banco", {
|
minetest.register_node("macromoney:atm", {
|
||||||
description = "Caixa de Banco (Depositos e Saques)",
|
description = "Automatic Teller Machine",
|
||||||
drawtype = "nodebox",
|
drawtype = "nodebox",
|
||||||
paramtype = "light",
|
paramtype = "light",
|
||||||
paramtype2 = "facedir",
|
paramtype2 = "facedir",
|
||||||
|
@ -20,12 +20,12 @@ minetest.register_node("macromoney:caixa_de_banco", {
|
||||||
sunlight_propagates = true,
|
sunlight_propagates = true,
|
||||||
light_source = LIGHT_MAX,
|
light_source = LIGHT_MAX,
|
||||||
tiles = {
|
tiles = {
|
||||||
"default_wood.png", -- Cima
|
"default_wood.png", -- Top
|
||||||
"default_wood.png", -- Baixo
|
"default_wood.png", -- Bottom
|
||||||
"default_wood.png", -- Lado direito
|
"default_wood.png", -- Right
|
||||||
"default_wood.png", -- Lado esquerda
|
"default_wood.png", -- Left
|
||||||
"default_wood.png", -- Fundo
|
"default_wood.png", -- Back
|
||||||
"macromoney_caixa_frente.png" -- Frente
|
"macromoney_caixa_frente.png" -- Front
|
||||||
},
|
},
|
||||||
node_box = {
|
node_box = {
|
||||||
type = "fixed",
|
type = "fixed",
|
||||||
|
@ -47,37 +47,50 @@ minetest.register_node("macromoney:caixa_de_banco", {
|
||||||
local formspec = "size[8,5.5;]"
|
local formspec = "size[8,5.5;]"
|
||||||
..default.gui_bg
|
..default.gui_bg
|
||||||
..default.gui_bg_img
|
..default.gui_bg_img
|
||||||
.."label[0.256,0;Voce pode Depositar ou Sacar 100 Macros]"
|
.."label[0.256,0;You can deposit or withdraw "..macromoney.get_text_number_value("macromoney:money", 100).."]"
|
||||||
.."button[1,0.5;2,1;sacar;Sacar]"
|
.."button[1,0.5;2,1;withdraw;Withdraw]"
|
||||||
.."button[5,0.5;2,1;depositar;Depositar]"
|
.."button[5,0.5;2,1;deposit;Deposit]"
|
||||||
.."list[current_player;main;0,1.5;8,4;]"
|
.."list[current_player;main;0,1.5;8,4;]"
|
||||||
|
|
||||||
minetest.show_formspec(player:get_player_name(), "macromoney:caixa_de_banco", formspec)
|
minetest.show_formspec(player:get_player_name(), "macromoney:atm", formspec)
|
||||||
end,
|
end,
|
||||||
})
|
})
|
||||||
|
|
||||||
-- Receber campos
|
-- Receive fields
|
||||||
minetest.register_on_player_receive_fields(function(player, formname, fields)
|
minetest.register_on_player_receive_fields(function(player, formname, fields)
|
||||||
if formname == "macromoney:caixa_de_banco" then
|
if formname == "macromoney:atm" then
|
||||||
if fields.sacar then
|
|
||||||
|
-- Withdraw
|
||||||
|
if fields.withdraw then
|
||||||
local player_name = player:get_player_name()
|
local player_name = player:get_player_name()
|
||||||
local player_inv = player:get_inventory()
|
local player_inv = player:get_inventory()
|
||||||
|
|
||||||
|
-- Check inventory
|
||||||
if not player_inv:room_for_item("main", "macromoney:macro 100") then
|
if not player_inv:room_for_item("main", "macromoney:macro 100") then
|
||||||
minetest.chat_send_player(player_name, "Inventario Lotado")
|
minetest.chat_send_player(player_name, "Crowded inventory")
|
||||||
return true
|
return true
|
||||||
elseif macromoney.subtrair(player_name, "macros", 100) == false then
|
|
||||||
minetest.chat_send_player(player_name, "Voce nao tem Macros suficientes na conta.")
|
-- Check account balance
|
||||||
|
elseif macromoney.get_account(player_name, "macromoney:money") < 100 then
|
||||||
|
minetest.chat_send_player(player_name, "Insufficient balance for this operation.")
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
|
|
||||||
|
macromoney.subtract_account(player_name, "macromoney:money", 100)
|
||||||
player_inv:add_item("main", "macromoney:macro 100")
|
player_inv:add_item("main", "macromoney:macro 100")
|
||||||
elseif fields.depositar then
|
|
||||||
|
-- Deposit
|
||||||
|
elseif fields.deposit then
|
||||||
local player_name = player:get_player_name()
|
local player_name = player:get_player_name()
|
||||||
local player_inv = player:get_inventory()
|
local player_inv = player:get_inventory()
|
||||||
|
|
||||||
|
-- Check inventory
|
||||||
if not player_inv:contains_item("main", "macromoney:macro 100") then
|
if not player_inv:contains_item("main", "macromoney:macro 100") then
|
||||||
minetest.chat_send_player(player_name, "Macros insuficientes para Depositar (tenha ao menos 100 Macros)")
|
minetest.chat_send_player(player_name, "You have enough money in your inventory.")
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
macromoney.somar(player_name, "macros", 100)
|
|
||||||
|
macromoney.add_account(player_name, "macromoney:money", 100)
|
||||||
player_inv:remove_item("main", "macromoney:macro 100")
|
player_inv:remove_item("main", "macromoney:macro 100")
|
||||||
end
|
end
|
||||||
end
|
end
|
|
@ -1,225 +0,0 @@
|
||||||
--[[
|
|
||||||
Mod Macromoney 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/>.
|
|
||||||
|
|
||||||
Banco de Dados
|
|
||||||
|
|
||||||
]]
|
|
||||||
|
|
||||||
-- Variavel de metodos
|
|
||||||
macromoney = {}
|
|
||||||
|
|
||||||
-- Variavel de Contas
|
|
||||||
local contas = {}
|
|
||||||
|
|
||||||
-- Diretorio do banco de dados
|
|
||||||
local pathbd = minetest.get_worldpath() .. "/macromoney"
|
|
||||||
|
|
||||||
-- Cria o diretorio caso nao exista ainda
|
|
||||||
local function mkdir(pathbd)
|
|
||||||
if minetest.mkdir then
|
|
||||||
minetest.mkdir(pathbd)
|
|
||||||
else
|
|
||||||
os.execute('mkdir "' .. pathbd .. '"')
|
|
||||||
end
|
|
||||||
end
|
|
||||||
mkdir(pathbd)
|
|
||||||
|
|
||||||
-- Carregar uma conta na memoria
|
|
||||||
local carregar_conta = function(name)
|
|
||||||
local input = io.open(pathbd .. "/conta_de_"..name, "r")
|
|
||||||
if input then
|
|
||||||
contas[name] = minetest.deserialize(input:read("*l"))
|
|
||||||
io.close(input)
|
|
||||||
return true
|
|
||||||
else
|
|
||||||
return false
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
-- Remover uma conta da memoria
|
|
||||||
local descarregar_conta = function(name)
|
|
||||||
contas[name] = nil
|
|
||||||
end
|
|
||||||
|
|
||||||
-- Salvar uma conta
|
|
||||||
local salvar_conta = function(name)
|
|
||||||
if not contas[name] then return false end
|
|
||||||
local output = io.open(pathbd .. "/conta_de_"..name, "w")
|
|
||||||
output:write(minetest.serialize(contas[name]))
|
|
||||||
io.close(output)
|
|
||||||
return true
|
|
||||||
end
|
|
||||||
|
|
||||||
-- Forçar carregamento temporario
|
|
||||||
local carregar_temporario = function(name)
|
|
||||||
minetest.after(TEMPO_CARREGAMENTO_TEMPORARIO, descarregar_conta, name)
|
|
||||||
return carregar_conta(name)
|
|
||||||
end
|
|
||||||
|
|
||||||
|
|
||||||
--
|
|
||||||
-----
|
|
||||||
--------
|
|
||||||
-- Metodos globais
|
|
||||||
--
|
|
||||||
-- Definir valores na conta
|
|
||||||
function macromoney.definir(name, tipo_v, valor)
|
|
||||||
if not contas[name] then
|
|
||||||
if carregar_temporario(name) == false then
|
|
||||||
return false
|
|
||||||
end
|
|
||||||
end
|
|
||||||
if not tipo_v or not valor then return false end
|
|
||||||
if tipo_v == "macros" then -- Macros
|
|
||||||
if tonumber(valor) then
|
|
||||||
contas[name].macros = tonumber(valor)
|
|
||||||
return salvar_conta(name)
|
|
||||||
end
|
|
||||||
elseif tipo_v == "medalhas" then -- Medalhas
|
|
||||||
if tonumber(valor) then
|
|
||||||
contas[name].medalhas = tonumber(valor)
|
|
||||||
return salvar_conta(name)
|
|
||||||
end
|
|
||||||
elseif tipo_v == "forum" then -- Nick no forum
|
|
||||||
if tostring(valor) then
|
|
||||||
contas[name].forum = tostring(valor)
|
|
||||||
return salvar_conta(name)
|
|
||||||
end
|
|
||||||
else
|
|
||||||
return false
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
-- Somar valores na conta
|
|
||||||
function macromoney.somar(name, tipo_v, valor)
|
|
||||||
if not contas[name] then
|
|
||||||
if carregar_temporario(name) == false then
|
|
||||||
return false
|
|
||||||
end
|
|
||||||
end
|
|
||||||
if not tipo_v or not valor then return false end
|
|
||||||
if tipo_v == "macros" then -- Macros
|
|
||||||
if tonumber(valor) then
|
|
||||||
contas[name].macros = contas[name].macros + tonumber(valor)
|
|
||||||
return salvar_conta(name)
|
|
||||||
end
|
|
||||||
|
|
||||||
elseif tipo_v == "medalhas" then -- Medalhas
|
|
||||||
if tonumber(valor) then
|
|
||||||
contas[name].medalhas = contas[name].medalhas + tonumber(valor)
|
|
||||||
return salvar_conta(name)
|
|
||||||
end
|
|
||||||
else
|
|
||||||
return false
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
-- Subtrair valores na conta
|
|
||||||
function macromoney.subtrair(name, tipo_v, valor, confisco)
|
|
||||||
if not contas[name] then
|
|
||||||
if carregar_temporario(name) == false then
|
|
||||||
return false
|
|
||||||
end
|
|
||||||
end
|
|
||||||
if not tipo_v or not valor then return false end
|
|
||||||
if tipo_v == "macros" then -- Macros
|
|
||||||
if contas[name].macros < tonumber(valor) then
|
|
||||||
if confisco then
|
|
||||||
contas[name].macros = 0
|
|
||||||
else
|
|
||||||
return false
|
|
||||||
end
|
|
||||||
else
|
|
||||||
contas[name].macros = contas[name].macros - tonumber(valor)
|
|
||||||
end
|
|
||||||
|
|
||||||
return salvar_conta(name)
|
|
||||||
elseif tipo_v == "medalhas" then -- Medalhas
|
|
||||||
if tonumber(valor) then
|
|
||||||
if contas[name].macros < tonumber(valor) then
|
|
||||||
if confisco then
|
|
||||||
contas[name].medalhas = 0
|
|
||||||
else
|
|
||||||
return false
|
|
||||||
end
|
|
||||||
else
|
|
||||||
contas[name].medalhas = contas[name].medalhas - tonumber(valor)
|
|
||||||
end
|
|
||||||
|
|
||||||
return salvar_conta(name)
|
|
||||||
end
|
|
||||||
else
|
|
||||||
return false
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
-- Consultar valores de conta
|
|
||||||
function macromoney.consultar(name, tipo_v)
|
|
||||||
if not contas[name] then
|
|
||||||
if carregar_temporario(name) == false then
|
|
||||||
return false
|
|
||||||
end
|
|
||||||
end
|
|
||||||
if not tipo_v then return false end
|
|
||||||
if tipo_v == "macros" then -- Macros
|
|
||||||
return contas[name].macros
|
|
||||||
elseif tipo_v == "medalhas" then
|
|
||||||
return contas[name].medalhas
|
|
||||||
elseif tipo_v == "forum" then
|
|
||||||
return contas[name].forum
|
|
||||||
else
|
|
||||||
return false
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
-- Verificar se uma conta existe
|
|
||||||
function macromoney.existe(name)
|
|
||||||
local input = io.open(pathbd .. "/conta_de_"..name, "r")
|
|
||||||
if input then
|
|
||||||
return true
|
|
||||||
else
|
|
||||||
return false
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
--
|
|
||||||
-- Fim dos metodos globais
|
|
||||||
--------
|
|
||||||
-----
|
|
||||||
--
|
|
||||||
|
|
||||||
-- Registrar novos jogadores
|
|
||||||
minetest.register_on_newplayer(function(player)
|
|
||||||
local name = player:get_player_name()
|
|
||||||
contas[name] = {
|
|
||||||
macros = 0,
|
|
||||||
medalhas = 0,
|
|
||||||
forum = ""
|
|
||||||
}
|
|
||||||
salvar_conta(name)
|
|
||||||
end)
|
|
||||||
|
|
||||||
-- Carregar dados quando o jogador conecta no servidor
|
|
||||||
minetest.register_on_joinplayer(function(player)
|
|
||||||
if macromoney.existe(player:get_player_name()) then
|
|
||||||
carregar_conta(player:get_player_name())
|
|
||||||
else
|
|
||||||
contas[player:get_player_name()] = {
|
|
||||||
macros = 0,
|
|
||||||
medalhas = 0,
|
|
||||||
forum = ""
|
|
||||||
}
|
|
||||||
salvar_conta(player:get_player_name())
|
|
||||||
end
|
|
||||||
end)
|
|
||||||
|
|
||||||
-- Remover dados da memoria quando o jogador desconecta do servidor
|
|
||||||
minetest.register_on_leaveplayer(function(player)
|
|
||||||
descarregar_conta(player:get_player_name())
|
|
||||||
end)
|
|
||||||
|
|
176
comandos.lua
|
@ -1,176 +0,0 @@
|
||||||
--[[
|
|
||||||
Mod Macromoney 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/>.
|
|
||||||
|
|
||||||
Comandos
|
|
||||||
|
|
||||||
]]
|
|
||||||
|
|
||||||
minetest.register_privilege("macromoney", "Manipular contas")
|
|
||||||
|
|
||||||
-- Definir o nick no forum
|
|
||||||
minetest.register_chatcommand("forum", {
|
|
||||||
privs = {},
|
|
||||||
params = "<nick_no_forum>",
|
|
||||||
description = "Informa seu nickname no forum da comunidade minetest brasil",
|
|
||||||
func = function(name, param)
|
|
||||||
if param then
|
|
||||||
if macromoney.definir(name, "forum", param) then
|
|
||||||
minetest.chat_send_player(name, "Obrigado por nos informar sua conta no forum")
|
|
||||||
else
|
|
||||||
minetest.chat_send_player(name, "Falha ao registrar nick. (Erro interno. Avise um administrador)")
|
|
||||||
end
|
|
||||||
else
|
|
||||||
minetest.chat_send_player(name, "Nenhuma conta especificada")
|
|
||||||
end
|
|
||||||
end
|
|
||||||
})
|
|
||||||
|
|
||||||
-- Registration "macromoney" command.
|
|
||||||
minetest.register_chatcommand("macromoney", {
|
|
||||||
privs = {macromoney=true},
|
|
||||||
params = "[<conta> | tirar/somar/definir <quantia> macros/medalhas <conta>]",
|
|
||||||
description = "Operar contas",
|
|
||||||
func = function(name, param)
|
|
||||||
|
|
||||||
-- Consultar propria conta
|
|
||||||
if param == "" then --/macromoney
|
|
||||||
if macromoney.existe(name) then
|
|
||||||
minetest.chat_send_player(name, "Sua conta Conta")
|
|
||||||
minetest.chat_send_player(name, "Macros: " .. macromoney.consultar(name, "macros"))
|
|
||||||
minetest.chat_send_player(name, "Medalhas: " .. macromoney.consultar(name, "medalhas"))
|
|
||||||
minetest.chat_send_player(name, "Registro no forum: " .. macromoney.consultar(name, "forum"))
|
|
||||||
return true
|
|
||||||
else
|
|
||||||
minetest.chat_send_player(name, "Sua conta nao existe (Erro interno)")
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
local m = string.split(param, " ")
|
|
||||||
local param1, param2, param3, param4 = m[1], m[2], m[3], m[4]
|
|
||||||
|
|
||||||
-- Consultar conta de outro
|
|
||||||
if param1 and not param2 then --/macromoney <conta>
|
|
||||||
-- Verificar se existe
|
|
||||||
if macromoney.existe(param1) then
|
|
||||||
minetest.chat_send_player(name, "Conta " .. param1)
|
|
||||||
minetest.chat_send_player(name, "Macros: " .. macromoney.consultar(param1, "macros"))
|
|
||||||
minetest.chat_send_player(name, "Medalhas: " .. macromoney.consultar(param1, "medalhas"))
|
|
||||||
minetest.chat_send_player(name, "Registro no forum: " .. macromoney.consultar(param1, "forum"))
|
|
||||||
else
|
|
||||||
minetest.chat_send_player(name, "Conta inexistente")
|
|
||||||
end
|
|
||||||
return true
|
|
||||||
end
|
|
||||||
|
|
||||||
if param1 and param2 and param3 and param4 then
|
|
||||||
|
|
||||||
-- Comando de tirar
|
|
||||||
if param1 == "tirar" then
|
|
||||||
if macromoney.existe(param4) then
|
|
||||||
|
|
||||||
if param3 == "macros" then -- Tirar macros
|
|
||||||
if tonumber(param2) then
|
|
||||||
if macromoney.subtrair(param4, param3, param2) then
|
|
||||||
minetest.chat_send_player(name, "Macros tiradas com sucesso.")
|
|
||||||
else
|
|
||||||
minetest.chat_send_player(name, "O jogador nao tem macros suficientes para tirar tudo isso.")
|
|
||||||
end
|
|
||||||
else
|
|
||||||
minetest.chat_send_player(name, "Voce tem que digitar um valor numerico")
|
|
||||||
end
|
|
||||||
|
|
||||||
elseif param3 == "medalhas" then -- Tirar medalhas
|
|
||||||
if tonumber(param2) then
|
|
||||||
if macromoney.subtrair(param4, param3, param2) then
|
|
||||||
minetest.chat_send_player(name, "Medalhas tiradas com sucesso.")
|
|
||||||
else
|
|
||||||
minetest.chat_send_player(name, "O jogador nao tem medalhas suficientes para tirar tudo isso.")
|
|
||||||
end
|
|
||||||
else
|
|
||||||
minetest.chat_send_player(name, "Voce tem que digitar um valor numerico")
|
|
||||||
end
|
|
||||||
else
|
|
||||||
minetest.chat_send_player(name, "Pode tirar apenas macros ou medalhas")
|
|
||||||
end
|
|
||||||
else
|
|
||||||
minetest.chat_send_player(name, "Jogador inexistente")
|
|
||||||
end
|
|
||||||
return true
|
|
||||||
|
|
||||||
-- Comando de somar
|
|
||||||
elseif param1 == "somar" then
|
|
||||||
if macromoney.existe(param4) then
|
|
||||||
|
|
||||||
if param3 == "macros" then -- Somar macros
|
|
||||||
if tonumber(param2) then
|
|
||||||
if macromoney.somar(param4, param3, param2) then
|
|
||||||
minetest.chat_send_player(name, "Macros somados com sucesso.")
|
|
||||||
else
|
|
||||||
minetest.chat_send_player(name, "Falha ao somar macros. (Erro interno)")
|
|
||||||
end
|
|
||||||
else
|
|
||||||
minetest.chat_send_player(name, "Voce tem que digitar um valor numerico")
|
|
||||||
end
|
|
||||||
|
|
||||||
elseif param3 == "medalhas" then -- Tirar medalhas
|
|
||||||
if tonumber(param2) then
|
|
||||||
if macromoney.somar(param4, param3, param2) then
|
|
||||||
minetest.chat_send_player(name, "Medalhas somados com sucesso.")
|
|
||||||
else
|
|
||||||
minetest.chat_send_player(name, "Falha ao somar medalhas. (Erro interno)")
|
|
||||||
end
|
|
||||||
else
|
|
||||||
minetest.chat_send_player(name, "Voce tem que digitar um valor numerico")
|
|
||||||
end
|
|
||||||
else
|
|
||||||
minetest.chat_send_player(name, "Pode tirar apenas macros ou medalhas")
|
|
||||||
end
|
|
||||||
else
|
|
||||||
minetest.chat_send_player(name, "Jogador inexistente")
|
|
||||||
end
|
|
||||||
return true
|
|
||||||
|
|
||||||
-- Comando de definir
|
|
||||||
elseif param1 == "definir" then
|
|
||||||
if macromoney.existe(param4) then
|
|
||||||
|
|
||||||
if param3 == "macros" then -- Definir macros
|
|
||||||
if tonumber(param2) then
|
|
||||||
if macromoney.definir(param4, param3, param2) then
|
|
||||||
minetest.chat_send_player(name, "Macros definidos com sucesso.")
|
|
||||||
else
|
|
||||||
minetest.chat_send_player(name, "Falha ao definir macros. (Erro interno)")
|
|
||||||
end
|
|
||||||
else
|
|
||||||
minetest.chat_send_player(name, "Voce tem que digitar um valor numerico")
|
|
||||||
end
|
|
||||||
|
|
||||||
elseif param3 == "medalhas" then -- definir medalhas
|
|
||||||
if tonumber(param2) then
|
|
||||||
if macromoney.definir(param4, param3, param2) then
|
|
||||||
minetest.chat_send_player(name, "Medalhas definidas com sucesso.")
|
|
||||||
else
|
|
||||||
minetest.chat_send_player(name, "Falha ao definir medalhas. (Erro interno)")
|
|
||||||
end
|
|
||||||
else
|
|
||||||
minetest.chat_send_player(name, "Voce tem que digitar um valor numerico")
|
|
||||||
end
|
|
||||||
else
|
|
||||||
minetest.chat_send_player(name, "Pode tirar apenas macros ou medalhas (veja /help macromoney)")
|
|
||||||
end
|
|
||||||
else
|
|
||||||
minetest.chat_send_player(name, "Jogador inexistente")
|
|
||||||
end
|
|
||||||
return true
|
|
||||||
else
|
|
||||||
minetest.chat_send_player(name, "Pode apenas tirar, subtrar ou definir (veja /help macromoney)")
|
|
||||||
end
|
|
||||||
end
|
|
||||||
minetest.chat_send_player(name, "Parametros invalidos (veja /help macromoney)")
|
|
||||||
end,
|
|
||||||
})
|
|
|
@ -0,0 +1,104 @@
|
||||||
|
--[[
|
||||||
|
Mod Macromoney 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/>.
|
||||||
|
|
||||||
|
Comandos
|
||||||
|
|
||||||
|
]]
|
||||||
|
|
||||||
|
-- Accounts manager privilege
|
||||||
|
minetest.register_privilege("macromoney_admin", "Accounts manager")
|
||||||
|
|
||||||
|
-- Get text number value
|
||||||
|
local to_text = macromoney.get_text_number_value
|
||||||
|
|
||||||
|
-- Send account on chat
|
||||||
|
local send_acct_on_chat = function(name, acct_name)
|
||||||
|
|
||||||
|
local acct_data = macromoney.db.get(acct_name)
|
||||||
|
|
||||||
|
for value_id,def in pairs(macromoney.registered_values) do
|
||||||
|
minetest.chat_send_player(name, def.description..": " .. to_text(value_id, acct_data[value_id]))
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
-- "macromoney" command
|
||||||
|
minetest.register_chatcommand("macromoney", {
|
||||||
|
privs = {macromoney_admin = true},
|
||||||
|
params = "[<account> | <add/subtract/set> <value_id>]",
|
||||||
|
description = "Manage accounts",
|
||||||
|
func = function(name, param)
|
||||||
|
|
||||||
|
-- Consult self account
|
||||||
|
if param == "" then --/macromoney
|
||||||
|
minetest.chat_send_player(name, "Your account")
|
||||||
|
send_acct_on_chat(name, name)
|
||||||
|
end
|
||||||
|
|
||||||
|
local m = string.split(param, " ")
|
||||||
|
local param1, param2, param3, param4 = m[1], m[2], m[3], m[4]
|
||||||
|
|
||||||
|
-- Check account
|
||||||
|
if macromoney.exist_account(param1) == false then
|
||||||
|
return false, "Account not exist."
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Consultar conta de outro
|
||||||
|
if param1 and not param2 then --/macromoney <conta>
|
||||||
|
minetest.chat_send_player(name, param1.." account")
|
||||||
|
send_acct_on_chat(name, param1)
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
if param2 and param3 and param4 then
|
||||||
|
|
||||||
|
-- Check tag
|
||||||
|
if macromoney.tags[param3] then
|
||||||
|
param3 = macromoney.tags[param3]
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Check value id
|
||||||
|
if macromoney.registered_values[param3] == nil then
|
||||||
|
return false, "Ivalid value type '"..param3.."'"
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Check and adjust numeric value
|
||||||
|
if macromoney.registered_values[param3].value_type == "number" then
|
||||||
|
if not tonumber(param4) then
|
||||||
|
return false, "Invalid operation. '"..param3.."' is not numeric value."
|
||||||
|
end
|
||||||
|
param4 = tonumber(param4)
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Substract
|
||||||
|
if param2 == "subtract" then
|
||||||
|
|
||||||
|
macromoney.subtract_account(param1, param3, param4)
|
||||||
|
|
||||||
|
return true, "Subtracted value. New balance is "..to_text(param3, macromoney.get_account(param1, param3))
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Add
|
||||||
|
if param2 == "add" then
|
||||||
|
|
||||||
|
macromoney.add_account(param1, param3, param4)
|
||||||
|
|
||||||
|
return true, "Added value. New balance is "..to_text(param3, macromoney.get_account(param1, param3))
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Set
|
||||||
|
if param2 == "set" then
|
||||||
|
|
||||||
|
macromoney.set_account(param1, param3, param4)
|
||||||
|
|
||||||
|
return true, "Setted value. New value is "..to_text(param3, macromoney.get_account(param1, param3))
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
return false
|
||||||
|
end,
|
||||||
|
})
|
104
contador.lua
|
@ -1,104 +0,0 @@
|
||||||
--[[
|
|
||||||
Mod Macromoney 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 Macros
|
|
||||||
|
|
||||||
]]
|
|
||||||
|
|
||||||
-- Formulario
|
|
||||||
local contador_form = "size[8,3]"..
|
|
||||||
"label[0,0;Contador de Macros]"..
|
|
||||||
"item_image_button[0,1;2,2;macromoney:maleta_de_macros;maleta_de_macros;]"..
|
|
||||||
"label[2.1,1;Maleta de Macros\nPrecisa de 100 Macros]"
|
|
||||||
--"item_image_button[0,3;2,2;macromoney:pacote_pagamento;pacote_de_pagamento;]"..
|
|
||||||
--"label[2.1,3;Pacote de Pagamento\nPrecisa de 10 Macros]"
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
-- Contador de Macros
|
|
||||||
minetest.register_node("macromoney:contador_de_macros", {
|
|
||||||
description = "Contador de Macros",
|
|
||||||
tiles = {
|
|
||||||
"macromoney_contador_de_macros_cima.png", -- Cima
|
|
||||||
"macromoney_contador_de_macros.png", -- Baixo
|
|
||||||
"macromoney_contador_de_macros.png", -- Lado Direito
|
|
||||||
"macromoney_contador_de_macros.png", -- Lado Esquerdo
|
|
||||||
"macromoney_contador_de_macros.png", -- Fundo
|
|
||||||
"macromoney_contador_de_macros_frente.png" -- Frente
|
|
||||||
},
|
|
||||||
drawtype = "nodebox",
|
|
||||||
paramtype = "light",
|
|
||||||
groups = {attached_node=1, oddly_breakable_by_hand=3,flammable=1},
|
|
||||||
legacy_facedir_simple = true,
|
|
||||||
is_ground_content = false,
|
|
||||||
paramtype2 = "facedir",
|
|
||||||
sounds = default.node_sound_wood_defaults(),
|
|
||||||
selection_box = {
|
|
||||||
type = "fixed",
|
|
||||||
fixed = {
|
|
||||||
{-0.4375, -0.5, -0.4375, 0.4375, 0.3375, 0.4375}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
node_box = {
|
|
||||||
type = "fixed",
|
|
||||||
fixed = {
|
|
||||||
{-0.4375, -0.5, -0.1875, 0.4375, 0.125, 0.4375}, -- Caixa
|
|
||||||
{-0.4375, -0.5, -0.4375, 0.4375, -0.4375, 0.4375}, -- NodeBox4
|
|
||||||
{-0.4375, -0.5, -0.4375, 0.4375, -0.375, -0.375}, -- NodeBox5
|
|
||||||
{0.375, -0.5, -0.4375, 0.4375, -0.375, 0.4375}, -- NodeBox6
|
|
||||||
{-0.4375, -0.5, -0.4375, -0.375, -0.375, 0.4375}, -- NodeBox7
|
|
||||||
{-0.3125, -0.125, -0.25, 0.3125, 0, -0.1875}, -- NodeBox8
|
|
||||||
{-0.375, -0.375, 0.3125, 0.375, 0.3125, 0.375}, -- NodeBox9
|
|
||||||
{-0.375, -0.375, 0.1875, 0.375, 0.1875, 0.25}, -- NodeBox10
|
|
||||||
{-0.375, -0.5, 0.25, -0.3125, 0.1875, 0.3125}, -- NodeBox11
|
|
||||||
{0.3125, -0.5, 0.25, 0.375, 0.1875, 0.3125}, -- NodeBox12
|
|
||||||
}
|
|
||||||
},
|
|
||||||
on_construct = function(pos)
|
|
||||||
local meta = minetest.get_meta(pos)
|
|
||||||
meta:set_string("formspec", contador_form)
|
|
||||||
meta:set_string("infotext", "Contador de Macros")
|
|
||||||
end,
|
|
||||||
on_receive_fields = function(pos, formname, fields, sender)
|
|
||||||
-- Botao de Maleta de Macros
|
|
||||||
if fields.maleta_de_macros then
|
|
||||||
local player_inv = sender:get_inventory()
|
|
||||||
if not player_inv:room_for_item("main", "macromoney:maleta_de_macros") then
|
|
||||||
return minetest.chat_send_player(sender:get_player_name(), "[Contador de Macros] Inventario Lotado. Tire alguns itens do seu inventario para poder pegar a Maleta de Macros")
|
|
||||||
elseif player_inv:contains_item("main", 'macromoney:macro 100') == false then
|
|
||||||
return minetest.chat_send_player(sender:get_player_name(), "[Contador de Macros] Macros Insuficientes. Tenha ao menos 100 Macros em seu inventario")
|
|
||||||
else
|
|
||||||
minetest.chat_send_player(sender:get_player_name(), "[Contador de Macros] Maleta de Macros montada")
|
|
||||||
player_inv:remove_item("main", 'macromoney:macro 100')
|
|
||||||
player_inv:add_item("main", "macromoney:maleta_de_macros")
|
|
||||||
end
|
|
||||||
end
|
|
||||||
-- Botao de Pacote de Pagamento [DESCONTINUADO]
|
|
||||||
if fields.pacote_de_pagamento then
|
|
||||||
local player_inv = sender:get_inventory()
|
|
||||||
if not player_inv:room_for_item("main", "macronodes:pacote_pagamento") then
|
|
||||||
return minetest.chat_send_player(sender:get_player_name(), "[Contador de Macros] Inventario Lotado. Tire alguns itens do seu inventario para poder pegar o Pacote de Pagamento")
|
|
||||||
elseif player_inv:contains_item("main", 'macromoney:macro 25') == false then
|
|
||||||
return minetest.chat_send_player(sender:get_player_name(), "[Contador de Macros] Macros Insuficientes. Tenha ao menos 25 Macros em seu inventario")
|
|
||||||
else
|
|
||||||
minetest.chat_send_player(sender:get_player_name(), "[Contador de Macros] Pacote de Pagamento montado")
|
|
||||||
player_inv:remove_item("main", 'macromoney:macro 25')
|
|
||||||
player_inv:add_item("main", "macromoney:pacote_pagamento")
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end,
|
|
||||||
})
|
|
||||||
|
|
||||||
minetest.register_craft({
|
|
||||||
output = 'macromoney:contador_de_macros',
|
|
||||||
recipe = {
|
|
||||||
{'default:steel_ingot', 'default:steel_ingot', 'default:steel_ingot'},
|
|
||||||
{'default:paper', 'default:paper', 'default:paper'},
|
|
||||||
{'default:steel_ingot', 'default:steel_ingot', 'default:steel_ingot'},
|
|
||||||
}
|
|
||||||
})
|
|
|
@ -0,0 +1,35 @@
|
||||||
|
--[[
|
||||||
|
Mod Minemacro 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/>.
|
||||||
|
|
||||||
|
Data base
|
||||||
|
]]
|
||||||
|
|
||||||
|
-- Load memor
|
||||||
|
macromoney.memor = dofile(minetest.get_modpath("macromoney") .. "/lib/memor.lua")
|
||||||
|
|
||||||
|
-- Data base methods
|
||||||
|
|
||||||
|
macromoney.db = {}
|
||||||
|
|
||||||
|
-- Exist account
|
||||||
|
macromoney.db.exist = function(name)
|
||||||
|
return macromoney.memor.verif("accts", name)
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Set data
|
||||||
|
macromoney.db.set = function(name, data)
|
||||||
|
macromoney.memor.salvar("accts", name, data)
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Get data
|
||||||
|
macromoney.db.get = function(name)
|
||||||
|
return macromoney.memor.pegar("accts", name)
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,28 +0,0 @@
|
||||||
--[[
|
|
||||||
Mod Macromoney 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/>.
|
|
||||||
|
|
||||||
Diretrizes
|
|
||||||
|
|
||||||
]]
|
|
||||||
|
|
||||||
-- Nickname administrativo
|
|
||||||
ADMIN = "BrunoMine"
|
|
||||||
|
|
||||||
-- Link do website
|
|
||||||
LINK_DO_FORUM = "www.minemacro.tk"
|
|
||||||
|
|
||||||
-- Definir o spawn para teleportar o jogador
|
|
||||||
SPAWNTP = {x = -2666, y = 23, z = -7131}
|
|
||||||
|
|
||||||
-- Tempo que dados temporarios ficam na memoria (en segundos)
|
|
||||||
--[[
|
|
||||||
Esse dados sao carregados quando uma funcao
|
|
||||||
exige aqueles dados mesmo o jogador estando
|
|
||||||
offline
|
|
||||||
]]
|
|
||||||
TEMPO_CARREGAMENTO_TEMPORARIO = 300 -- (5 Minutos)
|
|
45
init.lua
|
@ -1,36 +1,25 @@
|
||||||
--[[
|
--[[
|
||||||
Mod Macromoney para Minetest
|
Mod Minemacro for Minetest
|
||||||
Copyright (C) 2018 BrunoMine (https://github.com/BrunoMine)
|
Copyright (C) 2020 BrunoMine (https://github.com/BrunoMine)
|
||||||
|
|
||||||
Recebeste uma cópia da GNU Lesser General
|
You should have received a copy of the GNU General Public License
|
||||||
Public License junto com esse software,
|
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
se não, veja em <http://www.gnu.org/licenses/>.
|
|
||||||
|
|
||||||
Inicialização de scripts
|
|
||||||
|
|
||||||
]]
|
]]
|
||||||
|
|
||||||
|
local modpath = minetest.get_modpath("macromoney")
|
||||||
|
|
||||||
dofile(minetest.get_modpath("macromoney") .. "/diretrizes.lua") -- Carregar Diretrizes.
|
-- Global table
|
||||||
dofile(minetest.get_modpath("macromoney") .. "/banco_de_dados.lua")
|
macromoney = {}
|
||||||
dofile(minetest.get_modpath("macromoney") .. "/macro.lua")
|
|
||||||
--dofile(minetest.get_modpath("macromoney") .. "/pacote_pagamento.lua") [DESCONTINUADO]
|
dofile(modpath .. "/data_base.lua")
|
||||||
dofile(minetest.get_modpath("macromoney") .. "/caixa_de_banco.lua")
|
dofile(modpath .. "/api.lua")
|
||||||
--dofile(minetest.get_modpath("macromoney") .. "/painel_de_medalhas.lua") [DESCONTINUADO]
|
|
||||||
dofile(minetest.get_modpath("macromoney") .. "/contador.lua")
|
dofile(modpath .. "/commands.lua")
|
||||||
dofile(minetest.get_modpath("macromoney") .. "/comandos.lua")
|
|
||||||
|
-- Custom
|
||||||
|
dofile(modpath .. "/money.lua")
|
||||||
|
dofile(modpath .. "/safe_box.lua")
|
||||||
|
dofile(modpath .. "/atm.lua")
|
||||||
|
|
||||||
|
|
||||||
-- Tira uma medalhas quando morre [DESCONTINUADO]
|
|
||||||
--[[
|
|
||||||
minetest.register_on_dieplayer(function(player)
|
|
||||||
if player then
|
|
||||||
local name = player:get_player_name()
|
|
||||||
if macromoney.subtrair(name, "medalhas", 3) then
|
|
||||||
minetest.chat_send_player(name, "Perdeste 3 medalhas por morrer")
|
|
||||||
end
|
|
||||||
else
|
|
||||||
minetest.log("error", "[macromoney] Dados inacessivel (player) (em register_on_dieplayer)")
|
|
||||||
end
|
|
||||||
end)]]
|
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,302 @@
|
||||||
|
--[[
|
||||||
|
Lib Memor para Minetest
|
||||||
|
Memor v1.3 Copyright (C) 2018 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/>.
|
||||||
|
|
||||||
|
Script para manipulação simples de banco de dados de um mod
|
||||||
|
]]
|
||||||
|
|
||||||
|
local modname = minetest.get_current_modname()
|
||||||
|
|
||||||
|
local modpath = minetest.get_modpath(modname)
|
||||||
|
|
||||||
|
-- Variavel global
|
||||||
|
local memor = {}
|
||||||
|
|
||||||
|
-- Rotinas de interação com arquivos
|
||||||
|
|
||||||
|
-- Diretorio do mundo
|
||||||
|
local wpath = minetest.get_worldpath()
|
||||||
|
|
||||||
|
-- Cria um diretório na pasta do mundo
|
||||||
|
function memor.mkdir(dir)
|
||||||
|
if not dir then
|
||||||
|
minetest.log("error", "[Memor] Nenhum diretorio especificado (em memor.mkdir)")
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
|
||||||
|
dir = wpath.."/"..dir
|
||||||
|
|
||||||
|
if minetest.mkdir then
|
||||||
|
minetest.mkdir(dir)
|
||||||
|
else
|
||||||
|
os.execute('mkdir "' .. dir .. '"')
|
||||||
|
end
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Criar um arquivo com os dados serializados (Salvar)
|
||||||
|
function memor.escrever(dir, arquivo, dados, is_text)
|
||||||
|
|
||||||
|
if dir == nil or arquivo == nil or dados == nil then
|
||||||
|
minetest.log("error", "[Memor] Faltou dados (em memor.escrever)")
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
|
||||||
|
if is_text ~= true then
|
||||||
|
dados = minetest.serialize(dados)
|
||||||
|
else
|
||||||
|
dados = string.format(dados)
|
||||||
|
end
|
||||||
|
if dados == "" then
|
||||||
|
minetest.log("error", "[Memor] Dado fornecido invalido (em memor.escrever)")
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
local saida = io.open(wpath .. "/" .. modname .. "/" .. dir .. "/" .. arquivo, "w")
|
||||||
|
if saida then
|
||||||
|
saida:write(dados)
|
||||||
|
io.close(saida)
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
-- Cria diretorio (tabela) caso nao exista
|
||||||
|
memor.mkdir(modname.."/"..dir)
|
||||||
|
saida = io.open(wpath .. "/" .. modname .. "/" .. dir .. "/" .. arquivo, "w")
|
||||||
|
if saida then
|
||||||
|
saida:write(dados)
|
||||||
|
io.close(saida)
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
|
||||||
|
minetest.log("error", "[Memor] Impossivel escrever dados em "..modname.."/"..dir.."/"..arquivo.." (em memor.escrever)")
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Ler dados de um arquivo de memória (Carregar)
|
||||||
|
function memor.ler(dir, arquivo, is_text)
|
||||||
|
|
||||||
|
if dir == nil or arquivo == nil then
|
||||||
|
minetest.log("error", "[Memor] Faltou dados (em memor.ler)")
|
||||||
|
return nil
|
||||||
|
end
|
||||||
|
|
||||||
|
local entrada = io.open(wpath .. "/" .. modname .. "/" .. dir .. "/" .. arquivo, "r")
|
||||||
|
if entrada ~= nil then
|
||||||
|
local dados
|
||||||
|
if is_text ~= true then
|
||||||
|
dados = entrada:read("*l")
|
||||||
|
dados = minetest.deserialize(dados)
|
||||||
|
else
|
||||||
|
dados = entrada:read("*a")
|
||||||
|
dados = dados
|
||||||
|
end
|
||||||
|
io.close(entrada)
|
||||||
|
return dados
|
||||||
|
else
|
||||||
|
minetest.log("error", "[Memor] pasta e/ou arquivo inexiste(s) (em memor.ler)")
|
||||||
|
return nil
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Deletar um arquivo
|
||||||
|
function memor.deletar(dir, arquivo)
|
||||||
|
|
||||||
|
if not dir or not arquivo then
|
||||||
|
minetest.log("error", "[Memor] Faltou dados (em memor.deletar)")
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
|
||||||
|
os.remove(wpath .. "/" .. modname .. "/" .. dir .. "/" .. arquivo)
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
-- Deletar um diretório
|
||||||
|
function memor.deletar_dir(dir)
|
||||||
|
|
||||||
|
if not dir then
|
||||||
|
minetest.log("error", "[Memor] Faltou dados (em memor.deletar_dir)")
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
|
||||||
|
local list = minetest.get_dir_list(wpath .. "/" .. modname .. "/" .. dir)
|
||||||
|
|
||||||
|
for n, arquivo in ipairs(list) do
|
||||||
|
os.remove(wpath .. "/" .. modname .. "/" .. dir .. "/" .. arquivo)
|
||||||
|
end
|
||||||
|
|
||||||
|
os.remove(wpath .. "/" .. modname .. "/" .. dir)
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Fim
|
||||||
|
|
||||||
|
-- Rotinas de consutas a arquivos
|
||||||
|
|
||||||
|
-- Verifica diretorios e corrige
|
||||||
|
local verificar = function(subdir)
|
||||||
|
|
||||||
|
|
||||||
|
-- Verifica e corrige diretorio
|
||||||
|
local list = minetest.get_dir_list(minetest.get_worldpath(), true)
|
||||||
|
local r = false
|
||||||
|
for n, ndir in ipairs(list) do
|
||||||
|
if ndir == modname then
|
||||||
|
r = true
|
||||||
|
break
|
||||||
|
end
|
||||||
|
end
|
||||||
|
-- Diretorio inexistente
|
||||||
|
if r == false then
|
||||||
|
memor.mkdir(modname)
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Verifica e corrige subdiretorio
|
||||||
|
local list = minetest.get_dir_list(minetest.get_worldpath().."/"..modname, true)
|
||||||
|
local r = false
|
||||||
|
for n, ndir in ipairs(list) do
|
||||||
|
if ndir == subdir then
|
||||||
|
r = true
|
||||||
|
break
|
||||||
|
end
|
||||||
|
end
|
||||||
|
-- Subdiretorio inexistente
|
||||||
|
if r == false then
|
||||||
|
memor.mkdir(modname.."/"..subdir)
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
-- Inserir dados
|
||||||
|
memor.inserir = function(tb, index, valor, is_text)
|
||||||
|
|
||||||
|
-- Tenta inserir direto
|
||||||
|
if memor.escrever(tb, index, valor, is_text) == true then return true end
|
||||||
|
|
||||||
|
verificar(tb)
|
||||||
|
|
||||||
|
if memor.escrever(tb, index, valor, is_text) then
|
||||||
|
return true
|
||||||
|
else
|
||||||
|
minetest.log("error", "[Memor] Impossivel salvar dados (em memor.inserir)")
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
-- Ler dados
|
||||||
|
memor.consultar = function(tb, index, is_text)
|
||||||
|
|
||||||
|
local r = memor.ler(tb, index, is_text)
|
||||||
|
if r == nil then
|
||||||
|
local mod = modname
|
||||||
|
minetest.log("error", "[Memor] Registro acessado inexistente ("..dump(mod).."/"..dump(tb).."/"..dump(index)..") (em memor.consultar)")
|
||||||
|
end
|
||||||
|
|
||||||
|
return r
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
-- Verificar dados
|
||||||
|
memor.verificar = function(subdir, arquivo)
|
||||||
|
|
||||||
|
local dir = modname
|
||||||
|
|
||||||
|
local list = minetest.get_dir_list(wpath .. "/" .. dir .. "/" .. subdir)
|
||||||
|
local r = false
|
||||||
|
for n, arq in ipairs(list) do
|
||||||
|
if arq == arquivo then
|
||||||
|
r = true
|
||||||
|
break
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
if r then
|
||||||
|
return true
|
||||||
|
else
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Listar
|
||||||
|
memor.listar = function(subdir)
|
||||||
|
|
||||||
|
local dir = modname
|
||||||
|
|
||||||
|
if subdir then
|
||||||
|
|
||||||
|
local list = minetest.get_dir_list(wpath .. "/" .. dir .. "/" .. subdir)
|
||||||
|
|
||||||
|
if list == nil then
|
||||||
|
minetest.log("error", "[Memor] Impossivel listar diretorio (em memor.listar)")
|
||||||
|
return false
|
||||||
|
else
|
||||||
|
return list
|
||||||
|
end
|
||||||
|
|
||||||
|
else
|
||||||
|
local list = minetest.get_dir_list(wpath .. "/" .. dir)
|
||||||
|
|
||||||
|
if list == nil then
|
||||||
|
minetest.log("error", "[Memor] Impossivel listar diretorio (em memor.listar)")
|
||||||
|
return false
|
||||||
|
else
|
||||||
|
return list
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Fim
|
||||||
|
|
||||||
|
-- Montagem de banco de dados
|
||||||
|
|
||||||
|
bd = {}
|
||||||
|
|
||||||
|
-- Inserir dados comuns
|
||||||
|
bd.salvar = function(tb, index, valor)
|
||||||
|
return memor.inserir(tb, index, valor)
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Inserir textos complexos
|
||||||
|
bd.salvar_texto = function(tb, index, valor)
|
||||||
|
return memor.inserir(tb, index, valor, true)
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Consultar dados
|
||||||
|
bd.pegar = function(tb, index)
|
||||||
|
return memor.consultar(tb, index)
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Inserir dados
|
||||||
|
bd.pegar_texto = function(tb, index, valor)
|
||||||
|
return memor.consultar(tb, index, true)
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Verificar dados
|
||||||
|
bd.verif = function(tb, index)
|
||||||
|
return memor.verificar(tb, index)
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Remover dados
|
||||||
|
bd.remover = function(tb, index)
|
||||||
|
return memor.deletar(tb, index)
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Remover tabela
|
||||||
|
bd.drop_tb = function(tb)
|
||||||
|
return memor.deletar_dir(tb)
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Listar dados
|
||||||
|
bd.listar = function(tb)
|
||||||
|
return memor.listar(tb)
|
||||||
|
end
|
||||||
|
|
||||||
|
return bd
|
||||||
|
|
||||||
|
-- Fim
|
Before Width: | Height: | Size: 2.2 KiB After Width: | Height: | Size: 2.2 KiB |
Before Width: | Height: | Size: 1.9 KiB After Width: | Height: | Size: 1.9 KiB |
Before Width: | Height: | Size: 1.3 KiB After Width: | Height: | Size: 1.3 KiB |
Before Width: | Height: | Size: 1.5 KiB After Width: | Height: | Size: 1.5 KiB |
Before Width: | Height: | Size: 1.4 KiB After Width: | Height: | Size: 1.4 KiB |
Before Width: | Height: | Size: 1.5 KiB After Width: | Height: | Size: 1.5 KiB |
|
@ -10,18 +10,27 @@
|
||||||
|
|
||||||
]]
|
]]
|
||||||
|
|
||||||
|
-- Register macro money
|
||||||
|
macromoney.register_value("macromoney:money", {
|
||||||
|
description = "Macro money",
|
||||||
|
specimen_prefix = "M¢",
|
||||||
|
value_type = "number",
|
||||||
|
initial_value = 0,
|
||||||
|
tag = "money",
|
||||||
|
})
|
||||||
|
|
||||||
-- Macro
|
-- Macro
|
||||||
minetest.register_craftitem("macromoney:macro", {
|
minetest.register_craftitem("macromoney:macro", {
|
||||||
description = "Macro",
|
description = "Macro",
|
||||||
inventory_image = "macromoney_macro.png",
|
inventory_image = "macromoney_macro.png",
|
||||||
stack_max = 100,
|
stack_max = 100,
|
||||||
})
|
})
|
||||||
|
|
||||||
-- Maleta de Macros
|
-- Maleta de Macros
|
||||||
minetest.register_craftitem("macromoney:maleta_de_macros", {
|
minetest.register_craftitem("macromoney:maleta_de_macros", {
|
||||||
description = "Maleta de Macros",
|
description = "Maleta de Macros",
|
||||||
inventory_image = "macromoney_maleta_de_macros.png",
|
inventory_image = "macromoney_maleta_de_macros.png",
|
||||||
stack_max = 5,
|
stack_max = 5,
|
||||||
})
|
})
|
||||||
|
|
||||||
-- Maleta de Macros
|
-- Maleta de Macros
|
|
@ -1,34 +0,0 @@
|
||||||
--[[
|
|
||||||
Mod Macromoney 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/>.
|
|
||||||
|
|
||||||
Itens extras
|
|
||||||
|
|
||||||
]]
|
|
||||||
|
|
||||||
minetest.register_node("macromoney:pacote_pagamento", {
|
|
||||||
description = "Pacote de Pagamento",
|
|
||||||
tiles = {
|
|
||||||
"macromoney_pacote_pagamento_cima.png", -- Cima
|
|
||||||
"macromoney_pacote_pagamento_lado.png", -- Baixo
|
|
||||||
"macromoney_pacote_pagamento_lado.png", -- Lado direito
|
|
||||||
"macromoney_pacote_pagamento_lado.png", -- Lado esquerda
|
|
||||||
"macromoney_pacote_pagamento_lado.png", -- Fundo
|
|
||||||
"macromoney_pacote_pagamento_lado.png" -- Frente
|
|
||||||
},
|
|
||||||
stack_max = 1,
|
|
||||||
groups = {oddly_breakable_by_hand=1},
|
|
||||||
sounds = default.node_sound_wood_defaults(),
|
|
||||||
})
|
|
||||||
|
|
||||||
-- Pacote de Pagamento
|
|
||||||
minetest.register_craft({
|
|
||||||
output = "macromoney:macro 25",
|
|
||||||
recipe = {
|
|
||||||
{"macromoney:pacote_pagamento"},
|
|
||||||
}
|
|
||||||
})
|
|
|
@ -1,69 +0,0 @@
|
||||||
--
|
|
||||||
-- Mod Macromoney
|
|
||||||
--
|
|
||||||
-- Painel de Medalhas
|
|
||||||
|
|
||||||
-- Painel de Medalhas
|
|
||||||
local formspec_medalhas_off = "size[8,3]"..
|
|
||||||
"bgcolor[#080808BB;true]"..
|
|
||||||
"background[5,5;1,1;gui_formbg.png;true]"..
|
|
||||||
"image[0,0;3,3;macromoney_painel_medalhas.png]"..
|
|
||||||
"label[3,0;Quadro de Medalhas\n\nTroque medalhas por algo\nna Loja de Premios.\nVeja em www.minemacro.tk\n(Apenas contas vinculadas)]"
|
|
||||||
minetest.register_node("macromoney:painel_medalhas", {
|
|
||||||
description = "Quadro de Medalhas",
|
|
||||||
drawtype = "nodebox",
|
|
||||||
tiles = {"macromoney_painel_medalhas.png"},
|
|
||||||
inventory_image = "macromoney_painel_medalhas.png",
|
|
||||||
wield_image = "macromoney_painel_medalhas.png",
|
|
||||||
paramtype = "light",
|
|
||||||
paramtype2 = "wallmounted",
|
|
||||||
sunlight_propagates = true,
|
|
||||||
is_ground_content = false,
|
|
||||||
walkable = false,
|
|
||||||
node_box = {
|
|
||||||
type = "wallmounted",
|
|
||||||
wall_top = {-0.45, 0.45, -0.45, 0.45, 0.55, 0.45},
|
|
||||||
wall_bottom = {-0.45, -0.5, -0.45, 0.45, -0.45, 0.45},
|
|
||||||
wall_side = {-0.5, -0.45, -0.45, -0.45, 0.45, 0.45},
|
|
||||||
},
|
|
||||||
groups = {choppy=2,dig_immediate=2,attached_node=1},
|
|
||||||
legacy_wallmounted = true,
|
|
||||||
sounds = default.node_sound_defaults(),
|
|
||||||
on_construct = function(pos)
|
|
||||||
local meta = minetest.get_meta(pos)
|
|
||||||
meta:set_string("owner", "")
|
|
||||||
end,
|
|
||||||
after_place_node = function(pos, placer)
|
|
||||||
local meta = minetest.get_meta(pos)
|
|
||||||
meta:set_string("owner", placer:get_player_name() or "")
|
|
||||||
end,
|
|
||||||
on_rightclick = function(pos, node, player)
|
|
||||||
local meta = minetest.get_meta(pos)
|
|
||||||
if meta:get_string("owner") == player:get_player_name() then
|
|
||||||
local name = player:get_player_name()
|
|
||||||
if macromoney.existe(name) == false then
|
|
||||||
minetest.show_formspec(name, "", formspec_medalhas_off)
|
|
||||||
else
|
|
||||||
minetest.show_formspec(name, "",
|
|
||||||
"size[8,3]"..
|
|
||||||
"bgcolor[#080808BB;true]"..
|
|
||||||
"background[5,5;1,1;gui_formbg.png;true]"..
|
|
||||||
"image[0,0;3,3;macromoney_painel_medalhas.png]"..
|
|
||||||
"label[3,0;Seu Quadro de Medalhas\n\nAtualmente possui " .. macromoney.consultar(name, "medalhas") .. "\n\nTroque na Loja de Premios.\nVeja em www.minemacro.tk]"
|
|
||||||
)
|
|
||||||
end
|
|
||||||
else
|
|
||||||
minetest.chat_send_player(player:get_player_name(), "Esse Quadro de Medalhas pertence a " .. meta:get_string("owner"))
|
|
||||||
end
|
|
||||||
end
|
|
||||||
})
|
|
||||||
|
|
||||||
minetest.register_craft({
|
|
||||||
output = 'macromoney:painel_medalhas',
|
|
||||||
recipe = {
|
|
||||||
{'macronodes:pregos', 'default:jungletree', 'macronodes:pregos'},
|
|
||||||
{'default:gold_ingot', 'dye:dark_green', 'default:gold_ingot'},
|
|
||||||
{'macronodes:pregos', 'default:jungletree', 'macronodes:pregos'},
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
|
@ -26,27 +26,27 @@ local function has_safe_privilege(meta, player)
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
|
|
||||||
minetest.register_node("macromoney:cofre", {
|
minetest.register_node("macromoney:safe_box", {
|
||||||
description = "Cofre",
|
description = "Safe Box",
|
||||||
paramtype = "light",
|
paramtype = "light",
|
||||||
paramtype2 = "facedir",
|
paramtype2 = "facedir",
|
||||||
tiles = {"safe_side.png",
|
tiles = {"macromoney_safe_box_side.png",
|
||||||
"macromoney_cofre_side.png",
|
"macromoney_safe_box_side.png",
|
||||||
"macromoney_cofre_side.png",
|
"macromoney_safe_box_side.png",
|
||||||
"macromoney_cofre_side.png",
|
"macromoney_safe_box_side.png",
|
||||||
"macromoney_cofre_side.png",
|
"macromoney_safe_box_side.png",
|
||||||
"macromoney_cofre_front.png",},
|
"macromoney_safe_box_front.png",},
|
||||||
is_ground_content = false,
|
is_ground_content = false,
|
||||||
groups = {cracky=1},
|
groups = {cracky=1},
|
||||||
after_place_node = function(pos, placer)
|
after_place_node = function(pos, placer)
|
||||||
local meta = minetest.get_meta(pos)
|
local meta = minetest.get_meta(pos)
|
||||||
meta:set_string("owner", placer:get_player_name() or "")
|
meta:set_string("owner", placer:get_player_name() or "")
|
||||||
meta:set_string("infotext", "Cofre (Trancado por "..
|
meta:set_string("infotext", "Safe Box (Owner "..
|
||||||
meta:get_string("owner")..")")
|
meta:get_string("owner")..")")
|
||||||
end,
|
end,
|
||||||
on_construct = function(pos)
|
on_construct = function(pos)
|
||||||
local meta = minetest.get_meta(pos)
|
local meta = minetest.get_meta(pos)
|
||||||
meta:set_string("infotext", "Cofre")
|
meta:set_string("infotext", "Safe Box")
|
||||||
meta:set_string("owner", "")
|
meta:set_string("owner", "")
|
||||||
local inv = meta:get_inventory()
|
local inv = meta:get_inventory()
|
||||||
inv:set_size("main", 6*2)
|
inv:set_size("main", 6*2)
|
||||||
|
@ -60,29 +60,29 @@ minetest.register_node("macromoney:cofre", {
|
||||||
local meta = minetest.get_meta(pos)
|
local meta = minetest.get_meta(pos)
|
||||||
if not has_safe_privilege(meta, player) then
|
if not has_safe_privilege(meta, player) then
|
||||||
minetest.log("action", player:get_player_name()..
|
minetest.log("action", player:get_player_name()..
|
||||||
" tentou acessar um cofre pertencente a "..
|
" try access safe box of "..
|
||||||
meta:get_string("owner").." at "..
|
meta:get_string("owner").." at "..
|
||||||
minetest.pos_to_string(pos))
|
minetest.pos_to_string(pos))
|
||||||
return 0
|
return 0
|
||||||
end
|
end
|
||||||
return count
|
return count
|
||||||
end,
|
end,
|
||||||
allow_metadata_inventory_put = function(pos, listname, index, stack, player)
|
allow_metadata_inventory_put = function(pos, listname, index, stack, player)
|
||||||
local meta = minetest.get_meta(pos)
|
local meta = minetest.get_meta(pos)
|
||||||
if not has_safe_privilege(meta, player) then
|
if not has_safe_privilege(meta, player) then
|
||||||
minetest.log("action", player:get_player_name()..
|
minetest.log("action", player:get_player_name()..
|
||||||
" tentou acessar um cofre pertencente a "..
|
" try access safe box of "..
|
||||||
meta:get_string("owner").." at "..
|
meta:get_string("owner").." at "..
|
||||||
minetest.pos_to_string(pos))
|
minetest.pos_to_string(pos))
|
||||||
return 0
|
return 0
|
||||||
end
|
end
|
||||||
return stack:get_count()
|
return stack:get_count()
|
||||||
end,
|
end,
|
||||||
allow_metadata_inventory_take = function(pos, listname, index, stack, player)
|
allow_metadata_inventory_take = function(pos, listname, index, stack, player)
|
||||||
local meta = minetest.get_meta(pos)
|
local meta = minetest.get_meta(pos)
|
||||||
if not has_safe_privilege(meta, player) then
|
if not has_safe_privilege(meta, player) then
|
||||||
minetest.log("action", player:get_player_name()..
|
minetest.log("action", player:get_player_name()..
|
||||||
" tentou acessar um cofre pertencente a "..
|
" try access safe box of "..
|
||||||
meta:get_string("owner").." at "..
|
meta:get_string("owner").." at "..
|
||||||
minetest.pos_to_string(pos))
|
minetest.pos_to_string(pos))
|
||||||
return 0
|
return 0
|
||||||
|
@ -91,22 +91,22 @@ minetest.register_node("macromoney:cofre", {
|
||||||
end,
|
end,
|
||||||
on_metadata_inventory_move = function(pos, from_list, from_index, to_list, to_index, count, player)
|
on_metadata_inventory_move = function(pos, from_list, from_index, to_list, to_index, count, player)
|
||||||
minetest.log("action", player:get_player_name()..
|
minetest.log("action", player:get_player_name()..
|
||||||
" moveu algo no cofre em "..minetest.pos_to_string(pos))
|
" move an item in safe box of "..minetest.pos_to_string(pos))
|
||||||
end,
|
end,
|
||||||
on_metadata_inventory_put = function(pos, listname, index, stack, player)
|
on_metadata_inventory_put = function(pos, listname, index, stack, player)
|
||||||
minetest.log("action", player:get_player_name()..
|
minetest.log("action", player:get_player_name()..
|
||||||
" moveu algo no cofre em "..minetest.pos_to_string(pos))
|
" move an item in safe box of "..minetest.pos_to_string(pos))
|
||||||
end,
|
end,
|
||||||
on_metadata_inventory_take = function(pos, listname, index, stack, player)
|
on_metadata_inventory_take = function(pos, listname, index, stack, player)
|
||||||
minetest.log("action", player:get_player_name()..
|
minetest.log("action", player:get_player_name()..
|
||||||
" moveu algo no cofre em "..minetest.pos_to_string(pos))
|
" move an item in safe box of "..minetest.pos_to_string(pos))
|
||||||
end,
|
end,
|
||||||
on_rightclick = function(pos, node, clicker)
|
on_rightclick = function(pos, node, clicker)
|
||||||
local meta = minetest.get_meta(pos)
|
local meta = minetest.get_meta(pos)
|
||||||
if has_safe_privilege(meta, clicker) then
|
if has_safe_privilege(meta, clicker) then
|
||||||
minetest.show_formspec(
|
minetest.show_formspec(
|
||||||
clicker:get_player_name(),
|
clicker:get_player_name(),
|
||||||
"macromoney:cofre",
|
"macromoney:safe_box",
|
||||||
default.get_safe_formspec(pos)
|
default.get_safe_formspec(pos)
|
||||||
)
|
)
|
||||||
end
|
end
|
BIN
screenshot.png
Before Width: | Height: | Size: 45 KiB After Width: | Height: | Size: 46 KiB |
Before Width: | Height: | Size: 2.1 KiB |
Before Width: | Height: | Size: 1.5 KiB |
Before Width: | Height: | Size: 419 B After Width: | Height: | Size: 419 B |
Before Width: | Height: | Size: 208 B After Width: | Height: | Size: 208 B |