mirror of
https://codeberg.org/usrib/emeraldbank.git
synced 2025-01-08 22:37:36 +01:00
Can now change the balance of players while they are offline, and emeraldbank.add_emeralds also takes a string of the playername to select the player.
This commit is contained in:
parent
0bf4d57b2f
commit
20b0bdeb6b
24
commands.lua
24
commands.lua
@ -71,26 +71,26 @@ core.register_chatcommand("emeralds", {
|
|||||||
privs = {server=true},
|
privs = {server=true},
|
||||||
func = function(name, param)
|
func = function(name, param)
|
||||||
local playername, stringnum = param:match("([^ ]+) (.+)")
|
local playername, stringnum = param:match("([^ ]+) (.+)")
|
||||||
local player
|
|
||||||
local num = tonumber(stringnum)
|
local num = tonumber(stringnum)
|
||||||
if playername and num then
|
if playername and num then
|
||||||
player = core.get_player_by_name(playername)
|
local success = emeraldbank.add_emeralds(playername, num)
|
||||||
end
|
if success then
|
||||||
if player and num then
|
atm.read_account(playername)
|
||||||
emeraldbank.add_emeralds(player, num)
|
minetest.chat_send_player(name, S("@1 has now @2 emeralds in bank account",
|
||||||
atm.read_account(playername)
|
playername, atm.balance[playername]))
|
||||||
minetest.chat_send_player(name, S("@1 has now @2 emeralds in bank account",
|
return true
|
||||||
playername, atm.balance[playername]))
|
else
|
||||||
return true
|
minetest.chat_send_player(name, S("Player @1 not found or not online.", playername))
|
||||||
|
return false
|
||||||
|
end
|
||||||
else
|
else
|
||||||
-- Notify the command issuer that the player is not found or not online
|
-- Notify the command issuer that the input is invalid
|
||||||
minetest.chat_send_player(name, S("Player @1 not found or not online.", playername))
|
minetest.chat_send_player(name, S("Invalid input. Please specify a player and a number."))
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
-- experimental upgrade command
|
-- experimental upgrade command
|
||||||
core.register_chatcommand("upgrade", {
|
core.register_chatcommand("upgrade", {
|
||||||
description = S("Admin Command! Upgrade a shop"),
|
description = S("Admin Command! Upgrade a shop"),
|
||||||
|
@ -26,22 +26,36 @@ function emeraldbank.get_emeralds(name)
|
|||||||
return atm.balance[name]
|
return atm.balance[name]
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- Accepts a player object or player name as input now
|
||||||
function emeraldbank.add_emeralds(player, num)
|
function emeraldbank.add_emeralds(player, num)
|
||||||
if not player then return false end
|
if not player then return false end
|
||||||
local meta = player:get_meta()
|
|
||||||
local name = player:get_player_name()
|
local name
|
||||||
atm.read_account(name)
|
if type(player) == "string" then
|
||||||
if num then
|
name = player
|
||||||
if atm.balance[name] then
|
else
|
||||||
atm.balance[name] = math.floor(atm.balance[name] + num)
|
name = player:get_player_name()
|
||||||
else
|
end
|
||||||
atm.balance[name] = num
|
|
||||||
end
|
atm.read_account(name)
|
||||||
mcl_title.set(player, "actionbar", {text=S("Emeralds in Bank: @1", atm.balance[name]), color="yellow"})
|
|
||||||
atm.save_account(name)
|
-- Check if atm.balance[name] exists
|
||||||
return true
|
if atm.balance[name] == nil then
|
||||||
end
|
return false
|
||||||
return false
|
end
|
||||||
|
|
||||||
|
if num then
|
||||||
|
atm.balance[name] = math.floor(atm.balance[name] + num)
|
||||||
|
|
||||||
|
-- Update actionbar only if 'player' is a player object
|
||||||
|
if type(player) ~= "string" then
|
||||||
|
mcl_title.set(player, "actionbar", {text=S("Emeralds in Bank: @1", atm.balance[name]), color="yellow"})
|
||||||
|
end
|
||||||
|
|
||||||
|
atm.save_account(name)
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
return false
|
||||||
end
|
end
|
||||||
|
|
||||||
function emeraldbank.update_accounts()
|
function emeraldbank.update_accounts()
|
||||||
@ -139,39 +153,39 @@ function emeraldbank.upgrade_shop(pos)
|
|||||||
local old_inv = old_meta:get_inventory()
|
local old_inv = old_meta:get_inventory()
|
||||||
local old_list = old_inv:get_list("stock")
|
local old_list = old_inv:get_list("stock")
|
||||||
local old_stack = old_inv:get_stack("stock", 1)
|
local old_stack = old_inv:get_stack("stock", 1)
|
||||||
|
|
||||||
-- set the new shop node
|
-- set the new shop node
|
||||||
core.swap_node(pos, {name = "fancy_vend:player_vendor"})
|
core.swap_node(pos, {name = "fancy_vend:player_vendor"})
|
||||||
|
|
||||||
-- setup the new shop node
|
-- setup the new shop node
|
||||||
-- Set variables for access later (for various checks, etc.)
|
-- Set variables for access later (for various checks, etc.)
|
||||||
|
|
||||||
pos.y = pos.y + 1
|
pos.y = pos.y + 1
|
||||||
-- local above_node = minetest.get_node(pos).name
|
-- local above_node = minetest.get_node(pos).name
|
||||||
|
|
||||||
-- -- If node above is air or the display node, and it is not protected, attempt to place the vendor. If vendor sucessfully places, place display node above, otherwise alert the user
|
-- -- If node above is air or the display node, and it is not protected, attempt to place the vendor. If vendor sucessfully places, place display node above, otherwise alert the user
|
||||||
-- if (minetest.registered_nodes[above_node].buildable_to or above_node == "fancy_vend:display_node") and not minetest.is_protected(pos, owner) then
|
-- if (minetest.registered_nodes[above_node].buildable_to or above_node == "fancy_vend:display_node") and not minetest.is_protected(pos, owner) then
|
||||||
-- if above_node ~= "fancy_vend:display_node" then
|
-- if above_node ~= "fancy_vend:display_node" then
|
||||||
-- minetest.set_node(pos, minetest.registered_nodes["fancy_vend:display_node"])
|
-- minetest.set_node(pos, minetest.registered_nodes["fancy_vend:display_node"])
|
||||||
-- end
|
-- end
|
||||||
|
|
||||||
-- Set owner
|
-- Set owner
|
||||||
local owner = old_meta:get_string("owner") or ""
|
local owner = old_meta:get_string("owner") or ""
|
||||||
local meta = minetest.get_meta(pos)
|
local meta = minetest.get_meta(pos)
|
||||||
meta:set_string("owner", owner)
|
meta:set_string("owner", owner)
|
||||||
|
|
||||||
-- Set default meta
|
-- Set default meta
|
||||||
meta:set_string("log", minetest.serialize({"Vendor placed by "..owner,}))
|
meta:set_string("log", minetest.serialize({"Vendor placed by "..owner,}))
|
||||||
emeraldbank.reset_vendor_settings(pos)
|
emeraldbank.reset_vendor_settings(pos)
|
||||||
emeraldbank.refresh_vendor(pos)
|
emeraldbank.refresh_vendor(pos)
|
||||||
|
|
||||||
if minetest.get_modpath("pipeworks") then
|
if minetest.get_modpath("pipeworks") then
|
||||||
pipeworks.after_place(pos)
|
pipeworks.after_place(pos)
|
||||||
end
|
end
|
||||||
|
|
||||||
-- copy old metadata in new node
|
-- copy old metadata in new node
|
||||||
core.get_meta(pos):from_table(old_meta_table)
|
core.get_meta(pos):from_table(old_meta_table)
|
||||||
|
|
||||||
-- new node
|
-- new node
|
||||||
local node = core.get_node(pos)
|
local node = core.get_node(pos)
|
||||||
local meta = core.get_meta(pos)
|
local meta = core.get_meta(pos)
|
||||||
@ -192,8 +206,8 @@ function emeraldbank.upgrade_shop(pos)
|
|||||||
-- inv:set_size("wanted_item", 1*1)
|
-- inv:set_size("wanted_item", 1*1)
|
||||||
-- inv:set_size("given_item", 1*1)
|
-- inv:set_size("given_item", 1*1)
|
||||||
-- inv:set_stack("main", i, old_stack)
|
-- inv:set_stack("main", i, old_stack)
|
||||||
|
|
||||||
|
|
||||||
emeraldbank.set_vendor_settings(pos, settings)
|
emeraldbank.set_vendor_settings(pos, settings)
|
||||||
emeraldbank.refresh_vendor(pos)
|
emeraldbank.refresh_vendor(pos)
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user