armor.lua 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. -- Armorball: Test entity for testing armor groups
  2. -- Rightclick to change armor group
  3. local phasearmor = {
  4. [0]={icy=100},
  5. [1]={fiery=100},
  6. [2]={icy=100, fiery=100},
  7. [3]={fleshy=-100},
  8. [4]={fleshy=1},
  9. [5]={fleshy=10},
  10. [6]={fleshy=50},
  11. [7]={fleshy=100},
  12. [8]={fleshy=200},
  13. [9]={fleshy=1000},
  14. [10]={fleshy=32767},
  15. [11]={immortal=1},
  16. [12]={punch_operable=1},
  17. }
  18. local max_phase = 12
  19. core.register_entity("testentities:armorball", {
  20. initial_properties = {
  21. hp_max = 20,
  22. physical = false,
  23. collisionbox = {-0.4,-0.4,-0.4, 0.4,0.4,0.4},
  24. visual = "sprite",
  25. visual_size = {x=1, y=1},
  26. textures = {"testentities_armorball.png"},
  27. spritediv = {x=1, y=max_phase+1},
  28. initial_sprite_basepos = {x=0, y=0},
  29. },
  30. _phase = 7,
  31. on_activate = function(self, staticdata)
  32. core.log("action", "[testentities] armorball.on_activate")
  33. self.object:set_armor_groups(phasearmor[self._phase])
  34. self.object:set_sprite({x=0, y=self._phase})
  35. end,
  36. on_rightclick = function(self, clicker)
  37. -- Change armor group and sprite
  38. self._phase = self._phase + 1
  39. if self._phase >= max_phase + 1 then
  40. self._phase = 0
  41. end
  42. self.object:set_sprite({x=0, y=self._phase})
  43. self.object:set_armor_groups(phasearmor[self._phase])
  44. end,
  45. on_punch = function(self, puncher, time_from_last_punch, tool_capabilities, dir, damage)
  46. if not puncher then
  47. return
  48. end
  49. local name = puncher:get_player_name()
  50. if not name then
  51. return
  52. end
  53. core.chat_send_player(name, "time_from_last_punch="..string.format("%.3f", time_from_last_punch).."; damage="..tostring(damage))
  54. end,
  55. })