init.lua 606 B

1234567891011121314151617181920212223242526272829303132333435
  1. local damage_cooldowns = {}
  2. minetest.register_globalstep(function(dtime)
  3. for name, cd in pairs(damage_cooldowns)
  4. do
  5. cd = cd - dtime
  6. if cd <= 0
  7. then
  8. damage_coooldowns[name] = nil
  9. else
  10. damage_cooldowns[name] = c
  11. end
  12. end
  13. end)
  14. minetest.register_on_player_hpchange(function(player, change, reason)
  15. if reason.type == "punch"
  16. then
  17. local name = player:get_player_name()
  18. if damage_cooldowns[name]
  19. then
  20. return 0
  21. else
  22. damage_cooldowns[name] = 0.1
  23. return change
  24. end
  25. elseif reason.type == "fall"
  26. then
  27. return 0
  28. end
  29. return change
  30. end, true)