Allow particle effect overrides in gun spec

This commit is contained in:
stujones11 2019-03-17 16:46:27 +00:00
parent 52ed0d2340
commit 18e22a38fb
3 changed files with 68 additions and 38 deletions

View file

@ -16,6 +16,23 @@ shooter.config = {
camera_height = 1.5, camera_height = 1.5,
} }
shooter.default_particles = {
amount = 15,
time = 0.3,
minpos = {x=-0.1, y=-0.1, z=-0.1},
maxpos = {x=0.1, y=0.1, z=0.1},
minvel = {x=-1, y=1, z=-1},
maxvel = {x=1, y=2, z=1},
minacc = {x=-2, y=-2, z=-2},
maxacc = {x=2, y=-2, z=2},
minexptime = 0.1,
maxexptime = 0.75,
minsize = 1,
maxsize = 2,
collisiondetection = false,
texture = "shooter_hit.png",
}
local rounds = {} local rounds = {}
local shots = {} local shots = {}
local shooting = {} local shooting = {}
@ -74,29 +91,21 @@ shooter.register_weapon = function(name, def)
}) })
end end
shooter.spawn_particles = function(pos, texture) shooter.spawn_particles = function(pos, particles)
if config.enable_particle_fx == true then particles = particles or {}
if type(texture) ~= "string" then if not config.enable_particle_fx == true or particles.amount == 0 then
texture = config.explosion_texture return
end end
local spread = {x=0.1, y=0.1, z=0.1} local copy = function(v)
minetest.add_particlespawner({ return type(v) == "table" and table.copy(v) or v
amount = 15,
time = 0.3,
minpos = vector.subtract(pos, spread),
maxpos = vector.add(pos, spread),
minvel = {x=-1, y=1, z=-1},
maxvel = {x=1, y=2, z=1},
minacc = {x=-2, y=-2, z=-2},
maxacc = {x=2, y=-2, z=2},
minexptime = 0.1,
maxexptime = 0.75,
minsize = 1,
maxsize = 2,
collisiondetection = false,
texture = texture,
})
end end
local p = {}
for k, v in pairs(shooter.default_particles) do
p[k] = particles[k] and copy(particles[k]) or copy(v)
end
p.minpos = vector.subtract(pos, p.minpos)
p.maxpos = vector.add(pos, p.maxpos)
minetest.add_particlespawner(p)
end end
shooter.play_node_sound = function(node, pos) shooter.play_node_sound = function(node, pos)
@ -134,7 +143,7 @@ shooter.punch_node = function(pos, spec)
shooter.play_node_sound(node, pos) shooter.play_node_sound(node, pos)
if item.tiles then if item.tiles then
if item.tiles[1] then if item.tiles[1] then
shooter.spawn_particles(pos, item.tiles[1]) shooter.spawn_particles(pos, {texture=item.tiles[1]})
end end
end end
break break
@ -170,7 +179,7 @@ local function process_hit(pointed_thing, spec, dir)
if player then if player then
object:punch(player, nil, spec.tool_caps, dir) object:punch(player, nil, spec.tool_caps, dir)
local pos = pointed_thing.intersection_point or object:get_pos() local pos = pointed_thing.intersection_point or object:get_pos()
shooter.spawn_particles(pos, config.explosion_texture) shooter.spawn_particles(pos, spec.particles)
end end
end end
end end
@ -208,14 +217,16 @@ local function fire_weapon(player, itemstack, spec, extended)
end end
pos.y = pos.y + config.camera_height pos.y = pos.y + config.camera_height
minetest.sound_play(spec.sound, {object=player}) minetest.sound_play(spec.sound, {object=player})
if spec.bullet_image then
minetest.add_particle({ minetest.add_particle({
pos = pos, pos = pos,
velocity = vector.multiply(dir, 30), velocity = vector.multiply(dir, 30),
acceleration = {x=0, y=0, z=0}, acceleration = {x=0, y=0, z=0},
expirationtime = 0.5, expirationtime = 0.5,
size = 0.25, size = 0.25,
texture = spec.particle, texture = spec.bullet_image,
}) })
end
process_round({ process_round({
spec = spec, spec = spec,
pos = vector.add(pos, dir), pos = vector.add(pos, dir),

View file

@ -63,8 +63,7 @@ local function strike(arrow, pointed_thing, name)
if puncher and puncher ~= target then if puncher and puncher ~= target then
local groups = target:get_armor_groups() or {} local groups = target:get_armor_groups() or {}
if groups.fleshy then if groups.fleshy then
shooter.spawn_particles(hit_pos, shooter.spawn_particles(hit_pos)
shooter.config.explosion_texture)
end end
target:punch(object, nil, arrow_tool_caps, dir) target:punch(object, nil, arrow_tool_caps, dir)
if config.arrow_object_attach then if config.arrow_object_attach then

View file

@ -8,7 +8,12 @@ shooter.register_weapon("shooter_guns:pistol", {
tool_caps = {full_punch_interval=0.5, damage_groups={fleshy=2}}, tool_caps = {full_punch_interval=0.5, damage_groups={fleshy=2}},
groups = {snappy=3, fleshy=3, oddly_breakable_by_hand=3}, groups = {snappy=3, fleshy=3, oddly_breakable_by_hand=3},
sound = "shooter_pistol", sound = "shooter_pistol",
particle = "shooter_cap.png", bullet_image = "shooter_cap.png",
particles = {
amount = 8,
minsize = 0.25,
maxsize = 0.75,
},
}, },
}) })
@ -22,7 +27,12 @@ shooter.register_weapon("shooter_guns:rifle", {
tool_caps = {full_punch_interval=1.0, damage_groups={fleshy=3}}, tool_caps = {full_punch_interval=1.0, damage_groups={fleshy=3}},
groups = {snappy=3, crumbly=3, choppy=3, fleshy=2, oddly_breakable_by_hand=2}, groups = {snappy=3, crumbly=3, choppy=3, fleshy=2, oddly_breakable_by_hand=2},
sound = "shooter_rifle", sound = "shooter_rifle",
particle = "shooter_bullet.png", bullet_image = "shooter_bullet.png",
particles = {
amount = 12,
minsize = 0.75,
maxsize = 1.5,
},
}, },
}) })
@ -36,7 +46,12 @@ shooter.register_weapon("shooter_guns:shotgun", {
tool_caps = {full_punch_interval=1.5, damage_groups={fleshy=4}}, tool_caps = {full_punch_interval=1.5, damage_groups={fleshy=4}},
groups = {cracky=3, snappy=2, crumbly=2, choppy=2, fleshy=1, oddly_breakable_by_hand=1}, groups = {cracky=3, snappy=2, crumbly=2, choppy=2, fleshy=1, oddly_breakable_by_hand=1},
sound = "shooter_shotgun", sound = "shooter_shotgun",
particle = "smoke_puff.png", bullet_image = "smoke_puff.png",
particles = {
amount = 16,
minsize = 1,
maxsize = 2,
},
}, },
}) })
@ -51,7 +66,12 @@ shooter.register_weapon("shooter_guns:machine_gun", {
tool_caps = {full_punch_interval=0.1, damage_groups={fleshy=2}}, tool_caps = {full_punch_interval=0.1, damage_groups={fleshy=2}},
groups = {snappy=3, fleshy=3, oddly_breakable_by_hand=3}, groups = {snappy=3, fleshy=3, oddly_breakable_by_hand=3},
sound = "shooter_pistol", sound = "shooter_pistol",
particle = "shooter_cap.png", bullet_image = "shooter_cap.png",
particles = {
amount = 4,
minsize = 0.25,
maxsize = 0.75,
},
}, },
}) })