Advertisement
Guest User

init.lua

a guest
May 2nd, 2013
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 6.81 KB | None | 0 0
  1. dofile(minetest.get_modpath(minetest.get_current_modname()).."/armor_api.lua")
  2.  
  3. local time = 0
  4. local update_time = tonumber(minetest.setting_get("3d_armor_update_time"))
  5. if not update_time then
  6.     update_time = 1
  7.     minetest.setting_set("3d_armor_update_time", tostring(update_time))
  8. end
  9.  
  10. -- Regisiter Head Armor
  11.  
  12. minetest.register_tool("3d_armor:helmet_leather", {
  13.     description = "Leather Helmet",
  14.     inventory_image = "3d_armor_inv_helmet_leather.png",
  15.     groups = {armor_head=5, armor_heal=0, armor_use=100},
  16.     wear = 0,
  17. })
  18.  
  19. minetest.register_tool("3d_armor:helmet_steel", {
  20.     description = "Steel Helmet",
  21.     inventory_image = "3d_armor_inv_helmet_steel.png",
  22.     groups = {armor_head=10, armor_heal=5, armor_use=250},
  23.     wear = 0,
  24. })
  25.  
  26. minetest.register_tool("3d_armor:helmet_gold", {
  27.     description = "Golden Helmet",
  28.     inventory_image = "3d_armor_inv_helmet_gold.png",
  29.     groups = {armor_head=15, armor_heal=10, armor_use=500},
  30.     wear = 0,
  31. })
  32.  
  33. minetest.register_tool("3d_armor:helmet_diamond",{
  34.     decsription = "Diamond Helmet",
  35.     inventory_image = "3d_armor_inv_helmet_diamond",
  36.     groups = {armor_head=20, armor_heal=15, armor_use=750},
  37.     wear = 0,
  38. })
  39.  
  40. -- Regisiter Torso Armor
  41.  
  42. minetest.register_tool("3d_armor:chestplate_leather", {
  43.     description = "Leather Chestplate",
  44.     inventory_image = "3d_armor_inv_chestplate_leather.png",
  45.     groups = {armor_torso=15, armor_heal=0, armor_use=100},
  46.     wear = 0,
  47. })
  48.  
  49. minetest.register_tool("3d_armor:chestplate_steel", {
  50.     description = "Steel Chestplate",
  51.     inventory_image = "3d_armor_inv_chestplate_steel.png",
  52.     groups = {armor_torso=20, armor_heal=5, armor_use=250},
  53.     wear = 0,
  54. })
  55.  
  56. minetest.register_tool("3d_armor:chestplate_gold", {
  57.     description = "Golden Chestplate",
  58.     inventory_image = "3d_armor_inv_chestplate_gold.png",
  59.     groups = {armor_torso=25, armor_heal=10, armor_use=500},
  60.     wear = 0,
  61. })
  62.  
  63. minetest.register_tool("3d_armor:chestplate_diamond",{
  64.     decsription = "Diamond Helmet",
  65.     inventory_image = "3d_armor_inv_chestplate_diamond",
  66.     groups = {armor_torso=30, armor_heal=15, armor_use=750},
  67.     wear = 0,
  68. })
  69. -- Regisiter Leg Armor
  70.  
  71. minetest.register_tool("3d_armor:leggings_leather", {
  72.     description = "Leather Leggings",
  73.     inventory_image = "3d_armor_inv_leggings_leather.png",
  74.     groups = {armor_legs=10, armor_heal=0, armor_use=100},
  75.     wear = 0,
  76. })
  77.  
  78. minetest.register_tool("3d_armor:leggings_steel", {
  79.     description = "Steel Leggings",
  80.     inventory_image = "3d_armor_inv_leggings_steel.png",
  81.     groups = {armor_legs=15, armor_heal=5, armor_use=250},
  82.     wear = 0,
  83. })
  84.  
  85. minetest.register_tool("3d_armor:leggings_gold", {
  86.     description = "Golden Leggings",
  87.     inventory_image = "3d_armor_inv_leggings_gold.png",
  88.     groups = {armor_legs=20, armor_heal=10, armor_use=500},
  89.     wear = 0,
  90. })
  91.  
  92. minetest.register_tool("3d_armor:leggings_diamond",{
  93.     decsription = "Diamond Helmet",
  94.     inventory_image = "3d_armor_inv_leggings_diamond",
  95.     groups = {armor_legs=25, armor_heal=15, armor_use=750},
  96.     wear = 0,
  97. })
  98. -- Regisiter Boots
  99.  
  100. minetest.register_tool("3d_armor:boots_leather", {
  101.     description = "Leather Boots",
  102.     inventory_image = "3d_armor_inv_boots_leather.png",
  103.     groups = {armor_feet=5, armor_heal=0, armor_use=100},
  104.     wear = 0,
  105. })
  106.  
  107. minetest.register_tool("3d_armor:boots_steel", {
  108.     description = "Steel Boots",
  109.     inventory_image = "3d_armor_inv_boots_steel.png",
  110.     groups = {armor_feet=10, armor_heal=5, armor_use=250},
  111.     wear = 0,
  112. })
  113.  
  114. minetest.register_tool("3d_armor:boots_gold", {
  115.     description = "Golden Boots",
  116.     inventory_image = "3d_armor_inv_boots_gold.png",
  117.     groups = {armor_feet=15, armor_heal=10, armor_use=500},
  118.     wear = 0,
  119. })
  120.  
  121. minetest.register_tool("3d_armor:boots_diamond",{
  122.     decsription = "Diamond Helmet",
  123.     inventory_image = "3d_armor_inv_boots_diamond",
  124.     groups = {armor_feet=20, armor_heal=15, armor_use=750},
  125.     wear = 0,
  126. })
  127. -- Register Craft Recipies
  128.  
  129. local craft_ingreds = {
  130.     leather = "default:wood",
  131.     steel = "default:steel_ingot",
  132.     gold = "default:gold_ingot",
  133.     diamond = "default:diamond",
  134. }  
  135.  
  136. for k, v in pairs(craft_ingreds) do
  137.     minetest.register_craft({
  138.         output = "3d_armor:helmet_"..k,
  139.         recipe = {
  140.             {v, v, v},
  141.             {v, "", v},
  142.             {"", "", ""},
  143.         },
  144.     })
  145.     minetest.register_craft({
  146.         output = "3d_armor:chestplate_"..k,
  147.         recipe = {
  148.             {v, "", v},
  149.             {v, v, v},
  150.             {v, v, v},
  151.         },
  152.     })
  153.     minetest.register_craft({
  154.         output = "3d_armor:leggings_"..k,
  155.         recipe = {
  156.             {v, v, v},
  157.             {v, "", v},
  158.             {v, "", v},
  159.         },
  160.     })
  161.     minetest.register_craft({
  162.         output = "3d_armor:boots_"..k,
  163.         recipe = {
  164.             {"", "", ""},
  165.             {v, "", v},
  166.             {v, "", v},
  167.         },
  168.     })
  169. end
  170.  
  171. -- Register Callbacks
  172.  
  173. minetest.register_on_player_receive_fields(function(player, formname, fields)
  174.     local name = player:get_player_name()
  175.     --[[
  176.     if fields.outfit then
  177.         inventory_plus.set_inventory_formspec(player, "size[8,7.5]"
  178.         .."button[0,0;2,0.5;main;Back]"
  179.         .."list[current_player;main;0,3.5;8,4;]"
  180.         .."list[detached:"..name.."_outfit;armor_head;3,0;1,1;]"
  181.         .."list[detached:"..name.."_outfit;armor_torso;3,1;1,1;]"
  182.         .."list[detached:"..name.."_outfit;armor_legs;3,2;1,1;]"
  183.         .."list[detached:"..name.."_outfit;armor_shield;4,1;1,1;]")
  184.         return
  185.     end
  186.     ]]--
  187.     for field, _ in pairs(fields) do
  188.         if string.sub(field,0,string.len("skins_set_")) == "skins_set_" then
  189.             minetest.after(0, function(player)
  190.                 armor_api:set_player_armor(player)
  191.             end, player)
  192.         end
  193.     end
  194. end)
  195.  
  196. minetest.register_on_joinplayer(function(player)
  197.     --inventory_plus.register_button(player,"outfit", "Outfit")
  198.     local player_inv = player:get_inventory()
  199.     local name = player:get_player_name()
  200.     local armor_inv = minetest.create_detached_inventory(name.."_outfit",{
  201.         on_put = function(inv, listname, index, stack, player)
  202.             player:get_inventory():set_stack(listname, index, stack)
  203.             armor_api:set_player_armor(player)
  204.         end,
  205.         on_take = function(inv, listname, index, stack, player)
  206.             player:get_inventory():set_stack(listname, index, nil)
  207.             armor_api:set_player_armor(player)
  208.         end,
  209.         allow_put = function(inv, listname, index, stack, player)
  210.             if inv:is_empty(listname) then
  211.                 return 1
  212.             end
  213.             return 0
  214.         end,
  215.         allow_take = function(inv, listname, index, stack, player)
  216.             return stack:get_count()
  217.         end,
  218.         allow_move = function(inv, from_list, from_index, to_list, to_index, count, player)
  219.             return 0
  220.         end,
  221.     })
  222.     for _,v in ipairs({"head", "torso", "legs", "feet"}) do
  223.         local armor = "armor_"..v
  224.         player_inv:set_size(armor, 1)
  225.         armor_inv:set_size(armor, 1)
  226.         armor_inv:set_stack(armor, 1, player_inv:get_stack(armor, 1))
  227.     end
  228.     armor_api.player_hp[name] = 0
  229.     minetest.after(0, function(player)
  230.         armor_api:set_player_armor(player)
  231.     end, player)   
  232. end)
  233.  
  234. minetest.register_globalstep(function(dtime)
  235.     time = time + dtime
  236.     if time > update_time then
  237.         for _,player in ipairs(minetest.get_connected_players()) do
  238.             armor_api:update_armor(player)
  239.         end
  240.         time = 0
  241.     end
  242. end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement