api changes, and more vehicles

master
D00Med 2016-10-02 07:14:48 +10:00
parent 6c0fea5f58
commit 2ec441cad8
26 changed files with 664 additions and 246 deletions

422
api.lua
View File

@ -1,4 +1,4 @@
--vehicles/mounts api by, based on lib_mount(see below) --vehicles/mounts api by D00Med, based on lib_mount(see below)
--License of lib_mount: --License of lib_mount:
-- Minetest mod: lib_mount -- Minetest mod: lib_mount
@ -25,15 +25,14 @@
local mobs_redo = false local mobs_redo = false
if minetest.get_modpath("mobs")then
if mobs.mod and mobs.mod == "redo" then if mobs.mod and mobs.mod == "redo" then
mobs_redo = true mobs_redo = true
end end
local function is_group(pos, group)
local nn = minetest.get_node(pos).name
return minetest.get_item_group(nn, group) ~= 0
end end
--attach position seems broken, and eye offset will cause problems if the vehicle/mount/player is destroyed whilst driving/riding
local function force_detach(player) local function force_detach(player)
local attached_to = player:get_attach() local attached_to = player:get_attach()
if attached_to and attached_to:get_luaentity() then if attached_to and attached_to:get_luaentity() then
@ -47,15 +46,18 @@ local function force_detach(player)
player:set_eye_offset({x=0, y=0, z=0}, {x=0, y=0, z=0}) player:set_eye_offset({x=0, y=0, z=0}, {x=0, y=0, z=0})
end end
function object_attach(entity, player, attach_at, eye_offset) function object_attach(entity, player, attach_at, visible, eye_offset)
eye_offset = eye_offset or {x=0, y=0, z=0} eye_offset = eye_offset or {x=0, y=0, z=0}
force_detach(player) force_detach(player)
entity.driver = player entity.driver = player
entity.loaded = true entity.loaded = true
player:set_attach(entity.object, "", attach_at, {x=0, y=0, z=0}) player:set_attach(entity.object, "", attach_at, {x=0, y=0, z=0})
--this is to hide the player when the attaching doesn't work properly
if not visible then
player:set_properties({visual_size = {x=0, y=0}})
else
player:set_properties({visual_size = {x=1, y=1}}) player:set_properties({visual_size = {x=1, y=1}})
end
player:set_eye_offset(eye_offset, {x=0, y=2, z=-40}) player:set_eye_offset(eye_offset, {x=0, y=2, z=-40})
default.player_attached[player:get_player_name()] = true default.player_attached[player:get_player_name()] = true
minetest.after(0.2, function() minetest.after(0.2, function()
@ -70,6 +72,9 @@ function object_detach(entity, player, offset)
player:set_detach() player:set_detach()
default.player_attached[player:get_player_name()] = false default.player_attached[player:get_player_name()] = false
default.player_set_animation(player, "stand" , 30) default.player_set_animation(player, "stand" , 30)
player:set_properties({
visual_size = {x = 1, y = 1},
})
player:set_eye_offset({x=0, y=0, z=0}, {x=0, y=0, z=0}) player:set_eye_offset({x=0, y=0, z=0}, {x=0, y=0, z=0})
local pos = player:getpos() local pos = player:getpos()
pos = {x = pos.x + offset.x, y = pos.y + 0.2 + offset.y, z = pos.z + offset.z} pos = {x = pos.x + offset.x, y = pos.y + 0.2 + offset.y, z = pos.z + offset.z}
@ -100,7 +105,8 @@ end)
--mixed code(from this mod and lib_mount) --mixed code(from this mod and lib_mount)
function object_drive(entity, dtime, speed, decell, shoots, arrow, moving_anim, stand_anim, jumps) --basic driving, use for basic vehicles/mounts, with optional weapons
function object_drive(entity, dtime, speed, decell, shoots, arrow, reload, moving_anim, stand_anim, jumps)
local ctrl = entity.driver:get_player_control() local ctrl = entity.driver:get_player_control()
local velo = entity.object:getvelocity() local velo = entity.object:getvelocity()
local dir = entity.driver:get_look_dir(); local dir = entity.driver:get_look_dir();
@ -126,7 +132,7 @@ function object_drive(entity, dtime, speed, decell, shoots, arrow, moving_anim,
local yaw = entity.driver:get_look_yaw(); local yaw = entity.driver:get_look_yaw();
obj:setyaw(yaw+math.pi/2) obj:setyaw(yaw+math.pi/2)
obj:setvelocity(vec) obj:setvelocity(vec)
minetest.after(1, function() minetest.after(reload, function()
entity.loaded = true entity.loaded = true
end) end)
end end
@ -160,7 +166,7 @@ end
--simplified in an attempt to reduce lag
function object_drive_simple(entity, dtime, speed, decell) function object_drive_simple(entity, dtime, speed, decell)
local ctrl = entity.driver:get_player_control() local ctrl = entity.driver:get_player_control()
local velo = entity.object:getvelocity() local velo = entity.object:getvelocity()
@ -179,10 +185,10 @@ function object_drive_simple(entity, dtime, speed, decell)
end end
end end
--same as above but with improvements for cars and nitro/boost
function object_drive_car(entity, dtime, speed, decell, nitro_duration) function object_drive_car(entity, dtime, speed, decell, nitro_duration)
local ctrl = entity.driver:get_player_control() local ctrl = entity.driver:get_player_control()
local velo = entity.object:getvelocity() local velo = entity.object:getvelocity()
local nitro_remaining = entity.nitro
local dir = entity.driver:get_look_dir(); local dir = entity.driver:get_look_dir();
local vec_forward = {x=dir.x*speed,y=velo.y-0.5,z=dir.z*speed} local vec_forward = {x=dir.x*speed,y=velo.y-0.5,z=dir.z*speed}
local vec_nitro = {x=dir.x*(speed*1.5),y=velo.y-0.5,z=dir.z*(speed*1.5)} local vec_nitro = {x=dir.x*(speed*1.5),y=velo.y-0.5,z=dir.z*(speed*1.5)}
@ -199,7 +205,7 @@ function object_drive_car(entity, dtime, speed, decell, nitro_duration)
entity.object:setvelocity(vec_nitro) entity.object:setvelocity(vec_nitro)
local pos = entity.object:getpos() local pos = entity.object:getpos()
minetest.add_particlespawner( minetest.add_particlespawner(
15, --amount 10, --amount
1, --time 1, --time
{x=pos.x-0.5, y=pos.y, z=pos.z-0.5}, --minpos {x=pos.x-0.5, y=pos.y, z=pos.z-0.5}, --minpos
{x=pos.x+0.5, y=pos.y, z=pos.z+0.5}, --maxpos {x=pos.x+0.5, y=pos.y, z=pos.z+0.5}, --maxpos
@ -226,44 +232,129 @@ function object_drive_car(entity, dtime, speed, decell, nitro_duration)
end end
end end
function object_turret(entity, dtime, arrow, attack_anim, stand_anim) --for boats and watercraft
function object_float(entity, dtime, speed, decell)
local ctrl = entity.driver:get_player_control()
local velo = entity.object:getvelocity()
local dir = entity.driver:get_look_dir()
local pos = entity.object:getpos()
local vec_forward = {x=dir.x*speed,y=velo.y,z=dir.z*speed}
local vec_backward = {x=-dir.x*speed,y=velo.y,z=-dir.z*speed}
local vec_stop = {x=velo.x*decell,y=velo.y,z=velo.z*decell}
local yaw = entity.driver:get_look_yaw();
entity.object:setyaw(yaw+math.pi+math.pi/2)
if minetest.get_node(pos).name == "default:river_water_source" or minetest.get_node(pos).name == "default:water_source" then
entity.floating = true
else entity.floating = false
end
if ctrl.up and entity.floating then
entity.object:setvelocity(vec_forward)
elseif ctrl.down and entity.floating then
entity.object:setvelocity(vec_backward)
elseif not ctrl.down or ctrl.up then
entity.object:setvelocity(vec_stop)
end
end
--attempts to improve object_drive_car
-- function object_drive_experimental(entity, dtime, power, traction, nitro_duration)
-- local ctrl = entity.driver:get_player_control()
-- local velo = entity.object:getvelocity()
-- local speed = math.abs(velo.x)+math.abs(velo.z)
-- local nitro_remaining = entity.nitro
-- local dir = entity.driver:get_look_dir()
-- local yaw1 = entity.object:getyaw()
-- local dir_x = -math.sin(yaw1)
-- local dir_z = math.cos(yaw1)
-- local vec_forward = {x=dir_x*power,y=velo.y-0.5,z=dir_z*power}
-- local vec_nitro = {x=dir.x*(power*1.5),y=velo.y-0.5,z=dir.z*(power*1.5)}
-- local vec_backward = {x=-dir.x*power,y=velo.y-0.5,z=-dir.z*power}
-- local vec_stop = {x=velo.x*traction,y=velo.y-1,z=velo.z*traction}
-- local yaw = entity.driver:get_look_yaw();
-- if ctrl.left then
-- entity.object:setyaw(yaw1+math.pi/180+speed/360)
-- elseif ctrl.right then
-- entity.object:setyaw(yaw1-math.pi/180-speed/360)
-- else
-- entity.object:setyaw(yaw1)
-- end
-- if not entity.nitro then
-- minetest.after(4, function()
-- entity.nitro = true
-- end)
-- end
-- if ctrl.up and ctrl.sneak and entity.nitro then
-- entity.object:setvelocity(vec_nitro)
-- local pos = entity.object:getpos()
-- minetest.add_particlespawner(
-- 15, --amount
-- 1, --time
-- {x=pos.x-0.5, y=pos.y, z=pos.z-0.5}, --minpos
-- {x=pos.x+0.5, y=pos.y, z=pos.z+0.5}, --maxpos
-- {x=0, y=0, z=0}, --minvel
-- {x=-velo.x, y=-velo.y, z=-velo.z}, --maxvel
-- {x=-0,y=-0,z=-0}, --minacc
-- {x=0,y=0,z=0}, --maxacc
-- 0.1, --minexptime
-- 0.2, --maxexptime
-- 10, --minsize
-- 15, --maxsize
-- false, --collisiondetection
-- "vehicles_nitro.png" --texture
-- )
-- minetest.after(nitro_duration, function()
-- entity.nitro = false
-- end)
-- elseif ctrl.up then
-- entity.object:setvelocity(vec_forward)
-- elseif ctrl.down then
-- entity.object:setvelocity(vec_backward)
-- elseif not ctrl.down or ctrl.up then
-- entity.object:setvelocity(vec_stop)
-- end
-- end
--stationary object, useful for gun turrets etc.
function object_turret(entity, dtime, height, arrow, shoot_interval)
local ctrl = entity.driver:get_player_control() local ctrl = entity.driver:get_player_control()
local pos = entity.driver:getpos();
local yaw = entity.driver:get_look_yaw(); local yaw = entity.driver:get_look_yaw();
entity.object:setpos(pos)
entity.object:setyaw(yaw+math.pi+math.pi/2) entity.object:setyaw(yaw+math.pi+math.pi/2)
if ctrl.sneak and entity.loaded then if ctrl.sneak and entity.loaded then
entity.loaded = false entity.loaded = false
local pos = entity.object:getpos() local pos = entity.object:getpos()
local obj = minetest.env:add_entity({x=pos.x+0+dir.x*2,y=pos.y+1.5+dir.y,z=pos.z+0+dir.z*2}, arrow) local dir = entity.driver:get_look_dir();
local obj = minetest.env:add_entity({x=pos.x+dir.x*1.2,y=pos.y+height,z=pos.z+dir.z*1.2}, arrow)
local yaw = entity.driver:get_look_yaw(); local yaw = entity.driver:get_look_yaw();
local vec = {x=dir.x*9, y=dir.y*9, z=dir.z*9} local vec = {x=dir.x*9, y=dir.y*9, z=dir.z*9}
obj:setyaw(yaw+math.pi/2) obj:setyaw(yaw+math.pi/2)
set_animation(entity, attack_anim) obj:setvelocity(vec)
minetest.after(1, function() minetest.after(shoot_interval, function()
entity.loaded = true entity.loaded = true
end) end)
else
set_animation(entity, stand_anim_anim)
end end
end end
--basic flying, with optional weapons
function object_fly(entity, dtime, speed, accel, decell, shoots, arrow, moving_anim, stand_anim) function object_fly(entity, dtime, speed, accel, decell, shoots, arrow, moving_anim, stand_anim)
local ctrl = entity.driver:get_player_control() local ctrl = entity.driver:get_player_control()
local dir = entity.driver:get_look_dir(); local dir = entity.driver:get_look_dir();
local velo = entity.object:getvelocity() local velo = entity.object:getvelocity()
local vec_forward = {x=dir.x*speed,y=dir.y*speed+3,z=dir.z*speed} local vec_forward = {x=dir.x*speed,y=(dir.y*speed)/4+math.abs(velo.z+velo.x)/10,z=dir.z*speed}
local acc_forward = {x=dir.x*accel/2,y=dir.y*accel/2+3,z=dir.z*accel/2} local acc_forward = {x=dir.x*accel/2,y=dir.y*accel/2+3,z=dir.z*accel/2}
local vec_backward = {x=-dir.x*speed,y=dir.y*speed+3,z=-dir.z*speed} local vec_backward = {x=-dir.x*speed,y=dir.y*speed+3,z=-dir.z*speed}
local acc_backward = {x=dir.x*accel/2,y=dir.y*accel/2+3,z=dir.z*accel/2} local acc_backward = {x=dir.x*accel/2,y=dir.y*accel/2+3,z=dir.z*accel/2}
local vec_stop = {x=velo.x*decell, y=velo.y, z=velo.z*decell} local vec_stop = {x=velo.x*decell, y=velo.y, z=velo.z*decell}
local yaw = entity.driver:get_look_yaw(); local yaw = entity.driver:get_look_yaw();
--pitch doesn't work
--local pitch = entity.driver:get_look_pitch();
if ctrl.up then if ctrl.up then
entity.object:setyaw(yaw+math.pi+math.pi/2) entity.object:setyaw(yaw+math.pi+math.pi/2)
--entity.object:setpitch(pitch+math.pi+math.pi/2)
entity.object:setvelocity(vec_forward) entity.object:setvelocity(vec_forward)
entity.object:setacceleration(acc_forward) entity.object:setacceleration(acc_forward)
elseif ctrl.down then elseif ctrl.down then
entity.object:setyaw(yaw+math.pi+math.pi/2) entity.object:setyaw(yaw+math.pi+math.pi/2)
--entity.object:setpitch(pitch+math.pi+math.pi/2)
entity.object:setvelocity(vec_backward) entity.object:setvelocity(vec_backward)
entity.object:setacceleration(acc_backward) entity.object:setacceleration(acc_backward)
elseif not ctrl.down or ctrl.up then elseif not ctrl.down or ctrl.up then
@ -283,6 +374,7 @@ function object_fly(entity, dtime, speed, accel, decell, shoots, arrow, moving_a
end) end)
end end
--lib_mount animation --lib_mount animation
if minetest.get_modpath("mobs")then
if velo.x == 0 and velo.y == 0 and velo.z == 0 then if velo.x == 0 and velo.y == 0 and velo.z == 0 then
if stand_anim and stand_anim ~= nilthen then if stand_anim and stand_anim ~= nilthen then
set_animation(entity, stand_anim) set_animation(entity, stand_anim)
@ -292,8 +384,10 @@ function object_fly(entity, dtime, speed, accel, decell, shoots, arrow, moving_a
if moving_anim and moving_anim ~= nil then if moving_anim and moving_anim ~= nil then
set_animation(entity, moving_anim) set_animation(entity, moving_anim)
end end
end
end end
--flying with jump to increase height in addition to looking up/down
function object_fly_2(entity, dtime, speed, accel, decell, shoots, arrow, moving_anim, stand_anim) function object_fly_2(entity, dtime, speed, accel, decell, shoots, arrow, moving_anim, stand_anim)
local ctrl = entity.driver:get_player_control() local ctrl = entity.driver:get_player_control()
local dir = entity.driver:get_look_dir(); local dir = entity.driver:get_look_dir();
@ -347,6 +441,7 @@ function object_fly_2(entity, dtime, speed, accel, decell, shoots, arrow, moving
end end
end end
--gliding
function object_glide(entity, dtime, speed, decell, gravity, moving_anim, stand_anim) function object_glide(entity, dtime, speed, decell, gravity, moving_anim, stand_anim)
local ctrl = entity.driver:get_player_control() local ctrl = entity.driver:get_player_control()
local dir = entity.driver:get_look_dir(); local dir = entity.driver:get_look_dir();
@ -396,164 +491,165 @@ end
--lib_mount (not required by new functions) --lib_mount (not required by new functions)
local function is_group(pos, group) -- local function is_group(pos, group)
local nn = minetest.get_node(pos).name -- local nn = minetest.get_node(pos).name
return minetest.get_item_group(nn, group) ~= 0 -- return minetest.get_item_group(nn, group) ~= 0
end -- end
local function get_sign(i) -- local function get_sign(i)
i = i or 0 -- i = i or 0
if i == 0 then -- if i == 0 then
return 0 -- return 0
else -- else
return i / math.abs(i) -- return i / math.abs(i)
end -- end
end -- end
local function get_velocity(v, yaw, y) -- local function get_velocity(v, yaw, y)
local x = -math.sin(yaw) * v -- local x = -math.sin(yaw) * v
local z = math.cos(yaw) * v -- local z = math.cos(yaw) * v
return {x = x, y = y, z = z} -- return {x = x, y = y, z = z}
end -- end
local function get_v(v) -- local function get_v(v)
return math.sqrt(v.x ^ 2 + v.z ^ 2) -- return math.sqrt(v.x ^ 2 + v.z ^ 2)
end -- end
lib_mount = {} -- lib_mount = {}
function lib_mount.attach(entity, player, attach_at, eye_offset) -- function lib_mount.attach(entity, player, attach_at, eye_offset)
eye_offset = eye_offset or {x=0, y=0, z=0} -- eye_offset = eye_offset or {x=0, y=0, z=0}
force_detach(player) -- force_detach(player)
entity.driver = player -- entity.driver = player
player:set_attach(entity.object, "", attach_at, {x=0, y=0, z=0}) -- player:set_attach(entity.object, "", attach_at, {x=0, y=0, z=0})
player:set_properties({visual_size = {x=1, y=1}}) -- player:set_properties({visual_size = {x=1, y=1}})
player:set_eye_offset(eye_offset, {x=0, y=0, z=0}) -- player:set_eye_offset(eye_offset, {x=0, y=0, z=0})
default.player_attached[player:get_player_name()] = true -- default.player_attached[player:get_player_name()] = true
minetest.after(0.2, function() -- minetest.after(0.2, function()
default.player_set_animation(player, "sit" , 30) -- default.player_set_animation(player, "sit" , 30)
end) -- end)
entity.object:setyaw(player:get_look_yaw() - math.pi / 2) -- entity.object:setyaw(player:get_look_yaw() - math.pi / 2)
end -- end
function lib_mount.detach(entity, player, offset) -- function lib_mount.detach(entity, player, offset)
entity.driver = nil -- entity.driver = nil
player:set_detach() -- player:set_detach()
default.player_attached[player:get_player_name()] = false -- default.player_attached[player:get_player_name()] = false
default.player_set_animation(player, "stand" , 30) -- default.player_set_animation(player, "stand" , 30)
player:set_eye_offset({x=0, y=0, z=0}, {x=0, y=0, z=0}) -- player:set_eye_offset({x=0, y=0, z=0}, {x=0, y=0, z=0})
local pos = player:getpos() -- local pos = player:getpos()
pos = {x = pos.x + offset.x, y = pos.y + 0.2 + offset.y, z = pos.z + offset.z} -- pos = {x = pos.x + offset.x, y = pos.y + 0.2 + offset.y, z = pos.z + offset.z}
minetest.after(0.1, function() -- minetest.after(0.1, function()
player:setpos(pos) -- player:setpos(pos)
end) -- end)
end -- end
function lib_mount.drive(entity, dtime, moving_anim, stand_anim, can_fly) -- function lib_mount.drive(entity, dtime, moving_anim, stand_anim, can_fly)
entity.v = get_v(entity.object:getvelocity()) * get_sign(entity.v) -- entity.v = get_v(entity.object:getvelocity()) * get_sign(entity.v)
local ctrl = entity.driver:get_player_control() -- local ctrl = entity.driver:get_player_control()
local yaw = entity.object:getyaw() -- local yaw = entity.object:getyaw()
if ctrl.up then -- if ctrl.up then
entity.v = entity.v + 0.1 -- entity.v = entity.v + 0.1
elseif ctrl.down then -- elseif ctrl.down then
entity.v = entity.v - 0.1 -- entity.v = entity.v - 0.1
end -- end
if ctrl.left then -- if ctrl.left then
if entity.v < 0 then -- if entity.v < 0 then
entity.object:setyaw(yaw - (1 + dtime) * 0.03) -- entity.object:setyaw(yaw - (1 + dtime) * 0.03)
else -- else
entity.object:setyaw(yaw + (1 + dtime) * 0.03) -- entity.object:setyaw(yaw + (1 + dtime) * 0.03)
end -- end
elseif ctrl.right then -- elseif ctrl.right then
if entity.v < 0 then -- if entity.v < 0 then
entity.object:setyaw(yaw + (1 + dtime) * 0.03) -- entity.object:setyaw(yaw + (1 + dtime) * 0.03)
else -- else
entity.object:setyaw(yaw - (1 + dtime) * 0.03) -- entity.object:setyaw(yaw - (1 + dtime) * 0.03)
end -- end
end -- end
local velo = entity.object:getvelocity() -- local velo = entity.object:getvelocity()
if entity.v == 0 and velo.x == 0 and velo.y == 0 and velo.z == 0 then -- if entity.v == 0 and velo.x == 0 and velo.y == 0 and velo.z == 0 then
if stand_anim and stand_anim ~= nil and mobs_redo == true then -- if stand_anim and stand_anim ~= nil and mobs_redo == true then
set_animation(entity, stand_anim) -- set_animation(entity, stand_anim)
end -- end
entity.object:setpos(entity.object:getpos()) -- entity.object:setpos(entity.object:getpos())
return -- return
end -- end
if moving_anim and moving_anim ~= nil and mobs_redo == true then -- if moving_anim and moving_anim ~= nil and mobs_redo == true then
set_animation(entity, moving_anim) -- set_animation(entity, moving_anim)
end -- end
local s = get_sign(entity.v) -- local s = get_sign(entity.v)
entity.v = entity.v - 0.02 * s -- entity.v = entity.v - 0.02 * s
if s ~= get_sign(entity.v) then -- if s ~= get_sign(entity.v) then
entity.object:setvelocity({x = 0, y = 0, z = 0}) -- entity.object:setvelocity({x = 0, y = 0, z = 0})
entity.v = 0 -- entity.v = 0
return -- return
end -- end
if math.abs(entity.v) > 5 then -- if math.abs(entity.v) > 5 then
entity.v = 5 * get_sign(entity.v) -- entity.v = 5 * get_sign(entity.v)
end -- end
local p = entity.object:getpos() -- local p = entity.object:getpos()
p.y = p.y - 0.5 -- p.y = p.y - 0.5
local new_velo = {x = 0, y = 0, z = 0} -- local new_velo = {x = 0, y = 0, z = 0}
local new_acce = {x = 0, y = 0, z = 0} -- local new_acce = {x = 0, y = 0, z = 0}
if not is_group(p, "crumbly") then -- if not is_group(p, "crumbly") then
local nodedef = minetest.registered_nodes[minetest.get_node(p).name] -- local nodedef = minetest.registered_nodes[minetest.get_node(p).name]
if (not nodedef) or nodedef.walkable then -- if (not nodedef) or nodedef.walkable then
entity.v = 0 -- entity.v = 0
new_acce = {x = 0, y = 1, z = 0} -- new_acce = {x = 0, y = 1, z = 0}
else -- else
new_acce = {x = 0, y = -9.8, z = 0} -- new_acce = {x = 0, y = -9.8, z = 0}
end -- end
new_velo = get_velocity(entity.v, entity.object:getyaw(), -- new_velo = get_velocity(entity.v, entity.object:getyaw(),
entity.object:getvelocity().y) -- entity.object:getvelocity().y)
entity.object:setpos(entity.object:getpos()) -- entity.object:setpos(entity.object:getpos())
else -- else
p.y = p.y + 1 -- p.y = p.y + 1
if is_group(p, "crumbly") then -- if is_group(p, "crumbly") then
local y = entity.object:getvelocity().y -- local y = entity.object:getvelocity().y
if y >= 5 then -- if y >= 5 then
y = 5 -- y = 5
elseif y < 0 then -- elseif y < 0 then
new_acce = {x = 0, y = 20, z = 0} -- new_acce = {x = 0, y = 20, z = 0}
else -- else
new_acce = {x = 0, y = 5, z = 0} -- new_acce = {x = 0, y = 5, z = 0}
end -- end
new_velo = get_velocity(entity.v, entity.object:getyaw(), y) -- new_velo = get_velocity(entity.v, entity.object:getyaw(), y)
entity.object:setpos(entity.object:getpos()) -- entity.object:setpos(entity.object:getpos())
else -- else
new_acce = {x = 0, y = 0, z = 0} -- new_acce = {x = 0, y = 0, z = 0}
if math.abs(entity.object:getvelocity().y) < 1 then -- if math.abs(entity.object:getvelocity().y) < 1 then
local pos = entity.object:getpos() -- local pos = entity.object:getpos()
pos.y = math.floor(pos.y) + 0.5 -- pos.y = math.floor(pos.y) + 0.5
entity.object:setpos(pos) -- entity.object:setpos(pos)
new_velo = get_velocity(entity.v, entity.object:getyaw(), 0) -- new_velo = get_velocity(entity.v, entity.object:getyaw(), 0)
else -- else
new_velo = get_velocity(entity.v, entity.object:getyaw(), -- new_velo = get_velocity(entity.v, entity.object:getyaw(),
entity.object:getvelocity().y) -- entity.object:getvelocity().y)
entity.object:setpos(entity.object:getpos()) -- entity.object:setpos(entity.object:getpos())
end -- end
end -- end
end -- end
if can_fly and can_fly == true and ctrl.jump then -- if can_fly and can_fly == true and ctrl.jump then
new_velo.y = new_velo.y + 0.75 -- new_velo.y = new_velo.y + 0.75
end -- end
entity.object:setvelocity(new_velo) -- entity.object:setvelocity(new_velo)
entity.object:setacceleration(new_acce) -- entity.object:setacceleration(new_acce)
end -- end
--other stuff --other stuff
function register_vehicle_spawner(vehicle, desc, texture) function register_vehicle_spawner(vehicle, desc, texture, is_boat)
minetest.register_tool(vehicle.."_spawner", { minetest.register_tool(vehicle.."_spawner", {
description = desc, description = desc,
inventory_image = texture, inventory_image = texture,
liquids_pointable = is_boat,
wield_scale = {x = 1.5, y = 1.5, z = 1}, wield_scale = {x = 1.5, y = 1.5, z = 1},
tool_capabilities = { tool_capabilities = {
full_punch_interval = 0.7, full_punch_interval = 0.7,
@ -566,10 +662,14 @@ minetest.register_tool(vehicle.."_spawner", {
on_use = function(item, placer, pointed_thing) on_use = function(item, placer, pointed_thing)
local dir = placer:get_look_dir(); local dir = placer:get_look_dir();
local playerpos = placer:getpos(); local playerpos = placer:getpos();
if pointed_thing.type == "node" then if pointed_thing.type == "node" and not is_boat then
local obj = minetest.env:add_entity(pointed_thing.above, vehicle) local obj = minetest.env:add_entity(pointed_thing.above, vehicle)
item:take_item() item:take_item()
return item return item
elseif pointed_thing.type == "node" and minetest.get_item_group(pointed_thing.name, "water")then
local obj = minetest.env:add_entity(pointed_thing.under, vehicle)
item:take_item()
return item
end end
end, end,
}) })

488
init.lua
View File

@ -32,6 +32,7 @@ minetest.register_entity("vehicles:missile", {
self.object:remove() self.object:remove()
end) end)
for _, player in ipairs(minetest.get_connected_players()) do for _, player in ipairs(minetest.get_connected_players()) do
--never tested with multiple players
local dir = player:get_look_dir(); local dir = player:get_look_dir();
local vec = {x=dir.x*16,y=dir.y*16,z=dir.z*16} local vec = {x=dir.x*16,y=dir.y*16,z=dir.z*16}
local yaw = player:get_look_yaw(); local yaw = player:get_look_yaw();
@ -123,6 +124,86 @@ minetest.register_entity("vehicles:missile_2", {
end, end,
}) })
minetest.register_entity("vehicles:water", {
visual = "sprite",
textures = {"vehicles_trans.png"},
velocity = 15,
acceleration = -5,
damage = 2,
collisionbox = {0, 0, 0, 0, 0, 0},
on_activate = function(self)
self.object:setacceleration({x=0, y=-1, z=0})
end,
on_step = function(self, obj, pos)
minetest.after(5, function()
self.object:remove()
end)
local pos = self.object:getpos()
minetest.add_particlespawner({
amount = 1,
time = 1,
minpos = {x=pos.x, y=pos.y, z=pos.z},
maxpos = {x=pos.x, y=pos.y, z=pos.z},
minvel = {x=0, y=0, z=0},
maxvel = {x=0, y=-0.2, z=0},
minacc = {x=0, y=-1, z=0},
maxacc = {x=0, y=-1, z=0},
minexptime = 1,
maxexptime = 1,
minsize = 4,
maxsize = 5,
collisiondetection = false,
vertical = false,
texture = "vehicles_water.png",
})
local node = minetest.env:get_node(pos).name
if node == "fire:basic_flame" then
minetest.remove_node(pos)
end
end
})
minetest.register_entity("vehicles:bullet", {
visual = "sprite",
textures = {"vehicles_bullet.png"},
velocity = 15,
acceleration = -5,
damage = 2,
collisionbox = {0, 0, 0, 0, 0, 0},
on_step = function(self, obj, pos)
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 n ~= "vehicles:turret" and obj:get_luaentity().name ~= "__builtin:item" then
obj:punch(self.object, 1.0, {
full_punch_interval=1.0,
damage_groups={fleshy=0.5},
}, 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:bullet" and n ~= "air" then
self.object:remove()
return
end
end
end
end
end,
})
minetest.register_entity("vehicles:tank", { minetest.register_entity("vehicles:tank", {
visual = "mesh", visual = "mesh",
mesh = "tank.b3d", mesh = "tank.b3d",
@ -137,12 +218,12 @@ minetest.register_entity("vehicles:tank", {
if self.driver and clicker == self.driver then if self.driver and clicker == self.driver then
object_detach(self, clicker, {x=1, y=0, z=1}) object_detach(self, clicker, {x=1, y=0, z=1})
elseif not self.driver then elseif not self.driver then
object_attach(self, clicker, {x=0, y=5, z=4}, {x=0, y=2, z=4}, {x=0, y=3, z=-72}) object_attach(self, clicker, {x=0, y=5, z=4}, false, {x=0, y=2, z=4})
end end
end, end,
on_step = function(self, dtime) on_step = function(self, dtime)
if self.driver then if self.driver then
object_drive(self, dtime, 6, 0.5, true, "vehicles:missile_2", nil, nil, false) object_drive(self, dtime, 6, 0.5, true, "vehicles:missile_2", 1, nil, nil, false)
return false return false
end end
return true return true
@ -151,17 +232,61 @@ minetest.register_entity("vehicles:tank", {
minetest.register_entity("vehicles:turret", { minetest.register_entity("vehicles:turret", {
visual = "mesh", visual = "mesh",
mesh = "turret.b3d", mesh = "turret_gun.b3d",
textures = {"vehicles_tank.png"}, textures = {"vehicles_turret.png"},
velocity = 15, velocity = 15,
acceleration = -5, acceleration = -5,
stepheight = 1.5, stepheight = 1.5,
hp_max = 200, hp_max = 200,
physical = true, physical = true,
collisionbox = {-1, -0.6, -0.9, 1, 0.9, 0.9}, collisionbox = {-0.6, 0, -0.6, 0.6, 0.9, 0.6},
on_rightclick = function(self, clicker)
if self.driver and clicker == self.driver then
object_detach(self, clicker, {x=1, y=0, z=1})
elseif not self.driver then
object_attach(self, clicker, {x=0, y=5, z=4}, true, {x=0, y=2, z=4})
end
end,
on_step = function(self, dtime)
self.object:setvelocity({x=0, y=-1, z=0})
if self.driver then
object_turret(self, dtime, 1.5, "vehicles:bullet", 0.2)
return false
end
return true
end,
}) })
register_vehicle_spawner("vehicles:tank", "Tank", "vehicles_tank_inv.png") register_vehicle_spawner("vehicles:tank", "Tank", "vehicles_tank_inv.png")
register_vehicle_spawner("vehicles:turret", "Gun turret", "vehicles_turret_inv.png")
minetest.register_entity("vehicles:firetruck", {
visual = "mesh",
mesh = "firetruck.b3d",
textures = {"vehicles_firetruck.png"},
velocity = 15,
acceleration = -5,
stepheight = 1.5,
hp_max = 200,
physical = true,
collisionbox = {-1.1, 0, -1.1, 1.1, 1.9, 1.1},
on_rightclick = function(self, clicker)
if self.driver and clicker == self.driver then
object_detach(self, clicker, {x=1, y=0, z=1})
elseif not self.driver then
object_attach(self, clicker, {x=0, y=5, z=4}, false, {x=0, y=2, z=4})
end
end,
on_step = function(self, dtime)
if self.driver then
object_drive(self, dtime, 7, 0.5, true, "vehicles:water", 0.2, nil, nil, false)
return false
end
return true
end,
})
register_vehicle_spawner("vehicles:firetruck", "Fire truck", "vehicles_firetruck_inv.png")
minetest.register_entity("vehicles:ute", { minetest.register_entity("vehicles:ute", {
visual = "mesh", visual = "mesh",
@ -183,7 +308,7 @@ minetest.register_entity("vehicles:ute", {
clicker:set_detach() clicker:set_detach()
self.rider = false self.rider = false
elseif not self.driver then elseif not self.driver then
object_attach(self, clicker, {x=0, y=5, z=4}, {x=0, y=2, z=4}, {x=0, y=3, z=-72}) object_attach(self, clicker, {x=0, y=5, z=4}, false, {x=0, y=2, z=4})
end end
end, end,
on_activate = function(self) on_activate = function(self)
@ -237,7 +362,7 @@ minetest.register_entity("vehicles:ute2", {
clicker:set_detach() clicker:set_detach()
self.rider = false self.rider = false
elseif not self.driver then elseif not self.driver then
object_attach(self, clicker, {x=0, y=5, z=4}, {x=0, y=2, z=4}, {x=0, y=3, z=-72}) object_attach(self, clicker, {x=0, y=5, z=4}, false, {x=0, y=2, z=4})
end end
end, end,
on_activate = function(self) on_activate = function(self)
@ -254,6 +379,37 @@ minetest.register_entity("vehicles:ute2", {
register_vehicle_spawner("vehicles:ute2", "Ute (clean)", "vehicles_ute_inv.png") register_vehicle_spawner("vehicles:ute2", "Ute (clean)", "vehicles_ute_inv.png")
minetest.register_entity("vehicles:astonmaaton", {
visual = "mesh",
mesh = "astonmaaton.b3d",
textures = {"vehicles_astonmaaton.png"},
velocity = 15,
acceleration = -5,
stepheight = 1,
hp_max = 200,
physical = true,
collisionbox = {-1, 0, -1, 1.3, 1, 1},
on_rightclick = function(self, clicker)
if self.driver and clicker == self.driver then
object_detach(self, clicker, {x=1, y=0, z=1})
elseif not self.driver then
object_attach(self, clicker, {x=0, y=5, z=4}, false, {x=0, y=2, z=4})
end
end,
on_activate = function(self)
self.nitro = true
end,
on_step = function(self, dtime)
if self.driver then
object_drive_car(self, dtime, 14, 0.8, 5)
return false
end
return true
end,
})
register_vehicle_spawner("vehicles:astonmaaton", "Aston Maaton (white)", "vehicles_astonmaaton_inv.png")
minetest.register_entity("vehicles:nizzan", { minetest.register_entity("vehicles:nizzan", {
visual = "mesh", visual = "mesh",
mesh = "nizzan.b3d", mesh = "nizzan.b3d",
@ -268,7 +424,7 @@ minetest.register_entity("vehicles:nizzan", {
if self.driver and clicker == self.driver then if self.driver and clicker == self.driver then
object_detach(self, clicker, {x=1, y=0, z=1}) object_detach(self, clicker, {x=1, y=0, z=1})
elseif not self.driver then elseif not self.driver then
object_attach(self, clicker, {x=0, y=5, z=4}, {x=0, y=2, z=4}, {x=0, y=3, z=-72}) object_attach(self, clicker, {x=0, y=5, z=4}, false, {x=0, y=2, z=4})
end end
end, end,
on_activate = function(self) on_activate = function(self)
@ -316,7 +472,7 @@ minetest.register_entity("vehicles:nizzan2", {
if self.driver and clicker == self.driver then if self.driver and clicker == self.driver then
object_detach(self, clicker, {x=1, y=0, z=1}) object_detach(self, clicker, {x=1, y=0, z=1})
elseif not self.driver then elseif not self.driver then
object_attach(self, clicker, {x=0, y=5, z=4}, {x=0, y=2, z=4}, {x=0, y=3, z=-72}) object_attach(self, clicker, {x=0, y=5, z=4}, false, {x=0, y=2, z=4})
end end
end, end,
on_activate = function(self) on_activate = function(self)
@ -364,7 +520,7 @@ minetest.register_entity("vehicles:lambogoni", {
if self.driver and clicker == self.driver then if self.driver and clicker == self.driver then
object_detach(self, clicker, {x=1, y=0, z=1}) object_detach(self, clicker, {x=1, y=0, z=1})
elseif not self.driver then elseif not self.driver then
object_attach(self, clicker, {x=0, y=5, z=4}, {x=0, y=2, z=4}, {x=0, y=3, z=-72}) object_attach(self, clicker, {x=0, y=5, z=4}, false, {x=0, y=2, z=4})
end end
end, end,
on_activate = function(self) on_activate = function(self)
@ -395,7 +551,7 @@ minetest.register_entity("vehicles:masda", {
if self.driver and clicker == self.driver then if self.driver and clicker == self.driver then
object_detach(self, clicker, {x=1, y=0, z=1}) object_detach(self, clicker, {x=1, y=0, z=1})
elseif not self.driver then elseif not self.driver then
object_attach(self, clicker, {x=0, y=5, z=4}, {x=0, y=2, z=4}, {x=0, y=3, z=-72}) object_attach(self, clicker, {x=0, y=5, z=4}, false, {x=0, y=2, z=4})
end end
end, end,
on_activate = function(self) on_activate = function(self)
@ -426,7 +582,7 @@ minetest.register_entity("vehicles:musting", {
if self.driver and clicker == self.driver then if self.driver and clicker == self.driver then
object_detach(self, clicker, {x=1, y=0, z=1}) object_detach(self, clicker, {x=1, y=0, z=1})
elseif not self.driver then elseif not self.driver then
object_attach(self, clicker, {x=0, y=5, z=4}, {x=0, y=2, z=4}, {x=0, y=3, z=-72}) object_attach(self, clicker, {x=0, y=5, z=4}, false, {x=0, y=2, z=4})
end end
end, end,
on_activate = function(self) on_activate = function(self)
@ -457,7 +613,7 @@ minetest.register_entity("vehicles:musting2", {
if self.driver and clicker == self.driver then if self.driver and clicker == self.driver then
object_detach(self, clicker, {x=1, y=0, z=1}) object_detach(self, clicker, {x=1, y=0, z=1})
elseif not self.driver then elseif not self.driver then
object_attach(self, clicker, {x=0, y=5, z=4}, {x=0, y=2, z=4}, {x=0, y=3, z=-72}) object_attach(self, clicker, {x=0, y=5, z=4}, false, {x=0, y=2, z=4})
end end
end, end,
on_activate = function(self) on_activate = function(self)
@ -474,6 +630,90 @@ minetest.register_entity("vehicles:musting2", {
register_vehicle_spawner("vehicles:musting2", "Musting (white)", "vehicles_musting_inv.png") register_vehicle_spawner("vehicles:musting2", "Musting (white)", "vehicles_musting_inv.png")
minetest.register_entity("vehicles:fewawi", {
visual = "mesh",
mesh = "fewawi.b3d",
textures = {"vehicles_fewawi.png"},
velocity = 15,
acceleration = -5,
stepheight = 1,
hp_max = 200,
physical = true,
collisionbox = {-1, 0, -1, 1.3, 1, 1},
on_rightclick = function(self, clicker)
local ctrl = clicker:get_player_control()
if ctrl.sneak then
if not self.lights then
self.object:set_properties({textures = {"vehicles_fewawi_lights.png"},})
self.lights = true
else
self.object:set_properties({textures = {"vehicles_fewawi.png"},})
self.lights = false
end
else
if self.driver and clicker == self.driver then
object_detach(self, clicker, {x=1, y=0, z=1})
elseif not self.driver then
object_attach(self, clicker, {x=0, y=5, z=4}, false, {x=0, y=2, z=4})
end
end
end,
on_activate = function(self)
self.nitro = true
end,
on_step = function(self, dtime)
if self.driver then
object_drive_car(self, dtime, 15, 0.95, 4)
return false
end
return true
end,
})
register_vehicle_spawner("vehicles:fewawi", "Fewawi (red)", "vehicles_fewawi_inv.png")
minetest.register_entity("vehicles:fewawi2", {
visual = "mesh",
mesh = "fewawi.b3d",
textures = {"vehicles_fewawi2.png"},
velocity = 15,
acceleration = -5,
stepheight = 1,
hp_max = 200,
physical = true,
collisionbox = {-1, 0, -1, 1.3, 1, 1},
on_rightclick = function(self, clicker)
local ctrl = clicker:get_player_control()
if ctrl.sneak then
if not self.lights then
self.object:set_properties({textures = {"vehicles_fewawi_lights2.png"},})
self.lights = true
else
self.object:set_properties({textures = {"vehicles_fewawi2.png"},})
self.lights = false
end
else
if self.driver and clicker == self.driver then
object_detach(self, clicker, {x=1, y=0, z=1})
elseif not self.driver then
object_attach(self, clicker, {x=0, y=5, z=4}, false, {x=0, y=2, z=4})
end
end
end,
on_activate = function(self)
self.nitro = true
end,
on_step = function(self, dtime)
if self.driver then
object_drive_car(self, dtime, 15, 0.95, 4)
return false
end
return true
end,
})
register_vehicle_spawner("vehicles:fewawi2", "Fewawi (blue)", "vehicles_fewawi_inv2.png")
minetest.register_entity("vehicles:pooshe", { minetest.register_entity("vehicles:pooshe", {
visual = "mesh", visual = "mesh",
mesh = "pooshe.b3d", mesh = "pooshe.b3d",
@ -488,7 +728,7 @@ minetest.register_entity("vehicles:pooshe", {
if self.driver and clicker == self.driver then if self.driver and clicker == self.driver then
object_detach(self, clicker, {x=1, y=0, z=1}) object_detach(self, clicker, {x=1, y=0, z=1})
elseif not self.driver then elseif not self.driver then
object_attach(self, clicker, {x=0, y=5, z=4}, {x=0, y=2, z=4}, {x=0, y=3, z=-72}) object_attach(self, clicker, {x=0, y=5, z=4}, false, {x=0, y=2, z=4})
end end
end, end,
on_activate = function(self) on_activate = function(self)
@ -519,7 +759,7 @@ minetest.register_entity("vehicles:pooshe2", {
if self.driver and clicker == self.driver then if self.driver and clicker == self.driver then
object_detach(self, clicker, {x=1, y=0, z=1}) object_detach(self, clicker, {x=1, y=0, z=1})
elseif not self.driver then elseif not self.driver then
object_attach(self, clicker, {x=0, y=5, z=4}, {x=0, y=2, z=4}, {x=0, y=3, z=-72}) object_attach(self, clicker, {x=0, y=5, z=4}, false, {x=0, y=2, z=4})
end end
end, end,
on_activate = function(self) on_activate = function(self)
@ -550,7 +790,7 @@ minetest.register_entity("vehicles:masda2", {
if self.driver and clicker == self.driver then if self.driver and clicker == self.driver then
object_detach(self, clicker, {x=1, y=0, z=1}) object_detach(self, clicker, {x=1, y=0, z=1})
elseif not self.driver then elseif not self.driver then
object_attach(self, clicker, {x=0, y=5, z=4}, {x=0, y=2, z=4}, {x=0, y=3, z=-72}) object_attach(self, clicker, {x=0, y=5, z=4}, false, {x=0, y=2, z=4})
end end
end, end,
on_activate = function(self) on_activate = function(self)
@ -558,7 +798,7 @@ minetest.register_entity("vehicles:masda2", {
end, end,
on_step = function(self, dtime) on_step = function(self, dtime)
if self.driver then if self.driver then
object_drive_car(self, dtime, 15, 0.95, 4) object_drive_car(self, dtime, 15, 0.85, 4)
return false return false
end end
return true return true
@ -567,6 +807,34 @@ minetest.register_entity("vehicles:masda2", {
register_vehicle_spawner("vehicles:masda2", "Masda (orange)", "vehicles_masda_inv2.png") register_vehicle_spawner("vehicles:masda2", "Masda (orange)", "vehicles_masda_inv2.png")
minetest.register_entity("vehicles:boat", {
visual = "mesh",
mesh = "boat.b3d",
textures = {"vehicles_boat.png"},
velocity = 15,
acceleration = -5,
stepheight = 1,
hp_max = 200,
physical = true,
collisionbox = {-1, 0.2, -1, 1.3, 1, 1},
on_rightclick = function(self, clicker)
if self.driver and clicker == self.driver then
object_detach(self, clicker, {x=1, y=0, z=1})
elseif not self.driver then
object_attach(self, clicker, {x=0, y=5, z=4}, false, {x=0, y=2, z=4})
end
end,
on_step = function(self, dtime)
if self.driver then
object_float(self, dtime, 10, 0.85)
return false
end
return true
end,
})
register_vehicle_spawner("vehicles:boat", "Speedboat", "vehicles_boat_inv.png", true)
minetest.register_entity("vehicles:jet", { minetest.register_entity("vehicles:jet", {
visual = "mesh", visual = "mesh",
@ -578,20 +846,20 @@ minetest.register_entity("vehicles:jet", {
animation_speed = 5, animation_speed = 5,
physical = true, physical = true,
animations = { animations = {
gear = { x=1, x=1}, gear = {x=1, y=1},
nogear = { x=10, x=10}, nogear = {x=10, y=10},
}, },
collisionbox = {-1, -0.9, -0.9, 1, 0.9, 0.9}, collisionbox = {-1, -0.9, -0.9, 1, 0.9, 0.9},
on_rightclick = function(self, clicker) on_rightclick = function(self, clicker)
if self.driver and clicker == self.driver then if self.driver and clicker == self.driver then
object_detach(self, clicker, {x=1, y=0, z=1}) object_detach(self, clicker, {x=1, y=0, z=1})
elseif not self.driver then elseif not self.driver then
object_attach(self, clicker, {x=0, y=5, z=5}, {x=0, y=3, z=4}) object_attach(self, clicker, {x=0, y=5, z=5}, false, {x=0, y=3, z=4})
end end
end, end,
on_step = function(self, dtime) on_step = function(self, dtime)
if self.driver then if self.driver then
object_fly(self, dtime, 15, 0.1, 0.95, true, "vehicles:missile_2", { x=1, y=1}, { x=10, y=10}) object_fly(self, dtime, 14, 0.2, 0.95, true, "vehicles:missile_2", 1, {x=1, y=1}, {x=10, y=10})
return false return false
end end
return true return true
@ -600,6 +868,47 @@ minetest.register_entity("vehicles:jet", {
register_vehicle_spawner("vehicles:jet", "Jet", "vehicles_jet_inv.png") register_vehicle_spawner("vehicles:jet", "Jet", "vehicles_jet_inv.png")
minetest.register_entity("vehicles:plane", {
visual = "mesh",
mesh = "plane.b3d",
textures = {"vehicles_plane.png"},
velocity = 15,
acceleration = -5,
hp_max = 200,
animation_speed = 5,
physical = true,
animations = {
fly = { x=1, y=9},
nofly = { x=1, y=1},
},
collisionbox = {-1.1, 0, -1, 1, 1.9, 1.1},
on_rightclick = function(self, clicker)
if self.driver and clicker == self.driver then
object_detach(self, clicker, {x=1, y=0, z=1})
elseif not self.driver then
object_attach(self, clicker, {x=0, y=8, z=3}, false, {x=0, y=9, z=0})
end
end,
on_step = function(self, dtime)
if self.anim and not self.driver then
self.object:set_animation({x=1, y=1}, 5, 0)
end
if self.driver then
object_fly(self, dtime, 10, 0.1, 0.95, false, nil, "nofly", "fly")
if not self.anim then
self.object:set_animation({x=1, y=9}, 20, 0)
self.anim = true
end
return false
else
self.anim = false
end
return true
end,
})
register_vehicle_spawner("vehicles:plane", "Plane", "vehicles_plane_inv.png")
minetest.register_entity("vehicles:parachute", { minetest.register_entity("vehicles:parachute", {
visual = "mesh", visual = "mesh",
mesh = "parachute.b3d", mesh = "parachute.b3d",
@ -655,71 +964,72 @@ minetest.register_tool("vehicles:backpack", {
--wings --wings
-- minetest.register_entity("vehicles:wing_glider", { --currently doesn't work very well
-- visual = "mesh", minetest.register_entity("vehicles:wing_glider", {
-- mesh = "wings.b3d", visual = "mesh",
-- textures = {"vehicles_wings.png"}, mesh = "wings.b3d",
-- velocity = 15, textures = {"vehicles_wings.png"},
-- acceleration = -5, velocity = 15,
-- hp_max = 2, acceleration = -5,
-- physical = true, hp_max = 2,
-- collisionbox = {-0.5, -0.1, -0.5, 0.5, 0.1, 0.5}, physical = true,
-- on_step = function(self, dtime) collisionbox = {-0.5, -0.1, -0.5, 0.5, 0.1, 0.5},
-- if self.driver then on_step = function(self, dtime)
-- local dir = self.driver:get_look_dir(); if self.driver then
-- local velo = self.object:getvelocity(); local dir = self.driver:get_look_dir();
-- local vec = {x=dir.x*5,y=(dir.y*5)-0.5,z=dir.z*5} local velo = self.object:getvelocity();
-- local yaw = self.driver:get_look_yaw(); local vec = {x=dir.x*5,y=(-dir.y*2*velo.y/4-2.5)+dir.y*3,z=dir.z*5}
-- self.object:setyaw(yaw+math.pi/2) local yaw = self.driver:get_look_yaw();
-- self.object:setvelocity(vec) self.object:setyaw(yaw+math.pi/2)
-- self.driver:set_animation({x=162, y=167}, 0, 0) self.object:setvelocity(vec)
-- return false self.driver:set_animation({x=162, y=167}, 0, 0)
-- end return false
-- return true end
-- end, return true
-- }) end,
})
-- minetest.register_tool("vehicles:wings", { minetest.register_tool("vehicles:wings", {
-- description = "Wings", description = "Wings",
-- inventory_image = "vehicles_backpack.png", inventory_image = "vehicles_backpack.png",
-- wield_scale = {x = 1.5, y = 1.5, z = 1}, wield_scale = {x = 1.5, y = 1.5, z = 1},
-- tool_capabilities = { tool_capabilities = {
-- full_punch_interval = 0.7, full_punch_interval = 0.7,
-- max_drop_level=1, max_drop_level=1,
-- groupcaps={ groupcaps={
-- snappy={times={[1]=2.0, [2]=1.00, [3]=0.35}, uses=30, maxlevel=3}, snappy={times={[1]=2.0, [2]=1.00, [3]=0.35}, uses=30, maxlevel=3},
-- }, },
-- damage_groups = {fleshy=1}, damage_groups = {fleshy=1},
-- }, },
-- on_use = function(item, placer, pointed_thing) on_use = function(item, placer, pointed_thing)
-- local dir = placer:get_look_dir(); local dir = placer:get_look_dir();
-- local playerpos = placer:getpos(); local playerpos = placer:getpos();
-- local objs = minetest.get_objects_inside_radius({x=playerpos.x,y=playerpos.y,z=playerpos.z}, 2) local objs = minetest.get_objects_inside_radius({x=playerpos.x,y=playerpos.y,z=playerpos.z}, 2)
-- for k, obj2 in pairs(objs) do for k, obj2 in pairs(objs) do
-- if obj2:get_luaentity() ~= nil then if obj2:get_luaentity() ~= nil then
-- if obj2:get_luaentity().name == "vehicles:wings" then if obj2:get_luaentity().name == "vehicles:wings" then
-- local wings = false local wings = false
-- end end
-- end end
-- end end
-- if wings then if wings then
-- object_detach(obj2:get_luaentity(), placer, {x=1, y=0, z=1}) object_detach(obj2:get_luaentity(), placer, {x=1, y=0, z=1})
-- placer:set_properties({ placer:set_properties({
-- visual_size = {x=1, y=1}, visual_size = {x=1, y=1},
-- }) })
-- else else
-- 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:wing_glider") 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:wing_glider")
-- local entity = obj:get_luaentity() local entity = obj:get_luaentity()
-- placer:set_attach(entity.object, "", {x=0,y=-5,z=0}, {x=0,y=0,z=0}) placer:set_attach(entity.object, "", {x=0,y=-5,z=0}, {x=0,y=0,z=0})
-- entity.driver = placer entity.driver = placer
-- placer:set_properties({ placer:set_properties({
-- visual_size = {x=1, y=-1}, visual_size = {x=1, y=-1},
-- }) })
-- end end
-- item:add_wear(500) item:add_wear(500)
-- return item return item
-- end, end,
-- }) })
minetest.register_tool("vehicles:rc", { minetest.register_tool("vehicles:rc", {
description = "Rc", description = "Rc",
@ -773,6 +1083,13 @@ vehicles.register_simplenode("window", "Building glass", "vehicles_window.png",
vehicles.register_simplenode("stripes", "Hazard stipes", "vehicles_stripes.png", 10) vehicles.register_simplenode("stripes", "Hazard stipes", "vehicles_stripes.png", 10)
vehicles.register_simplenode("lights", "Tunnel lights", "vehicles_lights.png", 20) vehicles.register_simplenode("lights", "Tunnel lights", "vehicles_lights.png", 20)
stairs.register_stair_and_slab("road_surface", "vehicles:road",
{cracky = 1},
{"vehicles_road.png"},
"Road Surface Stair",
"Road Surface Slab",
default.node_sound_stone_defaults())
minetest.register_node("vehicles:neon_arrow", { minetest.register_node("vehicles:neon_arrow", {
description = "neon arrows (left)", description = "neon arrows (left)",
drawtype = "signlike", drawtype = "signlike",
@ -1025,6 +1342,7 @@ minetest.register_node("vehicles:flag", {
groups = {cracky=3,dig_immediate=3}, groups = {cracky=3,dig_immediate=3},
}) })
minetest.register_node("vehicles:tyres", { minetest.register_node("vehicles:tyres", {
description = "tyre stack", description = "tyre stack",
tiles = { tiles = {

BIN
models/astonmaaton.b3d Normal file

Binary file not shown.

BIN
models/boat.b3d Normal file

Binary file not shown.

BIN
models/fewawi.b3d Normal file

Binary file not shown.

BIN
models/firetruck.b3d Normal file

Binary file not shown.

BIN
models/plane.b3d Normal file

Binary file not shown.

BIN
models/turret_gun.b3d Normal file

Binary file not shown.

Binary file not shown.

After

Width:  |  Height:  |  Size: 49 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 458 B

BIN
textures/vehicles_boat.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 344 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 155 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 27 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 28 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 388 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 427 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 28 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 29 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 38 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 485 B

BIN
textures/vehicles_plane.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 10 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 322 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 440 B

BIN
textures/vehicles_water.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 616 B