Allow particle effect overrides in gun spec
This commit is contained in:
parent
52ed0d2340
commit
18e22a38fb
3 changed files with 68 additions and 38 deletions
|
@ -16,6 +16,23 @@ shooter.config = {
|
|||
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 shots = {}
|
||||
local shooting = {}
|
||||
|
@ -74,29 +91,21 @@ shooter.register_weapon = function(name, def)
|
|||
})
|
||||
end
|
||||
|
||||
shooter.spawn_particles = function(pos, texture)
|
||||
if config.enable_particle_fx == true then
|
||||
if type(texture) ~= "string" then
|
||||
texture = config.explosion_texture
|
||||
shooter.spawn_particles = function(pos, particles)
|
||||
particles = particles or {}
|
||||
if not config.enable_particle_fx == true or particles.amount == 0 then
|
||||
return
|
||||
end
|
||||
local spread = {x=0.1, y=0.1, z=0.1}
|
||||
minetest.add_particlespawner({
|
||||
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,
|
||||
})
|
||||
local copy = function(v)
|
||||
return type(v) == "table" and table.copy(v) or v
|
||||
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
|
||||
|
||||
shooter.play_node_sound = function(node, pos)
|
||||
|
@ -134,7 +143,7 @@ shooter.punch_node = function(pos, spec)
|
|||
shooter.play_node_sound(node, pos)
|
||||
if item.tiles then
|
||||
if item.tiles[1] then
|
||||
shooter.spawn_particles(pos, item.tiles[1])
|
||||
shooter.spawn_particles(pos, {texture=item.tiles[1]})
|
||||
end
|
||||
end
|
||||
break
|
||||
|
@ -170,7 +179,7 @@ local function process_hit(pointed_thing, spec, dir)
|
|||
if player then
|
||||
object:punch(player, nil, spec.tool_caps, dir)
|
||||
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
|
||||
|
@ -208,14 +217,16 @@ local function fire_weapon(player, itemstack, spec, extended)
|
|||
end
|
||||
pos.y = pos.y + config.camera_height
|
||||
minetest.sound_play(spec.sound, {object=player})
|
||||
if spec.bullet_image then
|
||||
minetest.add_particle({
|
||||
pos = pos,
|
||||
velocity = vector.multiply(dir, 30),
|
||||
acceleration = {x=0, y=0, z=0},
|
||||
expirationtime = 0.5,
|
||||
size = 0.25,
|
||||
texture = spec.particle,
|
||||
texture = spec.bullet_image,
|
||||
})
|
||||
end
|
||||
process_round({
|
||||
spec = spec,
|
||||
pos = vector.add(pos, dir),
|
||||
|
|
|
@ -63,8 +63,7 @@ local function strike(arrow, pointed_thing, name)
|
|||
if puncher and puncher ~= target then
|
||||
local groups = target:get_armor_groups() or {}
|
||||
if groups.fleshy then
|
||||
shooter.spawn_particles(hit_pos,
|
||||
shooter.config.explosion_texture)
|
||||
shooter.spawn_particles(hit_pos)
|
||||
end
|
||||
target:punch(object, nil, arrow_tool_caps, dir)
|
||||
if config.arrow_object_attach then
|
||||
|
|
|
@ -8,7 +8,12 @@ shooter.register_weapon("shooter_guns:pistol", {
|
|||
tool_caps = {full_punch_interval=0.5, damage_groups={fleshy=2}},
|
||||
groups = {snappy=3, fleshy=3, oddly_breakable_by_hand=3},
|
||||
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}},
|
||||
groups = {snappy=3, crumbly=3, choppy=3, fleshy=2, oddly_breakable_by_hand=2},
|
||||
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}},
|
||||
groups = {cracky=3, snappy=2, crumbly=2, choppy=2, fleshy=1, oddly_breakable_by_hand=1},
|
||||
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}},
|
||||
groups = {snappy=3, fleshy=3, oddly_breakable_by_hand=3},
|
||||
sound = "shooter_pistol",
|
||||
particle = "shooter_cap.png",
|
||||
bullet_image = "shooter_cap.png",
|
||||
particles = {
|
||||
amount = 4,
|
||||
minsize = 0.25,
|
||||
maxsize = 0.75,
|
||||
},
|
||||
},
|
||||
})
|
||||
|
||||
|
|
Loading…
Reference in a new issue