hook/project.lua

91 lines
2.7 KiB
Lua
Raw Permalink Normal View History

2018-08-07 12:16:37 -07:00
minetest.register_entity("hook:power",{
hp_max = 100,
physical = true,
collisionbox = {-0.2,-0.2,-0.2, 0.2,0.2,0.2},
2019-04-29 13:38:11 -07:00
visual = "mesh",
mesh = "hook_hook.obj",
visual_size = {x=10, y=10},
2019-08-31 09:38:29 -07:00
textures = {"hook_iron.png"},
2018-08-07 12:16:37 -07:00
is_visible = true,
makes_footstep_sound = 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
2019-04-29 13:38:11 -07:00
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
2018-08-07 12:16:37 -07:00
end
2019-04-29 13:38:11 -07:00
end,
2018-08-07 12:16:37 -07:00
on_step= function(self, dtime)
self.timer2=self.timer2+dtime
2018-08-07 13:07:10 -07:00
local pos=self.object:get_pos()
2018-08-07 12:16:37 -07:00
local kill=0
2019-04-29 13:38:11 -07:00
if hook.slingshot_def({x=pos.x+self.d.x,y=pos.y,z=pos.z+self.d.z},"walkable") and not hook.slingshot_def({x=pos.x+self.d.x,y=pos.y+1,z=pos.z+self.d.z},"walkable")
and hook.is_hook(pos,self.uname) and hook.is_hook({x=pos.x,y=pos.y+1,z=pos.z},self.uname) then
2018-08-07 12:16:37 -07:00
kill=1
if self.locked then
if self.user:get_inventory():contains_item("main", "hook:climb_rope_locked")==false then
2018-08-07 13:07:10 -07:00
self.object:remove()
2018-08-07 12:16:37 -07:00
return self
end
2019-04-29 13:38:11 -07:00
if hook.is_hook({x=pos.x,y=pos.y+1,z=pos.z},self.uname) then
2018-08-07 12:16:37 -07:00
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
2019-04-29 13:38:11 -07:00
if hook.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
2018-08-07 12:16:37 -07:00
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
2018-08-07 13:07:10 -07:00
self.object:remove()
2018-08-07 12:16:37 -07:00
return self
end
2019-04-29 13:38:11 -07:00
if hook.is_hook({x=pos.x,y=pos.y+1,z=pos.z},self.uname) then
2018-08-07 12:16:37 -07:00
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
2019-04-29 13:38:11 -07:00
if hook.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
2018-08-07 12:16:37 -07:00
end
end
end
if self.timer2>3 or kill==1 then
2018-08-07 13:07:10 -07:00
self.object:remove()
2018-08-07 12:16:37 -07:00
end
return self
end,
2021-01-26 05:18:27 -08:00
})