Update version 0.3.0, shoot nodes at long range

This commit is contained in:
stujones11 2013-12-13 19:34:39 +00:00
parent 058356cba2
commit 0f92ac9425
3 changed files with 71 additions and 40 deletions

View file

@ -1,9 +1,9 @@
Minetest Mod - Simple Shooter [shooter] Minetest Mod - Simple Shooter [shooter]
======================================= =======================================
Mod Version: 0.2.0 Mod Version: 0.3.0
Minetest Version: 0.4.8 Minetest Version: 0.4.8-dev d9ef072305
Depends: default Depends: default
@ -13,8 +13,6 @@ that which is currently being used by the firearms mod.
For the most part I think I have achieved this for straight pvp, however, For the most part I think I have achieved this for straight pvp, however,
the jury is still out as to whether it is any faster against entities (mobs) the jury is still out as to whether it is any faster against entities (mobs)
One big downside of this method is that it only works against ordinary nodes
within pointable range of the player.
By default this mod is configured to work only against other players in By default this mod is configured to work only against other players in
multiplayer (server) mode. This is overridden in singleplayer mode to work multiplayer (server) mode. This is overridden in singleplayer mode to work

View file

@ -5,6 +5,12 @@
-- Particle texture used when target it hit -- Particle texture used when target it hit
SHOOTER_EXPLOSION_TEXTURE = "shooter_hit.png" SHOOTER_EXPLOSION_TEXTURE = "shooter_hit.png"
-- Allow node destruction
SHOOTER_ALLOW_NODES = true
-- Maximum node rage, applies only if nodes are allowed
SHOOTER_NODE_RANGE = 50
-- Allow entities in multiplayer mode -- Allow entities in multiplayer mode
SHOOTER_ALLOW_ENTITIES = false SHOOTER_ALLOW_ENTITIES = false

View file

@ -1,7 +1,9 @@
shooter = {} shooter = {}
SHOOTER_EXPLOSION_TEXTURE = "shooter_hit.png" SHOOTER_EXPLOSION_TEXTURE = "shooter_hit.png"
SHOOTER_ALLOW_NODES = true
SHOOTER_ALLOW_ENTITIES = false SHOOTER_ALLOW_ENTITIES = false
SHOOTER_NODE_RANGE = 50
SHOOTER_OBJECT_RANGE = 50 SHOOTER_OBJECT_RANGE = 50
local modpath = minetest.get_modpath(minetest.get_current_modname()) local modpath = minetest.get_modpath(minetest.get_current_modname())
@ -44,6 +46,36 @@ local function is_valid_object(object)
return false return false
end end
local function punch_node(pos, def)
local node = minetest.get_node(pos)
if not node then
return
end
local item = minetest.registered_items[node.name]
if not item.groups then
return
end
for k, v in pairs(def.groups) do
local level = item.groups[k] or 0
if level >= v then
minetest.remove_node(pos)
local sounds = item.sounds
if sounds then
local soundspec = sounds.dug
if soundspec then
soundspec.pos = pos
minetest.sound_play(soundspec.name, soundspec)
end
end
local tiles = item.tiles
if tiles then
return tiles[1]
end
break
end
end
end
function shooter:fire_weapon(user, pointed_thing, def) function shooter:fire_weapon(user, pointed_thing, def)
local name = user:get_player_name() local name = user:get_player_name()
if shots[name] then if shots[name] then
@ -60,37 +92,12 @@ function shooter:fire_weapon(user, pointed_thing, def)
{x=0, y=0, z=0}, 0.5, 0.25, {x=0, y=0, z=0}, 0.5, 0.25,
false, def.particle false, def.particle
) )
if pointed_thing.type == "node" then if pointed_thing.type == "node" and SHOOTER_ALLOW_NODES == true then
local pos = minetest.get_pointed_thing_position(pointed_thing, false) local pos = minetest.get_pointed_thing_position(pointed_thing, false)
local node = minetest.get_node(pos) local texture = punch_node(pos, def)
if not node then if texture then
return spawn_particles({x=p1.x, y=p1.y + 0.75, z=p1.z},
end v1, vector.distance(p1, pos), texture)
local item = minetest.registered_items[node.name]
if not item.groups then
return
end
for k, v in pairs(def.groups) do
local level = item.groups[k] or 0
if level >= v then
minetest.remove_node(pos)
local sounds = item.sounds
if sounds then
local soundspec = sounds.dug
if soundspec then
soundspec.pos = pos
minetest.sound_play(soundspec.name, soundspec)
end
end
local tiles = item.tiles
if tiles then
if tiles[1] then
spawn_particles({x=p1.x, y=p1.y + 0.75, z=p1.z},
v1, vector.distance(p1, pos), tiles[1])
end
end
break
end
end end
return return
elseif pointed_thing.type == "object" then elseif pointed_thing.type == "object" then
@ -141,20 +148,40 @@ function shooter:fire_weapon(user, pointed_thing, def)
target = { target = {
object = object, object = object,
distance = x, distance = x,
direction = v1, pos = {x=p2.x, z=p2.z, y=p2.y+1.75},
pos1 = {x=p1.x, z=p1.z, y=p1.y+1},
pos2 = {x=p2.x, z=p2.z, y=p2.y+1.75},
} }
end end
end end
end end
end end
end end
local view_pos = {x=p1.x, y=p1.y + 1.75, z=p1.z}
if target.object then if target.object then
if minetest.line_of_sight(target.pos1, target.pos2, 1) then local success, pos = minetest.line_of_sight(view_pos, target.pos, 1)
target.object:punch(user, nil, def.tool_caps, target.direction) if success then
spawn_particles(target.pos1, target.direction, target.object:punch(user, nil, def.tool_caps, v1)
spawn_particles({x=p1.x, y=p1.y + 0.75, z=p1.z}, v1,
target.distance, SHOOTER_EXPLOSION_TEXTURE) target.distance, SHOOTER_EXPLOSION_TEXTURE)
elseif pos and SHOOTER_ALLOW_NODES == true then
local texture = punch_node(pos, def)
if texture then
spawn_particles({x=p1.x, y=p1.y + 0.75, z=p1.z},
v1, vector.distance(p1, pos), texture)
end
end
elseif SHOOTER_ALLOW_NODES == true then
local d = def.range
if d > SHOOTER_NODE_RANGE then
d = SHOOTER_NODE_RANGE
end
local p2 = vector.add(view_pos, vector.multiply(v1, {x=d, y=d, z=d}))
local success, pos = minetest.line_of_sight(view_pos, p2, 1)
if pos then
local texture = punch_node(pos, def)
if texture then
spawn_particles({x=p1.x, y=p1.y + 0.75, z=p1.z},
v1, vector.distance(p1, pos), texture)
end
end end
end end
end end