Page 1 of 5

[Mod] Simple Shooter [0.5.3] [shooter]

PostPosted: Tue Nov 26, 2013 21:24
by stu
Image

An experimental first person shooter mod using simple vector mathematics
in an effort to find an accurate and server-firendly method of hit detection.

By default this mod is configured to work only against other players in
multiplayer (server) mode. This is overridden in singleplayer mode to work
against all Simple Mobs entities instead.

Default configuration can be customised by adding a shooter.conf file to the
mod's main directory, see shooter.conf.example for more details.

This is still very much a work in progress which I plan to eventually use as
the base for a 'Spades' style FPS game using the minetest engine.

Depends: default, dye, tnt, wool

Download

Minetest 0.4.8 Version 0.2.0
Minetest 0.4.9 Version 0.3.0
Minetest 0.4.9 Version 0.4.1

Minetest 0.4.9, 0.4.10, 0.4.11 Version 0.5.3

Browse Code: Github

PostPosted: Tue Nov 26, 2013 22:25
by Jordach
A-TO-THE-MUDDA-FUCKING-K!

I will DEFINITELY test this tomorrow.

Oh, and weapons should have their own health and will need to be repaired.

The chances of weapons jamming increases when the health gets low, and stops working at zero health.

PostPosted: Tue Nov 26, 2013 23:03
by stu
Jordach wrote:A-TO-THE-MUDDA-FUCKING-K!

I will DEFINITELY test this tomorrow.

Oh, and weapons should have their own health and will need to be repaired.

The chances of weapons jamming increases when the health gets low, and stops working at zero health.


This mod uses the wear level as ammo, disposable guns ^.^
In the game I hope to make things will work differently, just not sure how yet but I'm always open to ideas

Thanks

PostPosted: Tue Nov 26, 2013 23:51
by Dopium
Awesome work, not too bad at all and with some tweaks it should come along well

PostPosted: Wed Nov 27, 2013 08:47
by rubenwardy
Kaeza's firearms uses rays and vectors :P

PostPosted: Wed Nov 27, 2013 19:30
by stu
rubenwardy wrote:Kaeza's firearms uses rays and vectors :P


For some reason I thought firearms primarily used entities,
however, looking more closely at the code I see that it actually
uses an enhanced version of minetest.line_of_sight() to determine
the closest pointed thing. This is very clever but unfortunately
rather cumbersome written in lua.

Kaeza's firearms is an excellent and very complete mod, much better
suited to the singleplayer game, with mobs etc. Only trouble is
that it does not scale well for a highly aggressive multiplayer game,
likes of which I am currently working on :P

PostPosted: Wed Nov 27, 2013 22:53
by Enke
I like this!

PostPosted: Thu Nov 28, 2013 01:16
by leetelate
i made one ages ago that used stored vectors in a table and had travelling nodes for projectiles, but projectiles just get IGNOREd (as in they hit an unloaded chunk)

:see whut i did there?: lololol

then there was the splat/bulletholes for where the bullet hit - has to be a friggin wallmount and i didn't understand how to do that in lua (still don't really)

i finally stuck with the gladiator thing - swords, fists, shields - made more sense

PostPosted: Thu Dec 05, 2013 20:35
by stu
Mod updated.

Added particle effects and support for shooting entities in singleplayer mode.
Nodes can also be shot at within the pointing range of the player.

PostPosted: Fri Dec 06, 2013 04:11
by kaeza
stu wrote:
rubenwardy wrote:Kaeza's firearms uses rays and vectors :P


For some reason I thought firearms primarily used entities,
however, looking more closely at the code I see that it actually
uses an enhanced version of minetest.line_of_sight() to determine
the closest pointed thing. This is very clever but unfortunately
rather cumbersome written in lua.

Kaeza's firearms is an excellent and very complete mod, much better
suited to the singleplayer game, with mobs etc. Only trouble is
that it does not scale well for a highly aggressive multiplayer game,
likes of which I am currently working on :P

Firearms was originally based on the `rifle' mod, but due to the old bugs with entities (duplication, now fixed), I decided to write a new weapons mod from scratch. The line_of_sight function (new at that time) was simply not filling my needs, so I also decided to code my own implementation, purely in Lua.

The main drawback was the calculations performed were all done in a single step in a loop, so it could potentially lock the server with weapons with high rate of fire (assault rifle), or many pellets (shotgun). I have since began rewriting firearms again, this time using "fake entities".

These "fake entities" are really just a lightweight implementation of entities purely in Lua. Again, this is slow, but was the QND implementation that fulfilled my main concerns: not locking the server for long periods of time in a single step (the fake entitiy code updates the position, etc once every step much like the C++ entity code), and it did not use real entities, so there were no problems with duplication.

Now that the entity duplication is finally fixed, this code could be removed, and real entities can be used again.

With respect to your approach, this has some drawbacks: if you set a `range' too high for the tool, you run the risk of letting players activate mesecons buttons, or open chests for example from long distances, and if it's *way* too high, the game may detect these as cheating (yes, it happened to me) and may even cause player bans with mods like sfan5's `nocheat' mod. Needless to say, setting a low `range' is pretty useless.

My current implementation of the sniper rifle, for example, is able to hit a simple mob standing up to 50 meters away; this is just not possible using `range' alone.

No approach is perfect; both have their advantages and disadvantages.

PostPosted: Fri Dec 06, 2013 19:28
by stu
kaeza wrote:
stu wrote:
rubenwardy wrote:Kaeza's firearms uses rays and vectors :P


For some reason I thought firearms primarily used entities,
however, looking more closely at the code I see that it actually
uses an enhanced version of minetest.line_of_sight() to determine
the closest pointed thing. This is very clever but unfortunately
rather cumbersome written in lua.

Kaeza's firearms is an excellent and very complete mod, much better
suited to the singleplayer game, with mobs etc. Only trouble is
that it does not scale well for a highly aggressive multiplayer game,
likes of which I am currently working on :P

Firearms was originally based on the `rifle' mod, but due to the old bugs with entities (duplication, now fixed), I decided to write a new weapons mod from scratch. The line_of_sight function (new at that time) was simply not filling my needs, so I also decided to code my own implementation, purely in Lua.

The main drawback was the calculations performed were all done in a single step in a loop, so it could potentially lock the server with weapons with high rate of fire (assault rifle), or many pellets (shotgun). I have since began rewriting firearms again, this time using "fake entities".

These "fake entities" are really just a lightweight implementation of entities purely in Lua. Again, this is slow, but was the QND implementation that fulfilled my main concerns: not locking the server for long periods of time in a single step (the fake entitiy code updates the position, etc once every step much like the C++ entity code), and it did not use real entities, so there were no problems with duplication.

Now that the entity duplication is finally fixed, this code could be removed, and real entities can be used again.

With respect to your approach, this has some drawbacks: if you set a `range' too high for the tool, you run the risk of letting players activate mesecons buttons, or open chests for example from long distances, and if it's *way* too high, the game may detect these as cheating (yes, it happened to me) and may even cause player bans with mods like sfan5's `nocheat' mod. Needless to say, setting a low `range' is pretty useless.

My current implementation of the sniper rifle, for example, is able to hit a simple mob standing up to 50 meters away; this is just not possible using `range' alone.

No approach is perfect; both have their advantages and disadvantages.


Thank you for the explanation and sharing your insight. With regard to using entities as projectiles,
my main concerns are with chunk boundaries and duplication (which I am still not conviced is 100% fixed)

What I would like to see is a c++ version of your find_pointed_thing() being added to the api
I think a find_objects_in_sight(distance) api method would be a very nice addition too.
line_of_sight() could be made more useful by retuning the blocking node position (another topic)

PostPosted: Fri Dec 13, 2013 19:51
by stu
Mod updated!

Thanks to a recent minetest commit, it now becomes possible to shoot nodes at much longer range.

Requires d9ef072305

PostPosted: Mon Dec 16, 2013 15:21
by AMMOnym
I like this mod so much ,pls can u make more guns, maybe : Image

PostPosted: Fri Dec 20, 2013 21:24
by stu
AMMOnym wrote:I like this mod so much ,pls can u make more guns, maybe : http://www.keepschoolssafe.org/wp-content/uploads/2009/02/clue_guns_pack.png


Wow, that is rather a lot. The difficulty is making them sufficiently different from each other and producing sensible craft grids for them all.

What I am currently working on is a semi-rapid-fire weapon (machine gun) that uses object caching to reduce server load while retaining some degree of realism.

I'm glad you like the mod, thank you for sharing your ideas.

PostPosted: Sat Dec 21, 2013 00:26
by Dopium
Awesome gun models, but you would really need a scope feature for rifles like the SVD Dragunov ect. Grenades would be very interesting though

PostPosted: Sat Dec 21, 2013 03:57
by jojoa1997
stu wrote:
AMMOnym wrote:I like this mod so much ,pls can u make more guns, maybe : http://www.keepschoolssafe.org/wp-content/uploads/2009/02/clue_guns_pack.png


Wow, that is rather a lot. The difficulty is making them sufficiently different from each other and producing sensible craft grids for them all.

What I am currently working on is a semi-rapid-fire weapon (machine gun) that uses object caching to reduce server load while retaining some degree of realism.

I'm glad you like the mod, thank you for sharing your ideas.

You can always make base guns like a sub machine gun and then make a modifier item and whn the modifier item and the base gun go into the crafting grid the certain gun comes out.

PostPosted: Sat Dec 21, 2013 13:32
by AMMOnym
i mean than machine gun can be placed on the ground like cannons or minecraft (flans mod WWII guns)

PostPosted: Tue Dec 24, 2013 19:59
by Froggy
When shooting at an unknown node, the game crashes.

debug.txt gives the following:

Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
Code: Select all
14:57:20: ACTION[ServerThread]: singleplayer uses shooter:shotgun, pointing at [node under=-28,2,-11 above=-28,2,-12]
14:57:20: ACTION[ServerThread]: singleplayer leaves game. List of players:
14:57:20: ERROR[main]: ServerError: LuaError: /home/optimus/.minetest/mods/shooter/shooter.lua:73: attempt to index local 'item' (a nil value)
14:57:20: ERROR[main]: stack traceback:
14:57:20: ERROR[main]:     /home/optimus/.minetest/mods/shooter/shooter.lua:73: in function 'fire_weapon'
14:57:20: ERROR[main]:     /home/optimus/.minetest/mods/shooter/init.lua:39: in function </home/optimus/.minetest/mods/shooter/init.lua:38>

PostPosted: Tue Dec 24, 2013 21:51
by stu
Froggy wrote:When shooting at an unknown node, the game crashes.

debug.txt gives the following:

Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
Code: Select all
14:57:20: ACTION[ServerThread]: singleplayer uses shooter:shotgun, pointing at [node under=-28,2,-11 above=-28,2,-12]
14:57:20: ACTION[ServerThread]: singleplayer leaves game. List of players:
14:57:20: ERROR[main]: ServerError: LuaError: /home/optimus/.minetest/mods/shooter/shooter.lua:73: attempt to index local 'item' (a nil value)
14:57:20: ERROR[main]: stack traceback:
14:57:20: ERROR[main]:     /home/optimus/.minetest/mods/shooter/shooter.lua:73: in function 'fire_weapon'
14:57:20: ERROR[main]:     /home/optimus/.minetest/mods/shooter/init.lua:39: in function </home/optimus/.minetest/mods/shooter/init.lua:38>


I have just pushed some changes that should hopefully prevent this, thank you for reporting it.

PostPosted: Thu Dec 26, 2013 03:05
by clarksallador
I hope that there will be more guns

PostPosted: Sun Mar 30, 2014 14:12
by Krock
Wow, nice work! I really like that mod, but I found something I wasn't sure if it's supposedto be that way or if it's a bug:

The "pointer" in the middle of the screen does not change back to normal if no gun is selected in the HUD.

PostPosted: Sun Apr 06, 2014 04:10
by ak399g
Idea for nondisposable guns: Craft the firearm with its respective ammo and it produces the original firearm: this should however reset the wear on the firearm. Also reflects real reload time, especially on large magazine weapons. Just carry a stack of ammo in your crafting grid for faster reloads.

Re: [Mod] Simple Shooter [0.3.0] [shooter]

PostPosted: Mon Apr 21, 2014 16:01
by Rhys
Love this mod, especially that it has the blood particles when a bullet hits a player. ;)

Re: [Mod] Simple Shooter [0.3.0] [shooter]

PostPosted: Thu Apr 24, 2014 00:36
by JPRuehmann
Hello
changed the shooter.lua so that the HUD is only Displayed iff you wield the right Item.
Here is my Code.
Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
Code: Select all
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())
local input = io.open(modpath.."/shooter.conf", "r")
if input then
   dofile(modpath.."/shooter.conf")
   input:close()
   input = nil
end
if minetest.is_singleplayer() == true then
   SHOOTER_ALLOW_ENTITIES = true
end
local timer = 1600
local shots = {}

local function spawn_particles(p, v, d, texture)
   if type(texture) ~= "string" then
      texture = SHOOTER_EXPLOSION_TEXTURE
   end
   local pos = vector.add(p, vector.multiply(v, {x=d, y=d, z=d}))
   pos.y = pos.y + 0.75
   local spread = {x=0.1, y=0.1, z=0.1}
   minetest.add_particlespawner(15, 0.3,
      vector.subtract(pos, spread), vector.add(pos, spread),
      {x=-1, y=1, z=-1}, {x=1, y=2, z=1},
      {x=-2, y=-2, z=-2}, {x=2, y=-2, z=2},
      0.1, 0.75, 1, 2, false, texture
   )
end

local function is_valid_object(object)
   if object:is_player() == true then
      return true
   end
   if SHOOTER_ALLOW_ENTITIES == true then
      local luaentity = object:get_luaentity()
      if luaentity then
         if minetest.registered_entities[luaentity.name] then
            return true
         end
      end
   end
   return false
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 item and item.groups then
      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
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
      if is_valid_object(object) == true then
         object:punch(user, nil, def.tool_caps, v1)
         local p2 = object:getpos()
         spawn_particles({x=p1.x, y=p1.y + 0.75, z=p1.z}, v1,
         vector.distance(p1, p2), SHOOTER_EXPLOSION_TEXTURE)
         return
      end
   end
   if def.range > 100 then
      def.range = 100
   end
   local target = {object=nil, distance=100}
   local objects = {}
   if SHOOTER_ALLOW_ENTITIES == true then
      local range = def.range
      if range > SHOOTER_OBJECT_RANGE then
         range = SHOOTER_OBJECT_RANGE
      end
      local r = math.ceil(range * 0.5)
      local p = vector.add(p1, vector.multiply(v1, {x=r, y=r, z=r}))
      objects = minetest.get_objects_inside_radius(p, r)
   else
      objects = minetest.get_connected_players()
   end
   for _,object in ipairs(objects) do
      if is_valid_object(object) == true then
         local p2 = object:getpos()
         if p1 and p2 then
            local x = vector.distance(p1, p2)
            p2.y = p2.y - 0.75
            if x > 0 and x < target.distance and x < def.range then
               local yx = 0
               if x > 30 then
                  yx = 0.001 * (10 - x * 0.1)
               else
                  yx = 0.00002 * (x * x) - 0.002 * x + 0.05
               end
               local yy = yx * 3
               local v2 = vector.normalize(vector.direction(p1, p2))
               local vd = vector.subtract(v1, v2)
               if math.abs(vd.x) < yx and
               math.abs(vd.z) < yx and
               math.abs(vd.y) < yy then
                  target = {
                     object = object,
                     distance = x,
                     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
      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
minetest.register_on_joinplayer(function(player)
  minetest.register_globalstep(function(dtime)
    timer = timer + dtime
    local name = player:get_player_name()
    local inventory = player:get_wielded_item()
    local weapon = inventory:get_name()
      if weapon == "shooter:riffle"
   or weapon == "shooter:shotgun"
   or weapon == "shooter:pistol"
      then
   player:hud_set_flags({crosshair = false})
   player:hud_remove(name)
   shooter_hud = player:hud_add({
   hud_elem_type = "image",
   position = {x=0.5,y=0.5},
   scale = {x=1.0,y=1.0},
   name = "Shooter Crosshair",
   text = "shooter_crosshair.png",
   })
      else
   if player:hud_remove(name) == nil then
     player:hud_set_flags({crosshair = true})
   else
     player:hud_remove(name)
     player:hud_set_flags({crosshair = true})
   end
      end
    end)
end)

Have Fun,
JPR

Re:

PostPosted: Fri Apr 25, 2014 01:10
by Daven
stu wrote:
rubenwardy wrote:Kaeza's firearms uses rays and vectors :P


For some reason I thought firearms primarily used entities,
however, looking more closely at the code I see that it actually
uses an enhanced version of minetest.line_of_sight() to determine
the closest pointed thing. This is very clever but unfortunately
rather cumbersome written in lua.

Kaeza's firearms is an excellent and very complete mod, much better
suited to the singleplayer game, with mobs etc. Only trouble is
that it does not scale well for a highly aggressive multiplayer game,
likes of which I am currently working on :P


which server is this and can u give me the port and IP

Re: [Mod] Simple Shooter [0.3.0] [shooter]

PostPosted: Fri Apr 25, 2014 08:49
by JPRuehmann
And that it is really buggy at the moment.
Let us wait for the next Update.

Re: [Mod] Simple Shooter [0.3.0] [shooter]

PostPosted: Fri Apr 25, 2014 09:21
by Achilles
Nice Mod :)

Any chance of making turrets?

Re: [Mod] Simple Shooter [0.3.0] [shooter]

PostPosted: Fri Apr 25, 2014 09:40
by Topywo
Achilles wrote:Nice Mod :)

Any chance of making turrets?


https://github.com/Bremaweb?tab=repositories

Re: [Mod] Simple Shooter [0.4.0] [shooter]

PostPosted: Mon Jun 02, 2014 19:04
by stu
I have recently made some updates to this if anyone is still interested.

  • Improved vector maths for better accuracy. (dot products are cheap)
  • Reworked object scanning and added a caching system for better performance.
  • Added a rapid fire automatic weapon. (previously not possible)
  • Increased the range of default guns.
  • Added default singleplayer support for Simple Mobs. (not required)
  • Added more configuration options to optimize server performance.
This seems to be working quite well on a LAN setup with mobs and a handful
of other players, it's not perfect as there will always be a tradeoff between
accuracy and performance. I would be interested to know how well it performs
on a public server, as compared to the firearms mod (for example).

Re: [Mod] Simple Shooter [0.4.0] [shooter]

PostPosted: Tue Jun 24, 2014 12:24
by knottyboy589
wow, most mods seem to not work on my minetest, I install them all correctly, but there is always apparently an isuue with the "init.lua" file! Please help as I can't get any of your mods or Pilz Adam's mods! :'-(

EDIT:

This is what was in my debug file:

Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
Code: Select all
-------------
  Separator 
-------------

13:33:12: ERROR[main]: Error loading mod "shooter-master": modname does not follow naming conventions: Only chararacters [a-z0-9_] are allowed.
13:33:12: ERROR[main]: Server: Failed to load and run C:\Users\Roy\Desktop\minetest-0.4.9\bin\..\mods\shooter-master\init.lua
13:33:12: ERROR[main]: ModError: ModError: Failed to load and run C:\Users\Roy\Desktop\minetest-0.4.9\bin\..\mods\shooter-master\init.lua
13:33:19: INFO: event_handler(): Ctrl+C, Close Event, Logoff Event or Shutdown Event, shutting down.