mirror of
https://codeberg.org/usrib/emeraldbank.git
synced 2025-01-03 20:07:32 +01:00
Made it so the transfer_emeralds function now takes player names as input as well as objects, and pay function now works when players are offline.
This commit is contained in:
parent
20b0bdeb6b
commit
a1d94e5615
36
commands.lua
36
commands.lua
@ -24,23 +24,29 @@ local S = core.get_translator(core.get_current_modname())
|
||||
|
||||
-- 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 name2, stringnum = param:match("([^ ]+) (.+)")
|
||||
local player2
|
||||
local num = tonumber(stringnum)
|
||||
if name2 and num then
|
||||
player2 = core.get_player_by_name(name2)
|
||||
end
|
||||
if player2 and num then
|
||||
return emeraldbank.transfer_emeralds(player1, player2, num)
|
||||
end
|
||||
return false
|
||||
end
|
||||
params = "<player> <num>",
|
||||
description = S("Pay money to other player. Transfer your emeralds to another bank account."),
|
||||
func = function(name, param)
|
||||
local name2, stringnum = param:match("([^ ]+) (.+)")
|
||||
local num = tonumber(stringnum)
|
||||
if name2 and num then
|
||||
-- Check if the balance exists for the target player
|
||||
atm.read_account(name2)
|
||||
if atm.balance[name2] == nil then
|
||||
core.chat_send_player(name, S("Player @1 does not exist or has no account.", name2))
|
||||
return false
|
||||
end
|
||||
|
||||
-- Use strings for player names in the transfer function
|
||||
return emeraldbank.transfer_emeralds(name, name2, num)
|
||||
else
|
||||
core.chat_send_player(name, S("Invalid input. Please specify a player and a number."))
|
||||
return false
|
||||
end
|
||||
end
|
||||
})
|
||||
|
||||
|
||||
-- user /money chat command
|
||||
core.register_chatcommand("money", {
|
||||
description = S("Return your emeralds in your bank account. Or if have server priv, other players too"),
|
||||
|
@ -111,40 +111,51 @@ function emeraldbank.get_stonks(pos)
|
||||
end
|
||||
|
||||
function emeraldbank.transfer_emeralds(player1, player2, num)
|
||||
local name = player1:get_player_name()
|
||||
local name2 = player2:get_player_name()
|
||||
atm.read_account(name)
|
||||
local bankemeralds1 = atm.balance[name]
|
||||
if num > 0 then
|
||||
if bankemeralds1 and bankemeralds1 >= num then
|
||||
core.chat_send_player(name, S("Pay Successfully! You have transferred @1 Emeralds." , num))
|
||||
core.chat_send_player(name2, S("Pay Successfully! You've gotten @1 Emeralds.", num))
|
||||
local msg = S("@1 has transferred @2 emeralds to @3", name, num, name2)
|
||||
if core.get_modpath("irc") then
|
||||
irc.say(msg)
|
||||
end
|
||||
if core.get_modpath("yl_matterbridge") then
|
||||
yl_matterbridge.send_to_bridge("EMERALDBANK", msg)
|
||||
end
|
||||
if core.get_modpath("beerchat") then
|
||||
beerchat.on_channel_message(beerchat.main_channel_name, "EMERALDBANK", msg)
|
||||
end
|
||||
emeraldbank.add_emeralds(player1, -num)
|
||||
emeraldbank.add_emeralds(player2, num)
|
||||
core.sound_play("cash", {
|
||||
to_player = name2,
|
||||
gain = 1.0,
|
||||
fade = 0.0,
|
||||
pitch = 1.0,
|
||||
})
|
||||
else
|
||||
core.chat_send_player(name, S("Not enough Emeralds in your account"))
|
||||
end
|
||||
else
|
||||
core.chat_send_player(name, S("Invalid pay"))
|
||||
end
|
||||
-- Determine player names based on whether input is a string or player object
|
||||
local name1 = type(player1) == "string" and player1 or player1:get_player_name()
|
||||
local name2 = type(player2) == "string" and player2 or player2:get_player_name()
|
||||
|
||||
atm.read_account(name1)
|
||||
local bankemeralds1 = atm.balance[name1]
|
||||
|
||||
if num > 0 then
|
||||
if bankemeralds1 and bankemeralds1 >= num then
|
||||
core.chat_send_player(name1, S("Pay Successfully! You have transferred @1 Emeralds.", num))
|
||||
core.chat_send_player(name2, S("Pay Successfully! You've gotten @1 Emeralds.", num))
|
||||
|
||||
local msg = S("@1 has transferred @2 emeralds to @3", name1, num, name2)
|
||||
-- Integration with external mods
|
||||
if core.get_modpath("irc") then
|
||||
irc.say(msg)
|
||||
end
|
||||
if core.get_modpath("yl_matterbridge") then
|
||||
yl_matterbridge.send_to_bridge("EMERALDBANK", msg)
|
||||
end
|
||||
if core.get_modpath("beerchat") then
|
||||
beerchat.on_channel_message(beerchat.main_channel_name, "EMERALDBANK", msg)
|
||||
end
|
||||
|
||||
emeraldbank.add_emeralds(name1, -num) -- Now using name1 instead of player1
|
||||
emeraldbank.add_emeralds(name2, num) -- Now using name2 instead of player2
|
||||
|
||||
-- Sound effect for player2
|
||||
if type(player2) ~= "string" then
|
||||
core.sound_play("cash", {
|
||||
to_player = name2,
|
||||
gain = 1.0,
|
||||
fade = 0.0,
|
||||
pitch = 1.0,
|
||||
})
|
||||
end
|
||||
else
|
||||
core.chat_send_player(name1, S("Not enough Emeralds in your account"))
|
||||
end
|
||||
else
|
||||
core.chat_send_player(name1, S("Invalid pay"))
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
function emeraldbank.upgrade_shop(pos)
|
||||
local oldnode = core.get_node(pos)
|
||||
local old_meta = core.get_meta(pos)
|
||||
|
Loading…
Reference in New Issue
Block a user