diff --git a/mods/ctf/ctf_crafting/init.lua b/mods/ctf/ctf_crafting/init.lua index 33a9516..4a8188d 100644 --- a/mods/ctf/ctf_crafting/init.lua +++ b/mods/ctf/ctf_crafting/init.lua @@ -279,6 +279,14 @@ crafting.register_recipe({ level = 1, }) +crafting.register_recipe({ + type = "inv", + output = "grenades:frag_sticky 1", + items = { "grenades:frag", "default:stick 4" }, + always_known = true, + level = 1, +}) + crafting.register_recipe({ type = "inv", output = "grenades:smoke 1", diff --git a/mods/pvp/grenades/api.md b/mods/pvp/grenades/api.md index e808d96..a26f9b5 100644 --- a/mods/pvp/grenades/api.md +++ b/mods/pvp/grenades/api.md @@ -18,6 +18,7 @@ grenades.register_grenade("name", { -- Name of the grenade (Like 'smoke' or 'fla -- the grenade object -- the name of the player that threw the grenade -- return true to cause grenade explosion + -- return "stop" to stop the grenade from moving end, clock = 3, -- Optional, controls how long until grenade detonates. Default is 3 particle = { -- Adds particles in the grenade's trail diff --git a/mods/pvp/grenades/grenades.lua b/mods/pvp/grenades/grenades.lua index 06aa946..72d57a7 100644 --- a/mods/pvp/grenades/grenades.lua +++ b/mods/pvp/grenades/grenades.lua @@ -9,7 +9,7 @@ local function remove_flora(pos, radius) end end -grenades.register_grenade("grenades:frag", { +local fragdef = { description = "Frag grenade (Kills anyone near blast)", image = "grenades_frag.png", on_explode = function(pos, name) @@ -71,7 +71,16 @@ grenades.register_grenade("grenades:frag", { end end end, -}) +} + +grenades.register_grenade("grenades:frag", table.copy(fragdef)) + +fragdef.description = "Sticky Frag grenade (Sticks to surfaces)" +fragdef.image = "grenades_frag_sticky.png" +fragdef.on_collide = function(obj) + return "stop" +end +grenades.register_grenade("grenades:frag_sticky", fragdef) -- Flashbang Grenade diff --git a/mods/pvp/grenades/init.lua b/mods/pvp/grenades/init.lua index a9fa222..8053b16 100644 --- a/mods/pvp/grenades/init.lua +++ b/mods/pvp/grenades/init.lua @@ -34,7 +34,7 @@ function grenades.register_grenade(name, def) sliding = 1, particle = 0, timer = 0, - on_step = function(self, dtime) + on_step = function(self, dtime, moveresult) local obj = self.object local vel = obj:get_velocity() local pos = obj:get_pos() @@ -48,27 +48,29 @@ function grenades.register_grenade(name, def) -- Check for a collision on the x/y/z axis - if not vector.equals(self.last_vel, vel) and vector.distance(self.last_vel, vel) > 4 then - if def.on_collide and def.on_collide(obj, self.thrower_name) then - if self.thrower_name then - minetest.log("action", "[Grenades] A grenade thrown by " .. self.thrower_name .. - " explodes at " .. minetest.pos_to_string(vector.round(pos))) - def.on_explode(pos, self.thrower_name) + if moveresult.collides and moveresult.collisions then + if def.on_collide then + local c_result = def.on_collide(obj, self.thrower_name) + + if c_result == true then + if self.thrower_name then + minetest.log("action", "[Grenades] A grenade thrown by " .. self.thrower_name .. + " explodes at " .. minetest.pos_to_string(vector.round(pos))) + def.on_explode(pos, self.thrower_name) + end + obj:remove() + elseif c_result == "stop" then + vel = vector.new() + self.last_vel = vector.new() + obj:set_velocity(vector.new()) + obj:set_acceleration(vector.new(0, 0, 0)) end - - obj:remove() end - if math.abs(self.last_vel.x - vel.x) > 5 then -- Check for a large reduction in velocity - vel.x = self.last_vel.x * -0.3 -- Invert velocity and reduce it a bit - end + if moveresult.collisions[1] and moveresult.collisions[1].axis then + local axis = moveresult.collisions[1].axis - if math.abs(self.last_vel.y - vel.y) > 5 then -- Check for a large reduction in velocity - vel.y = self.last_vel.y * -0.2 -- Invert velocity and reduce it a bit - end - - if math.abs(self.last_vel.z - vel.z) > 5 then -- Check for a large reduction in velocity - vel.z = self.last_vel.z * -0.3 -- Invert velocity and reduce it a bit + vel[axis] = self.last_vel[axis] * -0.3 end obj:set_velocity(vel) @@ -76,27 +78,22 @@ function grenades.register_grenade(name, def) self.last_vel = vel - if self.sliding == 1 and vel.y == 0 then -- Check if grenade is sliding - self.sliding = 2 -- Multiplies drag by 2 - elseif self.sliding > 1 and vel.y ~= 0 then - self.sliding = 1 -- Doesn't affect drag - end - - if self.sliding > 1 then -- Is the grenade sliding? - if vector.distance(vector.new(), vel) <= 1 and not vector.equals(vel, vector.new()) then -- Grenade is barely moving, make sure it stays that way - obj:set_velocity(vector.new()) - obj:set_acceleration(vector.new(0, -9.8, 0)) - end - else - norm_vel = vector.normalize(vel) + norm_vel = vector.normalize(vel) + if not vector.equals(vel, vector.new()) then obj:set_acceleration({ - x = -norm_vel.x * grenades.grenade_deaccel * self.sliding, + x = -norm_vel.x * grenades.grenade_deaccel * (moveresult.touching_ground and 2 or 1), y = -9.8, - z = -norm_vel.z * grenades.grenade_deaccel * self.sliding, + z = -norm_vel.z * grenades.grenade_deaccel * (moveresult.touching_ground and 2 or 1), }) end + if moveresult.touching_ground then -- Is the grenade sliding? + if vector.distance(vector.new(), vel) <= 2 and not vector.equals(vel, vector.new()) then -- Grenade is barely moving, make sure it stays that way + obj:set_velocity(vector.new()) + obj:set_acceleration(vector.new(0, -9.8, 0)) + end + end -- Grenade Particles diff --git a/mods/pvp/grenades/textures/grenades_frag.png b/mods/pvp/grenades/textures/grenades_frag.png index 5de4795..f781a62 100644 Binary files a/mods/pvp/grenades/textures/grenades_frag.png and b/mods/pvp/grenades/textures/grenades_frag.png differ diff --git a/mods/pvp/grenades/textures/grenades_frag_sticky.png b/mods/pvp/grenades/textures/grenades_frag_sticky.png new file mode 100644 index 0000000..422dd1f Binary files /dev/null and b/mods/pvp/grenades/textures/grenades_frag_sticky.png differ