change the bullet spawns
This commit is contained in:
parent
0d7ac9e4a3
commit
3373a6d7d1
24
api.lua
24
api.lua
@ -81,7 +81,11 @@ guns.fire_bullet = function(self, itemstack, player)
|
|||||||
velocity = velocity + bullet_velocity
|
velocity = velocity + bullet_velocity
|
||||||
accuracy = math.max(0, (100 - accuracy) / 10)
|
accuracy = math.max(0, (100 - accuracy) / 10)
|
||||||
|
|
||||||
local obj = minetest.add_entity({x=pos.x, y=pos.y + 1.7, z=pos.z}, "guns:bullet")
|
local obj = minetest.add_entity({
|
||||||
|
x=pos.x + dir.x * 2.5,
|
||||||
|
y=pos.y + dir.y * 2.5 + 1.5,
|
||||||
|
z=pos.z + dir.z * 2.5
|
||||||
|
}, "guns:bullet")
|
||||||
local ent = obj:get_luaentity()
|
local ent = obj:get_luaentity()
|
||||||
ent.itemstack = itemstack
|
ent.itemstack = itemstack
|
||||||
ent.owner = player
|
ent.owner = player
|
||||||
@ -146,22 +150,14 @@ guns.register_gun = function(self, name, def)
|
|||||||
def.range = 0
|
def.range = 0
|
||||||
def.inventory_image = def.inventory_image or "blank_gun.png"
|
def.inventory_image = def.inventory_image or "blank_gun.png"
|
||||||
|
|
||||||
if def.groups and def.groups.gun_automatic == 1 then
|
|
||||||
def.on_use = function(itemstack, player, pointed_thing)
|
def.on_use = function(itemstack, player, pointed_thing)
|
||||||
if minetest.is_player(player) then
|
if minetest.is_player(player) then
|
||||||
local pname = player:get_player_name()
|
local pname = player:get_player_name()
|
||||||
if not self.cooldown[pname] then
|
if not self.cooldown[pname] then
|
||||||
|
if def.groups and def.groups.gun_automatic == 1 then
|
||||||
self.cooldown[pname] = true
|
self.cooldown[pname] = true
|
||||||
self:fire_auto(player)
|
self:fire_auto(player)
|
||||||
end
|
elseif self:has_bullets(itemstack) then
|
||||||
end
|
|
||||||
return nil
|
|
||||||
end
|
|
||||||
else
|
|
||||||
def.on_use = function(itemstack, player, pointed_thing)
|
|
||||||
if minetest.is_player(player) then
|
|
||||||
local pname = player:get_player_name()
|
|
||||||
if not self.cooldown[pname] and self:has_bullets(itemstack) then
|
|
||||||
local meta = itemstack:get_meta()
|
local meta = itemstack:get_meta()
|
||||||
if def.groups and def.groups.gun_single == 1 then
|
if def.groups and def.groups.gun_single == 1 then
|
||||||
if meta:get_int("loaded") == 1 then
|
if meta:get_int("loaded") == 1 then
|
||||||
@ -184,11 +180,12 @@ guns.register_gun = function(self, name, def)
|
|||||||
return itemstack
|
return itemstack
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
return nil
|
|
||||||
end
|
end
|
||||||
|
return nil
|
||||||
end
|
end
|
||||||
|
|
||||||
def.on_secondary_use = function(itemstack, player, pointed_thing)
|
def.on_secondary_use = function(itemstack, player, pointed_thing)
|
||||||
|
if minetest.is_player(player) then
|
||||||
local meta = itemstack:get_meta()
|
local meta = itemstack:get_meta()
|
||||||
local bullets_loaded = meta:get_int("bullets_loaded")
|
local bullets_loaded = meta:get_int("bullets_loaded")
|
||||||
local bullets_name = meta:get_string("bullets_name")
|
local bullets_name = meta:get_string("bullets_name")
|
||||||
@ -200,12 +197,12 @@ guns.register_gun = function(self, name, def)
|
|||||||
end
|
end
|
||||||
|
|
||||||
if def._gun_magazine and def._gun_ammunition then
|
if def._gun_magazine and def._gun_ammunition then
|
||||||
self:run_on_reload(itemstack, player, "magazine")
|
|
||||||
local inv = player:get_inventory()
|
local inv = player:get_inventory()
|
||||||
for _, stack in ipairs(def._gun_ammunition) do
|
for _, stack in ipairs(def._gun_ammunition) do
|
||||||
local name = stack:get_name()
|
local name = stack:get_name()
|
||||||
local s = ItemStack(name)
|
local s = ItemStack(name)
|
||||||
if inv:contains_item("main", s) then
|
if inv:contains_item("main", s) then
|
||||||
|
self:run_on_reload(itemstack, player, "magazine")
|
||||||
local bullets_name = meta:get_string("bullets_name")
|
local bullets_name = meta:get_string("bullets_name")
|
||||||
if bullets_name ~= name then
|
if bullets_name ~= name then
|
||||||
local l = ItemStack({
|
local l = ItemStack({
|
||||||
@ -228,6 +225,7 @@ guns.register_gun = function(self, name, def)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
end
|
||||||
return nil
|
return nil
|
||||||
end
|
end
|
||||||
|
|
||||||
|
21
bullet.lua
21
bullet.lua
@ -1,7 +1,7 @@
|
|||||||
local bullet = {
|
local bullet = {
|
||||||
timer = 0,
|
timer = 0,
|
||||||
initial_properties = {
|
initial_properties = {
|
||||||
collide_with_objects = false,
|
collide_with_objects = true,
|
||||||
physical = true,
|
physical = true,
|
||||||
visual = "wielditem"
|
visual = "wielditem"
|
||||||
},
|
},
|
||||||
@ -23,7 +23,6 @@ end
|
|||||||
bullet.on_step = function(self, dtime, moveresult)
|
bullet.on_step = function(self, dtime, moveresult)
|
||||||
self.timer = self.timer + dtime
|
self.timer = self.timer + dtime
|
||||||
if self.timer < 10 and self.owner and self.itemstack then
|
if self.timer < 10 and self.owner and self.itemstack then
|
||||||
if moveresult.collides then
|
|
||||||
local col = moveresult.collisions[1]
|
local col = moveresult.collisions[1]
|
||||||
if col then
|
if col then
|
||||||
self:run_on_collision(self.itemstack, self.owner, col)
|
self:run_on_collision(self.itemstack, self.owner, col)
|
||||||
@ -34,7 +33,11 @@ bullet.on_step = function(self, dtime, moveresult)
|
|||||||
if node.tiles[1] then
|
if node.tiles[1] then
|
||||||
minetest.add_particle({
|
minetest.add_particle({
|
||||||
pos = self.object:get_pos(),
|
pos = self.object:get_pos(),
|
||||||
velocity = {x=math.random(-10,10), y=math.random(-10,10), z=math.random(-10,10)},
|
velocity = {
|
||||||
|
x=math.random(-10,10),
|
||||||
|
y=math.random(-10,10),
|
||||||
|
z=math.random(-10,10)
|
||||||
|
},
|
||||||
expirationtime = 0.5,
|
expirationtime = 0.5,
|
||||||
size = math.random(1,2),
|
size = math.random(1,2),
|
||||||
collisiondetection = true,
|
collisiondetection = true,
|
||||||
@ -45,23 +48,11 @@ bullet.on_step = function(self, dtime, moveresult)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
elseif col.type == "object" then
|
elseif col.type == "object" then
|
||||||
if col.object == self.owner then
|
|
||||||
return
|
|
||||||
end
|
|
||||||
local dmg = {full_punch_interval = 1, damage_groups = self.damage}
|
local dmg = {full_punch_interval = 1, damage_groups = self.damage}
|
||||||
col.object:punch(self.owner, 1, dmg, nil)
|
col.object:punch(self.owner, 1, dmg, nil)
|
||||||
end
|
end
|
||||||
self.object:remove()
|
self.object:remove()
|
||||||
end
|
end
|
||||||
elseif self.timer > 0.05 then
|
|
||||||
--This is a hack. There is probably a way to calculate the
|
|
||||||
--position where the player is looking a little ways away and
|
|
||||||
--spawn the bullet there so that the it doesn't collide with
|
|
||||||
--the player, but i don't know how to do that...
|
|
||||||
self.object:set_properties({
|
|
||||||
collide_with_objects = true
|
|
||||||
})
|
|
||||||
end
|
|
||||||
else
|
else
|
||||||
self.object:remove()
|
self.object:remove()
|
||||||
end
|
end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user