whereis.lua 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. -- Localize for performance.
  2. local vector_distance = vector.distance
  3. local vector_round = vector.round
  4. function serveressentials.whereis(pname, param)
  5. local target
  6. if param and param ~= "" then
  7. target = param
  8. else
  9. -- If no argument given, run function for all players.
  10. local players = minetest.get_connected_players()
  11. for _, player in ipairs(players) do
  12. local param = player:get_player_name()
  13. serveressentials.whereis(pname, param)
  14. end
  15. return
  16. end
  17. local player = minetest.get_player_by_name(target)
  18. if not player then
  19. minetest.chat_send_player(pname, "# Server: <" .. rename.gpn(target) .. "> is not online!")
  20. return
  21. end
  22. local pos = vector_round(player:get_pos())
  23. local owner = protector.get_node_owner(pos) or ""
  24. local area = "in unclaimed territory"
  25. if owner ~= "" then
  26. area = "on land claimed by <" .. rename.gpn(owner) .. ">"
  27. end
  28. local nearby = ""
  29. local plist = {}
  30. local allplayers = minetest.get_connected_players()
  31. for _, player in ipairs(allplayers) do
  32. local pn = player:get_player_name() or ""
  33. if pn ~= target and vector_distance(player:get_pos(), pos) <= 64 then
  34. plist[#plist+1] = rename.gpn(pn)
  35. end
  36. end
  37. nearby = "{" .. table.concat(plist, ", ") .. "}"
  38. local HP = "HP=" .. player:get_hp()
  39. local wieldname = serveressentials.get_short_stack_desc(player:get_wielded_item())
  40. if not wieldname or wieldname == "" then
  41. wieldname = "nothing"
  42. else
  43. wieldname = "'" .. wieldname .. "'"
  44. end
  45. local wielding = "wielding " .. wieldname
  46. minetest.chat_send_player(pname,
  47. "# Server: Player <" .. rename.gpn(target) .. ">: at " .. rc.pos_to_namestr(pos) .. ", " ..
  48. HP .. ", " .. wielding .. ", " .. area .. ". Nearby: " .. nearby .. ".")
  49. end