do some stuff

This commit is contained in:
2022-07-15 20:47:50 +02:00
parent 1e6271579d
commit ddf946f58a
7 changed files with 877 additions and 824 deletions

View File

@@ -431,24 +431,6 @@ minetest.register_craftitem(
--if pointing at turret then start breaking it
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
--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)
return itemstack

View File

@@ -11,34 +11,127 @@ wood_sounds.footstep = {name = "wood_walk", gain = 1.0}
wood_sounds.dug = {name = "wood_break", gain = 1.0}
wood_sounds.place = {name = "block_place", gain = 1.0}
minetest.register_node(
"portalgun:tureta",
{
description = "Tureta",
tiles = {"portalgun_sentry_turret.png"},
drawtype = "mesh",
mesh = "turret1.obj",
--spawn turretgun and set to air
on_place = function(itemstack, placer, pointed_thing)
local pos = pointed_thing.above
local obj = minetest.add_entity(pos, "portalgun:turretgun")
--rotate turret to face player
local dir = placer:get_look_dir()
local yaw = math.atan(dir.z, dir.x) + math.pi / 2
if dir.x < 0 then
yaw = yaw + math.pi
end
yaw = yaw + math.pi
local deg = math.deg(yaw)
deg = math.fmod(deg, 360)
deg = math.floor(deg / 90) * 90
deg = deg + 90
deg = math.fmod(deg, 360)
obj:set_yaw(math.rad(deg))
--set turret to air
minetest.set_node(pos, {name = "air"})
end
}
)
minetest.register_craftitem(
"portalgun:turret_rotator",
{
description = "Turret rotator",
inventory_image = "portalgun_turret_rotator.png",
stack_max = 1,
on_use = function(itemstack, user, pointed_thing)
--if pointing at a 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,
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(
"portalgun:turretgun2",
{
description = "Sentry turret",
groups = {oddly_breakable_by_hand = 1, not_in_creative_inventory = 1},
drop = "portalgun:turretgun",
paramtype = "light",
paramtype2 = "facedir",
sunlight_propagates = true,
sounds = stone_sounds,
tiles = {"portalgun_sentry_turret.png"},
drawtype = "mesh",
textures = {"portalgun_sentry_turret.png"},
visual = "mesh",
hp_max = 100,
physical = true,
collisionbox = {-0.5, -0.5, -0.5, 0.5, 0.5, 0.5},
weight = 5,
is_visible = true,
visual_size = {x = 6, y = 6},
make_footstep_sound = true,
_tmr = 0,
_stop = 1,
automatic_rotate = 0,
mesh = "turret2.obj",
selection_box = {
type = "fixed",
fixed = {
{-0.3, -0.5, -0.3, 0.3, 1, 0.3}
}
},
on_timer = function(pos, elapsed)
local p = minetest.get_node(pos).param2
on_step = function(self, elapsed, moveresult)
self._tmr = self._tmr + elapsed
self.object:set_yaw(math.rad(math.fmod((math.floor(math.fmod(math.deg(self.object:get_yaw()), 360) / 90) * 90), 360)))
--get yaw and convert it into param2
local p = self.object:getyaw()
--convert yaw from rad to degrees
local yaw = math.deg(p)
yaw = math.floor(yaw / 90)
--if param2 is less than 0, set it to 3
if yaw < 0 then
yaw = 3
end
p = yaw
--add -y force
local force = {x = 0, y = -10, z = 0}
self.object:setvelocity(force)
if self._tmr < 0.2 then
return
else
self._tmr = 0
end
local pos = self.object:getpos()
local pos1 = {x = pos.x, y = pos.y + 0.5, z = pos.z}
local d
--swap 1 and 3 in p
if p == 1 then
p = 3
elseif p == 3 then
p = 1
end
for i, ob in pairs(minetest.get_objects_inside_radius(pos, 10)) do
if
portalgun_visiable(pos1, ob) and
(ob:is_player() or
(ob:get_luaentity() and (ob:get_luaentity().type or ob:get_luaentity().portalgun == nil)))
then
if portalgun_visiable(pos1, ob) and (ob:is_player()) then
local a = ob:get_pos()
if a.y < pos.y + 2 and a.y > pos.y - 1 then
a = {x = math.floor(a.x), y = math.floor(a.y), z = math.floor(a.z)}
@@ -58,29 +151,13 @@ minetest.register_node(
end
end
end
local m = minetest.get_meta(pos)
if d then
m:set_int("stop", 0)
minetest.add_entity(pos1, "portalgun:bullet1"):set_velocity(d)
minetest.sound_play("portalgun_bullet1", {pos = pos, gain = 1, max_hear_distance = 15})
for i = 2, 5, 1 do
minetest.after(
i * 0.1,
function(pos, d)
minetest.add_entity(pos1, "portalgun:bullet1"):set_velocity(d)
minetest.sound_play("portalgun_bullet1", {pos = pos, gain = 1, max_hear_distance = 15})
end,
pos,
d
)
end
else
if m:get_int("stop") == 1 then
minetest.set_node(pos, {name = "portalgun:turretgun", param2 = p})
minetest.get_node_timer(pos):start(0.2)
else
m:set_int("stop", 1)
end
local obj = minetest.add_entity(pos1, "portalgun:turretgun")
obj:setyaw(self.object:getyaw())
self.object:remove()
end
return true
end
@@ -88,82 +165,55 @@ 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",
{
description = "Sentry turret",
groups = {oddly_breakable_by_hand = 1},
paramtype = "light",
paramtype2 = "facedir",
sunlight_propagates = true,
sounds = stone_sounds,
tiles = {"portalgun_sentry_turret.png"},
drawtype = "mesh",
textures = {"portalgun_sentry_turret.png"},
visual = "mesh",
hp_max = 100,
physical = true,
collisionbox = {-0.5, -0.5, -0.5, 0.5, 0.5, 0.5},
weight = 5,
is_visible = true,
make_footstep_sound = true,
automatic_rotate = 0,
_tmr = 0,
_stop = 1,
visual_size = {x = 6, y = 6},
mesh = "turret1.obj",
selection_box = {
type = "fixed",
fixed = {
{-0.3, -0.5, -0.3, 0.3, 1, 0.3}
}
},
on_construct = function(pos)
minetest.get_node_timer(pos):start(0.2)
end,
on_timer = function(pos, elapsed)
local p = minetest.get_node(pos).param2
on_step = function(self, elapsed, moveresult)
self.object:set_yaw(math.rad(math.fmod((math.floor(math.fmod(math.deg(self.object:get_yaw()), 360) / 90) * 90), 360)))
--get yaw and convert it into param2
local p = self.object:getyaw()
--convert yaw from rad to degrees
local yaw = math.deg(p)
yaw = math.floor(yaw / 90)
--if param2 is less than 0, set it to 3
if yaw < 0 then
yaw = 3
end
p = yaw
local pos = self.object:get_pos()
local pos1 = {x = pos.x, y = pos.y + 0.5, z = pos.z}
local force = {x = 0, y = -10, z = 0}
self.object:setvelocity(force)
self._tmr = self._tmr + elapsed
if self._tmr < 0.2 then
return
else
self._tmr = 0
minetest.chat_send_all("turret yaw " .. p .. "yaw" .. math.deg(self.object:getyaw()))
end
--swap 1 and 3 in p
if p == 1 then
p = 3
elseif p == 3 then
p = 1
end
local d
for i, ob in pairs(minetest.get_objects_inside_radius(pos1, 10)) do
if
portalgun_visiable(pos1, ob) and
(ob:is_player() or
(ob:get_luaentity() and (ob:get_luaentity().type or ob:get_luaentity().portalgun == nil)))
then
if portalgun_visiable(pos1, ob) and (ob:is_player()) then
local a = ob:get_pos()
if a.y < pos.y + 2 and a.y > pos.y - 1 then
a = {x = math.floor(a.x), y = math.floor(a.y), z = math.floor(a.z)}
@@ -185,21 +235,10 @@ minetest.register_node(
end
if d then
minetest.add_entity(pos1, "portalgun:bullet1"):set_velocity(d)
minetest.set_node(pos, {name = "portalgun:turretgun2", param2 = p})
minetest.get_node_timer(pos):start(1)
minetest.sound_play("portalgun_bullet1", {pos = pos, gain = 1, max_hear_distance = 15})
for i = 2, 5, 1 do
minetest.after(
i * 0.1,
function(pos, d)
minetest.add_entity(pos1, "portalgun:bullet1"):set_velocity(d)
minetest.sound_play("portalgun_bullet1", {pos = pos, gain = 1, max_hear_distance = 15})
end,
pos,
d
)
end
local obj = minetest.add_entity(pos1, "portalgun:turretgun2")
--set yaw to same as this object
obj:setyaw(self.object:getyaw())
self.object:remove()
end
return true
end
@@ -237,31 +276,6 @@ function portalgun_round(x)
end
return x - 0.5
end
function portalgun_ra2shoot(pos, ob)
local op = ob:get_pos()
local m = minetest.get_meta(pos)
local x = m:get_int("x")
local y = m:get_int("y")
local z = m:get_int("z")
local ox = portalgun_round(op.x)
local oy = portalgun_round(op.y)
local oz = portalgun_round(op.z)
if x == 1 and ox == pos.x and oz <= pos.z then
return true
end
if x == -1 and ox == pos.x and oz >= pos.z then
return true
end
if z == -1 and oz == pos.z and ox <= pos.x then
return true
end
if z == 1 and oz == pos.z and ox >= pos.x then
return true
end
return false
end
minetest.register_entity(
"portalgun:bullet1",
{
@@ -287,8 +301,9 @@ minetest.register_entity(
end
for i, ob in pairs(minetest.get_objects_inside_radius(pos, 1.5)) do
if ob:is_player() then
if ob:get_hp() > 2 then
ob:set_hp(ob:get_hp() - 2)
if ob:get_hp() > 3 then
ob:set_hp(ob:get_hp() - 3)
elseif ob:get_hp() == 0 then
else
ob:set_hp(0)
end