diff --git a/description.txt b/description.txt new file mode 100644 index 0000000..19beabe --- /dev/null +++ b/description.txt @@ -0,0 +1 @@ +Survive & climbing tools \ No newline at end of file diff --git a/init.lua b/init.lua new file mode 100644 index 0000000..37e32e4 --- /dev/null +++ b/init.lua @@ -0,0 +1,480 @@ +local hook_tmp_throw={} +local hook_tmp_throw_timer=0 +local hook_tmp_time= tonumber(minetest.settings:get("item_entity_ttl")) +hook={} +dofile(minetest.get_modpath("hook") .. "/project.lua") +dofile(minetest.get_modpath("hook") .. "/pchest.lua") +if hook_tmp_time=="" or hook_tmp_time==nil then + hook_tmp_time=890 +else + hook_tmp_time=hook_tmp_time-10 +end + +local function slingshot_onuse(itemstack, user) + local veloc=15 + local pos = user:getpos() + local upos={x=pos.x,y=pos.y+2,z=pos.z} + local dir = user:get_look_dir() + local item=itemstack:to_table() + local mode=minetest.deserialize(item["metadata"]) + if mode==nil then mode=1 else mode=mode.mode end + + local item=user:get_inventory():get_stack("main", user:get_wield_index()+mode):get_name() + if item=="" then return itemstack end + local e=minetest.add_item({x=pos.x,y=pos.y+2,z=pos.z},item) + e:setvelocity({x=dir.x*veloc, y=dir.y*veloc, z=dir.z*veloc}) + e:setacceleration({x=dir.x*-3, y=-5, z=dir.z*-3}) + e:get_luaentity().age=hook_tmp_time + table.insert(hook_tmp_throw,{ob=e,timer=2,user=user:get_player_name()}) + + if item=="hook:slingshot" then + itemstack:set_wear(9999999) + end + + user:get_inventory():remove_item("main", item) + minetest.sound_play("hook_throw", {pos=pos, gain = 1.0, max_hear_distance = 5,}) + return itemstack +end + + + +minetest.register_tool("hook:slingshot", { + description = "Slingshot", + range = 4, + inventory_image = "hook_slingshot.png", +on_use=function(itemstack, user, pointed_thing) + if pointed_thing.ref and pointed_thing.ref:is_player()==false and pointed_thing.ref:get_luaentity().name=="__builtin:item" then + pointed_thing.ref:punch(user, {full_punch_interval=1.0,damage_groups={fleshy=4}}, "default:bronze_pick", nil) + return itemstack + end + slingshot_onuse(itemstack, user) + return itemstack +end, +on_place=function(itemstack, user, pointed_thing) + local item=itemstack:to_table() + local meta=minetest.deserialize(item["metadata"]) + local mode=0 + if meta==nil then meta={} mode=1 end + if meta.mode==nil then meta.mode=1 end + mode=(meta.mode) + if mode==1 then + mode=-1 + minetest.chat_send_player(user:get_player_name(), "Use stack to left") + else + mode=1 + minetest.chat_send_player(user:get_player_name(), "Use stack to right ") + end + meta.mode=mode + item.metadata=minetest.serialize(meta) + item.meta=minetest.serialize(meta) + itemstack:replace(item) + return itemstack +end + +}) + +minetest.register_globalstep(function(dtime) + hook_tmp_throw_timer=hook_tmp_throw_timer+dtime + if hook_tmp_throw_timer<0.2 then return end + hook_tmp_throw_timer=0 + for i, t in pairs(hook_tmp_throw) do + t.timer=t.timer-0.25 + if t.timer<=0 or t.ob==nil or t.ob:getpos()==nil then table.remove(hook_tmp_throw,i) return end + for ii, ob in pairs(minetest.get_objects_inside_radius(t.ob:getpos(), 1.5)) do + if (not ob:get_luaentity()) or (ob:get_luaentity() and (ob:get_luaentity().name~="__builtin:item")) then + if (not ob:is_player()) or (ob:is_player() and ob:get_player_name(ob)~=t.user and minetest.setting_getbool("enable_pvp")==true) then + ob:set_hp(ob:get_hp()-5) + ob:punch(ob, {full_punch_interval=1.0,damage_groups={fleshy=4}}, "default:bronze_pick", nil) + t.ob:setvelocity({x=0, y=0, z=0}) + if ob:get_hp()<=0 and ob:is_player()==false then ob:remove() end + t.ob:setacceleration({x=0, y=-10,z=0}) + t.ob:setvelocity({x=0, y=-10, z=0}) + table.remove(hook_tmp_throw,i) + minetest.sound_play("hook_hard_punch", {pos=ob:getpos(), gain = 1.0, max_hear_distance = 5,}) + break + end + end + end + end +end) + +function is_hook(pos,name) + local nname=minetest.get_node(pos).name + if name==nil or minetest.is_protected(pos,name)==false then + + if nname=="air" or nname=="hook:rope" or + (nname=="hook:hooking" and minetest.get_meta(pos):get_int("a")==0) then + return true + end + end + return false + +end + +minetest.register_tool("hook:hook", { + description = "Hook with rope (hit a corner to climb)", + range = 2, + inventory_image = "hook_hook.png", + on_use = function(itemstack, user, pointed_thing) + if pointed_thing.type~="node" then return itemstack end + local d=minetest.dir_to_facedir(user:get_look_dir()) + local pos=pointed_thing.above + local pos2=pointed_thing.under + local name=user:get_player_name() + if minetest.registered_nodes[minetest.get_node(pos2).name].walkable and + minetest.registered_nodes[minetest.get_node({x=pos.x,y=pos.y-1,z=pos.z}).name].walkable==false and + (minetest.registered_nodes[minetest.get_node({x=pos2.x,y=pos2.y+1,z=pos2.z}).name].walkable==false or minetest.get_node({x=pos2.x,y=pos2.y+1,z=pos2.z}).name=="default:snow") and + is_hook(pos,name) and + minetest.registered_nodes[minetest.get_node({x=pos.x,y=pos.y+1,z=pos.z}).name].walkable==false then + if d==3 then d=1 + elseif d==1 then d=3 + elseif d==2 then d=0 + elseif d==0 then d=2 + end + if is_hook({x=pos.x,y=pos.y+1,z=pos.z},name) then minetest.set_node({x=pos.x,y=pos.y+1,z=pos.z},{name = "hook:hooking",param2=d}) else return itemstack end + if is_hook(pos,name) then minetest.set_node(pos,{name = "hook:rope",param2=d}) else return itemstack end + if is_hook({x=pos.x,y=pos.y-1,z=pos.z},name) then minetest.set_node({x=pos.x,y=pos.y-1,z=pos.z}, {name = "hook:rope",param2=d}) else return itemstack end + if is_hook({x=pos.x,y=pos.y-2,z=pos.z},name) then minetest.set_node({x=pos.x,y=pos.y-2,z=pos.z}, {name = "hook:rope",param2=d}) else return itemstack end + if is_hook({x=pos.x,y=pos.y-3,z=pos.z},name) then minetest.set_node({x=pos.x,y=pos.y-3,z=pos.z}, {name = "hook:rope",param2=d}) end + end + return itemstack + end, +}) + +minetest.register_tool("hook:hook_upgrade", { + description = "Hook with rope (double)", + range = 5, + inventory_image = "hook_hookup.png", + on_use = function(itemstack, user, pointed_thing) + if pointed_thing.type~="node" then return itemstack end + local d=minetest.dir_to_facedir(user:get_look_dir()) + local pos=pointed_thing.above + local pos2=pointed_thing.under + local name=user:get_player_name() + if minetest.registered_nodes[minetest.get_node(pos2).name].walkable and + minetest.registered_nodes[minetest.get_node({x=pos.x,y=pos.y-1,z=pos.z}).name].walkable==false and + (minetest.registered_nodes[minetest.get_node({x=pos2.x,y=pos2.y+1,z=pos2.z}).name].walkable==false or minetest.get_node({x=pos2.x,y=pos2.y+1,z=pos2.z}).name=="default:snow") and + is_hook(pos,name) and + minetest.registered_nodes[minetest.get_node({x=pos.x,y=pos.y+1,z=pos.z}).name].walkable==false then + if d==3 then d=1 + elseif d==1 then d=3 + elseif d==2 then d=0 + elseif d==0 then d=2 + end + if is_hook({x=pos.x,y=pos.y+1,z=pos.z},name) then minetest.set_node({x=pos.x,y=pos.y+1,z=pos.z},{name = "hook:hooking",param2=d}) else return itemstack end + if is_hook(pos,name) then minetest.set_node(pos,{name = "hook:rope",param2=d}) else return itemstack end + if is_hook({x=pos.x,y=pos.y-1,z=pos.z},name) then minetest.set_node({x=pos.x,y=pos.y-1,z=pos.z}, {name = "hook:rope",param2=d}) else return itemstack end + if is_hook({x=pos.x,y=pos.y-2,z=pos.z},name) then minetest.set_node({x=pos.x,y=pos.y-2,z=pos.z}, {name = "hook:rope",param2=d}) else return itemstack end + if is_hook({x=pos.x,y=pos.y-3,z=pos.z},name) then minetest.set_node({x=pos.x,y=pos.y-3,z=pos.z}, {name = "hook:rope",param2=d}) else return itemstack end + if is_hook({x=pos.x,y=pos.y-4,z=pos.z},name) then minetest.set_node({x=pos.x,y=pos.y-4,z=pos.z}, {name = "hook:rope",param2=d}) else return itemstack end + if is_hook({x=pos.x,y=pos.y-5,z=pos.z},name) then minetest.set_node({x=pos.x,y=pos.y-5,z=pos.z}, {name = "hook:rope",param2=d}) else return itemstack end + if is_hook({x=pos.x,y=pos.y-6,z=pos.z},name) then minetest.set_node({x=pos.x,y=pos.y-6,z=pos.z}, {name = "hook:rope",param2=d}) else return itemstack end + if is_hook({x=pos.x,y=pos.y-7,z=pos.z},name) then minetest.set_node({x=pos.x,y=pos.y-7,z=pos.z}, {name = "hook:rope",param2=d}) end + end + return itemstack + end, +}) + +minetest.register_tool("hook:climb_rope", { + description = "Climb rope", + range = 2, + inventory_image = "hook_rope2.png", + on_use = function(itemstack, user, pointed_thing) + if pointed_thing.type~="node" then + hook.user=user + hook.locked=false + local pos=user:getpos() + local d=user:get_look_dir() + local m=minetest.add_entity({x=pos.x,y=pos.y+1.5,z=pos.z}, "hook:power") + m:setvelocity({x=d.x*15, y=d.y*15, z=d.z*15}) + m:setacceleration({x=0, y=-5, z=0}) + return itemstack + else + local pos=pointed_thing.under + local d=minetest.dir_to_facedir(user:get_look_dir()) + local z=0 + local x=0 + local name=user:get_player_name() + if minetest.registered_nodes[minetest.get_node(pos).name].walkable then + if d==0 then z=1 end + if d==2 then z=-1 end + if d==1 then x=1 end + if d==3 then x=-1 end + if is_hook({x=pos.x+x,y=pos.y,z=pos.z+z},name) and is_hook({x=pos.x+x,y=pos.y+1,z=pos.z+z},name) then + minetest.set_node({x=pos.x+x,y=pos.y+1,z=pos.z+z},{name = "hook:hooking",param2=d}) + minetest.get_meta({x=pos.x+x,y=pos.y+1,z=pos.z+z}):set_int("a",1) + else return itemstack end + itemstack:take_item() + for i=0,20,1 do + if is_hook({x=pos.x+x,y=pos.y-i,z=pos.z+z},name) then minetest.set_node({x=pos.x+x,y=pos.y-i,z=pos.z+z},{name = "hook:rope2",param2=d}) else return itemstack end + end + end + return itemstack + end + end, +}) + + +minetest.register_tool("hook:climb_rope_locked", { + description = "Climb rope (Locked)", + range = 2, + inventory_image = "hook_rope_locked.png", + on_use = function(itemstack, user, pointed_thing) + if pointed_thing.type~="node" then + hook.user=user + hook.locked=true + local pos=user:getpos() + local d=user:get_look_dir() + local m=minetest.add_entity({x=pos.x,y=pos.y+1.5,z=pos.z}, "hook:power") + m:setvelocity({x=d.x*15, y=d.y*15, z=d.z*15}) + m:setacceleration({x=0, y=-5, z=0}) + return itemstack + else + local pos=pointed_thing.under + local d=minetest.dir_to_facedir(user:get_look_dir()) + local z=0 + local x=0 + local name=user:get_player_name() + if minetest.registered_nodes[minetest.get_node(pos).name].walkable then + if d==0 then z=1 end + if d==2 then z=-1 end + if d==1 then x=1 end + if d==3 then x=-1 end + if is_hook({x=pos.x+x,y=pos.y,z=pos.z+z},name) and is_hook({x=pos.x+x,y=pos.y+1,z=pos.z+z},name) then + minetest.set_node({x=pos.x+x,y=pos.y+1,z=pos.z+z},{name = "hook:hooking",param2=d}) + minetest.get_meta({x=pos.x+x,y=pos.y+1,z=pos.z+z}):set_int("a",1) + else return itemstack end + itemstack:take_item() + for i=0,20,1 do + if is_hook({x=pos.x+x,y=pos.y-i,z=pos.z+z},name) then + minetest.set_node({x=pos.x+x,y=pos.y-i,z=pos.z+z},{name = "hook:rope3",param2=d}) + minetest.get_meta({x=pos.x+x,y=pos.y-i,z=pos.z+z}):set_string("owner",user:get_player_name()) + else + return itemstack + end + end + end + return itemstack + end + end, +}) + + +minetest.register_node("hook:rope", { + description = "Rope (tempoary)", + drawtype = "nodebox", + node_box = { + type = "fixed", + fixed = { + {0, -0.5, -0.0625, 0.0625, 0.5, 0}, + } + }, + tiles = {"hook_rope.png"}, + paramtype = "light", + paramtype2 = "facedir", + drop = "", + liquid_viscosity = 1, + liquidtype = "source", + liquid_alternative_flowing="hook:rope", + liquid_alternative_source="hook:rope", + liquid_renewable = false, + liquid_range = 0, + sunlight_propagates = false, + walkable = false, + is_ground_content = false, + groups = {not_in_creative_inventory=1,fleshy = 3, dig_immediate = 3,}, + on_construct = function(pos) + minetest.get_node_timer(pos):start(3) + end, + on_timer = function (pos, elapsed) + for i, ob in pairs(minetest.get_objects_inside_radius(pos, 3)) do + if ob:is_player() then return true end + end + minetest.set_node(pos, {name = "air"}) + return false + end, +}) + +minetest.register_node("hook:rope2", { + description = "Rope", + drawtype = "nodebox", + node_box = { + type = "fixed", + fixed = { + {0, -0.5, -0.0625, 0.0625, 0.5, 0}, + } + }, + tiles = {"hook_rope.png"}, + paramtype = "light", + paramtype2 = "facedir", + drop = "", + liquid_viscosity = 1, + liquidtype = "source", + liquid_alternative_flowing="hook:rope2", + liquid_alternative_source="hook:rope2", + liquid_renewable = false, + liquid_range = 0, + sunlight_propagates = false, + walkable = false, + is_ground_content = false, + groups = {not_in_creative_inventory=1,fleshy = 3, dig_immediate = 3,}, + on_punch = function(pos, node, puncher, pointed_thing) + if minetest.is_protected(pos,puncher:get_player_name()) then + return false + end + puncher:get_inventory():add_item("main", ItemStack("hook:climb_rope")) + local name=puncher:get_player_name() + for i=0,20,1 do + if minetest.get_node({x=pos.x,y=pos.y-i,z=pos.z}).name=="hook:rope2" or minetest.get_node({x=pos.x,y=pos.y-i,z=pos.z}).name=="air" then minetest.set_node({x=pos.x,y=pos.y-i,z=pos.z},{name = "air"}) else break end + end + for i=0,20,1 do + if minetest.get_node({x=pos.x,y=pos.y+i,z=pos.z}).name=="hook:rope2" or minetest.get_node({x=pos.x,y=pos.y+i,z=pos.z}).name=="hook:hooking" or minetest.get_node({x=pos.x,y=pos.y+i,z=pos.z}).name=="air" then minetest.set_node({x=pos.x,y=pos.y+i,z=pos.z},{name = "air"}) else return false end + end + end, +}) + +minetest.register_node("hook:rope3", { + description = "Rope (locked)", + drawtype = "nodebox", + node_box = { + type = "fixed", + fixed = { + {0, -0.5, -0.0625, 0.0625, 0.5, 0}, + } + }, + tiles = {"hook_rope.png"}, + paramtype = "light", + paramtype2 = "facedir", + drop = "", + liquid_viscosity = 1, + liquidtype = "source", + liquid_alternative_flowing="hook:rope3", + liquid_alternative_source="hook:rope3", + liquid_renewable = false, + liquid_range = 0, + sunlight_propagates = false, + walkable = false, + is_ground_content = false, +can_dig = function(pos, player) + if minetest.get_meta(pos):get_string("owner")~=player:get_player_name() then + minetest.chat_send_player(player:get_player_name(), "This rope is owned by: ".. minetest.get_meta(pos):get_string("owner")) + return false + end + return true +end, + groups = {not_in_creative_inventory=1,fleshy = 3, dig_immediate = 3,}, +on_punch = function(pos, node, puncher, pointed_thing) + if minetest.get_meta(pos):get_string("owner")~=puncher:get_player_name() then + minetest.chat_send_player(puncher:get_player_name(), "This rope is owned by: ".. minetest.get_meta(pos):get_string("owner")) + return false + end + puncher:get_inventory():add_item("main", ItemStack("hook:climb_rope_locked")) + for i=0,20,1 do + if minetest.get_node({x=pos.x,y=pos.y-i,z=pos.z}).name=="hook:rope3" or minetest.get_node({x=pos.x,y=pos.y-i,z=pos.z}).name=="air" then minetest.set_node({x=pos.x,y=pos.y-i,z=pos.z},{name = "air"}) else break end + end + for i=0,20,1 do + if minetest.get_node({x=pos.x,y=pos.y+i,z=pos.z}).name=="hook:rope3" or minetest.get_node({x=pos.x,y=pos.y+i,z=pos.z}).name=="hook:hooking" or minetest.get_node({x=pos.x,y=pos.y+i,z=pos.z}).name=="air" then minetest.set_node({x=pos.x,y=pos.y+i,z=pos.z},{name = "air"}) else return false end + end +end, +}) + +minetest.register_node("hook:hooking", { + description = "Hooking", + drawtype = "plantlike", + tiles = {"hook_hooking.png"}, + paramtype = "light", + paramtype2 = "facedir", + walkable=false, + pointable=false, + drop = "", + sunlight_propagates = false, + groups = {not_in_creative_inventory=1}, + on_construct = function(pos) + minetest.get_node_timer(pos):start(3) + + end, + on_timer = function (pos, elapsed) + if minetest.get_meta(pos):get_int("a")==1 then return false end + local r=minetest.get_node({x=pos.x,y=pos.y-1,z=pos.z}).name + if r~="hook:rope" then + minetest.set_node(pos, {name="air"}) + return false + end + return true + end, +}) + + +minetest.register_tool("hook:mba", { + description = "Mouth breather assembly", + range = 1, + inventory_image = "hook_mba.png", +on_use=function(itemstack, user, pointed_thing) + local pos=user:getpos() + pos.y=pos.y+1.5 + if minetest.registered_nodes[minetest.get_node(pos).name].drowning==0 then + itemstack:set_wear(1) + else + local use=itemstack:get_wear()+(65536/10) + if use<65536 then + itemstack:set_wear(use) + user:set_breath(11) + end + end + return itemstack +end, +}) + +minetest.register_craft({ + output = "hook:mba", + recipe = { + {"","default:steel_ingot",""}, + {"default:steel_ingot","default:steel_ingot","default:steel_ingot"}, + {"default:steel_ingot","","default:steel_ingot"}, + } +}) + +minetest.register_craft({ + output = "hook:hook", + recipe = { + {"","default:steel_ingot",""}, + {"","default:steel_ingot","default:steel_ingot"}, + {"default:steel_ingot","",""}, + } +}) +minetest.register_craft({ + output = "hook:hook_upgrade", + recipe = { + {"","hook:hook",""}, + {"","hook:hook",""}, + {"","default:steel_ingot",""}, + } +}) + + + + +minetest.register_craft({ + output = "hook:climb_rope", + recipe = { + {"","default:steel_ingot",""}, + {"","default:steelblock",""}, + {"","default:steel_ingot",""}, + } +}) +minetest.register_craft({ + output = "hook:climb_rope_locked", + recipe = { + {"hook:climb_rope","default:steel_ingot",""}, + } +}) + +minetest.register_craft({ + output = "hook:slingshot", + recipe = { + {"default:steel_ingot","","default:steel_ingot"}, + {"","default:steelblock",""}, + {"","default:steel_ingot",""}, + } +}) + diff --git a/pchest.lua b/pchest.lua new file mode 100644 index 0000000..d71fd1d --- /dev/null +++ b/pchest.lua @@ -0,0 +1,144 @@ +pchest={} + + +minetest.register_craft({ + output = "hook:pchest", + recipe = { + {"default:stick","default:stick","default:stick"}, + {"default:stick","default:chest_locked", "default:diamond"}, + {"default:stick","default:stick","default:stick"}, + } +}) + +pchest.setpchest=function(pos,user) + local meta = minetest.get_meta(pos) + meta:set_string("owner", user:get_player_name()) + meta:set_int("state", 0) + meta:get_inventory():set_size("main", 32) + meta:get_inventory():set_size("trans", 1) + meta:set_string("formspec", + "size[8,8]" .. + "list[context;main;0,0;8,4;]" .. + "list[context;trans;0,0;0,0;]" .. + "list[current_player;main;0,4.3;8,4;]" .. + "listring[current_player;main]" .. + "listring[current_name;main]" .. + default.gui_bg .. + default.gui_bg_img .. + default.gui_slots .. + default.get_hotbar_bg(0,4.3)) + meta:set_string("infotext", "PChest by: " .. user:get_player_name()) +end + + + +minetest.register_tool("hook:pchest", { + description = "Portable locked chest", + inventory_image = "hook_extras_chest3.png", + on_place = function(itemstack, user, pointed_thing) + if minetest.is_protected(pointed_thing.above,user:get_player_name()) or minetest.registered_nodes[minetest.get_node(pointed_thing.above).name].walkable then + return itemstack + end + local p=minetest.dir_to_facedir(user:get_look_dir()) + local item=itemstack:to_table() + local meta=minetest.deserialize(item["metadata"]) + minetest.set_node(pointed_thing.above, {name = "hook:pchest_node",param1="",param2=p}) + pchest.setpchest(pointed_thing.above,user) + + minetest.sound_play("default_place_node_hard", {pos=pointed_thing.above, gain = 1.0, max_hear_distance = 5,}) + if meta==nil then + itemstack:take_item() + return itemstack + end + + local s=meta.stuff + local its=meta.stuff.split(meta.stuff,",",",") + local nmeta=minetest.get_meta(pointed_thing.above) + for i,it in pairs(its) do + if its~="" then + nmeta:get_inventory():set_stack("main",i, ItemStack(it)) + end + end + itemstack:take_item() + return itemstack:take_item() + end, +}) + + + + +minetest.register_node("hook:pchest_node", { + description = "Portable locked chest", + tiles = {"hook_extras_chest2.png","hook_extras_chest2.png","hook_extras_chest1.png","hook_extras_chest1.png","hook_extras_chest1.png","hook_extras_chest3.png"}, + groups = {dig_immediate = 2, not_in_creative_inventory=1,tubedevice = 1, tubedevice_receiver = 1}, + drop="hook:pchest", + paramtype2 = "facedir", + tube = {insert_object = function(pos, node, stack, direction) + local meta = minetest.get_meta(pos) + local inv = meta:get_inventory() + local added = inv:add_item("main", stack) + --after_inventory_change(pos) + return added + end, + can_insert = function(pos, node, stack, direction) + local meta = minetest.get_meta(pos) + local inv = meta:get_inventory() + return inv:room_for_item("main", stack) + end, + input_inventory = "main", + connect_sides = {left = 1, right = 1, front = 1, back = 1, top = 1, bottom = 1}}, +allow_metadata_inventory_put = function(pos, listname, index, stack, player) + local owner = minetest.get_meta(pos):get_string("owner") + if (stack:get_name()~="hook:pchest") and (owner==player:get_player_name() or owner=="") then + if minetest.deserialize(stack:get_metadata())~=nil then + minetest.chat_send_player(player:get_player_name(), "Warning: the meta (information that is saved in the item)") + minetest.chat_send_player(player:get_player_name(), "will be lost when pick up the chest") + end + return stack:get_count() + end + return 0 + end, +allow_metadata_inventory_take = function(pos, listname, index, stack, player) + local owner = minetest.get_meta(pos):get_string("owner") + if owner==player:get_player_name() or owner=="" then + return stack:get_count() + end + return 0 + end, +allow_metadata_inventory_move = function(pos, from_list, from_index, to_list, to_index, count, player) + local owner = minetest.get_meta(pos):get_string("owner") + if owner==player:get_player_name() or owner=="" then + return count + end + return 0 + end, +can_dig = function(pos, player) + local owner = minetest.get_meta(pos):get_string("owner") + return (owner=="" and minetest.get_meta(pos):get_inventory():is_empty("main")) + end, +on_punch = function(pos, node, player, pointed_thing) + if minetest.is_protected(pos,player:get_player_name()) then + return false + end + local meta=minetest.get_meta(pos) + if meta:get_string("owner")==player:get_player_name() then + local inv=meta:get_inventory() + local items="" + for i=1,32,1 do + if inv:get_stack("main",i):get_name()~="" then + items=items .. inv:get_stack("main",i):get_name() .." " .. inv:get_stack("main",i):get_count() .. " " .. inv:get_stack("main",i):get_wear() .."," + else + items=items .. "," + end + end + inv:add_item("trans", ItemStack("hook:pchest")) + local item=inv:get_stack("trans",1):to_table() + local tmeta={stuff=items} + item.metadata=minetest.serialize(tmeta) + item.meta=minetest.serialize(tmeta) + player:get_inventory():add_item("main", ItemStack(item)) + minetest.set_node(pos, {name = "air"}) + minetest.sound_play("default_dig_dig_immediate", {pos=pos, gain = 1.0, max_hear_distance = 5,}) + end + end, +}) \ No newline at end of file diff --git a/project.lua b/project.lua new file mode 100644 index 0000000..becfe24 --- /dev/null +++ b/project.lua @@ -0,0 +1,82 @@ +minetest.register_entity("hook:power",{ + hp_max = 100, + physical = true, + weight = 0, + collisionbox = {-0.2,-0.2,-0.2, 0.2,0.2,0.2}, + visual = "upright_sprite", + visual_size = {x=1, y=1}, + textures = {"hook_hooking.png"}, + spritediv = {x=1, y=1}, + is_visible = true, + makes_footstep_sound = false, + automatic_rotate = false, + timer2=0, + d=0, + uname="", + locked=false, +on_activate=function(self, staticdata) + if hook.user==nil then + self.object:remove() + return self + end + self.d=hook.user:get_look_dir() + self.fd=minetest.dir_to_facedir(self.d) + self.uname=hook.user:get_player_name() + self.user=hook.user + self.locked=hook.locked + hook.user=nil + if self.fd==3 then self.fd=1 + elseif self.fd==1 then self.fd=3 + elseif self.fd==2 then self.fd=0 + elseif self.fd==0 then self.fd=2 + end + end, +on_step= function(self, dtime) + self.timer2=self.timer2+dtime + local pos=self.object:getpos() + local kill=0 + if minetest.registered_nodes[minetest.get_node({x=pos.x+self.d.x,y=pos.y,z=pos.z+self.d.z}).name].walkable and minetest.registered_nodes[minetest.get_node({x=pos.x+self.d.x,y=pos.y+1,z=pos.z+self.d.z}).name].walkable==false and is_hook(pos,self.uname) and is_hook({x=pos.x,y=pos.y+1,z=pos.z},self.uname) then + kill=1 + if self.locked then + if self.user:get_inventory():contains_item("main", "hook:climb_rope_locked")==false then + self.object:set_hp(0) + self.object:punch(self.object, {full_punch_interval=1.0,damage_groups={fleshy=4}}, "default:bronze_pick", nil) + return self + end + if is_hook({x=pos.x,y=pos.y+1,z=pos.z},self.uname) then + minetest.set_node({x=pos.x,y=pos.y+1,z=pos.z},{name = "hook:hooking",param2=self.fd}) + minetest.get_meta({x=pos.x,y=pos.y+1,z=pos.z}):set_int("a",1) + else + return self + end + self.user:get_inventory():remove_item("main", "hook:climb_rope_locked") + for i=0,20,1 do + if is_hook({x=pos.x,y=pos.y-i,z=pos.z},self.uname) then minetest.set_node({x=pos.x,y=pos.y-i,z=pos.z},{name = "hook:rope3",param2=self.fd}) else break end + minetest.get_meta({x=pos.x,y=pos.y-i,z=pos.z}):set_string("owner",self.uname) + end + else + if self.user:get_inventory():contains_item("main", "hook:climb_rope")==false then + self.object:set_hp(0) + self.object:punch(self.object, {full_punch_interval=1.0,damage_groups={fleshy=4}}, "default:bronze_pick", nil) + return self + end + if is_hook({x=pos.x,y=pos.y+1,z=pos.z},self.uname) then + minetest.set_node({x=pos.x,y=pos.y+1,z=pos.z},{name = "hook:hooking",param2=self.fd}) + minetest.get_meta({x=pos.x,y=pos.y+1,z=pos.z}):set_int("a",1) + else + return self + end + self.user:get_inventory():remove_item("main", "hook:climb_rope") + for i=0,20,1 do + if is_hook({x=pos.x,y=pos.y-i,z=pos.z},self.uname) then minetest.set_node({x=pos.x,y=pos.y-i,z=pos.z},{name = "hook:rope2",param2=self.fd}) else break end + end + end + end + if self.timer2>3 or kill==1 then + self.object:set_hp(0) + self.object:punch(self.object, {full_punch_interval=1.0,damage_groups={fleshy=4}}, "default:bronze_pick", nil) + + end + return self +end, +}) \ No newline at end of file diff --git a/screenshot.png b/screenshot.png new file mode 100644 index 0000000..e51dcb4 Binary files /dev/null and b/screenshot.png differ diff --git a/sounds/hook_hard_punch.ogg b/sounds/hook_hard_punch.ogg new file mode 100644 index 0000000..b6740df Binary files /dev/null and b/sounds/hook_hard_punch.ogg differ diff --git a/sounds/hook_throw.ogg b/sounds/hook_throw.ogg new file mode 100644 index 0000000..f4f2ff9 Binary files /dev/null and b/sounds/hook_throw.ogg differ diff --git a/textures/hook_extras_chest1.png b/textures/hook_extras_chest1.png new file mode 100644 index 0000000..e30411c Binary files /dev/null and b/textures/hook_extras_chest1.png differ diff --git a/textures/hook_extras_chest2.png b/textures/hook_extras_chest2.png new file mode 100644 index 0000000..8c3dbea Binary files /dev/null and b/textures/hook_extras_chest2.png differ diff --git a/textures/hook_extras_chest3.png b/textures/hook_extras_chest3.png new file mode 100644 index 0000000..2b4c7ad Binary files /dev/null and b/textures/hook_extras_chest3.png differ diff --git a/textures/hook_hook.png b/textures/hook_hook.png new file mode 100644 index 0000000..1c8386f Binary files /dev/null and b/textures/hook_hook.png differ diff --git a/textures/hook_hooking.png b/textures/hook_hooking.png new file mode 100644 index 0000000..c091679 Binary files /dev/null and b/textures/hook_hooking.png differ diff --git a/textures/hook_hookup.png b/textures/hook_hookup.png new file mode 100644 index 0000000..b8066ff Binary files /dev/null and b/textures/hook_hookup.png differ diff --git a/textures/hook_mba.png b/textures/hook_mba.png new file mode 100644 index 0000000..cd7ad2f Binary files /dev/null and b/textures/hook_mba.png differ diff --git a/textures/hook_rope.png b/textures/hook_rope.png new file mode 100644 index 0000000..efba915 Binary files /dev/null and b/textures/hook_rope.png differ diff --git a/textures/hook_rope2.png b/textures/hook_rope2.png new file mode 100644 index 0000000..2ca4d0b Binary files /dev/null and b/textures/hook_rope2.png differ diff --git a/textures/hook_rope_locked.png b/textures/hook_rope_locked.png new file mode 100644 index 0000000..7baf445 Binary files /dev/null and b/textures/hook_rope_locked.png differ diff --git a/textures/hook_slingshot.png b/textures/hook_slingshot.png new file mode 100644 index 0000000..33629c3 Binary files /dev/null and b/textures/hook_slingshot.png differ