summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorcheapie <no-email-for-you@example.com>2014-08-07 00:17:40 -0500
committercheapie <no-email-for-you@example.com>2014-08-07 00:17:40 -0500
commit159ff8d1afcdbaeb682de8998119baa8a6d9fbd0 (patch)
treeff32dc23594ecf7cf4601280b445dd4321fa5e59
parent56782798743cea0a6a193a4f85110a19cfa0e0c0 (diff)
downloadcreative-159ff8d1afcdbaeb682de8998119baa8a6d9fbd0.tar
creative-159ff8d1afcdbaeb682de8998119baa8a6d9fbd0.tar.gz
creative-159ff8d1afcdbaeb682de8998119baa8a6d9fbd0.tar.bz2
creative-159ff8d1afcdbaeb682de8998119baa8a6d9fbd0.tar.xz
creative-159ff8d1afcdbaeb682de8998119baa8a6d9fbd0.zip
Added freebuild mode
-rw-r--r--init.lua26
1 files changed, 25 insertions, 1 deletions
diff --git a/init.lua b/init.lua
index de77964..ac3a3da 100644
--- a/init.lua
+++ b/init.lua
@@ -5,6 +5,12 @@
-- Shows the trash slot to players in survival mode
local SURVIVAL_TRASH = true
+-- Enables "Freebuild Mode", which allows players to grant/revoke their own creative priv with a button in the inventory.
+-- Switching from survival to creative is generally instant, however logging off and back on is required when switching to survival.
+-- Note that if players are in creative mode when this is turned off, they will become "stuck" there unless their creative priv is
+-- revoked by other means or this is turned back on.
+local FREEBUILD_MODE = false
+
-- "Special" Mode
local ALL_THE_THINGS = false
@@ -123,7 +129,7 @@ refill:set_size("main", 1)
creative_inventory.set_creative_formspec = function(player, start_i, pagenum)
pagenum = math.floor(pagenum)
local pagemax = math.floor((creative_inventory.creative_inventory_size-1) / (6*4) + 1)
- local formspec = ("size[13,7.5]"..
+ local formspec = ("size[14,7.5]"..
--"image[6,0.6;1,2;player.png]"..
"list[current_player;main;5,3.5;8,4;]"..
"list[current_player;craft;8,0;3,3;]"..
@@ -141,6 +147,9 @@ creative_inventory.set_creative_formspec = function(player, start_i, pagenum)
else
formspec = formspec.."button[6,2;2,1;clear;Clear Inventory]"
end
+ if (FREEBUILD_MODE) then
+ formspec = formspec.."button[11,0;3,1;creativeoff;Switch to Survival Mode]"
+ end
player:set_inventory_formspec(formspec)
end
creative_inventory.set_survival_formspec = function(player)
@@ -148,6 +157,9 @@ creative_inventory.set_survival_formspec = function(player)
if (SURVIVAL_TRASH) then
formspec = formspec.."list[detached:creative_trash;main;0,2;1,1;]".."label[0,1.5;Trash:]"
end
+ if (FREEBUILD_MODE) then
+ formspec = formspec.."button[5,0;3,1;creativeon;Switch to Creative Mode]"
+ end
player:set_inventory_formspec(formspec)
end
creative_inventory.clear_inventory = function(player)
@@ -155,6 +167,12 @@ creative_inventory.clear_inventory = function(player)
local player_name = player:get_player_name()
minetest.chat_send_player(player_name, 'Inventory Cleared!')
end
+creative_inventory.creative_on = function(player)
+ minetest.set_player_privs(player:get_player_name(),{creative=true})
+end
+creative_inventory.creative_off = function(player)
+ minetest.set_player_privs(player:get_player_name(),{creative=false})
+end
minetest.register_on_joinplayer(function(player)
-- If in creative mode, modify player's inventory forms
if not creative_inventory.is_creative(player) then
@@ -173,6 +191,12 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
if fields.clear then
creative_inventory.clear_inventory(player)
end
+ if fields.creativeon then
+ creative_inventory.creative_on(player)
+ end
+ if fields.creativeoff then
+ creative_inventory.creative_off(player)
+ end
if creative_inventory.is_creative(player) then
if fields.creative_prev then
start_i = start_i - 4*6