functions.lua 1.4 KB

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