This commit is contained in:
Bruno Rybársky 2022-07-12 12:39:06 +02:00
parent 3ebdae5ea1
commit 1e6271579d
2 changed files with 62 additions and 1 deletions

@ -432,7 +432,22 @@ minetest.register_craftitem(
if pointed_thing.type == "node" then
local node = minetest.get_node(pointed_thing.under)
if node.name == "portalgun:turretgun" or node.name == "portalgun:turretgun2" then
minetest.remove_node(pointed_thing.under)
--if 4 blocks or closer to player
local pos = user:getpos()
local pos2 = pointed_thing.under
local dist = math.sqrt(
(pos.x - pos2.x) * (pos.x - pos2.x) +
(pos.y - pos2.y) * (pos.y - pos2.y) +
(pos.z - pos2.z) * (pos.z - pos2.z)
)
if dist < 4 then
--set the node to air
minetest.set_node(pointed_thing.under, {name = "air"})
--create entity
local pos_tmp = pointed_thing.under
local obj = minetest.add_entity(pos_tmp, "portalgun:turret_held")
--set the turret to the user
end
end
end
portalgun_onuse(itemstack, user, pointed_thing, 1)

@ -87,6 +87,52 @@ minetest.register_node(
}
)
minetest.register_entity(
"portalgun:turret_held",
{
hp_max = 1000,
physical = true,
weight = 5,
visual = "mesh",
visual_size = {x = 10, y = 10},
mesh = "turret2.obj",
textures = {"portalgun_sentry_turret.png"},
is_visible = true,
makes_footstep_sound = true,
automatic_rotate = 1,
portalgun = 2,
on_step = function(self, dtime)
--if not held and on ground then transform to turret
self.object:set_acceleration({x = 0, y = -10, z = 0})
if self.held == false then
--check if on ground
local pos = self.object:get_pos()
pos = {x = math.floor(pos.x), y = math.floor(pos.y) - 1, z = math.floor(pos.z)}
local n = minetest.get_node(pos)
if n.name == "air" then
else
--create turret node
local p = self.object:get_pos()
p = {x = math.floor(p.x), y = math.floor(p.y), z = math.floor(p.z)}
--check if the node with pos p is air
local n = minetest.get_node(p)
if n.name == "air" then
local rotation_param2 = self.object:get_rotation().x
minetest.set_node(p, {name = "portalgun:turretgun2", param2 = rotation_param2})
minetest.get_node_timer(p):start(0.2)
self.object:remove()
end
end
end
end,
on_detach = function(self, player)
--set held variable to false
self.held = false
end,
_held = true,
}
)
minetest.register_node(
"portalgun:turretgun",
{