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.