Add Sticky grenades (#677)
* Improved grenade API * Added sticky grenade * Improved grenade textures
This commit is contained in:
parent
e4a64124cf
commit
81d7553f7c
6 changed files with 50 additions and 35 deletions
|
@ -279,6 +279,14 @@ crafting.register_recipe({
|
||||||
level = 1,
|
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({
|
crafting.register_recipe({
|
||||||
type = "inv",
|
type = "inv",
|
||||||
output = "grenades:smoke 1",
|
output = "grenades:smoke 1",
|
||||||
|
|
|
@ -18,6 +18,7 @@ grenades.register_grenade("name", { -- Name of the grenade (Like 'smoke' or 'fla
|
||||||
-- <obj> the grenade object
|
-- <obj> the grenade object
|
||||||
-- <name> the name of the player that threw the grenade
|
-- <name> the name of the player that threw the grenade
|
||||||
-- return true to cause grenade explosion
|
-- return true to cause grenade explosion
|
||||||
|
-- return "stop" to stop the grenade from moving
|
||||||
end,
|
end,
|
||||||
clock = 3, -- Optional, controls how long until grenade detonates. Default is 3
|
clock = 3, -- Optional, controls how long until grenade detonates. Default is 3
|
||||||
particle = { -- Adds particles in the grenade's trail
|
particle = { -- Adds particles in the grenade's trail
|
||||||
|
|
|
@ -9,7 +9,7 @@ local function remove_flora(pos, radius)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
grenades.register_grenade("grenades:frag", {
|
local fragdef = {
|
||||||
description = "Frag grenade (Kills anyone near blast)",
|
description = "Frag grenade (Kills anyone near blast)",
|
||||||
image = "grenades_frag.png",
|
image = "grenades_frag.png",
|
||||||
on_explode = function(pos, name)
|
on_explode = function(pos, name)
|
||||||
|
@ -71,7 +71,16 @@ grenades.register_grenade("grenades:frag", {
|
||||||
end
|
end
|
||||||
end
|
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
|
-- Flashbang Grenade
|
||||||
|
|
||||||
|
|
|
@ -34,7 +34,7 @@ function grenades.register_grenade(name, def)
|
||||||
sliding = 1,
|
sliding = 1,
|
||||||
particle = 0,
|
particle = 0,
|
||||||
timer = 0,
|
timer = 0,
|
||||||
on_step = function(self, dtime)
|
on_step = function(self, dtime, moveresult)
|
||||||
local obj = self.object
|
local obj = self.object
|
||||||
local vel = obj:get_velocity()
|
local vel = obj:get_velocity()
|
||||||
local pos = obj:get_pos()
|
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
|
-- 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 moveresult.collides and moveresult.collisions then
|
||||||
if def.on_collide and def.on_collide(obj, self.thrower_name) then
|
if def.on_collide then
|
||||||
if self.thrower_name then
|
local c_result = def.on_collide(obj, self.thrower_name)
|
||||||
minetest.log("action", "[Grenades] A grenade thrown by " .. self.thrower_name ..
|
|
||||||
" explodes at " .. minetest.pos_to_string(vector.round(pos)))
|
if c_result == true then
|
||||||
def.on_explode(pos, self.thrower_name)
|
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
|
end
|
||||||
|
|
||||||
obj:remove()
|
|
||||||
end
|
end
|
||||||
|
|
||||||
if math.abs(self.last_vel.x - vel.x) > 5 then -- Check for a large reduction in velocity
|
if moveresult.collisions[1] and moveresult.collisions[1].axis then
|
||||||
vel.x = self.last_vel.x * -0.3 -- Invert velocity and reduce it a bit
|
local axis = moveresult.collisions[1].axis
|
||||||
end
|
|
||||||
|
|
||||||
if math.abs(self.last_vel.y - vel.y) > 5 then -- Check for a large reduction in velocity
|
vel[axis] = self.last_vel[axis] * -0.3
|
||||||
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
|
|
||||||
end
|
end
|
||||||
|
|
||||||
obj:set_velocity(vel)
|
obj:set_velocity(vel)
|
||||||
|
@ -76,27 +78,22 @@ function grenades.register_grenade(name, def)
|
||||||
|
|
||||||
self.last_vel = vel
|
self.last_vel = vel
|
||||||
|
|
||||||
if self.sliding == 1 and vel.y == 0 then -- Check if grenade is sliding
|
norm_vel = vector.normalize(vel)
|
||||||
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)
|
|
||||||
|
|
||||||
|
if not vector.equals(vel, vector.new()) then
|
||||||
obj:set_acceleration({
|
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,
|
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
|
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
|
-- Grenade Particles
|
||||||
|
|
||||||
|
|
Binary file not shown.
Before Width: | Height: | Size: 225 B After Width: | Height: | Size: 1.9 KiB |
BIN
mods/pvp/grenades/textures/grenades_frag_sticky.png
Normal file
BIN
mods/pvp/grenades/textures/grenades_frag_sticky.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 2 KiB |
Loading…
Reference in a new issue