_
This commit is contained in:
@@ -160,24 +160,25 @@ minetest.register_node("portalgun:turretgun_spawner",
|
|||||||
drop = "",
|
drop = "",
|
||||||
on_construct = function(pos)
|
on_construct = function(pos)
|
||||||
local meta = minetest.get_meta(pos)
|
local meta = minetest.get_meta(pos)
|
||||||
meta:set_string("infotext", "Turret spawner")
|
|
||||||
meta:set_string("pos", minetest.pos_to_string(pos))
|
meta:set_string("pos", minetest.pos_to_string(pos))
|
||||||
meta:set_int("yaw", 0)
|
meta:set_int("yaw", 0)
|
||||||
|
meta:set_string("infotext", "Turret spawner (" .. meta:get_int("yaw") .. ")")
|
||||||
minetest.get_node_timer(pos):start(1.0)
|
minetest.get_node_timer(pos):start(1.0)
|
||||||
end,
|
end,
|
||||||
on_rightclick = function(pos, node, clicker, itemstack, pointed_thing)
|
on_punch = function(pos, node, puncher, pointed_thing)
|
||||||
--check if itemstack contains portalgun:turret_rotator
|
local haspriv, missingpriv = minetest.check_player_privs(puncher:get_player_name(), {server = true})
|
||||||
if itemstack:get_name() == "portalgun:turret_rotator" then
|
--if puncher has privilege server add 90 degrees to yaw
|
||||||
--get meta of pointed_thing
|
if haspriv then
|
||||||
local meta = minetest.get_meta(pointed_thing.under)
|
local meta = minetest.get_meta(pos)
|
||||||
--get yaw of itemstack
|
local tmppos = minetest.string_to_pos(meta:get_string("pos"))
|
||||||
|
if tmppos ~= pos then
|
||||||
|
minetest.crash("hehe")
|
||||||
|
end
|
||||||
local yaw = meta:get_int("yaw")
|
local yaw = meta:get_int("yaw")
|
||||||
yaw = yaw + 90
|
yaw = yaw + 90
|
||||||
--if yaw is greater than 360, set it to 0
|
yaw = yaw % 360
|
||||||
yaw = math.fmod(yaw, 360)
|
|
||||||
meta:set_int("yaw", yaw)
|
meta:set_int("yaw", yaw)
|
||||||
--return itemstack
|
meta:set_string("infotext", "Turret spawner (" .. meta:get_int("yaw") .. ")")
|
||||||
return itemstack
|
|
||||||
end
|
end
|
||||||
end,
|
end,
|
||||||
on_timer = function (pos, elapsed)
|
on_timer = function (pos, elapsed)
|
||||||
@@ -185,22 +186,18 @@ minetest.register_node("portalgun:turretgun_spawner",
|
|||||||
local pos = meta:get_string("pos")
|
local pos = meta:get_string("pos")
|
||||||
local pos1 = minetest.string_to_pos(pos)
|
local pos1 = minetest.string_to_pos(pos)
|
||||||
local pos2 = {x = pos1.x, y = pos1.y + 1, z = pos1.z}
|
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
|
local found = 0
|
||||||
for i, obj in pairs(objs) do
|
for i, obj in pairs(objs) do
|
||||||
if obj ~= nil then
|
|
||||||
if obj:get_luaentity().name == "portalgun:turretgun" then
|
if obj:get_luaentity().name == "portalgun:turretgun" then
|
||||||
found = 1
|
found = found + 1
|
||||||
break
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
if found == 0 then
|
if found == 0 then
|
||||||
local obj = minetest.add_entity(pos2, "portalgun:turretgun")
|
local obj = minetest.add_entity(pos2, "portalgun:turretgun")
|
||||||
obj:setyaw(math.rad(meta:get_int("yaw")))
|
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.get_node_timer(pos1):start(10)
|
||||||
end
|
end
|
||||||
})
|
})
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user