summaryrefslogtreecommitdiff
path: root/landsale.lua
diff options
context:
space:
mode:
authorBrandon <brandon@bremaweb.com>2013-06-22 22:58:52 -0500
committerBrandon <brandon@bremaweb.com>2013-06-22 22:58:52 -0500
commite3b5637e8ee2eb00ab42fd36f1b01e37ff3dbcd4 (patch)
tree9b74a6f96d834dc4451e7715daccb717c24ed83a /landsale.lua
parent33507be85a2b84b0c444a89fc134dd78d65ea2f3 (diff)
added land sale
Diffstat (limited to 'landsale.lua')
-rw-r--r--landsale.lua103
1 files changed, 103 insertions, 0 deletions
diff --git a/landsale.lua b/landsale.lua
new file mode 100644
index 0000000..540453b
--- /dev/null
+++ b/landsale.lua
@@ -0,0 +1,103 @@
+
+minetest.register_node("landrush:sale_block",{
+ description="Landrush Sale Block",
+ tiles={"landrush_sale_block.png"},
+ groups = {crumbly=2,snappy=2,oddly_breakable_by_hand=2},
+ drop = "landrush:sale_block",
+
+ after_place_node = function (pos, placer)
+ local name = placer:get_player_name()
+ local owner = landrush.get_owner(pos)
+ local meta = minetest.get_meta(pos)
+ if ( name == owner ) then
+ meta:set_int("price",0)
+ meta:set_string("infotext", "For sale by "..owner)
+ meta:set_string("note","")
+ meta:set_string("formspec", landrush.sell_formspec(pos, placer))
+ else
+ meta:set_string("infotext","Not for sale")
+ minetest.chat_send_player(name,"You can't sell a claim you don't own")
+ end
+ end,
+
+ on_punch = function (pos, node, puncher)
+ -- do the sale -- maybe a are you sure formspec?
+ local name = puncher:get_player_name()
+ local owner = landrush.get_owner(pos)
+ if ( name ~= owner ) then
+ local meta = minetest.get_meta(pos)
+ local price = meta:get_int("price")
+ if ( money.get(name) >= price ) then
+ local transfer = money.transfer(name,owner,price)
+ if ( transfer == nil ) then
+ chunk = landrush.get_chunk(pos)
+ claims[chunk] = {owner=name,shared={},claimtype='landclaim'}
+ landrush.save_claims()
+ minetest.chat_send_player(claims[chunk].owner, "You now own this claim.")
+ minetest.remove_node(pos)
+ else
+ minetest.chat_send_player(name,"Money transfer failed: "..transfer)
+ end
+ else
+ minetest.chat_send_player(name,"You do not have enough to purchase this claim")
+ end
+ end
+ end,
+--[[
+ on_rightclick = function (pos, node, player, itemstack)
+ name = player:get_player_name()
+ owner = landrush.get_owner(pos)
+ if ( name == owner ) then
+ minetest.show_formspec(name,"landrush_sell",landrush.sell_formspec(pos,player))
+ end
+ end,
+]]
+ on_receive_fields = function ( pos, formname, fields, sender )
+ --process formspec
+ local name = sender:get_player_name()
+ local owner = landrush.get_owner(pos)
+ if ( name == owner ) then
+ local meta = minetest.get_meta(pos)
+ meta:set_int("price",fields.price)
+ meta:set_string("note",fields.note)
+ meta:set_string("infotext","For sale by "..owner.." for " .. tostring(fields.price) .." "..fields.note)
+ meta:set_string("formspec",landrush.sell_formspec(pos,sender))
+ else
+ minetest.chat_send_player(name,"You can't configure this sale!")
+ end
+ end,
+
+})
+
+minetest.register_craft({
+ output = "landrush:sale_block",
+ recipe = {
+ {"default:wood","default:wood","default:wood"},
+ {"default:wood","default:wood","default:wood"},
+ {"","default:wood",""}
+ }
+})
+
+function landrush.sell_formspec(pos,player)
+ local meta = minetest.env:get_meta(pos)
+ local price = meta:get_int("price")
+ local note = meta:get_string("note")
+
+ local formspec = "size[4,6;]"
+ .."label[0,0;Setup Sale]"
+ .."field[.25,2;2,1;price;Sale Price;"..price.."]"
+ .."field[.25,4;4,1;note;Notes;"..note.."]"
+ .."button_exit[.75,5;2,1;save;Save]"
+
+ return formspec
+end
+
+function landrush.process_formspec(player, formname, fields)
+ if ( formname == "landrush_buy" ) then
+
+ end
+end
+
+
+
+minetest.register_on_player_receive_fields( landrush.process_formspec ) \ No newline at end of file