Initial commit
499
api.lua
Normal file
@ -0,0 +1,499 @@
|
|||||||
|
--vehicles/mounts api by, based on lib_mount(see below)
|
||||||
|
|
||||||
|
--License of lib_mount:
|
||||||
|
-- Minetest mod: lib_mount
|
||||||
|
-- =======================
|
||||||
|
-- by blert2112
|
||||||
|
|
||||||
|
-- Based on the Boats mod by PilzAdam.
|
||||||
|
|
||||||
|
|
||||||
|
-- -----------------------------------------------------------
|
||||||
|
-- -----------------------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
|
-- Minetest Game mod: boats
|
||||||
|
-- ========================
|
||||||
|
-- by PilzAdam
|
||||||
|
|
||||||
|
-- License of source code:
|
||||||
|
-- -----------------------
|
||||||
|
-- WTFPL
|
||||||
|
|
||||||
|
|
||||||
|
--from lib_mount (required by new functions)
|
||||||
|
|
||||||
|
|
||||||
|
local mobs_redo = false
|
||||||
|
if mobs.mod and mobs.mod == "redo" then
|
||||||
|
mobs_redo = true
|
||||||
|
end
|
||||||
|
|
||||||
|
local function is_group(pos, group)
|
||||||
|
local nn = minetest.get_node(pos).name
|
||||||
|
return minetest.get_item_group(nn, group) ~= 0
|
||||||
|
end
|
||||||
|
|
||||||
|
local function force_detach(player)
|
||||||
|
local attached_to = player:get_attach()
|
||||||
|
if attached_to and attached_to:get_luaentity() then
|
||||||
|
local entity = attached_to:get_luaentity()
|
||||||
|
if entity.driver then
|
||||||
|
if entity ~= nil then entity.driver = nil end
|
||||||
|
end
|
||||||
|
player:set_detach()
|
||||||
|
end
|
||||||
|
default.player_attached[player:get_player_name()] = false
|
||||||
|
player:set_eye_offset({x=0, y=0, z=0}, {x=0, y=0, z=0})
|
||||||
|
end
|
||||||
|
|
||||||
|
function object_attach(entity, player, attach_at, eye_offset)
|
||||||
|
eye_offset = eye_offset or {x=0, y=0, z=0}
|
||||||
|
force_detach(player)
|
||||||
|
entity.driver = player
|
||||||
|
entity.loaded = true
|
||||||
|
player:set_attach(entity.object, "", attach_at, {x=0, y=0, z=0})
|
||||||
|
|
||||||
|
player:set_properties({visual_size = {x=1, y=1}})
|
||||||
|
|
||||||
|
player:set_eye_offset(eye_offset, {x=0, y=2, z=-40})
|
||||||
|
default.player_attached[player:get_player_name()] = true
|
||||||
|
minetest.after(0.2, function()
|
||||||
|
default.player_set_animation(player, "sit" , 30)
|
||||||
|
end)
|
||||||
|
entity.object:setyaw(player:get_look_yaw() - math.pi / 2)
|
||||||
|
end
|
||||||
|
|
||||||
|
function object_detach(entity, player, offset)
|
||||||
|
entity.driver = nil
|
||||||
|
entity.object:setvelocity({x=0, y=0, z=0})
|
||||||
|
player:set_detach()
|
||||||
|
default.player_attached[player:get_player_name()] = false
|
||||||
|
default.player_set_animation(player, "stand" , 30)
|
||||||
|
player:set_eye_offset({x=0, y=0, z=0}, {x=0, y=0, z=0})
|
||||||
|
local pos = player:getpos()
|
||||||
|
pos = {x = pos.x + offset.x, y = pos.y + 0.2 + offset.y, z = pos.z + offset.z}
|
||||||
|
minetest.after(0.1, function()
|
||||||
|
player:setpos(pos)
|
||||||
|
end)
|
||||||
|
end
|
||||||
|
-------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
|
minetest.register_on_leaveplayer(function(player)
|
||||||
|
force_detach(player)
|
||||||
|
end)
|
||||||
|
|
||||||
|
minetest.register_on_shutdown(function()
|
||||||
|
local players = minetest.get_connected_players()
|
||||||
|
for i = 1,#players do
|
||||||
|
force_detach(players[i])
|
||||||
|
end
|
||||||
|
end)
|
||||||
|
|
||||||
|
minetest.register_on_dieplayer(function(player)
|
||||||
|
force_detach(player)
|
||||||
|
return true
|
||||||
|
end)
|
||||||
|
|
||||||
|
-------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
--mixed code(from this mod and lib_mount)
|
||||||
|
|
||||||
|
function object_drive(entity, dtime, speed, decell, shoots, arrow, moving_anim, stand_anim, jumps)
|
||||||
|
local ctrl = entity.driver:get_player_control()
|
||||||
|
local velo = entity.object:getvelocity()
|
||||||
|
local dir = entity.driver:get_look_dir();
|
||||||
|
local vec_forward = {x=dir.x*speed,y=velo.y+1*-2,z=dir.z*speed}
|
||||||
|
local vec_backward = {x=-dir.x*speed,y=velo.y+1*-2,z=-dir.z*speed}
|
||||||
|
local vec_stop = {x=velo.x*decell,y=velo.y+1*-2,z=velo.z*decell}
|
||||||
|
local yaw = entity.driver:get_look_yaw();
|
||||||
|
if ctrl.up then
|
||||||
|
entity.object:setyaw(yaw+math.pi+math.pi/2)
|
||||||
|
entity.object:setvelocity(vec_forward)
|
||||||
|
elseif ctrl.down then
|
||||||
|
entity.object:setyaw(yaw+math.pi+math.pi/2)
|
||||||
|
entity.object:setvelocity(vec_backward)
|
||||||
|
elseif not ctrl.down or ctrl.up then
|
||||||
|
entity.object:setyaw(yaw+math.pi+math.pi/2)
|
||||||
|
entity.object:setvelocity(vec_stop)
|
||||||
|
end
|
||||||
|
if ctrl.sneak and shoots and entity.loaded then
|
||||||
|
entity.loaded = false
|
||||||
|
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 vec = {x=dir.x*9,y=dir.y*9,z=dir.z*9}
|
||||||
|
local yaw = entity.driver:get_look_yaw();
|
||||||
|
obj:setyaw(yaw+math.pi/2)
|
||||||
|
obj:setvelocity(vec)
|
||||||
|
minetest.after(1, function()
|
||||||
|
entity.loaded = true
|
||||||
|
end)
|
||||||
|
end
|
||||||
|
--lib_mount animation
|
||||||
|
if velo.x == 0 and velo.y == 0 and velo.z == 0 then
|
||||||
|
if stand_anim and stand_anim ~= nil and mobs_redo == true then
|
||||||
|
set_animation(entity, stand_anim)
|
||||||
|
end
|
||||||
|
return
|
||||||
|
end
|
||||||
|
if moving_anim and moving_anim ~= nil then
|
||||||
|
set_animation(entity, moving_anim)
|
||||||
|
end
|
||||||
|
--jumping not working
|
||||||
|
-- local jumps = jumps or false
|
||||||
|
-- if jumps == true and ctrl.jump then
|
||||||
|
-- local xvel = entity.object:getvelocity().x
|
||||||
|
-- local zvel = entity.object:getvelocity().z
|
||||||
|
-- local yvel = entity.object:getvelocity().y
|
||||||
|
-- local vel = {x=xvel,y=10,z=zvel}
|
||||||
|
-- entity.object:setvelocity(vel)
|
||||||
|
-- minetest.after(1.5, function()
|
||||||
|
-- local xvel = entity.object:getvelocity().x
|
||||||
|
-- local zvel = entity.object:getvelocity().z
|
||||||
|
-- local yvel = entity.object:getvelocity().y
|
||||||
|
-- local vel = {x=xvel,y=-10,z=zvel}
|
||||||
|
-- entity.object:setvelocity(vel)
|
||||||
|
-- end)
|
||||||
|
-- end
|
||||||
|
end
|
||||||
|
|
||||||
|
function object_drive_simple(entity, dtime, speed, decell)
|
||||||
|
local ctrl = entity.driver:get_player_control()
|
||||||
|
local velo = entity.object:getvelocity()
|
||||||
|
local dir = entity.driver:get_look_dir();
|
||||||
|
local vec_forward = {x=dir.x*speed,y=velo.y+1*-2,z=dir.z*speed}
|
||||||
|
local vec_backward = {x=-dir.x*speed,y=velo.y+1*-2,z=-dir.z*speed}
|
||||||
|
local vec_stop = {x=velo.x*decell,y=velo.y+1*-2,z=velo.z*decell}
|
||||||
|
local yaw = entity.driver:get_look_yaw();
|
||||||
|
if ctrl.up then
|
||||||
|
entity.object:setyaw(yaw+math.pi+math.pi/2)
|
||||||
|
entity.object:setvelocity(vec_forward)
|
||||||
|
elseif ctrl.down then
|
||||||
|
entity.object:setyaw(yaw+math.pi+math.pi/2)
|
||||||
|
entity.object:setvelocity(vec_backward)
|
||||||
|
elseif not ctrl.down or ctrl.up then
|
||||||
|
entity.object:setyaw(yaw+math.pi+math.pi/2)
|
||||||
|
entity.object:setvelocity(vec_stop)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
function object_turret(entity, dtime, arrow, attack_anim, stand_anim)
|
||||||
|
local ctrl = entity.driver:get_player_control()
|
||||||
|
local pos = entity.driver:getpos();
|
||||||
|
local yaw = entity.driver:get_look_yaw();
|
||||||
|
entity.object:setpos(pos)
|
||||||
|
entity.object:setyaw(yaw+math.pi+math.pi/2)
|
||||||
|
if ctrl.sneak and entity.loaded then
|
||||||
|
entity.loaded = false
|
||||||
|
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 yaw = entity.driver:get_look_yaw();
|
||||||
|
local vec = {x=dir.x*9, y=dir.y*9, z=dir.z*9}
|
||||||
|
obj:setyaw(yaw+math.pi/2)
|
||||||
|
set_animation(entity, attack_anim)
|
||||||
|
minetest.after(1, function()
|
||||||
|
entity.loaded = true
|
||||||
|
end)
|
||||||
|
else
|
||||||
|
set_animation(entity, stand_anim_anim)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
function object_fly(entity, dtime, speed, accel, decell, shoots, arrow, moving_anim, stand_anim)
|
||||||
|
local ctrl = entity.driver:get_player_control()
|
||||||
|
local dir = entity.driver:get_look_dir();
|
||||||
|
local velo = entity.object:getvelocity()
|
||||||
|
local vec_forward = {x=dir.x*speed,y=dir.y*speed+3,z=dir.z*speed}
|
||||||
|
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 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 yaw = entity.driver:get_look_yaw();
|
||||||
|
if ctrl.up then
|
||||||
|
entity.object:setyaw(yaw+math.pi+math.pi/2)
|
||||||
|
entity.object:setvelocity(vec_forward)
|
||||||
|
entity.object:setacceleration(acc_forward)
|
||||||
|
elseif ctrl.down then
|
||||||
|
entity.object:setyaw(yaw+math.pi+math.pi/2)
|
||||||
|
entity.object:setvelocity(vec_backward)
|
||||||
|
entity.object:setacceleration(acc_backward)
|
||||||
|
elseif not ctrl.down or ctrl.up then
|
||||||
|
entity.object:setyaw(yaw+math.pi+math.pi/2)
|
||||||
|
entity.object:setvelocity(vec_stop)
|
||||||
|
entity.object:setacceleration({x=0, y=-4.5, z=0})
|
||||||
|
end
|
||||||
|
if ctrl.sneak and shoots and entity.loaded then
|
||||||
|
entity.loaded = false
|
||||||
|
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 vec = {x=dir.x*9,y=dir.y*9,z=dir.z*9}
|
||||||
|
obj:setyaw(yaw+math.pi/2)
|
||||||
|
obj:setvelocity(vec)
|
||||||
|
minetest.after(1, function()
|
||||||
|
entity.loaded = true
|
||||||
|
end)
|
||||||
|
end
|
||||||
|
--lib_mount animation
|
||||||
|
if velo.x == 0 and velo.y == 0 and velo.z == 0 then
|
||||||
|
if stand_anim and stand_anim ~= nilthen then
|
||||||
|
set_animation(entity, stand_anim)
|
||||||
|
end
|
||||||
|
return
|
||||||
|
end
|
||||||
|
if moving_anim and moving_anim ~= nil then
|
||||||
|
set_animation(entity, moving_anim)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
function object_fly_2(entity, dtime, speed, accel, decell, shoots, arrow, moving_anim, stand_anim)
|
||||||
|
local ctrl = entity.driver:get_player_control()
|
||||||
|
local dir = entity.driver:get_look_dir();
|
||||||
|
local yvel = entity.object:getvelocity().y
|
||||||
|
local vec_forward = {x=dir.x*speed,y=yvel,z=dir.z*speed}
|
||||||
|
local acc_forward = {x=dir.x*accel/2,y=yvel,z=dir.z*accel/2}
|
||||||
|
local vec_backward = {x=-dir.x*speed,y=yvel,z=-dir.z*speed}
|
||||||
|
local acc_backward = {x=dir.x*accel/2,y=yvel,z=dir.z*accel/2}
|
||||||
|
local vec_stop = {x=entity.object:getvelocity().x*decell, y=entity.object:getvelocity().y, z=entity.object:getvelocity().z*decell}
|
||||||
|
local vec_rise = {x=entity.object:getvelocity().x, y=speed*accel, z=entity.object:getvelocity().z}
|
||||||
|
local yaw = entity.driver:get_look_yaw();
|
||||||
|
if ctrl.up then
|
||||||
|
entity.object:setyaw(yaw+math.pi+math.pi/2)
|
||||||
|
entity.object:setvelocity(vec_forward)
|
||||||
|
entity.object:setacceleration(acc_forward)
|
||||||
|
elseif ctrl.down then
|
||||||
|
entity.object:setyaw(yaw+math.pi+math.pi/2)
|
||||||
|
entity.object:setvelocity(vec_backward)
|
||||||
|
entity.object:setacceleration(acc_backward)
|
||||||
|
elseif ctrl.jump then
|
||||||
|
entity.object:setyaw(yaw+math.pi+math.pi/2)
|
||||||
|
entity.object:setvelocity(vec_rise)
|
||||||
|
elseif not ctrl.down or ctrl.up or ctrl.jump then
|
||||||
|
entity.object:setyaw(yaw+math.pi+math.pi/2)
|
||||||
|
entity.object:setvelocity(vec_stop)
|
||||||
|
entity.object:setacceleration({x=0, y=-4.5, z=0})
|
||||||
|
end
|
||||||
|
if ctrl.sneak and shoots and entity.loaded then
|
||||||
|
entity.loaded = false
|
||||||
|
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 vec = {x=dir.x*9,y=dir.y*9,z=dir.z*9}
|
||||||
|
local yaw = entity.driver:get_look_yaw();
|
||||||
|
obj:setyaw(yaw+math.pi/2)
|
||||||
|
obj:setvelocity(vec)
|
||||||
|
minetest.after(1, function()
|
||||||
|
entity.loaded = true
|
||||||
|
end)
|
||||||
|
end
|
||||||
|
--lib_mount animation
|
||||||
|
local velo = entity.object:getvelocity()
|
||||||
|
if velo.x == 0 and velo.y == 0 and velo.z == 0 then
|
||||||
|
if stand_anim and stand_anim ~= nilthen then
|
||||||
|
set_animation(entity, stand_anim)
|
||||||
|
end
|
||||||
|
entity.object:setpos(entity.object:getpos())
|
||||||
|
return
|
||||||
|
end
|
||||||
|
if moving_anim and moving_anim ~= nil then
|
||||||
|
set_animation(entity, moving_anim)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
function object_glide(entity, dtime, speed, decell, gravity, moving_anim, stand_anim)
|
||||||
|
local ctrl = entity.driver:get_player_control()
|
||||||
|
local dir = entity.driver:get_look_dir();
|
||||||
|
local velo = entity.object:getvelocity();
|
||||||
|
local vec_glide = {x=dir.x*speed*decell, y=velo.y, z=dir.z*speed*decell}
|
||||||
|
local yaw = entity.driver:get_look_yaw();
|
||||||
|
if not ctrl.sneak then
|
||||||
|
entity.object:setyaw(yaw+math.pi+math.pi/2)
|
||||||
|
entity.object:setvelocity(vec_glide)
|
||||||
|
entity.object:setacceleration({x=0, y=gravity, z=0})
|
||||||
|
end
|
||||||
|
if ctrl.sneak then
|
||||||
|
local vec = {x=0,y=gravity*15,z=0}
|
||||||
|
local yaw = entity.driver:get_look_yaw();
|
||||||
|
entity.object:setyaw(yaw+math.pi+math.pi/2)
|
||||||
|
entity.object:setvelocity(vec)
|
||||||
|
end
|
||||||
|
if velo.y == 0 then
|
||||||
|
local pos = entity.object:getpos()
|
||||||
|
for dx=-1,1 do
|
||||||
|
for dy=-1,1 do
|
||||||
|
for dz=-1,1 do
|
||||||
|
local p = {x=pos.x+dx, y=pos.y-1, 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 ~= "massdestruct:parachute" and n ~= "air" then
|
||||||
|
local pos = entity.object:getpos()
|
||||||
|
entity.object:remove()
|
||||||
|
return
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
--lib_mount animation
|
||||||
|
if velo.x == 0 and velo.y == 0 and velo.z == 0 then
|
||||||
|
if stand_anim and stand_anim ~= nilthen then
|
||||||
|
set_animation(entity, stand_anim)
|
||||||
|
end
|
||||||
|
return
|
||||||
|
end
|
||||||
|
if moving_anim and moving_anim ~= nil then
|
||||||
|
set_animation(entity, moving_anim)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
--lib_mount (not required by new functions)
|
||||||
|
|
||||||
|
|
||||||
|
local function is_group(pos, group)
|
||||||
|
local nn = minetest.get_node(pos).name
|
||||||
|
return minetest.get_item_group(nn, group) ~= 0
|
||||||
|
end
|
||||||
|
|
||||||
|
local function get_sign(i)
|
||||||
|
i = i or 0
|
||||||
|
if i == 0 then
|
||||||
|
return 0
|
||||||
|
else
|
||||||
|
return i / math.abs(i)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
local function get_velocity(v, yaw, y)
|
||||||
|
local x = -math.sin(yaw) * v
|
||||||
|
local z = math.cos(yaw) * v
|
||||||
|
return {x = x, y = y, z = z}
|
||||||
|
end
|
||||||
|
|
||||||
|
local function get_v(v)
|
||||||
|
return math.sqrt(v.x ^ 2 + v.z ^ 2)
|
||||||
|
end
|
||||||
|
|
||||||
|
lib_mount = {}
|
||||||
|
|
||||||
|
function lib_mount.attach(entity, player, attach_at, eye_offset)
|
||||||
|
eye_offset = eye_offset or {x=0, y=0, z=0}
|
||||||
|
force_detach(player)
|
||||||
|
entity.driver = player
|
||||||
|
player:set_attach(entity.object, "", attach_at, {x=0, y=0, z=0})
|
||||||
|
|
||||||
|
player:set_properties({visual_size = {x=1, y=1}})
|
||||||
|
|
||||||
|
player:set_eye_offset(eye_offset, {x=0, y=0, z=0})
|
||||||
|
default.player_attached[player:get_player_name()] = true
|
||||||
|
minetest.after(0.2, function()
|
||||||
|
default.player_set_animation(player, "sit" , 30)
|
||||||
|
end)
|
||||||
|
entity.object:setyaw(player:get_look_yaw() - math.pi / 2)
|
||||||
|
end
|
||||||
|
|
||||||
|
function lib_mount.detach(entity, player, offset)
|
||||||
|
entity.driver = nil
|
||||||
|
player:set_detach()
|
||||||
|
default.player_attached[player:get_player_name()] = false
|
||||||
|
default.player_set_animation(player, "stand" , 30)
|
||||||
|
player:set_eye_offset({x=0, y=0, z=0}, {x=0, y=0, z=0})
|
||||||
|
local pos = player:getpos()
|
||||||
|
pos = {x = pos.x + offset.x, y = pos.y + 0.2 + offset.y, z = pos.z + offset.z}
|
||||||
|
minetest.after(0.1, function()
|
||||||
|
player:setpos(pos)
|
||||||
|
end)
|
||||||
|
end
|
||||||
|
|
||||||
|
function lib_mount.drive(entity, dtime, moving_anim, stand_anim, can_fly)
|
||||||
|
entity.v = get_v(entity.object:getvelocity()) * get_sign(entity.v)
|
||||||
|
|
||||||
|
local ctrl = entity.driver:get_player_control()
|
||||||
|
local yaw = entity.object:getyaw()
|
||||||
|
if ctrl.up then
|
||||||
|
entity.v = entity.v + 0.1
|
||||||
|
elseif ctrl.down then
|
||||||
|
entity.v = entity.v - 0.1
|
||||||
|
end
|
||||||
|
if ctrl.left then
|
||||||
|
if entity.v < 0 then
|
||||||
|
entity.object:setyaw(yaw - (1 + dtime) * 0.03)
|
||||||
|
else
|
||||||
|
entity.object:setyaw(yaw + (1 + dtime) * 0.03)
|
||||||
|
end
|
||||||
|
elseif ctrl.right then
|
||||||
|
if entity.v < 0 then
|
||||||
|
entity.object:setyaw(yaw + (1 + dtime) * 0.03)
|
||||||
|
else
|
||||||
|
entity.object:setyaw(yaw - (1 + dtime) * 0.03)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
local velo = entity.object:getvelocity()
|
||||||
|
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
|
||||||
|
set_animation(entity, stand_anim)
|
||||||
|
end
|
||||||
|
entity.object:setpos(entity.object:getpos())
|
||||||
|
return
|
||||||
|
end
|
||||||
|
if moving_anim and moving_anim ~= nil and mobs_redo == true then
|
||||||
|
set_animation(entity, moving_anim)
|
||||||
|
end
|
||||||
|
local s = get_sign(entity.v)
|
||||||
|
entity.v = entity.v - 0.02 * s
|
||||||
|
if s ~= get_sign(entity.v) then
|
||||||
|
entity.object:setvelocity({x = 0, y = 0, z = 0})
|
||||||
|
entity.v = 0
|
||||||
|
return
|
||||||
|
end
|
||||||
|
if math.abs(entity.v) > 5 then
|
||||||
|
entity.v = 5 * get_sign(entity.v)
|
||||||
|
end
|
||||||
|
|
||||||
|
local p = entity.object:getpos()
|
||||||
|
p.y = p.y - 0.5
|
||||||
|
local new_velo = {x = 0, y = 0, z = 0}
|
||||||
|
local new_acce = {x = 0, y = 0, z = 0}
|
||||||
|
if not is_group(p, "crumbly") then
|
||||||
|
local nodedef = minetest.registered_nodes[minetest.get_node(p).name]
|
||||||
|
if (not nodedef) or nodedef.walkable then
|
||||||
|
entity.v = 0
|
||||||
|
new_acce = {x = 0, y = 1, z = 0}
|
||||||
|
else
|
||||||
|
new_acce = {x = 0, y = -9.8, z = 0}
|
||||||
|
end
|
||||||
|
new_velo = get_velocity(entity.v, entity.object:getyaw(),
|
||||||
|
entity.object:getvelocity().y)
|
||||||
|
entity.object:setpos(entity.object:getpos())
|
||||||
|
else
|
||||||
|
p.y = p.y + 1
|
||||||
|
if is_group(p, "crumbly") then
|
||||||
|
local y = entity.object:getvelocity().y
|
||||||
|
if y >= 5 then
|
||||||
|
y = 5
|
||||||
|
elseif y < 0 then
|
||||||
|
new_acce = {x = 0, y = 20, z = 0}
|
||||||
|
else
|
||||||
|
new_acce = {x = 0, y = 5, z = 0}
|
||||||
|
end
|
||||||
|
new_velo = get_velocity(entity.v, entity.object:getyaw(), y)
|
||||||
|
entity.object:setpos(entity.object:getpos())
|
||||||
|
else
|
||||||
|
new_acce = {x = 0, y = 0, z = 0}
|
||||||
|
if math.abs(entity.object:getvelocity().y) < 1 then
|
||||||
|
local pos = entity.object:getpos()
|
||||||
|
pos.y = math.floor(pos.y) + 0.5
|
||||||
|
entity.object:setpos(pos)
|
||||||
|
new_velo = get_velocity(entity.v, entity.object:getyaw(), 0)
|
||||||
|
else
|
||||||
|
new_velo = get_velocity(entity.v, entity.object:getyaw(),
|
||||||
|
entity.object:getvelocity().y)
|
||||||
|
entity.object:setpos(entity.object:getpos())
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
if can_fly and can_fly == true and ctrl.jump then
|
||||||
|
new_velo.y = new_velo.y + 0.75
|
||||||
|
end
|
||||||
|
entity.object:setvelocity(new_velo)
|
||||||
|
entity.object:setacceleration(new_acce)
|
||||||
|
end
|
3
depends.txt
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
default
|
||||||
|
tnt
|
||||||
|
mobs?
|
362
init.lua
Normal file
@ -0,0 +1,362 @@
|
|||||||
|
|
||||||
|
--very laggy and buggy flight
|
||||||
|
-- minetest.register_globalstep(function(dtime)
|
||||||
|
-- for _, player in ipairs(minetest.get_connected_players()) do
|
||||||
|
-- local dir = player:get_look_dir();
|
||||||
|
-- local pos = player:getpos();
|
||||||
|
-- local ctrl = player:get_player_control();
|
||||||
|
-- local pos1 = {x=pos.x+dir.x*1,y=pos.y+dir.y*1,z=pos.z+dir.z*1}
|
||||||
|
-- if ctrl.up == true then
|
||||||
|
-- player:moveto(pos1, false)
|
||||||
|
-- else
|
||||||
|
-- end
|
||||||
|
-- end
|
||||||
|
-- end)
|
||||||
|
|
||||||
|
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)
|
||||||
|
minetest.after(10, function()
|
||||||
|
self.object:remove()
|
||||||
|
end)
|
||||||
|
for _, player in ipairs(minetest.get_connected_players()) do
|
||||||
|
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)
|
||||||
|
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:missile" and n ~= "vehicles:jet" and obj:get_luaentity().name ~= "__builtin:item" then
|
||||||
|
obj:punch(self.object, 1.0, {
|
||||||
|
full_punch_interval=1.0,
|
||||||
|
damage_groups={fleshy=1},
|
||||||
|
}, nil)
|
||||||
|
local pos = self.object:getpos()
|
||||||
|
tnt.boom(pos, {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})
|
||||||
|
self.object:remove()
|
||||||
|
return
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end,
|
||||||
|
})
|
||||||
|
|
||||||
|
|
||||||
|
minetest.register_craftitem("vehicles:miss", {
|
||||||
|
description = "Missile",
|
||||||
|
inventory_image = "vehicles_missile_inv.png"
|
||||||
|
})
|
||||||
|
|
||||||
|
|
||||||
|
minetest.register_entity("vehicles:missile_2", {
|
||||||
|
visual = "mesh",
|
||||||
|
mesh = "missile.b3d",
|
||||||
|
textures = {"vehicles_missile.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:missile_2" and n ~= "vehicles:tank" and n ~= "vehicles:jet" and obj:get_luaentity().name ~= "__builtin:item" then
|
||||||
|
obj:punch(self.object, 1.0, {
|
||||||
|
full_punch_interval=1.0,
|
||||||
|
damage_groups={fleshy=1},
|
||||||
|
}, 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()
|
||||||
|
tnt.boom(pos, {damage_radius=5,radius=5,ignore_protection=false})
|
||||||
|
self.object:remove()
|
||||||
|
return
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end,
|
||||||
|
})
|
||||||
|
|
||||||
|
minetest.register_entity("vehicles:tank", {
|
||||||
|
visual = "mesh",
|
||||||
|
mesh = "tank.b3d",
|
||||||
|
textures = {"vehicles_tank.png"},
|
||||||
|
velocity = 15,
|
||||||
|
acceleration = -5,
|
||||||
|
stepheight = 1.5,
|
||||||
|
hp_max = 200,
|
||||||
|
physical = true,
|
||||||
|
collisionbox = {-1, -0.6, -0.9, 1, 0.9, 0.9},
|
||||||
|
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}, {x=0, y=2, z=4}, {x=0, y=3, z=-72})
|
||||||
|
end
|
||||||
|
end,
|
||||||
|
on_step = function(self, dtime)
|
||||||
|
if self.driver then
|
||||||
|
object_drive(self, dtime, 6, 0.5, true, "vehicles:missile_2", nil, nil, true)
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
return true
|
||||||
|
end,
|
||||||
|
})
|
||||||
|
|
||||||
|
minetest.register_entity("vehicles:jet", {
|
||||||
|
visual = "mesh",
|
||||||
|
mesh = "jet.b3d",
|
||||||
|
textures = {"vehicles_jet.png"},
|
||||||
|
velocity = 15,
|
||||||
|
acceleration = -5,
|
||||||
|
hp_max = 200,
|
||||||
|
animation_speed = 5,
|
||||||
|
physical = true,
|
||||||
|
animations = {
|
||||||
|
gear = { x=1, y=1},
|
||||||
|
nogear = { x=10, y=10},
|
||||||
|
},
|
||||||
|
collisionbox = {-1, -0.9, -0.9, 1, 0.9, 0.9},
|
||||||
|
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=5}, {x=0, y=3, z=-52})
|
||||||
|
end
|
||||||
|
end,
|
||||||
|
on_step = function(self, dtime)
|
||||||
|
if self.driver then
|
||||||
|
object_fly(self, dtime, 20, 0.2, 0.92, true, "vehicles:missile_2", "nogear", "gear")
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
return true
|
||||||
|
end,
|
||||||
|
})
|
||||||
|
|
||||||
|
minetest.register_entity("vehicles:parachute", {
|
||||||
|
visual = "mesh",
|
||||||
|
mesh = "parachute.b3d",
|
||||||
|
textures = {"vehicles_parachute.png"},
|
||||||
|
velocity = 15,
|
||||||
|
acceleration = -5,
|
||||||
|
hp_max = 2,
|
||||||
|
physical = true,
|
||||||
|
collisionbox = {-0.5, -1, -0.5, 0.5, 1, 0.5},
|
||||||
|
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=0, z=-1.5}, {x=0, y=-4, z=0})
|
||||||
|
end
|
||||||
|
end,
|
||||||
|
on_step = function(self, dtime)
|
||||||
|
if self.driver then
|
||||||
|
object_glide(self, dtime, 8, 0.92, -0.2, "", "")
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
return true
|
||||||
|
end,
|
||||||
|
})
|
||||||
|
|
||||||
|
minetest.register_tool("vehicles:backpack", {
|
||||||
|
description = "Parachute",
|
||||||
|
inventory_image = "vehicles_backpack.png",
|
||||||
|
wield_scale = {x = 1.5, y = 1.5, z = 1},
|
||||||
|
tool_capabilities = {
|
||||||
|
full_punch_interval = 0.7,
|
||||||
|
max_drop_level=1,
|
||||||
|
groupcaps={
|
||||||
|
snappy={times={[1]=2.0, [2]=1.00, [3]=0.35}, uses=30, maxlevel=3},
|
||||||
|
},
|
||||||
|
damage_groups = {fleshy=1},
|
||||||
|
},
|
||||||
|
on_use = function(item, placer, pointed_thing)
|
||||||
|
local dir = placer:get_look_dir();
|
||||||
|
local playerpos = placer:getpos();
|
||||||
|
local pname = placer:get_player_name();
|
||||||
|
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:parachute")
|
||||||
|
local entity = obj:get_luaentity()
|
||||||
|
if obj.driver and placer == obj.driver then
|
||||||
|
object_detach(entity, placer, {x=1, y=0, z=1})
|
||||||
|
elseif not obj.driver then
|
||||||
|
object_attach(entity, placer, {x=0, y=0, z=0}, {x=0, y=2, z=0})
|
||||||
|
end
|
||||||
|
item:take_item()
|
||||||
|
return item
|
||||||
|
end,
|
||||||
|
})
|
||||||
|
|
||||||
|
minetest.register_entity("vehicles:wing_glider", {
|
||||||
|
visual = "mesh",
|
||||||
|
mesh = "wings.b3d",
|
||||||
|
textures = {"vehicles_wings.png"},
|
||||||
|
velocity = 15,
|
||||||
|
acceleration = -5,
|
||||||
|
hp_max = 2,
|
||||||
|
physical = true,
|
||||||
|
collisionbox = {-0.5, -1, -0.5, 0.5, 1, 0.5},
|
||||||
|
on_step = function(self, dtime)
|
||||||
|
if self.driver then
|
||||||
|
local dir = self.driver:get_look_dir();
|
||||||
|
local velo = self.object:getvelocity();
|
||||||
|
local vec = {x=dir.x*4,y=((1-velo.y)*dir.y)-9.8,z=dir.z*4}
|
||||||
|
local yaw = self.driver:get_look_yaw();
|
||||||
|
self.object:setyaw(yaw+math.pi/2)
|
||||||
|
self.object:setvelocity(vec)
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
return true
|
||||||
|
end,
|
||||||
|
})
|
||||||
|
|
||||||
|
minetest.register_tool("vehicles:wings", {
|
||||||
|
description = "Wings",
|
||||||
|
inventory_image = "vehicles_backpack.png",
|
||||||
|
wield_scale = {x = 1.5, y = 1.5, z = 1},
|
||||||
|
tool_capabilities = {
|
||||||
|
full_punch_interval = 0.7,
|
||||||
|
max_drop_level=1,
|
||||||
|
groupcaps={
|
||||||
|
snappy={times={[1]=2.0, [2]=1.00, [3]=0.35}, uses=30, maxlevel=3},
|
||||||
|
},
|
||||||
|
damage_groups = {fleshy=1},
|
||||||
|
},
|
||||||
|
on_use = function(item, placer, pointed_thing)
|
||||||
|
local dir = placer:get_look_dir();
|
||||||
|
local playerpos = placer:getpos();
|
||||||
|
local pname = placer:get_player_name();
|
||||||
|
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()
|
||||||
|
if obj.driver and placer == obj.driver then
|
||||||
|
object_detach(entity, placer, {x=1, y=0, z=1})
|
||||||
|
placer:set_properties({
|
||||||
|
visual_size = {x=1, y=1},
|
||||||
|
})
|
||||||
|
elseif not obj.driver then
|
||||||
|
default.player_set_animation(placer, "lay", 30)
|
||||||
|
placer:set_attach(entity.object, "", {x=0,y=0,z=0}, {x=0,y=1,z=0})
|
||||||
|
entity.driver = placer
|
||||||
|
placer:set_properties({
|
||||||
|
visual_size = {x=1, y=-1},
|
||||||
|
})
|
||||||
|
end
|
||||||
|
item:add_wear(500)
|
||||||
|
return item
|
||||||
|
end,
|
||||||
|
})
|
||||||
|
|
||||||
|
minetest.register_tool("vehicles:rc", {
|
||||||
|
description = "Rc",
|
||||||
|
inventory_image = "vehicles_rc.png",
|
||||||
|
wield_scale = {x = 1.5, y = 1.5, z = 1},
|
||||||
|
tool_capabilities = {
|
||||||
|
full_punch_interval = 0.7,
|
||||||
|
max_drop_level=1,
|
||||||
|
groupcaps={
|
||||||
|
snappy={times={[1]=2.0, [2]=1.00, [3]=0.35}, uses=30, maxlevel=3},
|
||||||
|
},
|
||||||
|
damage_groups = {fleshy=1},
|
||||||
|
},
|
||||||
|
on_use = function(item, placer, pointed_thing)
|
||||||
|
local dir = placer:get_look_dir();
|
||||||
|
local playerpos = placer:getpos();
|
||||||
|
local pname = placer:get_player_name();
|
||||||
|
local inv = minetest.get_inventory({type="player", name=pname});
|
||||||
|
if inv:contains_item("main", "vehicles:miss") then
|
||||||
|
local remov = inv:remove_item("main", "vehicles:miss")
|
||||||
|
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 vec = {x=dir.x*6,y=dir.y*6,z=dir.z*6}
|
||||||
|
obj:setvelocity(vec)
|
||||||
|
return item
|
||||||
|
end
|
||||||
|
end,
|
||||||
|
})
|
||||||
|
|
||||||
|
minetest.register_tool("vehicles:tank_placer", {
|
||||||
|
description = "Tank",
|
||||||
|
inventory_image = "vehicles_tank_inv.png",
|
||||||
|
wield_scale = {x = 1.5, y = 1.5, z = 1},
|
||||||
|
tool_capabilities = {
|
||||||
|
full_punch_interval = 0.7,
|
||||||
|
max_drop_level=1,
|
||||||
|
groupcaps={
|
||||||
|
snappy={times={[1]=2.0, [2]=1.00, [3]=0.35}, uses=30, maxlevel=3},
|
||||||
|
},
|
||||||
|
damage_groups = {fleshy=1},
|
||||||
|
},
|
||||||
|
on_use = function(item, placer, pointed_thing)
|
||||||
|
local dir = placer:get_look_dir();
|
||||||
|
local playerpos = placer:getpos();
|
||||||
|
local obj = minetest.env:add_entity({x=playerpos.x+2+dir.x,y=playerpos.y+1+dir.y,z=playerpos.z+2+dir.z}, "vehicles:tank")
|
||||||
|
item:take_item()
|
||||||
|
return item
|
||||||
|
end,
|
||||||
|
})
|
||||||
|
|
||||||
|
minetest.register_tool("vehicles:jet_placer", {
|
||||||
|
description = "Jet",
|
||||||
|
inventory_image = "vehicles_jet_inv.png",
|
||||||
|
wield_scale = {x = 1.5, y = 1.5, z = 1},
|
||||||
|
tool_capabilities = {
|
||||||
|
full_punch_interval = 0.7,
|
||||||
|
max_drop_level=1,
|
||||||
|
groupcaps={
|
||||||
|
snappy={times={[1]=2.0, [2]=1.00, [3]=0.35}, uses=30, maxlevel=3},
|
||||||
|
},
|
||||||
|
damage_groups = {fleshy=1},
|
||||||
|
},
|
||||||
|
on_use = function(item, placer, pointed_thing)
|
||||||
|
local dir = placer:get_look_dir();
|
||||||
|
local playerpos = placer:getpos();
|
||||||
|
local obj = minetest.env:add_entity({x=playerpos.x+2+dir.x,y=playerpos.y+1+dir.y,z=playerpos.z+2+dir.z}, "vehicles:jet")
|
||||||
|
item:take_item()
|
||||||
|
return item
|
||||||
|
end,
|
||||||
|
})
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
dofile(minetest.get_modpath("vehicles").."/api.lua")
|
BIN
models/jet.b3d
Normal file
BIN
models/jetc.b3d
Normal file
BIN
models/missile.b3d
Normal file
BIN
models/parachute.b3d
Normal file
BIN
models/tank.b3d
Normal file
BIN
models/wings.b3d
Normal file
BIN
textures/vehicles_backpack.png
Normal file
After Width: | Height: | Size: 286 B |
BIN
textures/vehicles_jet.png
Normal file
After Width: | Height: | Size: 18 KiB |
BIN
textures/vehicles_jet_inv.png
Normal file
After Width: | Height: | Size: 221 B |
BIN
textures/vehicles_missile.png
Normal file
After Width: | Height: | Size: 21 KiB |
BIN
textures/vehicles_missile_inv.png
Normal file
After Width: | Height: | Size: 211 B |
BIN
textures/vehicles_parachute.png
Normal file
After Width: | Height: | Size: 2.5 KiB |
BIN
textures/vehicles_rc.png
Normal file
After Width: | Height: | Size: 257 B |
BIN
textures/vehicles_tank.png
Normal file
After Width: | Height: | Size: 60 KiB |
BIN
textures/vehicles_tank_inv.png
Normal file
After Width: | Height: | Size: 217 B |
BIN
textures/vehicles_trans.png
Normal file
After Width: | Height: | Size: 91 B |
BIN
textures/vehicles_wings.png
Normal file
After Width: | Height: | Size: 373 B |