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]
=======================================
Mod Version: 0.2.0
Mod Version: 0.3.0
Minetest Version: 0.4.8
Minetest Version: 0.4.8-dev d9ef072305
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,
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
multiplayer (server) mode. This is overridden in singleplayer mode to work

View file

@ -5,6 +5,12 @@
-- Particle texture used when target it hit
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
SHOOTER_ALLOW_ENTITIES = false

View file

@ -1,7 +1,9 @@
shooter = {}
SHOOTER_EXPLOSION_TEXTURE = "shooter_hit.png"
SHOOTER_ALLOW_NODES = true
SHOOTER_ALLOW_ENTITIES = false
SHOOTER_NODE_RANGE = 50
SHOOTER_OBJECT_RANGE = 50
local modpath = minetest.get_modpath(minetest.get_current_modname())
@ -44,24 +46,7 @@ local function is_valid_object(object)
return false
end
function shooter:fire_weapon(user, pointed_thing, def)
local name = user:get_player_name()
if shots[name] then
if timer < shots[name] then
return
end
end
shots[name] = timer + def.tool_caps.full_punch_interval
minetest.sound_play(def.sound, {object=user})
local v1 = user:get_look_dir()
local p1 = user:getpos()
minetest.add_particle({x=p1.x, y=p1.y + 1.6, z=p1.z},
vector.multiply(v1, {x=30, y=30, z=30}),
{x=0, y=0, z=0}, 0.5, 0.25,
false, def.particle
)
if pointed_thing.type == "node" then
local pos = minetest.get_pointed_thing_position(pointed_thing, false)
local function punch_node(pos, def)
local node = minetest.get_node(pos)
if not node then
return
@ -84,14 +69,36 @@ function shooter:fire_weapon(user, pointed_thing, def)
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
return tiles[1]
end
break
end
end
end
function shooter:fire_weapon(user, pointed_thing, def)
local name = user:get_player_name()
if shots[name] then
if timer < shots[name] then
return
end
end
shots[name] = timer + def.tool_caps.full_punch_interval
minetest.sound_play(def.sound, {object=user})
local v1 = user:get_look_dir()
local p1 = user:getpos()
minetest.add_particle({x=p1.x, y=p1.y + 1.6, z=p1.z},
vector.multiply(v1, {x=30, y=30, z=30}),
{x=0, y=0, z=0}, 0.5, 0.25,
false, def.particle
)
if pointed_thing.type == "node" and SHOOTER_ALLOW_NODES == true then
local pos = minetest.get_pointed_thing_position(pointed_thing, false)
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
return
elseif pointed_thing.type == "object" then
local object = pointed_thing.ref
@ -141,20 +148,40 @@ function shooter:fire_weapon(user, pointed_thing, def)
target = {
object = object,
distance = x,
direction = v1,
pos1 = {x=p1.x, z=p1.z, y=p1.y+1},
pos2 = {x=p2.x, z=p2.z, y=p2.y+1.75},
pos = {x=p2.x, z=p2.z, y=p2.y+1.75},
}
end
end
end
end
end
local view_pos = {x=p1.x, y=p1.y + 1.75, z=p1.z}
if target.object then
if minetest.line_of_sight(target.pos1, target.pos2, 1) then
target.object:punch(user, nil, def.tool_caps, target.direction)
spawn_particles(target.pos1, target.direction,
local success, pos = minetest.line_of_sight(view_pos, target.pos, 1)
if success then
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)
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