forked from Mirrorlandia_minetest/emeraldbank
itemstack count to keep emeralds
This commit is contained in:
parent
ff78de484f
commit
e39bb4e085
56
init.lua
56
init.lua
@ -28,21 +28,34 @@ local income_count = tonumber(core.settings:get("emeraldbank.income_count")) or
|
|||||||
local income_period = tonumber(core.settings:get("emeraldbank.income_period")) or 600
|
local income_period = tonumber(core.settings:get("emeraldbank.income_period")) or 600
|
||||||
local maxbankgive = tonumber(core.settings:get("emeraldbank.max_bank_give")) or 100
|
local maxbankgive = tonumber(core.settings:get("emeraldbank.max_bank_give")) or 100
|
||||||
|
|
||||||
|
|
||||||
emeraldbank = {}
|
emeraldbank = {}
|
||||||
|
|
||||||
|
function emeraldbank.keep(player, itemstack)
|
||||||
function emeraldbank.keep(player, itemstack, num)
|
local meta = player:get_meta()
|
||||||
local player_meta = player:get_meta()
|
local bankemeralds = meta:get_int("emeraldbank:emerald") -- if nil "get_int()" return 0 Magic!
|
||||||
local bankemeralds = player_meta:get_int("emeraldbank:emerald") -- if nil "get_int()" convert in 0 Magic!
|
|
||||||
local name = player:get_player_name()
|
local name = player:get_player_name()
|
||||||
itemstack:take_item() -- allways take 1 item
|
local itemname = itemstack:get_name()
|
||||||
player_meta:set_int("emeraldbank:emerald", bankemeralds+num)
|
local itemcount = itemstack:get_count()
|
||||||
core.chat_send_player(name, S("Emeralds in Bank: @1", bankemeralds+num) )
|
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) )
|
||||||
|
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) )
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
core.chat_send_player(name, S("You need keep emeralds or emeraldblocks in your hand!") )
|
||||||
|
return false
|
||||||
end
|
end
|
||||||
|
|
||||||
function emeraldbank.take(player)
|
function emeraldbank.take(player)
|
||||||
local player_meta = player:get_meta()
|
local meta = player:get_meta()
|
||||||
local bankemeralds = player_meta:get_int("emeraldbank:emerald")
|
local bankemeralds = meta:get_int("emeraldbank:emerald")
|
||||||
local name = player:get_player_name()
|
local name = player:get_player_name()
|
||||||
local pos = player:get_pos()
|
local pos = player:get_pos()
|
||||||
local num = 1
|
local num = 1
|
||||||
@ -50,7 +63,7 @@ function emeraldbank.take(player)
|
|||||||
if bankemeralds >= 10 then
|
if bankemeralds >= 10 then
|
||||||
num = 10
|
num = 10
|
||||||
end
|
end
|
||||||
player_meta:set_int("emeraldbank:emerald", bankemeralds-num)
|
meta:set_int("emeraldbank:emerald", bankemeralds-num)
|
||||||
core.add_item(pos, "mcl_core:emerald "..num)
|
core.add_item(pos, "mcl_core:emerald "..num)
|
||||||
core.chat_send_player(name, S("Emeralds in Bank: @1", bankemeralds-num) )
|
core.chat_send_player(name, S("Emeralds in Bank: @1", bankemeralds-num) )
|
||||||
return true
|
return true
|
||||||
@ -73,16 +86,7 @@ core.register_node("emeraldbank:bank", {
|
|||||||
_mcl_hardness = 1,
|
_mcl_hardness = 1,
|
||||||
|
|
||||||
on_rightclick = function(pos, node, clicker, itemstack, pointed_thing)
|
on_rightclick = function(pos, node, clicker, itemstack, pointed_thing)
|
||||||
local wielditem = clicker:get_wielded_item()
|
emeraldbank.keep(clicker, itemstack)
|
||||||
local itemname = wielditem:get_name()
|
|
||||||
local name = clicker:get_player_name()
|
|
||||||
if itemname == "mcl_core:emerald" then
|
|
||||||
emeraldbank.keep(clicker, itemstack, 1)
|
|
||||||
elseif itemname == "mcl_core:emeraldblock" then
|
|
||||||
emeraldbank.keep(clicker, itemstack, 9)
|
|
||||||
else
|
|
||||||
core.chat_send_player(name, S("You need keep emeralds or emeraldblocks in your hand!") )
|
|
||||||
end
|
|
||||||
end,
|
end,
|
||||||
|
|
||||||
on_punch = function(pos, node, puncher, pointed_thing)
|
on_punch = function(pos, node, puncher, pointed_thing)
|
||||||
@ -115,9 +119,9 @@ core.register_chatcommand("emeraldbank", {
|
|||||||
player = core.get_player_by_name(playername)
|
player = core.get_player_by_name(playername)
|
||||||
end
|
end
|
||||||
if player and num then
|
if player and num then
|
||||||
local player_meta = player:get_meta()
|
local meta = player:get_meta()
|
||||||
local bankemeralds = player_meta:get_int("emeraldbank:emerald")
|
local bankemeralds = meta:get_int("emeraldbank:emerald")
|
||||||
player_meta:set_int("emeraldbank:emerald", bankemeralds+num)
|
meta:set_int("emeraldbank:emerald", bankemeralds+num)
|
||||||
core.chat_send_player(name, S("Emeralds in @1 bank account: @2", playername, bankemeralds+num) )
|
core.chat_send_player(name, S("Emeralds in @1 bank account: @2", playername, bankemeralds+num) )
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
@ -136,15 +140,15 @@ if income_enabled then
|
|||||||
timer = 0
|
timer = 0
|
||||||
for _, player in ipairs(core.get_connected_players()) do
|
for _, player in ipairs(core.get_connected_players()) do
|
||||||
if not player or player.is_fake_player then return end
|
if not player or player.is_fake_player then return end
|
||||||
local player_meta = player:get_meta()
|
local meta = player:get_meta()
|
||||||
local name = player:get_player_name()
|
local name = player:get_player_name()
|
||||||
local bankemeralds = player_meta:get_int("emeraldbank:emerald")
|
local bankemeralds = meta:get_int("emeraldbank:emerald")
|
||||||
local bankgive = math.floor(bankemeralds^(1/3))
|
local bankgive = math.floor(bankemeralds^(1/3))
|
||||||
if bankgive > maxbankgive then bankgive = maxbankgive end
|
if bankgive > maxbankgive then bankgive = maxbankgive end
|
||||||
local earned = income_count+bankgive
|
local earned = income_count+bankgive
|
||||||
local total = bankemeralds+earned
|
local total = bankemeralds+earned
|
||||||
|
|
||||||
player_meta:set_int("emeraldbank:emerald", total)
|
meta:set_int("emeraldbank:emerald", total)
|
||||||
core.chat_send_player(name, S("You have earned @1 emeralds in your bank account!", earned) )
|
core.chat_send_player(name, S("You have earned @1 emeralds in your bank account!", earned) )
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user