From 4e5af39fd8a312f19c6a3789d837678f1b5aea9d Mon Sep 17 00:00:00 2001 From: tenplus1 Date: Tue, 13 Jun 2023 12:50:58 +0100 Subject: [PATCH] keep globals inside nssm table --- darts.lua | 8 ++++---- mobs/ant_queen.lua | 2 +- mobs/black_widow.lua | 2 +- mobs/icelamander.lua | 2 +- mobs/icesnake.lua | 2 +- mobs/lava_titan.lua | 2 +- mobs/mese_dragon.lua | 2 +- mobs/mordain.lua | 2 +- mobs/morvalar.lua | 11 +++++++---- mobs/sandworm.lua | 2 +- mobs/snow_biter.lua | 2 +- mobs/stone_eater.lua | 3 +-- mobs/uloboros.lua | 2 +- nssm_api.lua | 38 +++++++++++++++++++------------------- nssm_materials.lua | 2 +- nssm_weapons.lua | 10 +++++----- 16 files changed, 47 insertions(+), 45 deletions(-) diff --git a/darts.lua b/darts.lua index 582c48e..aae8e63 100644 --- a/darts.lua +++ b/darts.lua @@ -319,7 +319,7 @@ mobs:register_arrow("nssm:phoenix_arrow", { }) -function gas_explosion(pos) +local function gas_explosion(pos) if minetest.is_protected(pos, "") then return @@ -375,7 +375,6 @@ mobs:register_arrow("nssm:roar_of_the_dragon", { on_step = function(self, dtime) local pos = self.object:get_pos() - local n = minetest.get_node(pos).name if self.timer == 0 then @@ -390,9 +389,10 @@ mobs:register_arrow("nssm:roar_of_the_dragon", { for _,obj in ipairs(objects) do - local name = obj:get_entity_name() + local ent = obj and obj:get_luaentity() + local name = ent and ent.name - if name ~= "nssm:roar_of_the_dragon" + if name and name ~= "nssm:roar_of_the_dragon" and name ~= "nssm:mese_dragon" then obj:set_hp(obj:get_hp() - 0.05) diff --git a/mobs/ant_queen.lua b/mobs/ant_queen.lua index e484f48..db37969 100644 --- a/mobs/ant_queen.lua +++ b/mobs/ant_queen.lua @@ -97,7 +97,7 @@ mobs:register_mob("nssm:ant_queen", { and minetest.get_node(pos1).name == "air" and counter < 4 then - explosion_particles(pos1, 1) + nssm:explosion_particles(pos1, 1) minetest.add_entity(pos1, "nssm:ant_soldier") end diff --git a/mobs/black_widow.lua b/mobs/black_widow.lua index acf7bf5..296648a 100644 --- a/mobs/black_widow.lua +++ b/mobs/black_widow.lua @@ -53,7 +53,7 @@ mobs:register_mob("nssm:black_widow", { do_custom = function(self) if nssm.spiders_litter_web then - webber_ability(self, "nssm:web", 2) + nssm:webber_ability(self, "nssm:web", 2) end end }) diff --git a/mobs/icelamander.lua b/mobs/icelamander.lua index f1a0801..88d8c4c 100644 --- a/mobs/icelamander.lua +++ b/mobs/icelamander.lua @@ -59,6 +59,6 @@ mobs:register_mob("nssm:icelamander", { }, do_custom = function(self) - midas_ability(self, "default:ice", self.run_velocity, 1, 3) + nssm:midas_ability(self, "default:ice", self.run_velocity, 1, 3) end }) diff --git a/mobs/icesnake.lua b/mobs/icesnake.lua index b1b10ff..26f11bb 100644 --- a/mobs/icesnake.lua +++ b/mobs/icesnake.lua @@ -53,6 +53,6 @@ mobs:register_mob("nssm:icesnake", { }, do_custom = function(self) - putting_ability(self, "default:ice", self.run_velocity) + nssm:putting_ability(self, "default:ice", self.run_velocity) end }) diff --git a/mobs/lava_titan.lua b/mobs/lava_titan.lua index 933dff9..0bd20cf 100644 --- a/mobs/lava_titan.lua +++ b/mobs/lava_titan.lua @@ -59,6 +59,6 @@ mobs:register_mob("nssm:lava_titan", { }, do_custom = function (self) - digging_attack(self, nil, self.run_velocity, {x = 0, y = 4, z = 0}) + nssm:digging_attack(self, nil, self.run_velocity, {x = 0, y = 4, z = 0}) end }) diff --git a/mobs/mese_dragon.lua b/mobs/mese_dragon.lua index d89b250..184e3f4 100644 --- a/mobs/mese_dragon.lua +++ b/mobs/mese_dragon.lua @@ -64,7 +64,7 @@ mobs:register_mob("nssm:mese_dragon", { }, do_custom = function(self) - midas_ability(self, "default:mese_block", self.run_velocity, 2, 3) + nssm:midas_ability(self, "default:mese_block", self.run_velocity, 2, 3) end, custom_attack = function(self) diff --git a/mobs/mordain.lua b/mobs/mordain.lua index f1f85e6..9915546 100644 --- a/mobs/mordain.lua +++ b/mobs/mordain.lua @@ -129,7 +129,7 @@ mobs:register_mob("nssm:mordain", { d.z = p.z + math.random(-m, m) d.y = p.y - local dist = dist_pos(d, p) + local dist = nssm:dist_pos(d, p) if dist >= 2 then diff --git a/mobs/morvalar.lua b/mobs/morvalar.lua index d0d8705..185bab7 100644 --- a/mobs/morvalar.lua +++ b/mobs/morvalar.lua @@ -440,7 +440,8 @@ mobs:register_mob("nssm:morvalar5", { mobs:set_animation(self, "punch") - tnt_boom_nssm(p, {damage_radius = 6, radius = 5, ignore_protection = false}) + nssm:tnt_boom_nssm(p, { + damage_radius = 6, radius = 5, ignore_protection = false}) self.morvalar5_timer = os.time() @@ -571,7 +572,7 @@ mobs:register_mob("nssm:morvalar4", { d.z = p.z + math.random(-m, m) d.y = p.y - local dist = dist_pos(d, p) + local dist = nssm:dist_pos(d, p) if dist >= 2 then @@ -1054,7 +1055,8 @@ minetest.register_entity("nssm:kamehameha_bad", { if obj:is_player() then - tnt_boom_nssm(pos, {damage_radius = 6, radius = 5, ignore_protection = false}) + nssm:tnt_boom_nssm(pos, { + damage_radius = 6, radius = 5, ignore_protection = false}) self.object:remove() @@ -1067,7 +1069,8 @@ minetest.register_entity("nssm:kamehameha_bad", { if name ~= "nssm:morvalar0" and name ~="nssm:kamehameha_bad" then - tnt_boom_nssm(pos, {damage_radius = 6, radius = 5, ignore_protection = false}) + nssm:tnt_boom_nssm(pos, { + damage_radius = 6, radius = 5, ignore_protection = false}) self.object:remove() end diff --git a/mobs/sandworm.lua b/mobs/sandworm.lua index 7f6ad20..dde03cd 100644 --- a/mobs/sandworm.lua +++ b/mobs/sandworm.lua @@ -53,6 +53,6 @@ mobs:register_mob("nssm:sandworm", { }, do_custom = function(self) - digging_attack(self, "sand", self.run_velocity, {x = 0, y = 3, z = 0}) + nssm:digging_attack(self, "sand", self.run_velocity, {x = 0, y = 3, z = 0}) end }) diff --git a/mobs/snow_biter.lua b/mobs/snow_biter.lua index d050725..1bfd7a4 100644 --- a/mobs/snow_biter.lua +++ b/mobs/snow_biter.lua @@ -57,6 +57,6 @@ mobs:register_mob("nssm:snow_biter", { }, do_custom = function(self) - putting_ability(self, "default:ice", self.run_velocity) + nssm:putting_ability(self, "default:ice", self.run_velocity) end }) diff --git a/mobs/stone_eater.lua b/mobs/stone_eater.lua index d997201..167f4bd 100644 --- a/mobs/stone_eater.lua +++ b/mobs/stone_eater.lua @@ -57,7 +57,6 @@ mobs:register_mob("nssm:stone_eater", { }, do_custom = function(self) - --digging_ability(self, "stone", self.run_velocity, {x=0, y=2, z=0}) - digging_attack(self, "stone", self.run_velocity, {x = 0, y = 1, z = 0}) + nssm:digging_attack(self, "stone", self.run_velocity, {x = 0, y = 1, z = 0}) end }) diff --git a/mobs/uloboros.lua b/mobs/uloboros.lua index 2c04fc0..e6d77da 100644 --- a/mobs/uloboros.lua +++ b/mobs/uloboros.lua @@ -55,7 +55,7 @@ mobs:register_mob("nssm:uloboros", { do_custom = function(self) if nssm.spiders_litter_web then - webber_ability(self, "nssm:web", 2) + nssm:webber_ability(self, "nssm:web", 2) end end }) diff --git a/nssm_api.lua b/nssm_api.lua index b17be16..cc8e7fb 100644 --- a/nssm_api.lua +++ b/nssm_api.lua @@ -9,7 +9,7 @@ nssm.lessvirulent = minetest.settings:get_bool("nssm.lessvirulent") or false nssm.safebones = minetest.settings:get_bool("nssm.safebones") or false nssm.cryosave = minetest.settings:get_bool("nssm.cryosave") or false -function nssm:virulence(mobe) +local function virulence(mobe) if not nssm.lessvirulent then return 0 @@ -23,21 +23,21 @@ function nssm:affectbones(mobe) -- as function for adaptable heuristic return not nssm.safebones end - +--[[ function drops(drop) if drop then - drop:setvelocity({ + drop:set_velocity({ x = math.random(-10, 10) / 9, y = 5, z = math.random(-10, 10) / 9 }) end end +]] - -function perpendicular_vector(vec) --returns a vector rotated of 90° in 2D +local function perpendicular_vector(vec) --returns a vector rotated of 90° in 2D local ang = math.pi / 2 local c = math.cos(ang) @@ -50,7 +50,7 @@ function perpendicular_vector(vec) --returns a vector rotated of 90° in 2D end -function add_entity_and_particles(entity, pos, particles, multiplier) +function nssm:add_entity_and_particles(entity, pos, particles, multiplier) minetest.add_particlespawner({ amount = 100 * multiplier, @@ -75,7 +75,7 @@ end -- get node but use fallback for nil or unknown -function node_ok(pos, fallback) +function nssm:node_ok(pos, fallback) fallback = fallback or "default:dirt" @@ -93,7 +93,7 @@ function node_ok(pos, fallback) end -function dist_pos(p, s) +function nssm:dist_pos(p, s) local v = { x = math.abs(s.x - p.x), @@ -104,7 +104,7 @@ function dist_pos(p, s) return math.sqrt(v.x ^ 2 + v.y ^ 2 + v.z ^ 2) end - +--[[ --check_for_death functions customized for monsters who respawns (Masticone) function check_for_death_hydra(self) @@ -140,9 +140,9 @@ function check_for_death_hydra(self) return true end +]] - -function round(n) +local function round(n) if (n > 0) then return n % 1 >= 0.5 and math.ceil(n) or math.floor(n) @@ -156,7 +156,7 @@ function round(n) end -function explosion_particles(pos, exp_radius) +function nssm:explosion_particles(pos, exp_radius) minetest.add_particlespawner({ amount = 100 * exp_radius / 2, @@ -177,7 +177,7 @@ function explosion_particles(pos, exp_radius) end -function digging_attack( +function nssm:digging_attack( self, --the entity of the mob group, --group of the blocks the mob can dig: nil=everything max_vel, --max velocity of the mob @@ -237,7 +237,7 @@ function digging_attack( end -function putting_ability( --puts under the mob the block defined as 'p_block' +function nssm:putting_ability( --puts under the mob the block defined as 'p_block' self, --the entity of the mob p_block, --definition of the block to use max_vel --max velocity of the mob @@ -308,14 +308,14 @@ function putting_ability( --puts under the mob the block defined as 'p_block' end -function webber_ability( --puts randomly around the block defined as w_block +function nssm:webber_ability( --puts randomly around the block defined as w_block self, --the entity of the mob w_block, --definition of the block to use radius --max distance the block can be put ) - if nssm:virulence(self) ~= 0 - and math.random(1, nssm:virulence(self)) ~= 1 then return end + if virulence(self) ~= 0 + and math.random(1, virulence(self)) ~= 1 then return end local pos = self.object:get_pos() @@ -336,7 +336,7 @@ function webber_ability( --puts randomly around the block defined as w_block end -function midas_ability( --ability to transform every blocks it touches in the m_block block +function nssm:midas_ability( --ability to transform every blocks it touches in the m_block block self, --the entity of the mob m_block, max_vel, --max velocity of the mob @@ -829,7 +829,7 @@ local function tnt_explode(pos, radius, ignore_protection, ignore_on_blast) end -function tnt_boom_nssm(pos, def) +function nssm:tnt_boom_nssm(pos, def) minetest.sound_play("tnt_explode", { pos = pos, gain = 1.5, max_hear_distance = 2 * 64}, true) diff --git a/nssm_materials.lua b/nssm_materials.lua index cfafce2..cf40aab 100644 --- a/nssm_materials.lua +++ b/nssm_materials.lua @@ -395,7 +395,7 @@ minetest.register_node("nssm:pumpbomb", { minetest.set_node(pos, {name = "air"}) - tnt_boom_nssm(pos, {damage_radius = 4, radius = 3, ignore_protection = false}) + nssm:tnt_boom_nssm(pos, {damage_radius = 4, radius = 3, ignore_protection = false}) end }) diff --git a/nssm_weapons.lua b/nssm_weapons.lua index dcc25ee..8722378 100644 --- a/nssm_weapons.lua +++ b/nssm_weapons.lua @@ -22,7 +22,7 @@ end local function hit(pos, self) - local node = node_ok(pos).name + local node = nssm:node_ok(pos).name self.hit_node(self, pos, node) self.object:remove() @@ -216,7 +216,7 @@ local function search_on_step( if min_dist < 1 then - local node = node_ok(pos).name + local node = nssm:node_ok(pos).name self.hit_node(self, pos, node) self.object:remove() @@ -231,7 +231,7 @@ local function search_on_step( if n ~= "air" and n ~= "default:water_source" and n ~= "default:water_flowing" then - local node = node_ok(pos).name + local node = nssm:node_ok(pos).name self.hit_node(self, pos, node) self.object:remove() @@ -259,7 +259,7 @@ local function default_on_step( if os.time() - self.life_time > max_time then - local node = node_ok(pos).name + local node = nssm:node_ok(pos).name self.hit_node(self, pos, node) self.object:remove() @@ -298,7 +298,7 @@ local function default_on_step( if n == not_transparent or minetest.get_item_group(n, not_transparent) == 1 then - local node = node_ok(pos).name + local node = nssm:node_ok(pos).name self.hit_node(self, pos, node) self.object:remove()