Advertisement
Guest User

Untitled

a guest
Oct 28th, 2016
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.07 KB | None | 0 0
  1. lottpotion = {}
  2.  
  3. dofile(minetest.get_modpath("lottpotion").."/cauldron.lua")
  4.  
  5. lottpotion = {
  6. players = {},
  7. effects = {
  8. phys_override = function(sname, name, fname, time, sdata, flags)
  9. local def = {
  10. on_use = function(itemstack, user, pointed_thing)
  11. lottpotion.grant(time, user:get_player_name(), fname.."_"..flags.type..sdata.type, name, flags)
  12.  
  13. local playerpos = user:getpos();
  14. minetest.add_particlespawner(
  15. 7, --amount
  16. 0.1, --time
  17. {x=playerpos.x-1, y=playerpos.y+1, z=playerpos.z-1}, --minpos
  18. {x=playerpos.x+1, y=playerpos.y+1, z=playerpos.z+1}, --maxpos
  19. {x=-0, y=3, z=-0}, --minvel
  20. {x=0, y=4, z=0}, --maxvel
  21. {x=-0.5,y=0,z=-0.5}, --minacc
  22. {x=0.5,y=1,z=0.5}, --maxacc
  23. 0.1, --minexptime
  24. 0.2, --maxexptime
  25. 1, --minsize
  26. 1, --maxsize
  27. false, --collisiondetection
  28. "bubble.png" --texture
  29. )
  30. -- play sound
  31. local pos = user:getpos()
  32. minetest.sound_play("pop", {
  33. pos = pos,
  34. gain = 1.0,
  35. max_hear_distance = 5
  36. })
  37.  
  38. itemstack:take_item()
  39. return itemstack
  40. end,
  41. lottpotion = {
  42. speed = 0,
  43. jump = 0,
  44. gravity = 0,
  45. air = 0,
  46. },
  47. }
  48. return def
  49. end,
  50. fixhp = function(sname, name, fname, time, sdata, flags)
  51. local def = {
  52. on_use = function(itemstack, user, pointed_thing)
  53. for i=0, (sdata.time or 0) do
  54. minetest.after(i, function()
  55. local hp = user:get_hp()
  56. if flags.inv==true then
  57. hp = hp - (sdata.hp or 3)
  58. else
  59. hp = hp + (sdata.hp or 3)
  60. end
  61. hp = math.min(20, hp)
  62. hp = math.max(0, hp)
  63. user:set_hp(hp)
  64. end)
  65. end
  66.  
  67. local playerpos = user:getpos();
  68. minetest.add_particlespawner(
  69. 7, --amount
  70. 0.1, --time
  71. {x=playerpos.x-1, y=playerpos.y+1, z=playerpos.z-1}, --minpos
  72. {x=playerpos.x+1, y=playerpos.y+1, z=playerpos.z+1}, --maxpos
  73. {x=-0, y=3, z=-0}, --minvel
  74. {x=0, y=4, z=0}, --maxvel
  75. {x=-0.5,y=0,z=-0.5}, --minacc
  76. {x=0.5,y=1,z=0.5}, --maxacc
  77. 0.1, --minexptime
  78. 0.2, --maxexptime
  79. 1, --minsize
  80. 1, --maxsize
  81. false, --collisiondetection
  82. "bubble.png" --texture
  83. )
  84. -- play sound
  85. local pos = user:getpos()
  86. minetest.sound_play("pop", {
  87. pos = pos,
  88. gain = 1.0,
  89. max_hear_distance = 5
  90. })
  91.  
  92. itemstack:take_item()
  93. return itemstack
  94. end,
  95. }
  96. def.mobs = {
  97. on_near = def.on_use,
  98. }
  99. return def
  100. end,
  101. air = function(sname, name, fname, time, sdata, flags)
  102. local def = {
  103. on_use = function(itemstack, user, pointed_thing)
  104. local lottpotion_e = lottpotion.players[user:get_player_name()]
  105. lottpotion_e.air = lottpotion_e.air + (sdata.time or 0)
  106. for i=0, (sdata.time or 0) do
  107. minetest.after(i, function()
  108. local br = user:get_breath()
  109. if flags.inv==true then
  110. br = br - (sdata.br or 3)
  111. else
  112. br = br + (sdata.br or 3)
  113. end
  114. br = math.min(11, br)
  115. br = math.max(0, br)
  116. user:set_breath(br)
  117.  
  118. if i==(sdata.time or 0) then
  119. lottpotion_e.air = lottpotion_e.air - (sdata.time or 0)
  120. end
  121. end)
  122. end
  123.  
  124. local playerpos = user:getpos();
  125. minetest.add_particlespawner(
  126. 7, --amount
  127. 0.1, --time
  128. {x=playerpos.x-1, y=playerpos.y+1, z=playerpos.z-1}, --minpos
  129. {x=playerpos.x+1, y=playerpos.y+1, z=playerpos.z+1}, --maxpos
  130. {x=-0, y=3, z=-0}, --minvel
  131. {x=0, y=4, z=0}, --maxvel
  132. {x=-0.5,y=0,z=-0.5}, --minacc
  133. {x=0.5,y=1,z=0.5}, --maxacc
  134. 0.1, --minexptime
  135. 0.2, --maxexptime
  136. 1, --minsize
  137. 1, --maxsize
  138. false, --collisiondetection
  139. "bubble.png" --texture
  140. )
  141. -- play sound
  142. local pos = user:getpos()
  143. local pos = user:getpos()
  144. minetest.sound_play("pop", {
  145. pos = pos,
  146. gain = 1.0,
  147. max_hear_distance = 5
  148. })
  149.  
  150. itemstack:take_item()
  151. return itemstack
  152. end,
  153. }
  154. return def
  155. end,
  156. },
  157. grant = function(time, playername, potion_name, type, flags)
  158. local rootdef = minetest.registered_items[potion_name]
  159. if rootdef == nil then
  160. return
  161. end
  162. if rootdef.lottpotion == nil then
  163. return
  164. end
  165. local def = {}
  166. for name, val in pairs(rootdef.lottpotion) do
  167. def[name] = val
  168. end
  169. if flags.inv==true then
  170. def.gravity = 0 - def.gravity
  171. def.speed = 0 - def.speed
  172. def.jump = 0 - def.jump
  173. end
  174. lottpotion.addPrefs(playername, def.speed, def.jump, def.gravity)
  175. lottpotion.refresh(playername)
  176.  
  177. --Disable physical effects
  178. minetest.after(time, function()
  179. lottpotion.addPrefs(playername, 0-def.speed, 0-def.jump, 0-def.gravity)
  180. lottpotion.refresh(playername)
  181. --minetest.chat_send_all(types[time])
  182. end)
  183. end,
  184. addPrefs = function(playername, speed, jump, gravity)
  185. local prefs = lottpotion.players[playername]
  186. prefs.speed = prefs.speed + speed
  187. prefs.jump = prefs.jump + jump
  188. prefs.gravity = prefs.gravity + gravity
  189. end,
  190. refresh = function(playername)
  191. if minetest.get_player_by_name(playername)~=nil then
  192. local prefs = lottpotion.players[playername]
  193. minetest.get_player_by_name(playername):set_physics_override(prefs.speed, prefs.jump, prefs.gravity)
  194. end
  195. end,
  196. -- Register potions
  197. register_potion = function(sname, name, fname, time, def)
  198. local tps = {"", "corrupted"}
  199. for t=1, #tps do
  200. for i=1, #def.types do
  201. local sdata = def.types[i]
  202. local item_def = {
  203. description = "Potion of "..name.." "..sdata.type.." "..tps[t],
  204. inventory_image = "lottpotion_"..(def.texture or sname)..".png^lottpotion_"..tps[t]..sdata.type..".png^lottpotion_bottle.png",
  205. drawtype = "plantlike",
  206. paramtype = "light",
  207. walkable = false,
  208. stack_max = 1,
  209. groups = {dig_immediate=3,attached_node=1,vessel=1},
  210. sounds = default.node_sound_glass_defaults(),
  211. }
  212. item_def.tiles = {item_def.inventory_image}
  213. local flags = {
  214. inv = false,
  215. type = tps[t],
  216. }
  217. if t == 2 then
  218. flags.inv = true
  219. end
  220. for name, val in pairs(lottpotion.effects[def.effect](sname, name, fname, time, sdata, flags)) do
  221. item_def[name] = val
  222. end
  223. for name, val in pairs(sdata.set) do
  224. item_def[name] = val
  225. end
  226. for name, val in pairs(sdata.effects) do
  227. item_def.lottpotion[name] = val
  228. end
  229.  
  230. minetest.register_node(fname.."_"..tps[t]..sdata.type, item_def)
  231. --potions.register_liquid(i..tps[t]..sname, name.." ("..tps[t].." "..i..")", item_def.on_use)
  232. if minetest.get_modpath("lottthrowing")~=nil then
  233. lottpotion.register_arrow(fname.."_"..tps[t]..sdata.type, i..tps[t]..sname, name.." ("..tps[t].." "..i..")", item_def.on_use,
  234. item_def.description, item_def.inventory_image)
  235. end
  236. end
  237. end
  238. end,
  239. }
  240.  
  241. lottpotion.register_potion("regeneration", "Regeneration", "lottpotion:regeneration", 100, {
  242. effect = "fixhp",
  243. types = {
  244. {
  245. type = 1,
  246. hp = 1,
  247. time = 10,
  248. set = {},
  249. effects = {
  250. },
  251. },
  252. {
  253. type = 2,
  254. hp = 2,
  255. time = 120,
  256. set = {},
  257. effects = {
  258. },
  259. },
  260. }
  261. })
  262.  
  263. lottpotion.register_potion("health", "Health", "lottpotion:health", 300, {
  264. effect = "fixhp",
  265. types = {
  266. {
  267. type = 1,
  268. hp = 5,
  269. set = {},
  270. effects = {
  271. },
  272. },
  273. {
  274. type = 2,
  275. hp = 10,
  276. set = {},
  277. effects = {
  278. },
  279. },
  280. }
  281. })
  282.  
  283. lottpotion.register_potion("speed", "Swiftness", "lottpotion:speed", 100, {
  284. effect = "phys_override",
  285. types = {
  286. {
  287. type = 1,
  288. time = 10,
  289. set = {},
  290. effects = {
  291. speed = 1,
  292. },
  293. },
  294. {
  295. type = 2,
  296. time = 100,
  297. set = {},
  298. effects = {
  299. speed = 1,
  300. },
  301. },
  302. }
  303. })
  304.  
  305. minetest.register_on_joinplayer(function(player)
  306. lottpotion.players[player:get_player_name()] = {
  307. speed = 1,
  308. jump = 1,
  309. gravity = 1,
  310. air = 0,
  311. }
  312. end)
  313.  
  314. minetest.register_chatcommand("effects", {
  315. params = "none",
  316. description = "Effects info",
  317. func = function(name, param)
  318. minetest.chat_send_player(name, "effects:")
  319. local lottpotion_e = lottpotion.players[name]
  320. if lottpotion_e~=nil then
  321. for potion_name, val in pairs(lottpotion_e) do
  322. minetest.chat_send_player(name, potion_name .. "=" .. val)
  323. end
  324. end
  325. end,
  326. })
  327.  
  328. function lottpotion.can_dig(pos, player)
  329. local meta = minetest.get_meta(pos)
  330. local inv = meta:get_inventory()
  331. if not ( inv:is_empty("src1") and inv:is_empty("src2") and inv:is_empty("src3")) or
  332. not inv:is_empty("dst") or not inv:is_empty("upgrade1") or not inv:is_empty("upgrade2") then
  333. --minetest.chat_send_player(player:get_player_name(), "Brewer cannot be removed because it is not empty")
  334. return false
  335. else
  336. return true
  337. end
  338. end
  339.  
  340. function lottpotion.swap_node(pos, name)
  341. local node = minetest.get_node(pos)
  342. if node.name ~= name then
  343. node.name = name
  344. minetest.swap_node(pos, node)
  345. end
  346. return node.name
  347. end
  348.  
  349. dofile(minetest.get_modpath("lottpotion").."/potionbrewing.lua")
  350. dofile(minetest.get_modpath("lottpotion").."/invisibility.lua")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement