mirror of
https://codeberg.org/usrib/emeraldbank.git
synced 2024-12-23 06:32:25 +01:00
function emeraldbank.add_emeralds()
This commit is contained in:
parent
178d60b689
commit
0ddd130cdb
24
bank.lua
24
bank.lua
@ -24,22 +24,31 @@ local S = core.get_translator(core.get_current_modname())
|
||||
local bankcraft = core.settings:get_bool("emeraldbank.craft") or true
|
||||
|
||||
|
||||
function emeraldbank.keep(player, itemstack)
|
||||
function emeraldbank.add_emeralds(player, num)
|
||||
if not player then return false end
|
||||
local meta = player:get_meta()
|
||||
local bankemeralds = meta:get_int("emeraldbank:emerald") -- if nil "get_int()" return 0 Magic!
|
||||
local name = player:get_player_name()
|
||||
if num then
|
||||
meta:set_int("emeraldbank:emerald", bankemeralds+num)
|
||||
core.chat_send_player(name, S("Emeralds in Bank: @1", bankemeralds+num) )
|
||||
return true
|
||||
end
|
||||
return false
|
||||
end
|
||||
|
||||
function emeraldbank.keep(player, itemstack)
|
||||
local itemname = itemstack:get_name()
|
||||
local itemcount = itemstack:get_count()
|
||||
local name = player:get_player_name()
|
||||
if itemname == "mcl_core:emerald" then
|
||||
itemstack:take_item(itemcount)
|
||||
meta:set_int("emeraldbank:emerald", bankemeralds+itemcount)
|
||||
core.chat_send_player(name, S("Emeralds in Bank: @1", bankemeralds+itemcount) )
|
||||
emeraldbank.add_emeralds(player, itemcount)
|
||||
return true
|
||||
end
|
||||
if itemname == "mcl_core:emeraldblock" then
|
||||
itemstack:take_item(itemcount*9)
|
||||
meta:set_int("emeraldbank:emerald", bankemeralds+itemcount*9)
|
||||
core.chat_send_player(name, S("Emeralds in Bank: @1", bankemeralds+itemcount*9) )
|
||||
itemstack:take_item(itemcount)
|
||||
emeraldbank.add_emeralds(player, itemcount*9)
|
||||
return true
|
||||
end
|
||||
core.chat_send_player(name, S("You need keep emeralds or emeraldblocks in your hand!") )
|
||||
@ -56,9 +65,8 @@ function emeraldbank.take(player)
|
||||
if bankemeralds >= 10 then
|
||||
num = 10
|
||||
end
|
||||
meta:set_int("emeraldbank:emerald", bankemeralds-num)
|
||||
emeraldbank.add_emeralds(player, -num)
|
||||
core.add_item(pos, "mcl_core:emerald "..num)
|
||||
core.chat_send_player(name, S("Emeralds in Bank: @1", bankemeralds-num) )
|
||||
return true
|
||||
end
|
||||
core.chat_send_player(name, S("Not enough Emeralds in your account") )
|
||||
|
19
commands.lua
19
commands.lua
@ -29,6 +29,8 @@ core.register_chatcommand("pay", {
|
||||
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 meta1 = player1:get_meta()
|
||||
local bankemeralds1 = meta1:get_int("emeraldbank:emerald")
|
||||
local playername2, stringnum = param:match("([^ ]+) (.+)")
|
||||
local player2
|
||||
local num = tonumber(stringnum)
|
||||
@ -36,16 +38,12 @@ core.register_chatcommand("pay", {
|
||||
player2 = core.get_player_by_name(playername2)
|
||||
end
|
||||
if player2 and num then
|
||||
local meta1 = player1:get_meta()
|
||||
local meta2 = player2:get_meta()
|
||||
local bankemeralds1 = meta1:get_int("emeraldbank:emerald")
|
||||
local bankemeralds2 = meta2:get_int("emeraldbank:emerald")
|
||||
if num > 0 then
|
||||
if bankemeralds1 >= num then
|
||||
meta1:set_int("emeraldbank:emerald", bankemeralds1-num)
|
||||
meta2:set_int("emeraldbank:emerald", bankemeralds2+num)
|
||||
core.chat_send_player(name, S("Pay Successfully! You have transferred @1 Emeralds. Now you have: @2", num, bankemeralds1-num) )
|
||||
core.chat_send_player(playername2, S("Pay Successfully! You've gotten @1 Emeralds. Now you have: @2", num, bankemeralds2+num) )
|
||||
core.chat_send_player(name, S("Pay Successfully! You have transferred @1 Emeralds." , num) )
|
||||
core.chat_send_player(playername2, S("Pay Successfully! You've gotten @1 Emeralds.", num) )
|
||||
emeraldbank.add_emeralds(player1, -num)
|
||||
emeraldbank.add_emeralds(player2, num)
|
||||
else
|
||||
core.chat_send_player(name, S("Not enough Emeralds in your account") )
|
||||
end
|
||||
@ -71,10 +69,7 @@ core.register_chatcommand("emeralds", {
|
||||
player = core.get_player_by_name(playername)
|
||||
end
|
||||
if player and num then
|
||||
local meta = player:get_meta()
|
||||
local bankemeralds = meta:get_int("emeraldbank:emerald")
|
||||
meta:set_int("emeraldbank:emerald", bankemeralds+num)
|
||||
core.chat_send_player(name, S("Emeralds in @1 bank account: @2", playername, bankemeralds+num) )
|
||||
emeraldbank.add_emeralds(player, num)
|
||||
return true
|
||||
end
|
||||
return false
|
||||
|
Loading…
Reference in New Issue
Block a user