diff options
author | Gabriel Pérez-Cerezo <gabriel@gpcf.eu> | 2016-10-23 16:43:34 +0200 |
---|---|---|
committer | Gabriel Pérez-Cerezo <gabriel@gpcf.eu> | 2016-10-23 16:43:34 +0200 |
commit | 6fe6a28c21760dd609613c69564b3e008e0241c7 (patch) | |
tree | 0822a974239bd717adcccb47c02d5603ee019252 | |
parent | 53f771e504edc66d8956af2df2d2b40af8d1e4c4 (diff) | |
download | apartment-6fe6a28c21760dd609613c69564b3e008e0241c7.tar.gz apartment-6fe6a28c21760dd609613c69564b3e008e0241c7.tar.bz2 apartment-6fe6a28c21760dd609613c69564b3e008e0241c7.zip |
Give everyone an apartment on login, enable /aphome to go to any rented apartment.
-rw-r--r-- | init.lua | 28 |
1 files changed, 23 insertions, 5 deletions
@@ -829,7 +829,7 @@ minetest.register_node("apartment:apartment_occupied", { if( apartment.enable_aphome_command ) then minetest.register_chatcommand("aphome", { - params = "", + params = "<category>", 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(); |