-
Notifications
You must be signed in to change notification settings - Fork 20
/
functions.lua
42 lines (38 loc) · 1.4 KB
/
functions.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
local S = cottages.S
--- if no owner is set, all players may use the node; else only the owner
cottages.player_can_use = function( meta, player )
if( not( player) or not( meta )) then
return false;
end
local pname = player:get_player_name();
local owner = meta:get_string('owner' );
local public = meta:get_string('public')
if( not(owner) or owner=="" or owner==pname or public=="public") then
return true;
end
return false;
end
-- call this in on_receive_fields and add suitable buttons in order
-- to switch between public and private use
cottages.switch_public = function(pos, formname, fields, sender, name_of_the_thing)
-- switch between public and private
local meta = minetest.get_meta(pos)
local public = meta:get_string("public")
local owner = meta:get_string("owner")
if( sender and sender:get_player_name() == owner and fields.public) then
if( public ~= "public") then
meta:set_string("public", "public")
meta:set_string("infotext",
S("Public "..name_of_the_thing.." (owned by %s)"):format(owner))
minetest.chat_send_player(owner,
S("Your "..name_of_the_thing.." can now be used by other players as well."))
else
meta:set_string("public", "")
meta:set_string("infotext",
S("Private "..name_of_the_thing.." (owned by %s)"):format(owner))
minetest.chat_send_player(owner,
S("Your "..name_of_the_thing.." can only be used by yourself."))
end
return true
end
end