rc, bullet, missile, ...: fix bugs, fix creative mods, cleanup codes
This commit is contained in:
parent
6e2ae2c126
commit
11d0f6f724
8
api.lua
8
api.lua
@ -195,6 +195,7 @@ function vehicles.object_drive(entity, dtime, def)
|
||||
local dir = entity.driver:get_look_dir()
|
||||
local vec_backward = {x=-dir.x*speed/4,y=velo.y+1*-2,z=-dir.z*speed/4}
|
||||
local yaw = entity.driver:get_look_yaw()
|
||||
local creative_mode = creative and creative.is_enabled_for and creative.is_enabled_for(entity.driver:get_player_name())
|
||||
|
||||
--dummy variables
|
||||
local vec_rise = {}
|
||||
@ -508,7 +509,7 @@ function vehicles.object_drive(entity, dtime, def)
|
||||
--shoot weapons
|
||||
if ctrl.sneak and shoots and entity.loaded then
|
||||
if inv:contains_item("main", arrow.."_item") or infinite_arrow then
|
||||
local remov = inv:remove_item("main", arrow.."_item")
|
||||
if not creative_mode then inv:remove_item("main", arrow.."_item") end
|
||||
entity.loaded = false
|
||||
local obj = minetest.env:add_entity({x=pos.x+0+dir.x*2,y=pos.y+shoot_y+dir.y,z=pos.z+0+dir.z*2}, arrow)
|
||||
local vec = {x=dir.x*14,y=dir.y*14+shoot_angle,z=dir.z*14}
|
||||
@ -532,7 +533,7 @@ function vehicles.object_drive(entity, dtime, def)
|
||||
|
||||
if ctrl.aux1 and shoots2 and entity.loaded2 then
|
||||
if inv:contains_item("main", arrow2.."_item") or infinite_arrow2 then
|
||||
local remov = inv:remove_item("main", arrow2.."_item")
|
||||
if not creative_mode then inv:remove_item("main", arrow2.."_item") end
|
||||
entity.loaded2 = false
|
||||
local obj = minetest.env:add_entity({x=pos.x+0+dir.x*2,y=pos.y+shoot_y2+dir.y,z=pos.z+0+dir.z*2}, arrow2)
|
||||
local vec = {x=dir.x*20,y=dir.y*20+shoot_angle,z=dir.z*20}
|
||||
@ -742,8 +743,7 @@ function vehicles.on_punch(self, puncher)
|
||||
end
|
||||
vehicles.explodinate(self, 5)
|
||||
end
|
||||
if not self.driver then
|
||||
return end
|
||||
if not self.driver then return end
|
||||
local creative_mode = creative and creative.is_enabled_for and creative.is_enabled_for(self.driver:get_player_name())
|
||||
if self.driver == puncher and (hp == self.hp_max-5 or hp == self.hp_max or creative_mode) then
|
||||
local name = self.object:get_luaentity().name
|
||||
|
195
init.lua
195
init.lua
@ -9,31 +9,40 @@ local step = 1.1
|
||||
local enable_built_in = true
|
||||
|
||||
if enable_built_in then
|
||||
minetest.register_entity("vehicles:missile", {
|
||||
visual = "mesh",
|
||||
mesh = "missile.b3d",
|
||||
textures = {"vehicles_missile.png"},
|
||||
velocity = 15,
|
||||
acceleration = -5,
|
||||
damage = 2,
|
||||
collisionbox = {-1, -0.5, -1, 1, 0.5, 1},
|
||||
on_rightclick = function(self, clicker)
|
||||
clicker:set_attach(self.object, "", {x=0,y=0,z=0}, {x=0,y=1,z=0})
|
||||
end,
|
||||
on_step = function(self, obj, pos)
|
||||
local function missile_bullet_hit_check(self, obj, pos)
|
||||
local pos = self.object:getpos()
|
||||
do
|
||||
local return_v = {}
|
||||
local if_return = false
|
||||
for _, obj in ipairs(minetest.get_objects_inside_radius({x=pos.x,y=pos.y,z=pos.z}, 2)) do
|
||||
if obj:get_luaentity() ~= nil and obj ~= self.object and obj ~= self.vehicle and obj ~= self.launcher and obj ~= self.launcher:get_attach() and obj:get_luaentity().name ~= "__builtin:item" then
|
||||
if_return = true
|
||||
return_v[#return_v+1]=obj
|
||||
end
|
||||
end
|
||||
if if_return then
|
||||
return return_v
|
||||
end
|
||||
end
|
||||
|
||||
for dx=-1,1 do
|
||||
for dy=-1,1 do
|
||||
for dz=-1,1 do
|
||||
local p = {x=pos.x+dx, y=pos.y, z=pos.z+dz}
|
||||
local t = {x=pos.x+dx, y=pos.y+dy, z=pos.z+dz}
|
||||
local n = minetest.env:get_node(p)
|
||||
if n.name ~= "air" and n.drawtype ~= "airlike" then
|
||||
return {}
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
return false
|
||||
end
|
||||
local function missile_on_step_auxiliary(self, obj, pos)
|
||||
minetest.after(10, function()
|
||||
self.object:remove()
|
||||
end)
|
||||
local player = self.launcher
|
||||
if player == nil or player:get_player_name() == "" then
|
||||
self.object:remove()
|
||||
return
|
||||
end
|
||||
local dir = player:get_look_dir()
|
||||
local vec = {x=dir.x*16,y=dir.y*16,z=dir.z*16}
|
||||
local yaw = player:get_look_yaw()
|
||||
self.object:setyaw(yaw+math.pi/2)
|
||||
self.object:setvelocity(vec)
|
||||
local pos = self.object:getpos()
|
||||
local vec = self.object:getvelocity()
|
||||
minetest.add_particlespawner({
|
||||
@ -52,36 +61,43 @@ minetest.register_entity("vehicles:missile", {
|
||||
collisiondetection = false,
|
||||
texture = "vehicles_smoke.png",
|
||||
})
|
||||
local objs = minetest.get_objects_inside_radius({x=pos.x,y=pos.y,z=pos.z}, 2)
|
||||
for k, obj in pairs(objs) do
|
||||
if obj:get_luaentity() ~= nil then
|
||||
if obj:get_luaentity().name ~= "vehicles:missile" and obj ~= self.vehicle and obj ~= self.launcher and obj:get_luaentity().name ~= "__builtin:item" then
|
||||
obj:punch(self.object, 1.0, {
|
||||
local objs = missile_bullet_hit_check(self, obj, pos)
|
||||
if objs then
|
||||
for _, obj in ipairs(objs) do
|
||||
local puncher = self.object
|
||||
if self.launcher then puncher = self.launcher end
|
||||
obj:punch(puncher, 1.0, {
|
||||
full_punch_interval=1.0,
|
||||
damage_groups={fleshy=12},
|
||||
}, nil)
|
||||
local pos = self.object:getpos()
|
||||
tnt.boom(pos, {damage_radius=5,radius=5,ignore_protection=false})
|
||||
end
|
||||
tnt.boom(self.object:getpos(), {damage_radius=5,radius=5,ignore_protection=false})
|
||||
self.object:remove()
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
for dx=-1,1 do
|
||||
for dy=-1,1 do
|
||||
for dz=-1,1 do
|
||||
local p = {x=pos.x+dx, y=pos.y, z=pos.z+dz}
|
||||
local t = {x=pos.x+dx, y=pos.y+dy, z=pos.z+dz}
|
||||
local n = minetest.env:get_node(p).name
|
||||
if n ~= "vehicles:missile" and n ~= "vehicles:jet" and n ~= "air" then
|
||||
local pos = self.object:getpos()
|
||||
tnt.boom(pos, {damage_radius=5,radius=5,ignore_protection=false})
|
||||
minetest.register_entity("vehicles:missile", {
|
||||
visual = "mesh",
|
||||
mesh = "missile.b3d",
|
||||
textures = {"vehicles_missile.png"},
|
||||
velocity = 15,
|
||||
acceleration = -5,
|
||||
damage = 2,
|
||||
collisionbox = {-1, -0.5, -1, 1, 0.5, 1},
|
||||
on_rightclick = function(self, clicker)
|
||||
clicker:set_attach(self.object, "", {x=0,y=0,z=0}, {x=0,y=1,z=0})
|
||||
end,
|
||||
on_step = function(self, obj, pos)
|
||||
local player = self.launcher
|
||||
if player == nil or player:get_player_name() == "" then
|
||||
self.object:remove()
|
||||
return
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
local dir = player:get_look_dir()
|
||||
local vec = {x=dir.x*16,y=dir.y*16,z=dir.z*16}
|
||||
local yaw = player:get_look_yaw()
|
||||
self.object:setyaw(yaw+math.pi/2)
|
||||
self.object:setvelocity(vec)
|
||||
missile_on_step_auxiliary(self, obj, pos)
|
||||
end,
|
||||
})
|
||||
|
||||
@ -106,9 +122,6 @@ minetest.register_entity("vehicles:missile_2", {
|
||||
damage = 2,
|
||||
collisionbox = {0, 0, 0, 0, 0, 0},
|
||||
on_step = function(self, obj, pos)
|
||||
minetest.after(10, function()
|
||||
self.object:remove()
|
||||
end)
|
||||
local velo = self.object:getvelocity()
|
||||
if velo.y <= 1.2 and velo.y >= -1.2 then
|
||||
self.object:set_animation({x=1, y=1}, 5, 0)
|
||||
@ -117,67 +130,7 @@ minetest.register_entity("vehicles:missile_2", {
|
||||
elseif velo.y >= 1.2 then
|
||||
self.object:set_animation({x=2, y=2}, 5, 0)
|
||||
end
|
||||
local pos = self.object:getpos()
|
||||
minetest.add_particlespawner({
|
||||
amount = 2,
|
||||
time = 0.5,
|
||||
minpos = {x=pos.x-0.2, y=pos.y, z=pos.z-0.2},
|
||||
maxpos = {x=pos.x+0.2, y=pos.y, z=pos.z+0.2},
|
||||
minvel = {x=-velo.x/2, y=-velo.y/2, z=-velo.z/2},
|
||||
maxvel = {x=-velo.x, y=-velo.y, z=-velo.z},
|
||||
minacc = {x=0, y=-1, z=0},
|
||||
maxacc = {x=0, y=-1, z=0},
|
||||
minexptime = 0.2,
|
||||
maxexptime = 0.6,
|
||||
minsize = 3,
|
||||
maxsize = 4,
|
||||
collisiondetection = false,
|
||||
texture = "vehicles_smoke.png",
|
||||
})
|
||||
local objs = minetest.get_objects_inside_radius({x=pos.x,y=pos.y,z=pos.z}, 2)
|
||||
for k, obj in pairs(objs) do
|
||||
if obj:get_luaentity() ~= nil then
|
||||
if obj:get_luaentity().name ~= "vehicles:missile_2" and obj ~= self.vehicle and obj:get_luaentity().name ~= "__builtin:item" then
|
||||
obj:punch(self.launcher, 1.0, {
|
||||
full_punch_interval=1.0,
|
||||
damage_groups={fleshy=12},
|
||||
}, nil)
|
||||
self.object:remove()
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
for dx=-1,1 do
|
||||
for dy=-1,1 do
|
||||
for dz=-1,1 do
|
||||
local p = {x=pos.x+dx, y=pos.y, z=pos.z+dz}
|
||||
local t = {x=pos.x+dx, y=pos.y+dy, z=pos.z+dz}
|
||||
local n = minetest.env:get_node(p).name
|
||||
if n ~= "vehicles:missile_2" and n ~= "vehicles:tank" and n ~= "vehicles:jet" and n ~= "air" then
|
||||
local pos = self.object:getpos()
|
||||
minetest.add_particlespawner({
|
||||
amount = 30,
|
||||
time = 0.5,
|
||||
minpos = {x=pos.x-0.5, y=pos.y-0.5, z=pos.z-0.5},
|
||||
maxpos = {x=pos.x+0.5, y=pos.y+0.5, z=pos.z+0.5},
|
||||
minvel = {x=-1, y=-1, z=-1},
|
||||
maxvel = {x=1, y=1, z=1},
|
||||
minacc = {x=0, y=0.2, z=0},
|
||||
maxacc = {x=0, y=0.6, z=0},
|
||||
minexptime = 0.5,
|
||||
maxexptime = 1,
|
||||
minsize = 10,
|
||||
maxsize = 20,
|
||||
collisiondetection = false,
|
||||
texture = "vehicles_explosion.png"
|
||||
})
|
||||
tnt.boom(pos, {damage_radius=5,radius=5,ignore_protection=false})
|
||||
self.object:remove()
|
||||
return
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
missile_on_step_auxiliary(self, obj, pos)
|
||||
end,
|
||||
})
|
||||
|
||||
@ -237,33 +190,16 @@ minetest.register_entity("vehicles:bullet", {
|
||||
minetest.after(10, function()
|
||||
self.object:remove()
|
||||
end)
|
||||
local pos = self.object:getpos()
|
||||
local objs = minetest.get_objects_inside_radius({x=pos.x,y=pos.y,z=pos.z}, 2)
|
||||
for k, obj in pairs(objs) do
|
||||
if obj:get_luaentity() ~= nil then
|
||||
if obj:get_luaentity().name ~= "vehicles:bullet" and obj ~= self.vehicle and obj:get_luaentity().name ~= "__builtin:item" then
|
||||
local objs = missile_bullet_hit_check(self, obj, pos)
|
||||
if objs then
|
||||
for _, obj in ipairs(objs) do
|
||||
obj:punch(self.launcher, 1.0, {
|
||||
full_punch_interval=1.0,
|
||||
damage_groups={fleshy=5},
|
||||
}, nil)
|
||||
end
|
||||
self.object:remove()
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
for dx=-1,1 do
|
||||
for dy=-1,1 do
|
||||
for dz=-1,1 do
|
||||
local p = {x=pos.x+dx, y=pos.y, z=pos.z+dz}
|
||||
local t = {x=pos.x+dx, y=pos.y+dy, z=pos.z+dz}
|
||||
local n = minetest.env:get_node(p).name
|
||||
if n ~= "vehicles:bullet" and n ~= "air" then
|
||||
self.object:remove()
|
||||
return
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end,
|
||||
})
|
||||
|
||||
@ -1883,7 +1819,8 @@ minetest.register_tool("vehicles:rc", {
|
||||
local pname = placer:get_player_name()
|
||||
local inv = minetest.get_inventory({type="player", name=pname})
|
||||
if inv:contains_item("main", "vehicles:missile_2_item") then
|
||||
local remov = inv:remove_item("main", "vehicles:missile_2_item")
|
||||
local creative_mode = creative and creative.is_enabled_for and creative.is_enabled_for(placer:get_player_name())
|
||||
if not creative_mode then inv:remove_item("main", "vehicles:missile_2_item") end
|
||||
local obj = minetest.env:add_entity({x=playerpos.x+0+dir.x,y=playerpos.y+1+dir.y,z=playerpos.z+0+dir.z}, "vehicles:missile")
|
||||
local object = obj:get_luaentity()
|
||||
object.launcher = placer
|
||||
|
Loading…
x
Reference in New Issue
Block a user