/pay command

This commit is contained in:
Nathaniel Freeman 2021-10-05 20:55:38 +02:00
parent b7666591a5
commit 4aea2d3258
3 changed files with 43 additions and 5 deletions

@ -10,6 +10,8 @@
Keep your Emeralds in a bank!
Why Emeralds? In MineClone the emerald is money to trade with villagers!
Multiplayer compat!
Add a crafteable Emerald bank node. Craft can be disable in mod settings.

@ -25,7 +25,7 @@ local S = core.get_translator(core.get_current_modname())
local bankcraft = core.settings:get_bool("emeraldbank.craft") or true
local income_enabled = core.settings:get_bool("emeraldbank.income_enabled", true)
local income_count = tonumber(core.settings:get("emeraldbank.income_count")) or 1
local income_period = tonumber(core.settings:get("emeraldbank.income_period")) or 600
local income_period = tonumber(core.settings:get("emeraldbank.income_period")) or 1800
local maxbankgive = tonumber(core.settings:get("emeraldbank.max_bank_give")) or 100
@ -107,14 +107,50 @@ end
-- chat command
-- user /pay chat command
core.register_chatcommand("pay", {
params = "<player> <num>",
description = S("Pay money to other player. Transfer your emeralds to another bank account."),
func = function(name, param)
local player1 = core.get_player_by_name(name)
local playername2, stringnum = param:match("([^ ]+) (.+)")
local player2
local num = tonumber(stringnum)
if playername2 and num then
player2 = core.get_player_by_name(playername2)
end
if player2 and num then
local meta1 = player1:get_meta()
local meta2 = player2:get_meta()
local bankemeralds1 = meta1:get_int("emeraldbank:emerald")
local bankemeralds2 = meta2:get_int("emeraldbank:emerald")
if num > 0 then
if bankemeralds1 >= num then
meta1:set_int("emeraldbank:emerald", bankemeralds1-num)
meta2:set_int("emeraldbank:emerald", bankemeralds2+num)
core.chat_send_player(name, S("Pay Successfully! You have transferred @1 Emeralds. Now you have: @2", num, bankemeralds1-num) )
core.chat_send_player(playername2, S("Pay Successfully! You've gotten @1 Emeralds. Now you have: @2", num, bankemeralds2+num) )
else
core.chat_send_player(name, S("Not enough Emeralds in your account") )
end
else
core.chat_send_player(name, S("Invalid pay") )
end
return true
end
return false
end
})
-- admin chat command
core.register_chatcommand("emeraldbank", {
params = "<player> <num>",
description = S("Add player emeralds in bank account, also can use negative numbers"),
description = S("Admin Command! Add player emeralds in bank account, also can use negative numbers"),
privs = {server=true},
func = function(name, param)
local playername, num = param:match("([^ ]+) (.+)")
local playername, stringnum = param:match("([^ ]+) (.+)")
local player
local num = tonumber(stringnum)
if playername and num then
player = core.get_player_by_name(playername)
end

@ -9,7 +9,7 @@ emeraldbank.income_enabled (Is income enabled?) bool true
emeraldbank.income_count (number of emeralds) int 1
# Length of time (in seconds) between checking if a user should get income
emeraldbank.income_period (time between income) int 600
emeraldbank.income_period (time between income) int 1800
# Bank will give some of money extra in function of emeralds in bank account. That is the max.
emeraldbank.max_bank_give (max extra emeralds) int 100