cooldown_stuff.lua 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. minetest.register_globalstep(function(dtime, player)
  2. for _, player in pairs(minetest.get_connected_players()) do
  3. local w_item = player:get_wielded_item()
  4. local controls = player:get_player_control()
  5. if w_item:get_definition().weapon_zoom ~= nil then
  6. if controls.zoom then
  7. player:hud_change(scope_hud, "text", "rangedweapons_scopehud.png")
  8. else
  9. player:hud_change(scope_hud, "text", "rangedweapons_empty_icon.png")
  10. end
  11. local wpn_zoom = w_item:get_definition().weapon_zoom
  12. if player:get_properties().zoom_fov ~= wpn_zoom then
  13. player:set_properties({zoom_fov = wpn_zoom})
  14. end
  15. end
  16. if w_item:get_definition().weapon_zoom == nil then
  17. player:hud_change(scope_hud, "text", "rangedweapons_empty_icon.png")
  18. if player:get_inventory():contains_item(
  19. "main", "binoculars:binoculars") then
  20. new_zoom_fov = 10
  21. if player:get_properties().zoom_fov ~= new_zoom_fov then
  22. player:set_properties({zoom_fov = new_zoom_fov})
  23. end
  24. else
  25. new_zoom_fov = 0
  26. if player:get_properties().zoom_fov ~= new_zoom_fov then
  27. player:set_properties({zoom_fov = new_zoom_fov})
  28. end
  29. end
  30. end
  31. local u_meta = player:get_meta()
  32. local cool_down = u_meta:get_float("rw_cooldown") or 0
  33. if u_meta:get_float("rw_cooldown") > 0 then
  34. u_meta:set_float("rw_cooldown", cool_down - dtime)
  35. end
  36. local itemstack = player:get_wielded_item()
  37. if controls.LMB then
  38. if player:get_wielded_item():get_definition().RW_gun_capabilities then
  39. if
  40. player:get_wielded_item():get_definition().RW_gun_capabilities.automatic_gun and player:get_wielded_item():get_definition().RW_gun_capabilities.automatic_gun > 0 then
  41. rangedweapons_shoot_gun(itemstack, player)
  42. player:set_wielded_item(itemstack)
  43. end end
  44. if player:get_wielded_item():get_definition().RW_powergun_capabilities then
  45. if player:get_wielded_item():get_definition().RW_powergun_capabilities.automatic_gun and player:get_wielded_item():get_definition().RW_powergun_capabilities.automatic_gun > 0 then
  46. rangedweapons_shoot_powergun(itemstack, player)
  47. player:set_wielded_item(itemstack)
  48. end end
  49. end
  50. --minetest.chat_send_all(u_meta:get_float("rw_cooldown"))
  51. if u_meta:get_float("rw_cooldown") <= 0 then
  52. if player:get_wielded_item():get_definition().loaded_gun ~= nil then
  53. local itemstack = player:get_wielded_item()
  54. if player:get_wielded_item():get_definition().loaded_sound ~= nil then
  55. minetest.sound_play(itemstack:get_definition().loaded_sound, {player})
  56. end
  57. itemstack:set_name(player:get_wielded_item():get_definition().loaded_gun)
  58. player:set_wielded_item(itemstack)
  59. end
  60. if player:get_wielded_item():get_definition().rw_next_reload ~= nil then
  61. local itemstack = player:get_wielded_item()
  62. if itemstack:get_definition().load_sound ~= nil then
  63. minetest.sound_play(itemstack:get_definition().load_sound, {player})
  64. end
  65. gunMeta = itemstack:get_meta()
  66. u_meta:set_float("rw_cooldown",gunMeta:get_float("RW_reload_delay"))
  67. itemstack:set_name(player:get_wielded_item():get_definition().rw_next_reload)
  68. player:set_wielded_item(itemstack)
  69. end
  70. end
  71. end end)