[Mod] Simple Shooter [0.5.3] [shooter]

User avatar
stu
Member
Posts: 923
Joined: Sat Feb 02, 2013 02:51
GitHub: stujones11
Location: United Kingdom

[Mod] Simple Shooter [0.5.3] [shooter]

by stu » Post

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
Last edited by stu on Sun Jan 25, 2015 21:03, edited 15 times in total.

Jordach
Member
Posts: 4534
Joined: Mon Oct 03, 2011 17:58
GitHub: Jordach
IRC: Jordach
In-game: Jordach
Location: Blender Scene

by Jordach » Post

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.

User avatar
stu
Member
Posts: 923
Joined: Sat Feb 02, 2013 02:51
GitHub: stujones11
Location: United Kingdom

by stu » Post

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

User avatar
Dopium
Member
Posts: 233
Joined: Sat Jun 09, 2012 15:43
Location: Australia

by Dopium » Post

Awesome work, not too bad at all and with some tweaks it should come along well
Running @1.19 MHz, 128 bytes of RAM and interchangeable 4kb ROM carts!

User avatar
rubenwardy
Moderator
Posts: 6972
Joined: Tue Jun 12, 2012 18:11
GitHub: rubenwardy
IRC: rubenwardy
In-game: rubenwardy
Location: Bristol, United Kingdom
Contact:

by rubenwardy » Post

Kaeza's firearms uses rays and vectors :P
Renewed Tab (my browser add-on) | Donate | Mods | Minetest Modding Book

Hello profile reader

User avatar
stu
Member
Posts: 923
Joined: Sat Feb 02, 2013 02:51
GitHub: stujones11
Location: United Kingdom

by stu » Post

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
Last edited by stu on Wed Nov 27, 2013 19:33, edited 1 time in total.

User avatar
Enke
Member
Posts: 469
Joined: Fri Nov 15, 2013 02:56
GitHub: NANOsoldierEnke
IRC: Enke
In-game: Enke
Location: The internet

by Enke » Post

I like this!
Lush8
ExtraVars for Red Eclipse

<Anarchid> my turn was still the most awesome, yielding all the cripples, two captured paranormals, and death rate of about 30%
<ORCACommander> Anarchid: you need to work harder
<ORCACommander> I am hereby putting you under review until you can increase the casualty rate

leetelate
Member
Posts: 205
Joined: Thu Aug 29, 2013 18:07
Location: 한인 타운, Huntsville,Alabama,USA

by leetelate » Post

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
Last edited by leetelate on Thu Nov 28, 2013 01:32, edited 1 time in total.
MT IS MC'S SMARTER BROTHER
minetest 0.4.8 compiled from latest git on linux mint 15 with qjoypad and wired 360 controller
freeminer, pilztest, buildcraft and next are the idea factories
my minetest page is http://1337318.zymichost.com if zymic isn't down - meh, it is free...

User avatar
stu
Member
Posts: 923
Joined: Sat Feb 02, 2013 02:51
GitHub: stujones11
Location: United Kingdom

by stu » Post

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.

User avatar
kaeza
Moderator
Posts: 2162
Joined: Thu Oct 18, 2012 05:00
GitHub: kaeza
IRC: kaeza diemartin blaaaaargh
In-game: kaeza
Location: Montevideo, Uruguay
Contact:

by kaeza » Post

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.
Your signature is not the place for a blog post. Please keep it as concise as possible. Thank you!

Check out my stuff! | Donations greatly appreciated! PayPal

User avatar
stu
Member
Posts: 923
Joined: Sat Feb 02, 2013 02:51
GitHub: stujones11
Location: United Kingdom

by stu » Post

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)
Last edited by stu on Fri Dec 06, 2013 19:37, edited 1 time in total.

User avatar
stu
Member
Posts: 923
Joined: Sat Feb 02, 2013 02:51
GitHub: stujones11
Location: United Kingdom

by stu » Post

Mod updated!

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

Requires d9ef072305

User avatar
AMMOnym
Member
Posts: 682
Joined: Tue Sep 10, 2013 14:18
IRC: AMMOnym
In-game: AMMOnym
Location: Slovakia

by AMMOnym » Post

I like this mod so much ,pls can u make more guns, maybe : Image
Last edited by AMMOnym on Mon Dec 16, 2013 15:22, edited 1 time in total.

User avatar
stu
Member
Posts: 923
Joined: Sat Feb 02, 2013 02:51
GitHub: stujones11
Location: United Kingdom

by stu » Post

AMMOnym wrote:I like this mod so much ,pls can u make more guns, maybe : http://www.keepschoolssafe.org/wp-conte ... s_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.

User avatar
Dopium
Member
Posts: 233
Joined: Sat Jun 09, 2012 15:43
Location: Australia

by Dopium » Post

Awesome gun models, but you would really need a scope feature for rifles like the SVD Dragunov ect. Grenades would be very interesting though
Running @1.19 MHz, 128 bytes of RAM and interchangeable 4kb ROM carts!

User avatar
jojoa1997
Member
Posts: 2890
Joined: Thu Dec 13, 2012 05:11
Location: Earth

by jojoa1997 » Post

stu wrote:
AMMOnym wrote:I like this mod so much ,pls can u make more guns, maybe : http://www.keepschoolssafe.org/wp-conte ... s_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.
Coding;
1X coding
3X debugging
12X tweaking to be just right

User avatar
AMMOnym
Member
Posts: 682
Joined: Tue Sep 10, 2013 14:18
IRC: AMMOnym
In-game: AMMOnym
Location: Slovakia

by AMMOnym » Post

i mean than machine gun can be placed on the ground like cannons or minecraft (flans mod WWII guns)
Last edited by AMMOnym on Sat Dec 21, 2013 19:05, edited 1 time in total.

User avatar
Froggy
Member
Posts: 24
Joined: Wed Jun 12, 2013 00:32

by Froggy » Post

When shooting at an unknown node, the game crashes.

debug.txt gives the following:

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>

User avatar
stu
Member
Posts: 923
Joined: Sat Feb 02, 2013 02:51
GitHub: stujones11
Location: United Kingdom

by stu » Post

Froggy wrote:When shooting at an unknown node, the game crashes.

debug.txt gives the following:

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.

clarksallador
Member
Posts: 57
Joined: Sun Sep 30, 2012 03:18
Location: Philippines

by clarksallador » Post

I hope that there will be more guns

User avatar
Krock
Developer
Posts: 4649
Joined: Thu Oct 03, 2013 07:48
GitHub: SmallJoker
Location: Switzerland
Contact:

by Krock » Post

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.
Look, I programmed a bug for you. >> Mod Search Engine << - Mods by Krock - DuckDuckGo mod search bang: !mtmod <keyword here>

User avatar
ak399g
Member
Posts: 160
Joined: Tue Jul 30, 2013 02:36
In-game: SAFR
Contact:

by ak399g » Post

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.
aka SAFR

Rhys
Member
Posts: 379
Joined: Wed May 22, 2013 15:22

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

by Rhys » Post

Love this mod, especially that it has the blood particles when a bullet hits a player. ;)

User avatar
JPRuehmann
Member
Posts: 334
Joined: Fri Mar 21, 2014 21:40
Location: Germany
Contact:

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

by JPRuehmann » Post

Hello
changed the shooter.lua so that the HUD is only Displayed iff you wield the right Item.
Here is my Code.

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

Daven
Member
Posts: 26
Joined: Mon Jan 20, 2014 21:51
Location: Inside the white whale

Re:

by Daven » Post

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

Post Reply

Who is online

Users browsing this forum: No registered users and 18 guests