mirror of
https://codeberg.org/usrib/emeraldbank.git
synced 2024-12-22 22:22:25 +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},
|
||||
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)
|
||||
atm.read_account(playername)
|
||||
minetest.chat_send_player(name, S("@1 has now @2 emeralds in bank account",
|
||||
playername, atm.balance[playername]))
|
||||
return true
|
||||
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
|
||||
minetest.chat_send_player(name, S("Player @1 not found or not online.", playername))
|
||||
return false
|
||||
end
|
||||
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))
|
||||
-- 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,22 +26,36 @@ 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)
|
||||
else
|
||||
atm.balance[name] = num
|
||||
end
|
||||
mcl_title.set(player, "actionbar", {text=S("Emeralds in Bank: @1", atm.balance[name]), color="yellow"})
|
||||
atm.save_account(name)
|
||||
return true
|
||||
end
|
||||
return false
|
||||
if not player then return false end
|
||||
|
||||
local name
|
||||
if type(player) == "string" then
|
||||
name = player
|
||||
else
|
||||
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
|
||||
return false
|
||||
end
|
||||
|
||||
function emeraldbank.update_accounts()
|
||||
|
Loading…
Reference in New Issue
Block a user