Improve Smoke Grenades
This commit is contained in:
parent
4922c3115f
commit
98928211f6
3 changed files with 88 additions and 76 deletions
|
@ -140,7 +140,7 @@ local function sqdist(a, b)
|
||||||
return x*x + y*y + z*z
|
return x*x + y*y + z*z
|
||||||
end
|
end
|
||||||
|
|
||||||
local function get_flag_pos(player)
|
function ctf_classes.get_flag_pos(player)
|
||||||
local tplayer = ctf.player(player:get_player_name())
|
local tplayer = ctf.player(player:get_player_name())
|
||||||
if not tplayer or not tplayer.team then
|
if not tplayer or not tplayer.team then
|
||||||
return nil
|
return nil
|
||||||
|
@ -162,7 +162,7 @@ function ctf_classes.can_change(player)
|
||||||
return false, "You need to wait to change classes again!"
|
return false, "You need to wait to change classes again!"
|
||||||
end
|
end
|
||||||
|
|
||||||
local flag_pos = get_flag_pos(player)
|
local flag_pos = ctf_classes.get_flag_pos(player)
|
||||||
if flag_pos then
|
if flag_pos then
|
||||||
return sqdist(player:get_pos(), flag_pos) < 25,
|
return sqdist(player:get_pos(), flag_pos) < 25,
|
||||||
"Move closer to the flag to change classes!"
|
"Move closer to the flag to change classes!"
|
||||||
|
|
|
@ -82,86 +82,25 @@ end
|
||||||
grenades.register_grenade("grenades:frag", table.copy(fragdef))
|
grenades.register_grenade("grenades:frag", table.copy(fragdef))
|
||||||
--grenades.register_grenade("grenades:frag_sticky", fragdef)
|
--grenades.register_grenade("grenades:frag_sticky", fragdef)
|
||||||
|
|
||||||
-- Flashbang Grenade
|
|
||||||
|
|
||||||
-- local flash_huds = {}
|
|
||||||
|
|
||||||
-- grenades.register_grenade("grenades:flashbang", {
|
|
||||||
-- description = "Flashbang grenade (Blinds all who look at blast)",
|
|
||||||
-- image = "grenades_flashbang.png",
|
|
||||||
-- clock = 4,
|
|
||||||
-- on_explode = function(pos)
|
|
||||||
-- for _, v in ipairs(minetest.get_objects_inside_radius(pos, 20)) do
|
|
||||||
-- local hit = minetest.raycast(pos, v:get_pos(), true, true):next()
|
|
||||||
|
|
||||||
-- if hit and v:is_player() and v:get_hp() > 0 and not flash_huds[v:get_player_name()] and hit.type == "object" and
|
|
||||||
-- hit.ref:is_player() and hit.ref:get_player_name() == v:get_player_name() then
|
|
||||||
-- local playerdir = vector.round(v:get_look_dir())
|
|
||||||
-- local grenadedir = vector.round(vector.direction(v:get_pos(), pos))
|
|
||||||
-- local pname = v:get_player_name()
|
|
||||||
|
|
||||||
-- minetest.sound_play("glasslike_break", {
|
|
||||||
-- pos = pos,
|
|
||||||
-- gain = 1.0,
|
|
||||||
-- max_hear_distance = 32,
|
|
||||||
-- })
|
|
||||||
|
|
||||||
-- if math.acos(playerdir.x*grenadedir.x + playerdir.y*grenadedir.y + playerdir.z*grenadedir.z) <= math.pi/4 then
|
|
||||||
-- flash_huds[pname] = {}
|
|
||||||
|
|
||||||
-- for i = 0, 5, 1 do
|
|
||||||
-- local key = v:hud_add({
|
|
||||||
-- hud_elem_type = "image",
|
|
||||||
-- position = {x = 0, y = 0},
|
|
||||||
-- name = "flashbang hud "..pname,
|
|
||||||
-- scale = {x = -200, y = -200},
|
|
||||||
-- text = "default_cloud.png^[colorize:white:255^[opacity:"..tostring(255 - (i * 20)),
|
|
||||||
-- alignment = {x = 0, y = 0},
|
|
||||||
-- offset = {x = 0, y = 0}
|
|
||||||
-- })
|
|
||||||
|
|
||||||
-- flash_huds[pname][i+1] = key
|
|
||||||
|
|
||||||
-- minetest.after(2 * i, function()
|
|
||||||
-- if minetest.get_player_by_name(pname) then
|
|
||||||
-- minetest.get_player_by_name(pname):hud_remove(key)
|
|
||||||
|
|
||||||
-- if flash_huds[pname] then
|
|
||||||
-- table.remove(flash_huds[pname], 1)
|
|
||||||
-- end
|
|
||||||
|
|
||||||
-- if i == 5 then
|
|
||||||
-- flash_huds[pname] = nil
|
|
||||||
-- end
|
|
||||||
-- end
|
|
||||||
-- end)
|
|
||||||
-- end
|
|
||||||
-- end
|
|
||||||
|
|
||||||
-- end
|
|
||||||
-- end
|
|
||||||
-- end,
|
|
||||||
-- })
|
|
||||||
|
|
||||||
-- minetest.register_on_dieplayer(function(player)
|
|
||||||
-- local name = player:get_player_name()
|
|
||||||
|
|
||||||
-- if flash_huds[name] then
|
|
||||||
-- for _, v in ipairs(flash_huds[name]) do
|
|
||||||
-- player:hud_remove(v)
|
|
||||||
-- end
|
|
||||||
|
|
||||||
-- flash_huds[name] = nil
|
|
||||||
-- end
|
|
||||||
-- end)
|
|
||||||
|
|
||||||
-- Smoke Grenade
|
-- Smoke Grenade
|
||||||
|
|
||||||
local SMOKE_GRENADE_TIME = 30
|
local SMOKE_GRENADE_TIME = 30
|
||||||
grenades.register_grenade("grenades:smoke", {
|
grenades.register_grenade("grenades:smoke", {
|
||||||
description = "Smoke grenade (Generates smoke around blast site)",
|
description = "Smoke grenade (Generates smoke around blast site)",
|
||||||
image = "grenades_smoke_grenade.png",
|
image = "grenades_smoke_grenade.png",
|
||||||
on_explode = function(pos)
|
on_collide = function(obj)
|
||||||
|
return true
|
||||||
|
end,
|
||||||
|
on_explode = function(pos, pname)
|
||||||
|
local player = minetest.get_player_by_name(pname)
|
||||||
|
if not player or not pos then return end
|
||||||
|
|
||||||
|
if vector.distance(pos, ctf_classes.get_flag_pos(player)) <= 15 then
|
||||||
|
minetest.chat_send_player(pname, "You can't explode smoke grenades so close to your flag!")
|
||||||
|
player:get_inventory():add_item("main", "grenades:smoke")
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
minetest.sound_play("grenades_glasslike_break", {
|
minetest.sound_play("grenades_glasslike_break", {
|
||||||
pos = pos,
|
pos = pos,
|
||||||
gain = 1.0,
|
gain = 1.0,
|
||||||
|
@ -206,3 +145,76 @@ grenades.register_grenade("grenades:smoke", {
|
||||||
interval = 0.3,
|
interval = 0.3,
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
-- Flashbang Grenade
|
||||||
|
|
||||||
|
--[[ local flash_huds = {}
|
||||||
|
|
||||||
|
grenades.register_grenade("grenades:flashbang", {
|
||||||
|
description = "Flashbang grenade (Blinds all who look at blast)",
|
||||||
|
image = "grenades_flashbang.png",
|
||||||
|
clock = 4,
|
||||||
|
on_explode = function(pos)
|
||||||
|
for _, v in ipairs(minetest.get_objects_inside_radius(pos, 20)) do
|
||||||
|
local hit = minetest.raycast(pos, v:get_pos(), true, true):next()
|
||||||
|
|
||||||
|
if hit and v:is_player() and v:get_hp() > 0 and not flash_huds[v:get_player_name()] and hit.type == "object" and
|
||||||
|
hit.ref:is_player() and hit.ref:get_player_name() == v:get_player_name() then
|
||||||
|
local playerdir = vector.round(v:get_look_dir())
|
||||||
|
local grenadedir = vector.round(vector.direction(v:get_pos(), pos))
|
||||||
|
local pname = v:get_player_name()
|
||||||
|
|
||||||
|
minetest.sound_play("glasslike_break", {
|
||||||
|
pos = pos,
|
||||||
|
gain = 1.0,
|
||||||
|
max_hear_distance = 32,
|
||||||
|
})
|
||||||
|
|
||||||
|
if math.acos(playerdir.x*grenadedir.x + playerdir.y*grenadedir.y + playerdir.z*grenadedir.z) <= math.pi/4 then
|
||||||
|
flash_huds[pname] = {}
|
||||||
|
|
||||||
|
for i = 0, 5, 1 do
|
||||||
|
local key = v:hud_add({
|
||||||
|
hud_elem_type = "image",
|
||||||
|
position = {x = 0, y = 0},
|
||||||
|
name = "flashbang hud "..pname,
|
||||||
|
scale = {x = -200, y = -200},
|
||||||
|
text = "default_cloud.png^[colorize:white:255^[opacity:"..tostring(255 - (i * 20)),
|
||||||
|
alignment = {x = 0, y = 0},
|
||||||
|
offset = {x = 0, y = 0}
|
||||||
|
})
|
||||||
|
|
||||||
|
flash_huds[pname][i+1] = key
|
||||||
|
|
||||||
|
minetest.after(2 * i, function()
|
||||||
|
if minetest.get_player_by_name(pname) then
|
||||||
|
minetest.get_player_by_name(pname):hud_remove(key)
|
||||||
|
|
||||||
|
if flash_huds[pname] then
|
||||||
|
table.remove(flash_huds[pname], 1)
|
||||||
|
end
|
||||||
|
|
||||||
|
if i == 5 then
|
||||||
|
flash_huds[pname] = nil
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end,
|
||||||
|
})
|
||||||
|
|
||||||
|
minetest.register_on_dieplayer(function(player)
|
||||||
|
local name = player:get_player_name()
|
||||||
|
|
||||||
|
if flash_huds[name] then
|
||||||
|
for _, v in ipairs(flash_huds[name]) do
|
||||||
|
player:hud_remove(v)
|
||||||
|
end
|
||||||
|
|
||||||
|
flash_huds[name] = nil
|
||||||
|
end
|
||||||
|
end) ]]
|
||||||
|
|
Binary file not shown.
Before Width: | Height: | Size: 126 B After Width: | Height: | Size: 109 B |
Loading…
Reference in a new issue