This commit is contained in:
Bruno Rybársky 2022-08-13 09:57:23 +02:00
parent c0ccf3afca
commit ff70d2e461
2 changed files with 18 additions and 23 deletions

@ -48,7 +48,7 @@ minetest.register_entity(
time = 0.1, time = 0.1,
portalgun_power = 1, portalgun_power = 1,
portalgun = 1, portalgun = 1,
lifelime = 100, lifetime = 100,
on_activate = function(self, staticdata) on_activate = function(self, staticdata)
if portalgun_power.user then if portalgun_power.user then
self.user = portalgun_power.user self.user = portalgun_power.user
@ -78,8 +78,8 @@ minetest.register_entity(
end end
end end
if self.player then if self.player then
self.lifelime = self.lifelime - 1 self.lifetime = self.lifetime - 1
if self.lifelime < 0 then if self.lifetime < 0 then
self.target:set_detach() self.target:set_detach()
return self return self
end end
@ -118,7 +118,7 @@ minetest.register_entity(
time = 0.025, time = 0.025,
portalgun_power = 1, portalgun_power = 1,
portalgun = 1, portalgun = 1,
lifelime = 1000, lifetime = 1000,
v = 0.3, v = 0.3,
ltime = 0, ltime = 0,
on_activate = function(self, staticdata) on_activate = function(self, staticdata)
@ -150,16 +150,16 @@ minetest.register_entity(
self.ltime = self.ltime - self.v self.ltime = self.ltime - self.v
if self.ltime < self.v or (v2.x + v2.y + v2.z == 0) then if self.ltime < self.v or (v2.x + v2.y + v2.z == 0) then
self.lifelime = -1 self.lifetime = -1
end end
local nexpos = {x = pos.x + (v.x * 0.05), y = pos.y + (v.y * 0.05) + 1, z = pos.z + (v.z * 0.05)} local nexpos = {x = pos.x + (v.x * 0.05), y = pos.y + (v.y * 0.05) + 1, z = pos.z + (v.z * 0.05)}
if minetest.registered_nodes[minetest.get_node(nexpos).name].walkable then if minetest.registered_nodes[minetest.get_node(nexpos).name].walkable then
self.lifelime = -1 self.lifetime = -1
end end
self.lifelime = self.lifelime - 1 self.lifetime = self.lifetime - 1
if self.lifelime < 0 then if self.lifetime < 0 then
self.target:set_detach() self.target:set_detach()
end end

@ -3,7 +3,7 @@ portalgun_portal_tmp_user_abort = 0
portalgun_portal_tmp_user = "" portalgun_portal_tmp_user = ""
local portalgun_timer = 1.2 local portalgun_timer = 1.2
local portalgun_time = 0 local portalgun_time = 0
portalgun_lifelime = 1200 --deletes portals that not used after a while portalgun_lifetime = 1200 --deletes portals that not used after a while
portalgun_max_rage = 100 portalgun_max_rage = 100
portalgun_max_use_per_secund_time = 4 --destroys the portal if excessive used portalgun_max_use_per_secund_time = 4 --destroys the portal if excessive used
portalgun_max_use_per_secund = 25 --4 & 25 is default = teleported (teleported 25 times in 4 sec) portalgun_max_use_per_secund = 25 --4 & 25 is default = teleported (teleported 25 times in 4 sec)
@ -101,15 +101,15 @@ portalgun_on_step = function(self, dtime)
return self return self
end end
if portalgun_portal[name].lifelime < 0 then if portalgun_portal[name].lifetime < 0 then
portal_delete(name, 0) portal_delete(name, 0)
return self return self
end end
if portalgun_portal[name].portal1_active and portalgun_portal[name].portal2_active then -- makes lifetime equal when both is acive, or it will be half if portalgun_portal[name].portal1_active and portalgun_portal[name].portal2_active then -- makes lifetime equal when both is acive, or it will be half
portalgun_portal[name].lifelime = portalgun_portal[name].lifelime - 0.5 portalgun_portal[name].lifetime = portalgun_portal[name].lifetime - 0.5
else else
portalgun_portal[name].lifelime = portalgun_portal[name].lifelime - 1 portalgun_portal[name].lifetime = portalgun_portal[name].lifetime - 1
return self -- abort when only 1 is active (saves cpu) return self -- abort when only 1 is active (saves cpu)
end end
@ -274,7 +274,7 @@ portalgun_on_step = function(self, dtime)
portalgun_portal[name].timer = 0.2 portalgun_portal[name].timer = 0.2
self.portal_max_use = self.portal_max_use + 1 self.portal_max_use = self.portal_max_use + 1
ob:set_pos(obpos, false) ob:set_pos(obpos, false)
portalgun_portal[name].lifelime = portalgun_lifelime portalgun_portal[name].lifetime = portalgun_lifetime
minetest.sound_play( minetest.sound_play(
"portalgun_teleport", "portalgun_teleport",
{pos = portalgun_portal[name].portal1_pos, max_hear_distance = 10, gain = 30} {pos = portalgun_portal[name].portal1_pos, max_hear_distance = 10, gain = 30}
@ -433,8 +433,6 @@ local function rnd(r)
return math.floor(r + 0.5) return math.floor(r + 0.5)
end end
minetest.register_privilege("allblocksportal", "Can use place portals everywhere")
function portalgun_onuse(itemstack, user, pointed_thing, mode) -- using the gun function portalgun_onuse(itemstack, user, pointed_thing, mode) -- using the gun
if pointed_thing.type == "object" then if pointed_thing.type == "object" then
portalgun_gravity(itemstack, user, pointed_thing) portalgun_gravity(itemstack, user, pointed_thing)
@ -449,7 +447,7 @@ function portalgun_onuse(itemstack, user, pointed_thing, mode) -- using the gun
local item = itemstack:to_table() local item = itemstack:to_table()
local ob = {} local ob = {}
ob.project = 1 ob.project = 1
ob.lifelime = portalgun_lifelime ob.lifetime = portalgun_lifetime
ob.portal1 = 0 ob.portal1 = 0
ob.portal2 = 0 ob.portal2 = 0
ob.portal1_dir = 0 ob.portal1_dir = 0
@ -460,7 +458,7 @@ function portalgun_onuse(itemstack, user, pointed_thing, mode) -- using the gun
if portalgun_portal[name] == nil then -- new portal profile if portalgun_portal[name] == nil then -- new portal profile
portalgun_portal[name] = { portalgun_portal[name] = {
lifelime = portalgun_lifelime, lifetime = portalgun_lifetime,
project = 1, project = 1,
timer = 0, timer = 0,
portal1_active = false, portal1_active = false,
@ -480,19 +478,16 @@ function portalgun_onuse(itemstack, user, pointed_thing, mode) -- using the gun
-- the project -- the project
for i = 1, portalgun_max_rage, 0.5 do for i = 1, portalgun_max_rage, 0.5 do
local nname = local nname = minetest.get_node({x = pos.x + (dir.x * i), y = pos.y + (dir.y * i), z = pos.z + (dir.z * i)}).name
minetest.get_node({x = pos.x + (dir.x * i), y = pos.y + (dir.y * i), z = pos.z + (dir.z * i)}).name
if minetest.registered_nodes[nname].walkable then if minetest.registered_nodes[nname].walkable then
portalgun_portal[name].lifelime = portalgun_lifelime portalgun_portal[name].lifetime = portalgun_lifetime
-- if minetest.get_node_group(nname, "antiportal") > 0 then -- if minetest.get_node_group(nname, "antiportal") > 0 then
-- minetest.sound_play("portalgun_error", {pos = pos, max_hear_distance = 5, gain = 3}) -- minetest.sound_play("portalgun_error", {pos = pos, max_hear_distance = 5, gain = 3})
-- return itemstack -- return itemstack
-- end -- end
--check if the name doesnt start with portalgun:testblock or if has priv allblocksportal
local allplace = minetest.check_player_privs(user:get_player_name(), {allblocksportal = true})
local istestblock = string.find(nname, "portalgun:testblock", 1) local istestblock = string.find(nname, "portalgun:testblock", 1)
if not istestblock and not allplace then if not istestblock then
minetest.sound_play("portalgun_error", {pos = pos, max_hear_distance = 5, gain = 3}) minetest.sound_play("portalgun_error", {pos = pos, max_hear_distance = 5, gain = 3})
return itemstack return itemstack
end end