mirror of
https://codeberg.org/usrib/emeraldbank.git
synced 2025-01-24 06:51:32 +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
14
commands.lua
14
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
|
|
||||||
emeraldbank.add_emeralds(player, num)
|
|
||||||
atm.read_account(playername)
|
atm.read_account(playername)
|
||||||
minetest.chat_send_player(name, S("@1 has now @2 emeralds in bank account",
|
minetest.chat_send_player(name, S("@1 has now @2 emeralds in bank account",
|
||||||
playername, atm.balance[playername]))
|
playername, atm.balance[playername]))
|
||||||
return true
|
return true
|
||||||
else
|
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))
|
minetest.chat_send_player(name, S("Player @1 not found or not online.", playername))
|
||||||
return false
|
return false
|
||||||
end
|
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
|
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,18 +26,32 @@ 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
|
|
||||||
atm.balance[name] = math.floor(atm.balance[name] + num)
|
|
||||||
else
|
else
|
||||||
atm.balance[name] = num
|
name = player:get_player_name()
|
||||||
end
|
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"})
|
mcl_title.set(player, "actionbar", {text=S("Emeralds in Bank: @1", atm.balance[name]), color="yellow"})
|
||||||
|
end
|
||||||
|
|
||||||
atm.save_account(name)
|
atm.save_account(name)
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user