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
|
-- user /pay chat command
|
||||||
core.register_chatcommand("pay", {
|
core.register_chatcommand("pay", {
|
||||||
params = "<player> <num>",
|
params = "<player> <num>",
|
||||||
description = S("Pay money to other player. Transfer your emeralds to another bank account."),
|
description = S("Pay money to other player. Transfer your emeralds to another bank account."),
|
||||||
func = function(name, param)
|
func = function(name, param)
|
||||||
local player1 = core.get_player_by_name(name)
|
local name2, stringnum = param:match("([^ ]+) (.+)")
|
||||||
local name2, stringnum = param:match("([^ ]+) (.+)")
|
local num = tonumber(stringnum)
|
||||||
local player2
|
if name2 and num then
|
||||||
local num = tonumber(stringnum)
|
-- Check if the balance exists for the target player
|
||||||
if name2 and num then
|
atm.read_account(name2)
|
||||||
player2 = core.get_player_by_name(name2)
|
if atm.balance[name2] == nil then
|
||||||
end
|
core.chat_send_player(name, S("Player @1 does not exist or has no account.", name2))
|
||||||
if player2 and num then
|
return false
|
||||||
return emeraldbank.transfer_emeralds(player1, player2, num)
|
end
|
||||||
end
|
|
||||||
return false
|
-- Use strings for player names in the transfer function
|
||||||
end
|
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
|
-- user /money chat command
|
||||||
core.register_chatcommand("money", {
|
core.register_chatcommand("money", {
|
||||||
description = S("Return your emeralds in your bank account. Or if have server priv, other players too"),
|
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
|
end
|
||||||
|
|
||||||
function emeraldbank.transfer_emeralds(player1, player2, num)
|
function emeraldbank.transfer_emeralds(player1, player2, num)
|
||||||
local name = player1:get_player_name()
|
-- Determine player names based on whether input is a string or player object
|
||||||
local name2 = player2:get_player_name()
|
local name1 = type(player1) == "string" and player1 or player1:get_player_name()
|
||||||
atm.read_account(name)
|
local name2 = type(player2) == "string" and player2 or player2:get_player_name()
|
||||||
local bankemeralds1 = atm.balance[name]
|
|
||||||
if num > 0 then
|
atm.read_account(name1)
|
||||||
if bankemeralds1 and bankemeralds1 >= num then
|
local bankemeralds1 = atm.balance[name1]
|
||||||
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))
|
if num > 0 then
|
||||||
local msg = S("@1 has transferred @2 emeralds to @3", name, num, name2)
|
if bankemeralds1 and bankemeralds1 >= num then
|
||||||
if core.get_modpath("irc") then
|
core.chat_send_player(name1, S("Pay Successfully! You have transferred @1 Emeralds.", num))
|
||||||
irc.say(msg)
|
core.chat_send_player(name2, S("Pay Successfully! You've gotten @1 Emeralds.", num))
|
||||||
end
|
|
||||||
if core.get_modpath("yl_matterbridge") then
|
local msg = S("@1 has transferred @2 emeralds to @3", name1, num, name2)
|
||||||
yl_matterbridge.send_to_bridge("EMERALDBANK", msg)
|
-- Integration with external mods
|
||||||
end
|
if core.get_modpath("irc") then
|
||||||
if core.get_modpath("beerchat") then
|
irc.say(msg)
|
||||||
beerchat.on_channel_message(beerchat.main_channel_name, "EMERALDBANK", msg)
|
end
|
||||||
end
|
if core.get_modpath("yl_matterbridge") then
|
||||||
emeraldbank.add_emeralds(player1, -num)
|
yl_matterbridge.send_to_bridge("EMERALDBANK", msg)
|
||||||
emeraldbank.add_emeralds(player2, num)
|
end
|
||||||
core.sound_play("cash", {
|
if core.get_modpath("beerchat") then
|
||||||
to_player = name2,
|
beerchat.on_channel_message(beerchat.main_channel_name, "EMERALDBANK", msg)
|
||||||
gain = 1.0,
|
end
|
||||||
fade = 0.0,
|
|
||||||
pitch = 1.0,
|
emeraldbank.add_emeralds(name1, -num) -- Now using name1 instead of player1
|
||||||
})
|
emeraldbank.add_emeralds(name2, num) -- Now using name2 instead of player2
|
||||||
else
|
|
||||||
core.chat_send_player(name, S("Not enough Emeralds in your account"))
|
-- Sound effect for player2
|
||||||
end
|
if type(player2) ~= "string" then
|
||||||
else
|
core.sound_play("cash", {
|
||||||
core.chat_send_player(name, S("Invalid pay"))
|
to_player = name2,
|
||||||
end
|
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
|
end
|
||||||
|
|
||||||
|
|
||||||
function emeraldbank.upgrade_shop(pos)
|
function emeraldbank.upgrade_shop(pos)
|
||||||
local oldnode = core.get_node(pos)
|
local oldnode = core.get_node(pos)
|
||||||
local old_meta = core.get_meta(pos)
|
local old_meta = core.get_meta(pos)
|
||||||
|
Loading…
Reference in New Issue
Block a user