chat_commands.lua 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. minetest.register_privilege("xpfwset", {description="Set experience level"})
  2. minetest.register_chatcommand("xpset", {
  3. privs = {
  4. xpfwset = true
  5. },
  6. params = "<name>",
  7. description = "Set the statistics/experience for yourself",
  8. func = function(name, param)
  9. -- print(name,param)
  10. local xp= string.split(param, " ")
  11. -- print(dump2(xp))
  12. player=minetest.get_player_by_name(name)
  13. if xpfw.player_get_attribute(player,xp[1]) ~= nil then
  14. xpfw.player_set_attribute(player,xp[1],xp[2])
  15. minetest.chat_send_player(name, "Attribut "..xp[1].." set to "..xp[2])
  16. else
  17. minetest.chat_send_player(name, "Attribut "..xp[1].." not fount")
  18. end
  19. end
  20. })
  21. minetest.register_chatcommand("xpreset", {
  22. privs = {
  23. xpfwset = true
  24. },
  25. description = "Reset the statistics/experience for yourself",
  26. func = function(name, param)
  27. xpfw.player_reset_attributes(minetest.get_player_by_name(name))
  28. minetest.chat_send_player(name, "All Attributs resetted")
  29. end
  30. })
  31. minetest.register_chatcommand("xphud", {
  32. privs = {
  33. xpfwset = true
  34. },
  35. description = "Toggle hud on/off",
  36. func = function(name, param)
  37. xpfw.player_hud_toggle(name)
  38. minetest.chat_send_player(name, "hud on/off")
  39. end
  40. })
  41. minetest.register_chatcommand("xpfw", {
  42. params = "<name>",
  43. description = "Get the statistics for the given player or yourself",
  44. func = function(name, param)
  45. if not param or param == "" then
  46. param = name
  47. end
  48. minetest.chat_send_player(name, param)
  49. local player = ""
  50. for att_def in pairs(xpfw.attributes) do
  51. player=player.."; "..att_def..": "..math.ceil(xpfw.player_get_attribute(minetest.get_player_by_name(name),att_def))
  52. end
  53. minetest.chat_send_player(name, dump(player))
  54. end
  55. })