diff options
-rw-r--r-- | init.lua | 31 | ||||
-rw-r--r-- | landsale.lua | 103 |
2 files changed, 122 insertions, 12 deletions
@@ -20,6 +20,8 @@ local offense = {} gstepCount = 0 playerHudItems = {} +local path = minetest.get_modpath("landrush") + -- These are items that can be dug in unclaimed areas when requireClaim is true local global_dig_list = {["default:ladder"]=true,["default:leaves"]=true,["default:tree"]=true,["default:grass"]=true,["default:grass_1"]=true,["default:grass_2"]=true,["default:grass_3"]=true,["default:grass_4"]=true} @@ -303,7 +305,7 @@ minetest.register_entity("landrush:showarea",{ weight = 0, collisionbox = {-8,-8,-8,8,8,8}, visual = "mesh", - visual_size = {x=16.1, y=16.1}, + visual_size = {x=16.1, y=120.1}, mesh = "landrush_showarea.x", textures = {"landrush_showarea.png", "landrush_showarea.png", "landrush_showarea.png", "landrush_showarea.png", "landrush_showarea.png", "landrush_showarea.png"}, -- number of required textures depends on visual colors = {}, -- number of required colors depends on visual @@ -318,8 +320,9 @@ minetest.register_entity("landrush:showarea",{ minetest.register_globalstep(function(dtime) gstepCount = gstepCount + dtime if ( gstepCount > 2 ) then - - for _,player in ipairs(minetest.get_connected_players()) do + gstepCount=0 + local oplayers = minetest.get_connected_players() + for _,player in ipairs(oplayers) do local name = player:get_player_name() local sameowner = false owner = landrush.get_owner(player:getpos()) @@ -337,7 +340,7 @@ minetest.register_globalstep(function(dtime) end if ( owner ~= nil and sameowner == false ) then - minetest.log('action','Redraw hud for '..name) + --minetest.log('action','Redraw hud for '..name) playerHudItems[name] = {hud = player:hud_add({ hud_elem_type = "text", name = "LandOwner", @@ -348,27 +351,31 @@ minetest.register_globalstep(function(dtime) alignment = {x=0, y=0}, }), lastowner=owner} end - end - gstepCount = 0 + end end end) function landrush.get_distance(pos1,pos2) -if ( pos1 ~= nil and pos2 ~= nil ) then - return math.abs(math.floor(math.sqrt( (pos1.x - pos2.x)^2 + (pos1.y - pos2.y)^2 + (pos1.z - pos2.z)^2 ))) -else - return 0 + if ( pos1 ~= nil and pos2 ~= nil ) then + return math.abs(math.floor(math.sqrt( (pos1.x - pos2.x)^2 + (pos1.y - pos2.y)^2 + (pos1.z - pos2.z)^2 ))) + else + return 0 + end + end + +if ( minetest.get_modpath("money2") ) then + dofile(path.."/landsale.lua") end -minetest.after( 10, function () -local path = minetest.get_modpath("landrush") +minetest.after(0, function () dofile(path.."/bucket.lua") dofile(path.."/default.lua") dofile(path.."/doors.lua") dofile(path.."/fire.lua") dofile(path.."/chatcommands.lua") + end )
\ No newline at end of file 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 |