SHARE
TWEET

pot

Amadin Nov 3rd, 2016 (edited) 14 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. lottpotion = {}
  2.  
  3. dofile(minetest.get_modpath("lottpotion").."/cauldron.lua")
  4. dofile(minetest.get_modpath("lottpotion").."/others_potions.lua")
  5. dofile(minetest.get_modpath("lottpotion").."/config.lua") -- others are bottom
  6.  
  7. --effect
  8. lottpotion_particles = function(playerpos)
  9.            
  10.     minetest.add_particlespawner(
  11.     7, --amount
  12.     0.1, --time
  13.     {x=playerpos.x-1, y=playerpos.y+1, z=playerpos.z-1}, --minpos
  14.     {x=playerpos.x+1, y=playerpos.y+1, z=playerpos.z+1}, --maxpos
  15.     {x=-0, y=3, z=-0}, --minvel
  16.     {x=0, y=4, z=0}, --maxvel
  17.     {x=-0.5,y=0,z=-0.5}, --minacc
  18.     {x=0.5,y=1,z=0.5}, --maxacc
  19.     0.1, --minexptime
  20.     0.2, --maxexptime
  21.     1, --minsize
  22.     2, --maxsize
  23.     false, --collisiondetection
  24.     "bubble.png" --texture
  25.     )  
  26.     -- sound           
  27.     minetest.sound_play("pop", {
  28.     pos = playerpos,
  29.     gain = 1.0,
  30.     max_hear_distance = 5
  31.     })
  32. end
  33.  
  34. lottpotion = {
  35.     players = {},
  36.     effects = {
  37.         phys_override = function(sname, name, fname, time, sdata, flags)
  38.             local def = {
  39.                 on_use = function(itemstack, user, pointed_thing)
  40.                 lottpotion.grant(time, user:get_player_name(), fname.."_"..flags.type..sdata.type, name, flags)
  41.                    
  42.                 local playerpos = user:getpos();
  43.                 --effects
  44.                 lottpotion_particles(playerpos)    
  45.                     itemstack:take_item()
  46.                     return itemstack
  47.                 end,
  48.                 lottpotion = {
  49.                     speed = 0,
  50.                     jump = 0,
  51.                     gravity = 0,
  52.                     --air = 0,
  53.                 },
  54.             }
  55.             return def
  56.         end,
  57.         fixhp = function(sname, name, fname, time, sdata, flags)
  58.             local def = {
  59.                 on_use = function(itemstack, user, pointed_thing)
  60.                
  61.                     for i=0, (sdata.time or 0) do
  62.                         minetest.after(i, function()
  63.                             local hp = user:get_hp()
  64.                             if flags.inv==true then
  65.                                 hp = hp - (sdata.hp or 3)
  66.                             else
  67.                                 hp = hp + (sdata.hp or 3)
  68.                             end
  69.                             hp = math.min(20, hp)
  70.                             hp = math.max(0, hp)
  71.                             user:set_hp(hp)
  72.                         end)
  73.                     end
  74.                    
  75.                     local playerpos = user:getpos();
  76.                     --effects
  77.                     lottpotion_particles(playerpos)                
  78.                     itemstack:take_item()
  79.                     return itemstack
  80.                 end,
  81.                 }
  82.                 def.mobs = {
  83.                 on_near = def.on_use,
  84.                 }
  85.             return def
  86.         end,
  87.     },
  88.    
  89.     grant = function(time, playername, potion_name, type, flags)
  90.         local rootdef = minetest.registered_items[potion_name]
  91.         if rootdef == nil then
  92.             return
  93.         end
  94.         if rootdef.lottpotion == nil then
  95.             return
  96.         end
  97.         local def = {}
  98.         for name, val in pairs(rootdef.lottpotion) do
  99.             def[name] = val
  100.         end
  101.         if flags.inv==true then
  102.             def.gravity = 0 - def.gravity
  103.             def.speed = 0 - def.speed
  104.             def.jump = 0 - def.jump
  105.         end
  106.         lottpotion.addPrefs(playername, def.speed, def.jump, def.gravity)
  107.         lottpotion.refresh(playername)
  108.         --minetest.chat_send_player(playername, "You are under the effects of the "..type.." potion.")
  109.         minetest.after(time, function()
  110.             lottpotion.addPrefs(playername, 0-def.speed, 0-def.jump, 0-def.gravity)
  111.             lottpotion.refresh(playername)
  112.             --minetest.chat_send_player(playername, "The effects of the "..type.." potion have worn off.")
  113.         end)
  114.     end,
  115.     addPrefs = function(playername, speed, jump, gravity)
  116.         local prefs = lottpotion.players[playername]
  117.         prefs.speed = prefs.speed + speed
  118.         prefs.jump = prefs.jump + jump
  119.         prefs.gravity = prefs.gravity + gravity
  120.     end,
  121.     refresh = function(playername)
  122.         if minetest.get_player_by_name(playername)~=nil then
  123.             local prefs = lottpotion.players[playername]
  124.             minetest.get_player_by_name(playername):set_physics_override(prefs.speed, prefs.jump, prefs.gravity)
  125.         end
  126.     end,
  127.     -- Register potions
  128.     register_potion = function(sname, name, fname, time, def)
  129.         local tps = {"", "corrupted"}
  130.         for t=1, #tps do
  131.             for i=1, #def.types do
  132.                 local sdata = def.types[i]
  133.                 -- Different descriptions for instant and not instant potions
  134.                 if sdata.time ~= nil then
  135.                 description2 = "Potion of "..name.." ("..sdata.time.." sec.) "..tps[t]
  136.                 else
  137.                     --if potion not have time then show text
  138.                     if sdata.time == nil and sdata.hp ~= nil then
  139.                     description2 = "Potion of "..name.." "..sdata.hp.."hp (instant) "..tps[t]
  140.                         end
  141.                 end
  142.                 local item_def = {
  143.                     description = description2,
  144.                     inventory_image = "lottpotion_"..(def.texture or sname)..".png^lottpotion_"..tps[t]..".png^vessels_glass_bottle.png",
  145.                     drawtype = "plantlike",
  146.                     paramtype = "light",
  147.                     walkable = false,
  148.                     stack_max = 1,
  149.                     groups = {dig_immediate=3,attached_node=1,vessel=1},
  150.                 sounds = default.node_sound_glass_defaults(),
  151.                 }
  152.                 item_def.tiles = {item_def.inventory_image}
  153.                 local flags = {
  154.                     inv = false,
  155.                     type = tps[t],
  156.                 }
  157.                 if t == 2 then
  158.                     flags.inv = true
  159.                 end
  160.                 for name, val in pairs(lottpotion.effects[def.effect](sname, name, fname, sdata.time or time, sdata, flags)) do
  161.                     item_def[name] = val
  162.                 end
  163.                 for name, val in pairs(sdata.set) do
  164.                     item_def[name] = val
  165.                 end
  166.                 for name, val in pairs(sdata.effects) do
  167.                     item_def.lottpotion[name] = val
  168.                 end
  169.                
  170.                 minetest.register_node(fname.."_"..tps[t]..sdata.type, item_def)
  171.                 --potions.register_liquid(i..tps[t]..sname, name.." ("..tps[t].." "..i..")", item_def.on_use)
  172.                 if minetest.get_modpath("lottthrowing")~=nil then
  173.                     lottpotion.register_arrow(fname.."_"..tps[t]..sdata.type, i..tps[t]..sname, name.." ("..tps[t].." "..i..")", item_def.on_use,
  174.                             item_def.description, item_def.inventory_image)
  175.                 end
  176.             end
  177.         end
  178.     end,
  179. }
  180.      
  181. lottpotion.register_potion("regeneration", "Regeneration", "lottpotion:regeneration", 120, {
  182.     effect = "fixhp",
  183.     types = {
  184.         {
  185.             type = 1,
  186.                hp = 1,
  187.                time = 45,
  188.             set = {},
  189.             effects = {
  190.             },
  191.         },
  192.         {
  193.             type = 2,
  194.                hp = 1,
  195.                time = 120,
  196.             set = {},
  197.             effects = {
  198.             },
  199.         },
  200.     }
  201. })
  202.  
  203. lottpotion.register_potion("health", "Health", "lottpotion:health", 10, {
  204.     effect = "fixhp",
  205.     types = {
  206.         {
  207.             type = 1,
  208.             hp = 3,
  209.             set = {},
  210.             effects = {
  211.             },
  212.         },
  213.         {
  214.             type = 2,
  215.             hp = 10,
  216.             set = {},
  217.             effects = {
  218.             },
  219.         },
  220.     }
  221. })
  222.  
  223. lottpotion.register_potion("speed", "Swiftness", "lottpotion:speed", 480, {
  224.     effect = "phys_override",
  225.     types = {
  226.         {
  227.             type = 1,
  228.             time = 120,
  229.             set = {},
  230.             effects = {
  231.                 speed = 1,
  232.             },
  233.         },
  234.         {
  235.             type = 2,
  236.             time = 480,
  237.             set = {},
  238.             effects = {
  239.                 speed = 1,
  240.             },
  241.         },
  242.     }
  243. })
  244.  
  245. minetest.register_on_joinplayer(function(player)
  246.     lottpotion.players[player:get_player_name()] = {
  247.         speed = 1,
  248.         jump = 1,
  249.         gravity = 1,
  250.         --air = 0,
  251.     }
  252. end)
  253. --[[
  254. minetest.register_on_respawnplayer(function(sdata)
  255.    
  256. end)--]]
  257.  
  258.  
  259. minetest.register_chatcommand("effects", {
  260.     params = "none",
  261.     description = "Effects info",
  262.     func = function(name, param)
  263.         minetest.chat_send_player(name, "")
  264.         local lottpotion_e = lottpotion.players[name]
  265.         if lottpotion_e~=nil then
  266.             for potion_name, val in pairs(lottpotion_e) do
  267.                 minetest.chat_send_player(name, potion_name .. "=" .. val)
  268.             end
  269.         end
  270.     end,
  271. })
  272.  
  273. function lottpotion.can_dig(pos, player)
  274.     local meta = minetest.get_meta(pos)
  275.     local inv = meta:get_inventory()
  276.     if not ( inv:is_empty("src1") and inv:is_empty("src2") and inv:is_empty("src3")) or
  277.         not inv:is_empty("dst") or  not inv:is_empty("upgrade1") or not inv:is_empty("upgrade2") then
  278.         --minetest.chat_send_player(player:get_player_name(), "Brewer cannot be removed because it is not empty")
  279.         return false
  280.     else
  281.         return true
  282.     end
  283. end
  284.  
  285. function lottpotion.swap_node(pos, name)
  286.     local node = minetest.get_node(pos)
  287.     if node.name ~= name then
  288.         node.name = name
  289.         minetest.swap_node(pos, node)
  290.     end
  291.     return node.name
  292. end
  293.  
  294. dofile(minetest.get_modpath("lottpotion").."/potionbrewing.lua")
  295. dofile(minetest.get_modpath("lottpotion").."/mushroom.lua")
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top