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:
James David Clarke 2024-01-14 23:48:51 +00:00 committed by impulse
parent 0bf4d57b2f
commit 20b0bdeb6b
2 changed files with 52 additions and 38 deletions

@ -71,26 +71,26 @@ core.register_chatcommand("emeralds", {
privs = {server=true},
func = function(name, param)
local playername, stringnum = param:match("([^ ]+) (.+)")
local player
local num = tonumber(stringnum)
if playername and num then
player = core.get_player_by_name(playername)
end
if player and num then
emeraldbank.add_emeralds(player, num)
local success = emeraldbank.add_emeralds(playername, num)
if success then
atm.read_account(playername)
minetest.chat_send_player(name, S("@1 has now @2 emeralds in bank account",
playername, atm.balance[playername]))
return true
else
-- Notify the command issuer that the player is not found or not online
minetest.chat_send_player(name, S("Player @1 not found or not online.", playername))
return false
end
else
-- Notify the command issuer that the input is invalid
minetest.chat_send_player(name, S("Invalid input. Please specify a player and a number."))
return false
end
end
})
-- experimental upgrade command
core.register_chatcommand("upgrade", {
description = S("Admin Command! Upgrade a shop"),

@ -26,18 +26,32 @@ function emeraldbank.get_emeralds(name)
return atm.balance[name]
end
-- Accepts a player object or player name as input now
function emeraldbank.add_emeralds(player, num)
if not player then return false end
local meta = player:get_meta()
local name = player:get_player_name()
atm.read_account(name)
if num then
if atm.balance[name] then
atm.balance[name] = math.floor(atm.balance[name] + num)
local name
if type(player) == "string" then
name = player
else
atm.balance[name] = num
name = player:get_player_name()
end
atm.read_account(name)
-- Check if atm.balance[name] exists
if atm.balance[name] == nil then
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