Skip to content

Commit

Permalink
Disallow using void nade to cross walls
Browse files Browse the repository at this point in the history
  • Loading branch information
savilli committed Mar 20, 2022
1 parent 3375e0c commit 31a3090
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 39 deletions.
5 changes: 3 additions & 2 deletions mods/ctf/ctf_modes/ctf_mode_nade_fight/tool.lua
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ grenades.register_grenade("ctf_mode_nade_fight:black_hole_grenade", {
on_collide = function()
return true
end,
on_explode = function(def, pos, name)
on_explode = function(def, obj, pos, name)
pos = vector.round(pos)
local black_hole = minetest.add_entity(pos, "ctf_mode_nade_fight:black_hole")

local corners = {-black_hole_radius, black_hole_radius}
Expand Down Expand Up @@ -165,7 +166,7 @@ grenades.register_grenade("ctf_mode_nade_fight:knockback_grenade", {
on_collide = function()
return true
end,
on_explode = function(def, pos, name)
on_explode = function(def, obj, pos, name)
minetest.add_particle({
pos = pos,
velocity = {x=0, y=0, z=0},
Expand Down
2 changes: 1 addition & 1 deletion mods/other/throwable_snow/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ grenades.register_grenade("throwable_snow:snowball", {
collide_with_objects = true,
stack_max = 99,
throw_cooldown = 0.9,
on_explode = function(def, pos, name)
on_explode = function(def, obj, pos, name)
minetest.add_particlespawner({
amount = 9,
time = 0.01,
Expand Down
6 changes: 4 additions & 2 deletions mods/pvp/grenades/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,10 @@ grenades.register_grenade("name", { -- Name of the grenade (Like 'smoke' or 'fla
image = "", -- The name of the grenade's texture
collide_with_objects = false, -- (Default: false) Controls whether the grenade collides with objects. Grenade will never collide with thrower regardless of this setting
throw_cooldown = 0, -- How often player can throw grenades, in seconds
on_explode = function(def, pos, name)
on_explode = function(def, obj, pos, name)
-- This function is called when the grenade 'explodes'
-- <def> grenade object definition
-- <obj> the grenade object
-- <pos> the place the grenade 'exploded' at
-- <name> the name of the player that threw the grenade
end,
Expand All @@ -21,8 +22,9 @@ grenades.register_grenade("name", { -- Name of the grenade (Like 'smoke' or 'fla
-- <def> grenade object definition
-- <obj> the grenade object
-- <name> the name of the player that threw the grenade
-- <moveresult> table with collision info
-- return true to cause grenade explosion
-- return "stop" to stop the grenade from moving
-- return false 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
Expand Down
12 changes: 7 additions & 5 deletions mods/pvp/grenades/grenades.lua
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@ local fragdef = {
image = "grenades_frag.png",
explode_radius = 10,
explode_damage = 26,
on_collide = function(def, obj)
on_collide = function()
return true
end,
on_explode = function(def, pos, name)
on_explode = function(def, obj, pos, name)
if not name or not pos then return end

local player = minetest.get_player_by_name(name)
Expand Down Expand Up @@ -114,7 +114,9 @@ grenades.register_grenade("grenades:frag", fragdef)
local fragdef_sticky = table.copy(fragdef)
fragdef_sticky.description = "Sticky Frag grenade (Sticks to surfaces)"
fragdef_sticky.image = "grenades_frag_sticky.png"
fragdef_sticky.on_collide = function() return false end
fragdef_sticky.on_collide = function()
return
end
grenades.register_grenade("grenades:frag_sticky", fragdef_sticky)

-- Smoke Grenade
Expand All @@ -127,7 +129,7 @@ grenades.register_grenade("grenades:smoke", {
on_collide = function()
return true
end,
on_explode = function(def, pos, pname)
on_explode = function(def, obj, pos, pname)
local player = minetest.get_player_by_name(pname)
if not player or not pos then return end

Expand Down Expand Up @@ -202,7 +204,7 @@ grenades.register_grenade("grenades:flashbang", {
description = "Flashbang grenade (Blinds all who look at blast)",
image = "grenades_flashbang.png",
clock = 4,
on_explode = function(def, pos)
on_explode = function(def, obj, pos)
for _, v in ipairs(minetest.get_objects_inside_radius(pos, 20)) do
local hit = minetest.raycast(pos, v:get_pos(), true, true):next()
Expand Down
57 changes: 28 additions & 29 deletions mods/pvp/grenades/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,20 @@ local cooldown = ctf_core.init_cooldowns()

function grenades.throw_grenade(name, startspeed, player)
local dir = player:get_look_dir()
local pos = player:get_pos()
local obj = minetest.add_entity(vector.new(pos.x, pos.y + player:get_properties().eye_height, pos.z), name)
local pos = vector.offset(player:get_pos(), 0, player:get_properties().eye_height, 0)

local obj = minetest.add_entity(pos, name)
if not obj then
return
end

obj:set_velocity(vector.add(vector.multiply(dir, startspeed), player:get_velocity()))
obj:set_acceleration({x = 0, y = -9.8, z = 0})

obj:get_luaentity().thrower_name = player:get_player_name()
local data = obj:get_luaentity()
data.thrower_name = player:get_player_name()

return obj:get_luaentity()
return data
end

function grenades.register_grenade(name, def)
Expand Down Expand Up @@ -54,34 +56,31 @@ function grenades.register_grenade(name, def)
-- Check for a collision on the x/y/z axis

if moveresult.collides and moveresult.collisions then
if self.thrower_name and moveresult.collisions[1] and (moveresult.collisions[1].type ~= "object" or
moveresult.collisions[1].object ~= minetest.get_player_by_name(self.thrower_name)) then
if def.on_collide then
local c_result = def:on_collide(obj, self.thrower_name, moveresult)

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
else
if moveresult.collisions[1] and moveresult.collisions[1].axis then
local axis = moveresult.collisions[1].axis

vel[axis] = self.last_vel[axis] * -0.3
if def.on_collide then
local c_result = def:on_collide(obj, self.thrower_name, moveresult)

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(obj, pos, self.thrower_name)
end
obj:remove()
elseif c_result == false then
vel = vector.new()
self.last_vel = vector.new()
obj:set_velocity(vector.new())
obj:set_acceleration(vector.new(0, 0, 0))
end
else
if moveresult.collisions[1] and moveresult.collisions[1].axis then
local axis = moveresult.collisions[1].axis

obj:set_velocity(vel)
vel[axis] = self.last_vel[axis] * -0.3
end
end

obj:set_velocity(vel)
end

self.last_vel = vel
Expand Down Expand Up @@ -131,7 +130,7 @@ function grenades.register_grenade(name, def)
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)
def:on_explode(obj, pos, self.thrower_name)
end

obj:remove()
Expand Down

0 comments on commit 31a3090

Please sign in to comment.