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.
rubenwardy wrote:Kaeza's firearms uses rays and vectors :P
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
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.
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
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.
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>
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>
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)
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
-------------
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.
Users browsing this forum: No registered users and 34 guests