This commit is contained in:
Bruno Rybársky 2022-08-14 14:36:22 +02:00
parent f5718d37eb
commit e6726191a4

@ -160,24 +160,25 @@ minetest.register_node("portalgun:turretgun_spawner",
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)
meta:set_string("infotext", "Turret spawner (" .. meta:get_int("yaw") .. ")")
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
on_punch = function(pos, node, puncher, pointed_thing)
local haspriv, missingpriv = minetest.check_player_privs(puncher:get_player_name(), {server = true})
--if puncher has privilege server add 90 degrees to yaw
if haspriv then
local meta = minetest.get_meta(pos)
local tmppos = minetest.string_to_pos(meta:get_string("pos"))
if tmppos ~= pos then
minetest.crash("hehe")
end
local yaw = meta:get_int("yaw")
yaw = yaw + 90
--if yaw is greater than 360, set it to 0
yaw = math.fmod(yaw, 360)
yaw = yaw % 360
meta:set_int("yaw", yaw)
--return itemstack
return itemstack
meta:set_string("infotext", "Turret spawner (" .. meta:get_int("yaw") .. ")")
end
end,
on_timer = function (pos, elapsed)
@ -185,22 +186,18 @@ minetest.register_node("portalgun:turretgun_spawner",
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 objs = minetest.get_objects_inside_radius(pos2, 1)
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
if obj:get_luaentity().name == "portalgun:turretgun" then
found = found + 1
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
minetest.get_node_timer(pos1):start(10)
end
})