commands.lua 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. local S = minetest.get_translator("folks")
  2. ChatCmdBuilder.new("folks", function(cmd)
  3. -- command for editing selected npc name
  4. cmd:sub("edit name :name:text", function(pname, new_name)
  5. local player = minetest.get_player_by_name(pname)
  6. if player then
  7. local meta = player:get_meta()
  8. if meta then
  9. local editing_npc = meta:get_string("folks_editing_npc")
  10. if editing_npc == "" then
  11. minetest.chat_send_player(pname, minetest.colorize("#ff0000", S("You are not editing an NPC. Click the NPC you want to edit with the NPC editor item.")))
  12. return
  13. end
  14. local npc = folks.backend.get_npc(editing_npc)
  15. if npc then
  16. folks.edit_npc_name(editing_npc, new_name)
  17. meta:set_string("folks_editing_npc", "")
  18. minetest.chat_send_player(pname, minetest.colorize("#00ff00", S("Edited NPC: @1", editing_npc)))
  19. end
  20. end
  21. end
  22. end)
  23. -- command for editing selected npc name color
  24. cmd:sub("edit name_color :color:text", function(pname, new_color)
  25. local player = minetest.get_player_by_name(pname)
  26. if player then
  27. local meta = player:get_meta()
  28. if meta then
  29. local editing_npc = meta:get_string("folks_editing_npc")
  30. if editing_npc == "" then
  31. minetest.chat_send_player(pname, minetest.colorize("#ff0000", S("You are not editing an NPC. Click the NPC you want to edit with the NPC editor item.")))
  32. return
  33. end
  34. local npc = folks.backend.get_npc(editing_npc)
  35. if npc then
  36. folks.edit_npc_name_color(editing_npc, new_color)
  37. meta:set_string("folks_editing_npc", "")
  38. minetest.chat_send_player(pname, minetest.colorize("#00ff00", S("Edited NPC: @1", editing_npc)))
  39. end
  40. end
  41. end
  42. end)
  43. -- command for editing selected npc texture
  44. cmd:sub("edit texture :name:text", function(pname, new_texture)
  45. local player = minetest.get_player_by_name(pname)
  46. if player then
  47. local meta = player:get_meta()
  48. if meta then
  49. local editing_npc = meta:get_string("folks_editing_npc")
  50. if editing_npc == "" then
  51. minetest.chat_send_player(pname, minetest.colorize("#ff0000", S("You are not editing an NPC. Click the NPC you want to edit with the NPC editor item.")))
  52. return
  53. end
  54. local npc = folks.backend.get_npc(editing_npc)
  55. if npc then
  56. folks.edit_npc_texture(editing_npc, new_texture)
  57. meta:set_string("folks_editing_npc", "")
  58. minetest.chat_send_player(pname, minetest.colorize("#00ff00", S("Edited NPC: @1", editing_npc)))
  59. end
  60. end
  61. end
  62. end)
  63. -- command to bind name and texture of npc to a player, needs skins_collectible
  64. cmd:sub("bind :name:text", function(pname, bind_to)
  65. if folks.skins_c then
  66. local player = minetest.get_player_by_name(pname)
  67. if player then
  68. local meta = player:get_meta()
  69. if meta then
  70. local editing_npc = meta:get_string("folks_editing_npc")
  71. if editing_npc == "" then
  72. minetest.chat_send_player(pname, minetest.colorize("#ff0000", S("You are not editing an NPC. Click the NPC you want to edit with the NPC editor item.")))
  73. return
  74. end
  75. local npc = folks.backend.get_npc(editing_npc)
  76. if npc then
  77. if folks.bind_npc_to_player(editing_npc, bind_to) then
  78. minetest.chat_send_player(pname, minetest.colorize("#00ff00", S("Edited NPC: @1", editing_npc)))
  79. else
  80. minetest.chat_send_player(pname, minetest.colorize("#ff0000", S("Couldn't retrieve player texture (is it online?)")))
  81. end
  82. meta:set_string("folks_editing_npc", "")
  83. end
  84. end
  85. end
  86. else
  87. minetest.chat_send_player(pname, minetest.colorize("#ff0000", S("You need skins_collectible to use this feature")))
  88. end
  89. end)
  90. end, {
  91. description = S("Manage folks npcs"),
  92. privs = {
  93. folks_admin = true
  94. }
  95. })