From 2558f91a44b280e63b7d5a9c4bc0ea1ff5da6ac0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gabriel=20P=C3=A9rez-Cerezo?= Date: Sun, 9 Oct 2016 19:32:43 +0200 Subject: If owner is empty, assume that it's owned by the apartment owner, added support for smartshop. --- init.lua | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) (limited to 'init.lua') diff --git a/init.lua b/init.lua index 2d4a2e3..346d823 100644 --- a/init.lua +++ b/init.lua @@ -445,11 +445,14 @@ apartment.rent = function( pos, pname, oldmetadata, actor ) local m = minetest.get_meta( {x=px, y=py, z=pz}); if( m ) then - local s = m:get_string( 'owner' ); + local s = m:get_string( 'owner' ); -- doors are diffrent if( not( s ) or s=='' ) then s = m:get_string( 'doors_owner' ); end + if ( not s or s == '' )then + s = original_owner + end -- change owner to the new player if( s and s ~= '' and (s==original_owner or s==owner)) then -- change the actual owner @@ -462,7 +465,8 @@ apartment.rent = function( pos, pname, oldmetadata, actor ) else itext = "Locked Chest in Ap. "..descr.." ("..rented_by..")"; end - elseif( n.name == 'doors:door_steel_b_1' or n.name == 'doors:door_steel_t_1' + elseif( n.name == 'doors:door_steel_b_1' or n.name == 'doors:door_steel_t_1' + or n.name == 'doors:door_steel_a' or n.name == 'doors:door_steel_a' or n.name == 'doors:door_steel_b_2' or n.name == 'doors:door_steel_t_2' ) then if( pname=='' ) then itext = "Locked Door (owned by "..original_owner..")"; @@ -560,14 +564,16 @@ apartment.rent = function( pos, pname, oldmetadata, actor ) elseif( n.name == "currency:safe") then itext = "Safe ("..rented_by..")"; elseif( n.name == "currency:shop") then - itext = "Exchange shop ("..rented_by..")"; - + itext = "Exchange shop ("..rented_by..")"; + elseif( n.name == "bitchange:bank" ) then itext = "Bank ("..rented_by..")"; elseif( n.name == "bitchange:moneychanger" ) then itext = "Moneychanger ("..rented_by..")"; elseif( n.name == "bitchange:warehouse" ) then - itext = "Warehouse ("..rented_by..")"; + itext = "Warehouse ("..rented_by..")"; + elseif (n.name == "smartshop:shop") then + itext = "Shop by " .. rented_by elseif( n.name == "bitchange:shop" ) then if( m:get_string('title') and m:get_string('title') ~= '' ) then itext = "Exchange shop \""..( m:get_string('title')).."\" ("..rented_by..")"; -- cgit v1.2.3 From 425d0e2db882bb3850c2efacfc1e7dd9c1a1fa34 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gabriel=20P=C3=A9rez-Cerezo?= Date: Sun, 9 Oct 2016 20:57:09 +0200 Subject: Added mechanism to handle duplicate appartments, fixed formspec. --- init.lua | 34 ++++++++++++++++++++++++++++++++-- 1 file changed, 32 insertions(+), 2 deletions(-) (limited to 'init.lua') diff --git a/init.lua b/init.lua index 346d823..aef4388 100644 --- a/init.lua +++ b/init.lua @@ -131,8 +131,8 @@ apartment.get_formspec = function( pos, placer ) return 'size[6,3]'.. 'label[2.0,-0.3;Apartment \''..minetest.formspec_escape( descr )..'\']'.. size_txt.. - 'label[0.5,1.4;Do you want to rent this]'.. - 'label[2.8,1.4;apartment? It\'s free!]'.. + 'label[0.5,1.8;Do you want to rent this]'.. + 'label[2.8,1.8;apartment? It\'s free!]'.. 'button_exit[3,2.5;2,0.5;rent;Yes, rent it]'.. 'button_exit[1,2.5;1,0.5;abort;No.]'; end @@ -899,6 +899,36 @@ minetest.register_abm({ end }) +minetest.register_abm({ + -- handle duplicates + nodenames= {"apartment:apartment_free" }, + interval = 1, + chance = 1, + action = function(pos,node) + local meta = minetest.get_meta( pos ); + local name = meta:get_string('descr'); +-- minetest.chat_send_all(name) + if apartment.apartments[name] and ( apartment.apartments[name].pos.x ~= pos.x + or apartment.apartments[name].pos.y ~= pos.y or apartment.apartments[name].pos.z ~= pos.z ) then + -- duplicate name + old = apartment.apartments[name] + local number = name:match('%d+$') + if number then + n = name:sub(1,-tostring(number):len()-1)..tostring(number+1) + else + n = name..' 1' + end +-- minetest.chat_send_all(n) + meta:set_string('descr', n) + meta:set_string('formspec', apartment.get_formspec(pos, "")) + if not apartment.apartments[ n ] then + apartment.apartments[ n ] = { pos={x=pos.x, y=pos.y, z=pos.z}, original_owner = old.original_owner, owner='', category = old.category, + start_pos = old.start_pos, + end_pos = old.end_pos }; + end + end + end +}) -- upon server start, read the savefile apartment.restore_data(); -- cgit v1.2.3 From 00ef4946a9a401d901e0a1d6a72332a0c5a5e240 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gabriel=20P=C3=A9rez-Cerezo?= Date: Sun, 9 Oct 2016 21:17:53 +0200 Subject: Improved formspecs --- init.lua | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'init.lua') diff --git a/init.lua b/init.lua index aef4388..9196a1e 100644 --- a/init.lua +++ b/init.lua @@ -131,8 +131,8 @@ apartment.get_formspec = function( pos, placer ) return 'size[6,3]'.. 'label[2.0,-0.3;Apartment \''..minetest.formspec_escape( descr )..'\']'.. size_txt.. - 'label[0.5,1.8;Do you want to rent this]'.. - 'label[2.8,1.8;apartment? It\'s free!]'.. + 'label[0.3,1.8;Do you want to rent this]'.. + 'label[3.0,1.8;apartment? It\'s free!]'.. 'button_exit[3,2.5;2,0.5;rent;Yes, rent it]'.. 'button_exit[1,2.5;1,0.5;abort;No.]'; end @@ -156,9 +156,9 @@ apartment.get_formspec = function( pos, placer ) 'label[0.5,0.8;Category (i.e. house, shop):]'.. 'field[5.0,1.4;2.0,0.5;category;;apartment]'.. - 'label[0.5,1.3;The apartment shall extend]'.. - 'label[3.3,1.3;this many blocks from here:]'.. - 'label[0.5,1.5;(relative to this panel)]'.. + 'label[0.5,1.7;The apartment shall extend]'.. + 'label[3.4,1.7;this many blocks from here:]'.. + 'label[0.5,2.1;(relative to this panel)]'.. 'label[1.3,3.5;left:]' ..'field[2.0,4.0;1.0,0.5;size_left;;' ..tostring( size_left )..']'.. 'label[4.6,3.5;right]' ..'field[4.0,4.0;1.0,0.5;size_right;;'..tostring( size_right )..']'.. -- cgit v1.2.3 From 070aeb91f14065c408ed8c5193ac95c009495cc1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gabriel=20P=C3=A9rez-Cerezo?= Date: Sun, 9 Oct 2016 21:50:19 +0200 Subject: Forbids players from renting unlimited shops --- init.lua | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'init.lua') diff --git a/init.lua b/init.lua index 9196a1e..b2e80a7 100644 --- a/init.lua +++ b/init.lua @@ -573,7 +573,9 @@ apartment.rent = function( pos, pname, oldmetadata, actor ) elseif( n.name == "bitchange:warehouse" ) then itext = "Warehouse ("..rented_by..")"; elseif (n.name == "smartshop:shop") then - itext = "Shop by " .. rented_by + itext = "Shop " .. rented_by + m:set_int("creative", 0) + m:set_int("type",1) elseif( n.name == "bitchange:shop" ) then if( m:get_string('title') and m:get_string('title') ~= '' ) then itext = "Exchange shop \""..( m:get_string('title')).."\" ("..rented_by..")"; -- cgit v1.2.3 From 53f771e504edc66d8956af2df2d2b40af8d1e4c4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gabriel=20P=C3=A9rez-Cerezo?= Date: Sun, 9 Oct 2016 21:52:41 +0200 Subject: Further improvements on formspecs. --- init.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'init.lua') diff --git a/init.lua b/init.lua index b2e80a7..e8892f6 100644 --- a/init.lua +++ b/init.lua @@ -123,8 +123,8 @@ apartment.get_formspec = function( pos, placer ) return 'size[6.5,3]'.. 'label[2.0,-0.3;Apartment \''..minetest.formspec_escape( descr )..'\']'.. size_txt.. - 'label[0.5,1.4;This apartment is rented by:]'.. - 'label[3.5,1.4;'..tostring( owner )..']'.. + 'label[0.5,1.7;This apartment is rented by:]'.. + 'label[3.5,1.7;'..tostring( owner )..']'.. 'button_exit[3,2.5;2,0.5;unrent;Move out]'.. 'button_exit[1,2.5;1,0.5;abort;OK]'; end -- cgit v1.2.3 From 6fe6a28c21760dd609613c69564b3e008e0241c7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gabriel=20P=C3=A9rez-Cerezo?= Date: Sun, 23 Oct 2016 16:43:34 +0200 Subject: Give everyone an apartment on login, enable /aphome to go to any rented apartment. --- init.lua | 28 +++++++++++++++++++++++----- 1 file changed, 23 insertions(+), 5 deletions(-) (limited to 'init.lua') diff --git a/init.lua b/init.lua index e8892f6..8b14c30 100644 --- a/init.lua +++ b/init.lua @@ -829,7 +829,7 @@ minetest.register_node("apartment:apartment_occupied", { if( apartment.enable_aphome_command ) then minetest.register_chatcommand("aphome", { - params = "", + params = "", description = "Teleports you back to the apartment you rented.", privs = {}, func = function(name, param) @@ -837,19 +837,24 @@ if( apartment.enable_aphome_command ) then if( not( name )) then return; end - + local category; + if (not param or param == "") then + category = 'apartment' + else + category = param + end local player = minetest.env:get_player_by_name(name); for k,v in pairs( apartment.apartments ) do -- found the apartment the player rented - if( v and v.owner and v.owner==name ) then + if( v and v.owner and v.owner==name and v.category == category) then player:moveto( v.pos, false); minetest.chat_send_player(name, "Welcome back to your apartment "..k.."."); return; end end - - minetest.chat_send_player(name, "Please rent an apartment first."); + + minetest.chat_send_player(name, "Please rent a "..category.." first."); end }) end @@ -932,5 +937,18 @@ minetest.register_abm({ end }) +-- give each player an apartment upon joining the server -- + +minetest.register_on_newplayer(function(player) + for k,v in pairs( apartment.apartments ) do + if (v.owner == '' and v.category == 'apartment') then + if (apartment.rent( v.pos, player:get_player_name(), nil, player )) then + player:moveto( v.pos, false); + minetest.chat_send_player(player:get_player_name(),"Welcome to your new apartment. You can return here by saying '/aphome'") + break + end + end + end +end) -- upon server start, read the savefile apartment.restore_data(); -- cgit v1.2.3 From cd95fc79771124a8c0e6bbd9cbabce3650fc75da Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gabriel=20P=C3=A9rez-Cerezo?= Date: Sun, 23 Oct 2016 16:57:22 +0200 Subject: Sets the right formspec when renting automatically --- init.lua | 2 ++ 1 file changed, 2 insertions(+) (limited to 'init.lua') diff --git a/init.lua b/init.lua index 8b14c30..15050c5 100644 --- a/init.lua +++ b/init.lua @@ -944,6 +944,8 @@ minetest.register_on_newplayer(function(player) if (v.owner == '' and v.category == 'apartment') then if (apartment.rent( v.pos, player:get_player_name(), nil, player )) then player:moveto( v.pos, false); + local meta = minetest.get_meta( v.pos ); + meta:set_string( 'formspec', apartment.get_formspec( pos, player )); minetest.chat_send_player(player:get_player_name(),"Welcome to your new apartment. You can return here by saying '/aphome'") break end -- cgit v1.2.3 From 418a9606bf79abbb6d4c9d488b5093309eae1b4d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gabriel=20P=C3=A9rez-Cerezo?= Date: Sun, 23 Oct 2016 17:10:34 +0200 Subject: Fixed fatal error --- init.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'init.lua') diff --git a/init.lua b/init.lua index 15050c5..e5ac1f6 100644 --- a/init.lua +++ b/init.lua @@ -945,7 +945,7 @@ minetest.register_on_newplayer(function(player) if (apartment.rent( v.pos, player:get_player_name(), nil, player )) then player:moveto( v.pos, false); local meta = minetest.get_meta( v.pos ); - meta:set_string( 'formspec', apartment.get_formspec( pos, player )); + meta:set_string( 'formspec', apartment.get_formspec( v.pos, player )); minetest.chat_send_player(player:get_player_name(),"Welcome to your new apartment. You can return here by saying '/aphome'") break end -- cgit v1.2.3 From 3c79ab6847a1a22bdcda9f806ee2062797e5ce83 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gabriel=20P=C3=A9rez-Cerezo?= Date: Sun, 23 Oct 2016 18:10:47 +0200 Subject: Fixed bug with doors Now also open doors will be rented. --- init.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'init.lua') diff --git a/init.lua b/init.lua index e5ac1f6..8efe261 100644 --- a/init.lua +++ b/init.lua @@ -466,7 +466,7 @@ apartment.rent = function( pos, pname, oldmetadata, actor ) itext = "Locked Chest in Ap. "..descr.." ("..rented_by..")"; end elseif( n.name == 'doors:door_steel_b_1' or n.name == 'doors:door_steel_t_1' - or n.name == 'doors:door_steel_a' or n.name == 'doors:door_steel_a' + or n.name == 'doors:door_steel_a' or n.name == 'doors:door_steel_b' or n.name == 'doors:door_steel_b_2' or n.name == 'doors:door_steel_t_2' ) then if( pname=='' ) then itext = "Locked Door (owned by "..original_owner..")"; -- cgit v1.2.3 From dcbf1fce1e9303a00be15451e1802c2d4004070f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gabriel=20P=C3=A9rez-Cerezo?= Date: Mon, 24 Oct 2016 09:15:59 +0200 Subject: Assigning apartments to players is now configurabe, enabled by default. --- init.lua | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) (limited to 'init.lua') diff --git a/init.lua b/init.lua index 8efe261..5e5ddfd 100644 --- a/init.lua +++ b/init.lua @@ -938,19 +938,21 @@ minetest.register_abm({ }) -- give each player an apartment upon joining the server -- - -minetest.register_on_newplayer(function(player) - for k,v in pairs( apartment.apartments ) do - if (v.owner == '' and v.category == 'apartment') then - if (apartment.rent( v.pos, player:get_player_name(), nil, player )) then - player:moveto( v.pos, false); - local meta = minetest.get_meta( v.pos ); - meta:set_string( 'formspec', apartment.get_formspec( v.pos, player )); - minetest.chat_send_player(player:get_player_name(),"Welcome to your new apartment. You can return here by saying '/aphome'") - break +local apartment_give_player = minetest.setting_getbool("apartment_give_newplayer") or true; +if apartment_give_player then + minetest.register_on_newplayer(function(player) + for k,v in pairs( apartment.apartments ) do + if (v.owner == '' and v.category == 'apartment') then + if (apartment.rent( v.pos, player:get_player_name(), nil, player )) then + player:moveto( v.pos, false); + local meta = minetest.get_meta( v.pos ); + meta:set_string( 'formspec', apartment.get_formspec( v.pos, player )); + minetest.chat_send_player(player:get_player_name(),"Welcome to your new apartment. You can return here by saying '/aphome'") + break + end end end - end -end) + end) +end -- upon server start, read the savefile apartment.restore_data(); -- cgit v1.2.3 From 1c9bdfad03ab7247ccb55158988ab28929738681 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gabriel=20P=C3=A9rez-Cerezo?= Date: Mon, 24 Oct 2016 09:49:41 +0200 Subject: Deal with apartment database corruption. --- init.lua | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'init.lua') diff --git a/init.lua b/init.lua index 5e5ddfd..c790e5a 100644 --- a/init.lua +++ b/init.lua @@ -943,12 +943,15 @@ if apartment_give_player then minetest.register_on_newplayer(function(player) for k,v in pairs( apartment.apartments ) do if (v.owner == '' and v.category == 'apartment') then - if (apartment.rent( v.pos, player:get_player_name(), nil, player )) then + local meta = minetest.get_meta( v.pos ); + local node = minetest.get_node( v.pos ); + if (node.name == 'apartment:apartment_free' and apartment.rent( v.pos, player:get_player_name(), nil, player )) then player:moveto( v.pos, false); - local meta = minetest.get_meta( v.pos ); meta:set_string( 'formspec', apartment.get_formspec( v.pos, player )); minetest.chat_send_player(player:get_player_name(),"Welcome to your new apartment. You can return here by saying '/aphome'") break + elseif node.name == 'apartment:apartment_occupied' then -- Possible case of database corruption... + apartment.apartments[k] = nil end end end -- cgit v1.2.3 From 6ebe3b99fe7b1c1eb199b5cee0de879fcdf8ee42 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gabriel=20P=C3=A9rez-Cerezo?= Date: Mon, 24 Oct 2016 09:56:12 +0200 Subject: Deal with unloaded apartments. --- init.lua | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'init.lua') diff --git a/init.lua b/init.lua index c790e5a..ba95ff5 100644 --- a/init.lua +++ b/init.lua @@ -943,8 +943,13 @@ if apartment_give_player then minetest.register_on_newplayer(function(player) for k,v in pairs( apartment.apartments ) do if (v.owner == '' and v.category == 'apartment') then + local meta = minetest.get_meta( v.pos ); local node = minetest.get_node( v.pos ); + if node.name == "ignore" then -- deal with unloaded nodes. + minetest.get_voxel_manip():read_from_map(pos, pos) + node = minetest.get_node(pos) + end if (node.name == 'apartment:apartment_free' and apartment.rent( v.pos, player:get_player_name(), nil, player )) then player:moveto( v.pos, false); meta:set_string( 'formspec', apartment.get_formspec( v.pos, player )); -- cgit v1.2.3 From 4ac603ef6fc7b2c80b9bea482142f6f6294b485c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gabriel=20P=C3=A9rez-Cerezo?= Date: Mon, 24 Oct 2016 09:56:43 +0200 Subject: Don't copy and paste without double-checking! --- init.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'init.lua') diff --git a/init.lua b/init.lua index ba95ff5..3e55e89 100644 --- a/init.lua +++ b/init.lua @@ -947,8 +947,8 @@ if apartment_give_player then local meta = minetest.get_meta( v.pos ); local node = minetest.get_node( v.pos ); if node.name == "ignore" then -- deal with unloaded nodes. - minetest.get_voxel_manip():read_from_map(pos, pos) - node = minetest.get_node(pos) + minetest.get_voxel_manip():read_from_map(v.pos, v.pos) + node = minetest.get_node(v.pos) end if (node.name == 'apartment:apartment_free' and apartment.rent( v.pos, player:get_player_name(), nil, player )) then player:moveto( v.pos, false); -- cgit v1.2.3 From 3a79693bef3c1531dca61ede91cb31922d5f3007 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gabriel=20P=C3=A9rez-Cerezo?= Date: Mon, 24 Oct 2016 11:32:52 +0200 Subject: Prevent crash. --- init.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'init.lua') diff --git a/init.lua b/init.lua index 3e55e89..9cf7c5a 100644 --- a/init.lua +++ b/init.lua @@ -915,7 +915,7 @@ minetest.register_abm({ local meta = minetest.get_meta( pos ); local name = meta:get_string('descr'); -- minetest.chat_send_all(name) - if apartment.apartments[name] and ( apartment.apartments[name].pos.x ~= pos.x + if apartment.apartments[name] and apartment.apartments[name].pos and ( apartment.apartments[name].pos.x ~= pos.x or apartment.apartments[name].pos.y ~= pos.y or apartment.apartments[name].pos.z ~= pos.z ) then -- duplicate name old = apartment.apartments[name] -- cgit v1.2.3