init.lua 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441
  1. arrows = {
  2. {"lottthrowing:arrow", "lottthrowing:arrow_entity"},
  3. {"lottthrowing:arrow_mithril", "lottthrowing:arrow_mithril_entity"},
  4. {"lottthrowing:arrow_fire", "lottthrowing:arrow_fire_entity"},
  5. {"lottthrowing:arrow_fire_blue", "lottthrowing:arrow_fire_blue_entity"},
  6. {"lottthrowing:arrow_magical", "lottthrowing:arrow_magical_entity"},
  7. }
  8. bolts = {
  9. {"lottthrowing:bolt", "lottthrowing:bolt_entity"},
  10. {"lottthrowing:bolt_mithril", "lottthrowing:bolt_mithril_entity"},
  11. {"lottthrowing:bolt_fire", "lottthrowing:bolt_fire_entity"},
  12. }
  13. local time_bow = {}
  14. local time_crossbow = {}
  15. local ids = {}
  16. local count = 0
  17. minetest.register_globalstep(function(dtime)
  18. count = count + dtime
  19. if count > 1 then
  20. for i, v in pairs(time_bow) do
  21. if v > 0 then
  22. local player = minetest.get_player_by_name(i)
  23. time_bow[i] = v - 1
  24. if player ~= nil then
  25. if time_bow[i] <= 0 then
  26. player:hud_remove(ids[i .. " img"])
  27. player:hud_remove(ids[i .. " txt"])
  28. v = 0
  29. end
  30. player:hud_change(ids[i .. " txt"], "text",
  31. "Reloading bow... " .. v .. " s)")
  32. end
  33. end
  34. end
  35. for i, v in pairs(time_crossbow) do
  36. if v > 0 then
  37. local player = minetest.get_player_by_name(i)
  38. time_crossbow[i] = v - 1
  39. if player ~= nil then
  40. if time_crossbow[i] <= 0 then
  41. player:hud_remove(ids[i .. " cimg"])
  42. player:hud_remove(ids[i .. " ctxt"])
  43. v = 0
  44. end
  45. player:hud_change(ids[i .. " ctxt"], "text",
  46. "Reloading crossbow... (" .. v .. " s)")
  47. end
  48. end
  49. end
  50. count = 0
  51. end
  52. end)
  53. minetest.register_on_leaveplayer(function(player)
  54. time_bow[player:get_player_name()] = nil
  55. time_crossbow[player:get_player_name()] = nil
  56. end)
  57. local lottthrowing_shoot_arrow = function(itemstack, player, pointed_thing, drawspeed)
  58. local name = player:get_player_name()
  59. if time_bow[name] == nil then
  60. time_bow[name] = 0
  61. end
  62. for _,arrow in ipairs(arrows) do
  63. if player:get_inventory():get_stack("main", player:get_wield_index()+1):get_name() == arrow[1]
  64. and time_bow[name] == 0 then
  65. if not minetest.setting_getbool("creative_mode") then
  66. player:get_inventory():remove_item("main", arrow[1])
  67. end
  68. local playerpos = player:getpos()
  69. time_bow[name] = drawspeed
  70. ids[name .. " img"] = player:hud_add({
  71. hud_elem_type = "image",
  72. scale = { x = 2, y = 2 },
  73. position = { x = 0.9, y = 0.5 },
  74. name = "lottthrowing_bow_wood.png",
  75. text = "lottthrowing_bow_wood.png",
  76. direction = 0,
  77. --offset = { x = -186, y = pos*20 },
  78. })
  79. ids[name .. " txt"] = player:hud_add({
  80. hud_elem_type = "text",
  81. position = { x = 0.9, y = 0.55 },
  82. name = "text",
  83. text = "Reloading bow... ("..drawspeed.." s)",
  84. --offset = { x = -186, y = pos*20 },
  85. })
  86. local obj = minetest.add_entity({x=playerpos.x,y=playerpos.y+1.5,z=playerpos.z}, arrow[2])
  87. obj:get_luaentity().player = player or nil
  88. local dir = player:get_look_dir()
  89. obj:setvelocity({x=dir.x*19, y=dir.y*19, z=dir.z*19})
  90. obj:setacceleration({x=dir.x*-3, y=-10, z=dir.z*-3})
  91. obj:setyaw(player:get_look_yaw()+math.pi)
  92. minetest.sound_play("lottthrowing_sound", {pos=playerpos})
  93. if obj:get_luaentity().player == "" then
  94. obj:get_luaentity().player = player
  95. end
  96. obj:get_luaentity().node = player:get_inventory():get_stack("main", 1):get_name()
  97. return true
  98. end
  99. end
  100. return false
  101. end
  102. local lottthrowing_shoot_bolt = function(itemstack, player, pointed_thing, drawspeed)
  103. local name = player:get_player_name()
  104. if time_crossbow[name] == nil then
  105. time_crossbow[name] = 0
  106. end
  107. for _,arrow in ipairs(bolts) do
  108. if player:get_inventory():get_stack("main", player:get_wield_index()+1):get_name() == arrow[1]
  109. and time_crossbow[name] == 0 then
  110. if not minetest.setting_getbool("creative_mode") then
  111. player:get_inventory():remove_item("main", arrow[1])
  112. end
  113. local playerpos = player:getpos()
  114. time_crossbow[name] = drawspeed
  115. ids[name .. " cimg"] = player:hud_add({
  116. hud_elem_type = "image",
  117. scale = { x = 2, y = 2 },
  118. position = { x = 0.9, y = 0.4 },
  119. name = "lottthrowing_crossbow_steel.png",
  120. text = "lottthrowing_crossbow_steel.png",
  121. direction = 0,
  122. --offset = { x = -186, y = pos*20 },
  123. })
  124. ids[name .. " ctxt"] = player:hud_add({
  125. hud_elem_type = "text",
  126. position = { x = 0.875, y = 0.45 },
  127. name = "text",
  128. text = "Reloading crossbow... ("..drawspeed.." s)",
  129. --offset = { x = -186, y = pos*20 },
  130. })
  131. local obj = minetest.add_entity({x=playerpos.x,y=playerpos.y+1.5,z=playerpos.z}, arrow[2])
  132. obj:get_luaentity().player = player or nil
  133. local dir = player:get_look_dir()
  134. obj:setvelocity({x=dir.x*25, y=dir.y*25, z=dir.z*25})
  135. obj:setacceleration({x=dir.x*-1, y=-5, z=dir.z*-1})
  136. obj:setyaw(player:get_look_yaw()+math.pi)
  137. minetest.sound_play("lottthrowing_sound", {pos=playerpos})
  138. if obj:get_luaentity().player == "" then
  139. obj:get_luaentity().player = player
  140. end
  141. obj:get_luaentity().node = player:get_inventory():get_stack("main", 1):get_name()
  142. return true
  143. end
  144. end
  145. return false
  146. end
  147. minetest.register_tool("lottthrowing:bow_wood", {
  148. description = "Normal Wood Bow",
  149. inventory_image = "lottthrowing_bow_wood.png",
  150. stack_max = 1,
  151. on_use = function(itemstack, user, pointed_thing)
  152. if lottthrowing_shoot_arrow(itemstack, user, pointed_thing, 5) then
  153. if not minetest.setting_getbool("creative_mode") then
  154. itemstack:add_wear(65535/50)
  155. end
  156. end
  157. return itemstack
  158. end,
  159. })
  160. minetest.register_tool("lottthrowing:bow_wood_alder", {
  161. description = "Alder Wood Bow",
  162. inventory_image = "lottthrowing_bow_wood_alder.png",
  163. stack_max = 1,
  164. on_use = function(itemstack, user, pointed_thing)
  165. if lottthrowing_shoot_arrow(item, user, pointed_thing, 4) then
  166. if not minetest.setting_getbool("creative_mode") then
  167. itemstack:add_wear(65535/70)
  168. end
  169. end
  170. return itemstack
  171. end,
  172. })
  173. minetest.register_tool("lottthrowing:bow_wood_birch", {
  174. description = "Birch Wood Bow",
  175. inventory_image = "lottthrowing_bow_wood_birch.png",
  176. stack_max = 1,
  177. on_use = function(itemstack, user, pointed_thing)
  178. if lottthrowing_shoot_arrow(item, user, pointed_thing, 3) then
  179. if not minetest.setting_getbool("creative_mode") then
  180. itemstack:add_wear(65535/100)
  181. end
  182. end
  183. return itemstack
  184. end,
  185. })
  186. minetest.register_tool("lottthrowing:bow_wood_lebethron", {
  187. description = "Lebethron Wood Bow",
  188. inventory_image = "lottthrowing_bow_wood_lebethron.png",
  189. stack_max = 1,
  190. on_use = function(itemstack, user, pointed_thing)
  191. if lottthrowing_shoot_arrow(item, user, pointed_thing, 2) then
  192. if not minetest.setting_getbool("creative_mode") then
  193. itemstack:add_wear(65535/150)
  194. end
  195. end
  196. return itemstack
  197. end,
  198. })
  199. minetest.register_tool("lottthrowing:bow_wood_mallorn", {
  200. description = "Mallorn Bow",
  201. inventory_image = "lottthrowing_bow_wood_mallorn.png",
  202. stack_max = 1,
  203. on_use = function(itemstack, user, pointed_thing)
  204. if lottthrowing_shoot_arrow(item, user, pointed_thing, 1) then
  205. if not minetest.setting_getbool("creative_mode") then
  206. itemstack:add_wear(65535/300)
  207. end
  208. end
  209. return itemstack
  210. end,
  211. })
  212. minetest.register_craft({
  213. output = 'lottthrowing:bow_wood',
  214. recipe = {
  215. {'farming:string', 'default:wood', ''},
  216. {'farming:string', '', 'default:wood'},
  217. {'farming:string', 'default:wood', ''},
  218. }
  219. })
  220. minetest.register_craft({
  221. output = 'lottthrowing:bow_wood_alder',
  222. recipe = {
  223. {'farming:string', 'lottplants:alderwood', ''},
  224. {'farming:string', '', 'lottplants:alderwood'},
  225. {'farming:string', 'lottplants:alderwood', ''},
  226. }
  227. })
  228. minetest.register_craft({
  229. output = 'lottthrowing:bow_wood_birch',
  230. recipe = {
  231. {'farming:string', 'lottplants:birchwood', ''},
  232. {'farming:string', '', 'lottplants:birchwood'},
  233. {'farming:string', 'lottplants:birchwood', ''},
  234. }
  235. })
  236. minetest.register_craft({
  237. output = 'lottthrowing:bow_wood_lebethron',
  238. recipe = {
  239. {'farming:string', 'lottplants:lebethronwood', ''},
  240. {'farming:string', '', 'lottplants:lebethronwood'},
  241. {'farming:string', 'lottplants:lebethronwood', ''},
  242. }
  243. })
  244. minetest.register_craft({
  245. output = 'lottthrowing:bow_wood_mallorn',
  246. recipe = {
  247. {'farming:string', 'lottplants:mallornwood', ''},
  248. {'farming:string', '', 'lottplants:mallornwood'},
  249. {'farming:string', 'lottplants:mallornwood', ''},
  250. }
  251. })
  252. minetest.register_tool("lottthrowing:crossbow_wood", {
  253. description = "Wooden Crossbow",
  254. inventory_image = "lottthrowing_crossbow_wood.png",
  255. stack_max = 1,
  256. on_use = function(itemstack, user, pointed_thing)
  257. if lottthrowing_shoot_bolt(itemstack, user, pointed_thing, 10) then
  258. if not minetest.setting_getbool("creative_mode") then
  259. itemstack:add_wear(65535/50)
  260. end
  261. end
  262. return itemstack
  263. end,
  264. })
  265. minetest.register_tool("lottthrowing:crossbow_steel", {
  266. description = "Steel Crossbow",
  267. inventory_image = "lottthrowing_crossbow_steel.png",
  268. stack_max = 1,
  269. on_use = function(itemstack, user, pointed_thing)
  270. if lottthrowing_shoot_bolt(item, user, pointed_thing, 9) then
  271. if not minetest.setting_getbool("creative_mode") then
  272. itemstack:add_wear(65535/70)
  273. end
  274. end
  275. return itemstack
  276. end,
  277. })
  278. minetest.register_tool("lottthrowing:crossbow_tin", {
  279. description = "Tin Crossbow",
  280. inventory_image = "lottthrowing_crossbow_tin.png",
  281. stack_max = 1,
  282. on_use = function(itemstack, user, pointed_thing)
  283. if lottthrowing_shoot_bolt(item, user, pointed_thing, 8) then
  284. if not minetest.setting_getbool("creative_mode") then
  285. itemstack:add_wear(65535/100)
  286. end
  287. end
  288. return itemstack
  289. end,
  290. })
  291. minetest.register_tool("lottthrowing:crossbow_silver", {
  292. description = "Silver Crossbow",
  293. inventory_image = "lottthrowing_crossbow_silver.png",
  294. stack_max = 1,
  295. on_use = function(itemstack, user, pointed_thing)
  296. if lottthrowing_shoot_bolt(item, user, pointed_thing, 7) then
  297. if not minetest.setting_getbool("creative_mode") then
  298. itemstack:add_wear(65535/150)
  299. end
  300. end
  301. return itemstack
  302. end,
  303. })
  304. minetest.register_tool("lottthrowing:crossbow_gold", {
  305. description = "Gold Crossbow",
  306. inventory_image = "lottthrowing_crossbow_gold.png",
  307. stack_max = 1,
  308. on_use = function(itemstack, user, pointed_thing)
  309. if lottthrowing_shoot_bolt(item, user, pointed_thing, 6) then
  310. if not minetest.setting_getbool("creative_mode") then
  311. itemstack:add_wear(65535/200)
  312. end
  313. end
  314. return itemstack
  315. end,
  316. })
  317. minetest.register_tool("lottthrowing:crossbow_galvorn", {
  318. description = "Galvorn Crossbow",
  319. inventory_image = "lottthrowing_crossbow_galvorn.png",
  320. groups = {forbidden=1},
  321. stack_max = 1,
  322. on_use = function(itemstack, user, pointed_thing)
  323. if lottthrowing_shoot_bolt(item, user, pointed_thing, 5) then
  324. if not minetest.setting_getbool("creative_mode") then
  325. itemstack:add_wear(65535/300)
  326. end
  327. end
  328. return itemstack
  329. end,
  330. })
  331. minetest.register_tool("lottthrowing:crossbow_mithril", {
  332. description = "Mithril Crossbow",
  333. inventory_image = "lottthrowing_crossbow_mithril.png",
  334. stack_max = 1,
  335. on_use = function(itemstack, user, pointed_thing)
  336. if lottthrowing_shoot_bolt(item, user, pointed_thing, 4) then
  337. if not minetest.setting_getbool("creative_mode") then
  338. itemstack:add_wear(65535/500)
  339. end
  340. end
  341. return itemstack
  342. end,
  343. })
  344. minetest.register_craft({
  345. output = 'lottthrowing:crossbow_wood',
  346. recipe = {
  347. {'', 'farming:string', 'default:wood'},
  348. {'default:wood', 'default:wood', 'default:wood'},
  349. {'', 'farming:string', 'default:wood'},
  350. }
  351. })
  352. minetest.register_craft({
  353. output = 'lottthrowing:crossbow_steel',
  354. recipe = {
  355. {'', 'farming:string', 'default:steel_ingot'},
  356. {'default:wood', 'default:wood', 'default:steel_ingot'},
  357. {'', 'farming:string', 'default:steel_ingot'},
  358. }
  359. })
  360. minetest.register_craft({
  361. output = 'lottthrowing:crossbow_tin',
  362. recipe = {
  363. {'', 'farming:string', 'lottores:tin_ingot'},
  364. {'default:wood', 'default:wood', 'lottores:tin_ingot'},
  365. {'', 'farming:string', 'lottores:tin_ingot'},
  366. }
  367. })
  368. minetest.register_craft({
  369. output = 'lottthrowing:crossbow_silver',
  370. recipe = {
  371. {'', 'farming:string', 'lottores:silver_ingot'},
  372. {'default:wood', 'default:wood', 'lottores:silver_ingot'},
  373. {'', 'farming:string', 'lottores:silver_ingot'},
  374. }
  375. })
  376. minetest.register_craft({
  377. output = 'lottthrowing:crossbow_gold',
  378. recipe = {
  379. {'', 'farming:string', 'default:gold_ingot'},
  380. {'default:wood', 'default:wood', 'default:gold_ingot'},
  381. {'', 'farming:string', 'default:gold_ingot'},
  382. }
  383. })
  384. minetest.register_craft({
  385. output = 'lottthrowing:crossbow_galvorn',
  386. recipe = {
  387. {'', 'farming:string', 'lottores:galvorn_ingot'},
  388. {'default:wood', 'default:wood', 'lottores:galvorn_ingot'},
  389. {'', 'farming:string', 'lottores:galvorn_ingot'},
  390. }
  391. })
  392. minetest.register_craft({
  393. output = 'lottthrowing:crossbow_mithril',
  394. recipe = {
  395. {'', 'farming:string', 'lottores:mithril_ingot'},
  396. {'default:wood', 'default:wood', 'lottores:mithril_ingot'},
  397. {'', 'farming:string', 'lottores:mithril_ingot'},
  398. }
  399. })
  400. dofile(minetest.get_modpath("lottthrowing").."/arrow.lua")
  401. dofile(minetest.get_modpath("lottthrowing").."/mithril_arrow.lua")
  402. dofile(minetest.get_modpath("lottthrowing").."/fire_arrow.lua")
  403. dofile(minetest.get_modpath("lottthrowing").."/bluefire_arrow.lua")
  404. dofile(minetest.get_modpath("lottthrowing").."/magical_arrow.lua")
  405. dofile(minetest.get_modpath("lottthrowing").."/bolt.lua")
  406. dofile(minetest.get_modpath("lottthrowing").."/mithril_bolt.lua")
  407. dofile(minetest.get_modpath("lottthrowing").."/fire_bolt.lua")
  408. dofile(minetest.get_modpath("lottthrowing").."/axe.lua")