skills.lua 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. minetest.register_on_joinplayer(function(player)
  2. local meta = player:get_meta()
  3. if meta:get_int("handgun_skill") == 0
  4. then
  5. meta:set_int("handgun_skill",100)
  6. end
  7. if meta:get_int("mp_skill") == 0
  8. then
  9. meta:set_int("mp_skill",100)
  10. end
  11. if meta:get_int("smg_skill") == 0
  12. then
  13. meta:set_int("smg_skill",100)
  14. end
  15. if meta:get_int("shotgun_skill") == 0
  16. then
  17. meta:set_int("shotgun_skill",100)
  18. end
  19. if meta:get_int("heavy_skill") == 0
  20. then
  21. meta:set_int("heavy_skill",100)
  22. end
  23. if meta:get_int("arifle_skill") == 0
  24. then
  25. meta:set_int("arifle_skill",100)
  26. end
  27. if meta:get_int("revolver_skill") == 0
  28. then
  29. meta:set_int("revolver_skill",100)
  30. end
  31. if meta:get_int("rifle_skill") == 0
  32. then
  33. meta:set_int("rifle_skill",100)
  34. end
  35. if meta:get_int("throw_skill") == 0
  36. then
  37. meta:set_int("throw_skill",100)
  38. end
  39. end)
  40. minetest.register_chatcommand("gunskills", {
  41. func = function(name, param)
  42. for _, player in pairs(minetest.get_connected_players()) do
  43. local meta = player:get_meta()
  44. local handguns = meta:get_int("handgun_skill")
  45. local mps = meta:get_int("mp_skill")
  46. local smgs = meta:get_int("smg_skill")
  47. local shotguns = meta:get_int("shotgun_skill")
  48. local heavy = meta:get_int("heavy_skill")
  49. local arifle = meta:get_int("arifle_skill")
  50. local revolver = meta:get_int("revolver_skill")
  51. local rifle = meta:get_int("rifle_skill")
  52. local throw = meta:get_int("throw_skill")
  53. minetest.show_formspec(name, "rangedweapons:gunskills_form",
  54. "size[11,7]"..
  55. "label[0,0;Gun efficiency: increases damage, accuracy and crit chance.]"..
  56. "image[0,1;1,1;rangedweapons_handgun_img.png]"..
  57. "label[1,1.2;Handgun efficiency: " .. handguns .. "%]"..
  58. "image[0,2;1,1;rangedweapons_machinepistol_img.png]"..
  59. "label[1,2.2;M.Pistol efficiency: " .. mps .. "%]"..
  60. "image[0,3;1,1;rangedweapons_smg_img.png]"..
  61. "label[1,3.2;S.M.G efficiency: " .. smgs .. "%]"..
  62. "image[0,4;1,1;rangedweapons_shotgun_img.png]"..
  63. "label[1,4.2;Shotgun efficiency: " .. shotguns .. "%]"..
  64. "image[0,5;1,1;rangedweapons_heavy_img.png]"..
  65. "label[1,5.2;Heavy.MG efficiency: " .. heavy .. "%]"..
  66. "image[0,6;1,1;rangedweapons_arifle_img.png]"..
  67. "label[1,6.2;A.rifle efficiency: " .. arifle .. "%]"..
  68. "image[5,1;1,1;rangedweapons_revolver_img.png]"..
  69. "label[6,1.2;Revl./mgn. efficiency: " .. revolver .. "%]"..
  70. "image[5,2;1,1;rangedweapons_rifle_img.png]"..
  71. "label[6,2.2;Rifle efficiency: " .. rifle .. "%]"..
  72. "image[5,3;1,1;rangedweapons_yeetable_img.png]"..
  73. "label[6,3.2;Throwing efficiency: " .. throw .. "%]"..
  74. "button_exit[9,0;2,1;exit;Done]")
  75. end
  76. end
  77. })
  78. local timer = 0
  79. minetest.register_globalstep(function(dtime, player)
  80. timer = timer + dtime;
  81. if timer >= 60.0 then
  82. for _, player in pairs(minetest.get_connected_players()) do
  83. local meta = player:get_meta()
  84. local handguns = meta:get_int("handgun_skill")
  85. local mps = meta:get_int("mp_skill")
  86. local smgs = meta:get_int("smg_skill")
  87. local shotguns = meta:get_int("shotgun_skill")
  88. local heavy = meta:get_int("heavy_skill")
  89. local arifle = meta:get_int("arifle_skill")
  90. local revolver = meta:get_int("revolver_skill")
  91. local rifle = meta:get_int("rifle_skill")
  92. local throw = meta:get_int("throw_skill")
  93. if math.random(1, 40) == 1 then
  94. if handguns > rweapons_min_gun_efficiency then
  95. meta:set_int("handgun_skill", handguns - 1)
  96. minetest.chat_send_player(player:get_player_name(), "" ..core.colorize("#ff0000","Handgun skill degraded! "))
  97. end
  98. end
  99. if math.random(1, 40) == 1 then
  100. if mps > rweapons_min_gun_efficiency then
  101. meta:set_int("mp_skill", mps - 1)
  102. minetest.chat_send_player(player:get_player_name(), "" ..core.colorize("#ff0000","Machine Pistol skill degraded! "))
  103. end
  104. end
  105. if math.random(1, 40) == 1 then
  106. if smgs > rweapons_min_gun_efficiency then
  107. meta:set_int("smg_skill", smgs - 1)
  108. minetest.chat_send_player(player:get_player_name(), "" ..core.colorize("#ff0000","S.M.G skill degraded! "))
  109. end
  110. end
  111. if math.random(1, 40) == 1 then
  112. if shotguns > rweapons_min_gun_efficiency then
  113. meta:set_int("shotgun_skill", shotguns - 1)
  114. minetest.chat_send_player(player:get_player_name(), "" ..core.colorize("#ff0000","Shotgun skill degraded! "))
  115. end
  116. end
  117. if math.random(1, 40) == 1 then
  118. if heavy > rweapons_min_gun_efficiency then
  119. meta:set_int("heavy_skill", heavy - 1)
  120. minetest.chat_send_player(player:get_player_name(), "" ..core.colorize("#ff0000","Heavy.MG skill degraded! "))
  121. end
  122. end
  123. if math.random(1, 40) == 1 then
  124. if arifle > rweapons_min_gun_efficiency then
  125. meta:set_int("arifle_skill", arifle - 1)
  126. minetest.chat_send_player(player:get_player_name(), "" ..core.colorize("#ff0000","A.Rifle skill degraded! "))
  127. end
  128. end
  129. if math.random(1, 40) == 1 then
  130. if revolver > rweapons_min_gun_efficiency then
  131. meta:set_int("revolver_skill", revolver - 1)
  132. minetest.chat_send_player(player:get_player_name(), "" ..core.colorize("#ff0000","Revolver/magnum skill degraded! "))
  133. end
  134. end
  135. if math.random(1, 40) == 1 then
  136. if rifle > rweapons_min_gun_efficiency then
  137. meta:set_int("rifle_skill", rifle - 1)
  138. minetest.chat_send_player(player:get_player_name(), "" ..core.colorize("#ff0000","Rifle skill degraded! "))
  139. end
  140. end
  141. if math.random(1, 40) == 1 then
  142. if throw > rweapons_min_gun_efficiency then
  143. meta:set_int("throw_skill", throw - 1)
  144. minetest.chat_send_player(player:get_player_name(), "" ..core.colorize("#ff0000","Throwing skill degraded! "))
  145. end
  146. end
  147. timer = 0
  148. end
  149. end
  150. end)