_
This commit is contained in:
@@ -63,24 +63,6 @@ minetest.register_craftitem(
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
end,
|
end,
|
||||||
on_place = function(itemstack, placer, pointed_thing)
|
|
||||||
--if pointing at an entity
|
|
||||||
if pointed_thing.type == "object" then
|
|
||||||
local obj = pointed_thing.ref
|
|
||||||
--if entity is a turret
|
|
||||||
if obj:get_luaentity().name == "portalgun:turretgun" then
|
|
||||||
--get object yaw
|
|
||||||
local yaw = obj:get_yaw()
|
|
||||||
local deg = math.deg(yaw)
|
|
||||||
deg = math.fmod(deg, 360)
|
|
||||||
deg = math.floor(deg / 90) * 90
|
|
||||||
deg = deg - 90
|
|
||||||
deg = math.fmod(deg, 360)
|
|
||||||
--set object yaw
|
|
||||||
obj:set_yaw(math.rad(deg))
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
minetest.register_entity(
|
minetest.register_entity(
|
||||||
@@ -164,6 +146,63 @@ minetest.register_entity(
|
|||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
minetest.register_node("portalgun:turretgun_spawner",
|
||||||
|
{
|
||||||
|
--this node spawns a turret on top of the block if there is no turret nearby
|
||||||
|
description = "Turret spawner",
|
||||||
|
tiles = {"portalgun_turret_spawner.png"},
|
||||||
|
groups = {cracky = 3},
|
||||||
|
sounds = stone_sounds,
|
||||||
|
drawtype = "allfaces",
|
||||||
|
paramtype = "light",
|
||||||
|
paramtype2 = "facedir",
|
||||||
|
drop = "",
|
||||||
|
on_construct = function(pos)
|
||||||
|
local meta = minetest.get_meta(pos)
|
||||||
|
meta:set_string("infotext", "Turret spawner")
|
||||||
|
meta:set_string("pos", minetest.pos_to_string(pos))
|
||||||
|
meta:set_int("yaw", 0)
|
||||||
|
minetest.get_node_timer(pos):start(1.0)
|
||||||
|
end,
|
||||||
|
on_rightclick = function(pos, node, clicker, itemstack, pointed_thing)
|
||||||
|
--check if itemstack contains portalgun:turret_rotator
|
||||||
|
if itemstack:get_name() == "portalgun:turret_rotator" then
|
||||||
|
--get meta of pointed_thing
|
||||||
|
local meta = minetest.get_meta(pointed_thing.under)
|
||||||
|
--get yaw of itemstack
|
||||||
|
local yaw = meta:get_int("yaw")
|
||||||
|
yaw = yaw + 90
|
||||||
|
--if yaw is greater than 360, set it to 0
|
||||||
|
yaw = math.fmod(yaw, 360)
|
||||||
|
meta:set_int("yaw", yaw)
|
||||||
|
--return itemstack
|
||||||
|
return itemstack
|
||||||
|
end
|
||||||
|
end,
|
||||||
|
on_timer = function (pos, elapsed)
|
||||||
|
local meta = minetest.get_meta(pos)
|
||||||
|
local pos = meta:get_string("pos")
|
||||||
|
local pos1 = minetest.string_to_pos(pos)
|
||||||
|
local pos2 = {x = pos1.x, y = pos1.y + 1, z = pos1.z}
|
||||||
|
local objs = minetest.get_objects_inside_radius(pos2, 2)
|
||||||
|
local found = 0
|
||||||
|
for i, obj in pairs(objs) do
|
||||||
|
if obj ~= nil then
|
||||||
|
if obj:get_luaentity().name == "portalgun:turretgun" then
|
||||||
|
found = 1
|
||||||
|
break
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
if found == 0 then
|
||||||
|
local obj = minetest.add_entity(pos2, "portalgun:turretgun")
|
||||||
|
obj:setyaw(math.rad(meta:get_int("yaw")))
|
||||||
|
meta:set_string("infotext", "Turret spawner " .. meta:get_int("yaw"))
|
||||||
|
minetest.get_node_timer(pos1):start(10)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
})
|
||||||
|
|
||||||
minetest.register_entity(
|
minetest.register_entity(
|
||||||
"portalgun:turretgun",
|
"portalgun:turretgun",
|
||||||
{
|
{
|
||||||
@@ -202,7 +241,6 @@ minetest.register_entity(
|
|||||||
return
|
return
|
||||||
else
|
else
|
||||||
self._tmr = 0
|
self._tmr = 0
|
||||||
minetest.chat_send_all("turret yaw " .. p .. "yaw" .. math.deg(self.object:getyaw()))
|
|
||||||
end
|
end
|
||||||
--swap 1 and 3 in p
|
--swap 1 and 3 in p
|
||||||
if p == 1 then
|
if p == 1 then
|
||||||
|
Reference in New Issue
Block a user