Various tweaks and fixes for passengers
This commit is contained in:
parent
64785bb0e7
commit
de43121ba1
@ -3,7 +3,7 @@
|
|||||||
Made by [blert2112](https://github.com/blert2112).\
|
Made by [blert2112](https://github.com/blert2112).\
|
||||||
Improved by [Panquesito7](https://github.com/Panquesito7).
|
Improved by [Panquesito7](https://github.com/Panquesito7).
|
||||||
|
|
||||||
Current version: 1.1.1
|
Current version: 1.1.2
|
||||||
|
|
||||||
## Dependencies
|
## Dependencies
|
||||||
- `default` (included in [Minetest Game](https://github.com/minetest/minetest_game))
|
- `default` (included in [Minetest Game](https://github.com/minetest/minetest_game))
|
||||||
|
101
init.lua
101
init.lua
@ -15,7 +15,7 @@
|
|||||||
You should have received a copy of the GNU Lesser General Public
|
You should have received a copy of the GNU Lesser General Public
|
||||||
License along with this library; if not, write to the Free Software
|
License along with this library; if not, write to the Free Software
|
||||||
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
|
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
|
||||||
USA
|
USA
|
||||||
|
|
||||||
-----------------------------------------------------------------------------
|
-----------------------------------------------------------------------------
|
||||||
|
|
||||||
@ -23,6 +23,10 @@ Dependencies: default, player_api (both included in Minetest Game)
|
|||||||
Optional dependencies: mobs
|
Optional dependencies: mobs
|
||||||
--]]
|
--]]
|
||||||
|
|
||||||
|
lib_mount = {
|
||||||
|
passengers = {}
|
||||||
|
}
|
||||||
|
|
||||||
local enable_crash = true
|
local enable_crash = true
|
||||||
local crash_threshold = 6.5 -- ignored if enable_crash=false
|
local crash_threshold = 6.5 -- ignored if enable_crash=false
|
||||||
|
|
||||||
@ -85,6 +89,13 @@ local function force_detach(player)
|
|||||||
entity.driver = nil
|
entity.driver = nil
|
||||||
elseif entity.passenger and entity.passenger == player then
|
elseif entity.passenger and entity.passenger == player then
|
||||||
entity.passenger = nil
|
entity.passenger = nil
|
||||||
|
lib_mount.passengers[player] = nil
|
||||||
|
elseif entity.passenger2 and entity.passenger2 == player then
|
||||||
|
entity.passenger2 = nil
|
||||||
|
lib_mount.passengers[player] = nil
|
||||||
|
elseif entity.passenger3 and entity.passenger3 == player then
|
||||||
|
entity.passenger3 = nil
|
||||||
|
lib_mount.passengers[player] = nil
|
||||||
end
|
end
|
||||||
player:set_detach()
|
player:set_detach()
|
||||||
player_api.player_attached[player:get_player_name()] = false
|
player_api.player_attached[player:get_player_name()] = false
|
||||||
@ -94,7 +105,6 @@ end
|
|||||||
|
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
minetest.register_on_leaveplayer(function(player)
|
minetest.register_on_leaveplayer(function(player)
|
||||||
force_detach(player)
|
force_detach(player)
|
||||||
end)
|
end)
|
||||||
@ -113,12 +123,12 @@ end)
|
|||||||
|
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
|
|
||||||
lib_mount = {}
|
|
||||||
|
|
||||||
function lib_mount.attach(entity, player, is_passenger, passenger_number)
|
function lib_mount.attach(entity, player, is_passenger, passenger_number)
|
||||||
local attach_at, eye_offset = {}, {}
|
local attach_at, eye_offset = {}, {}
|
||||||
local attach_at2, eye_offset2 = {}, {}
|
|
||||||
local attach_at3, eye_offset3 = {}, {}
|
if not is_passenger then
|
||||||
|
passenger_number = nil
|
||||||
|
end
|
||||||
|
|
||||||
if not entity.player_rotation then
|
if not entity.player_rotation then
|
||||||
entity.player_rotation = {x=0, y=0, z=0}
|
entity.player_rotation = {x=0, y=0, z=0}
|
||||||
@ -129,7 +139,7 @@ function lib_mount.attach(entity, player, is_passenger, passenger_number)
|
|||||||
rot_view = math.pi/2
|
rot_view = math.pi/2
|
||||||
end
|
end
|
||||||
|
|
||||||
if is_passenger == true then
|
if is_passenger == true and passenger_number == 1 then
|
||||||
if not entity.passenger_attach_at then
|
if not entity.passenger_attach_at then
|
||||||
entity.passenger_attach_at = {x=0, y=0, z=0}
|
entity.passenger_attach_at = {x=0, y=0, z=0}
|
||||||
end
|
end
|
||||||
@ -137,7 +147,13 @@ function lib_mount.attach(entity, player, is_passenger, passenger_number)
|
|||||||
entity.passenger_eye_offset = {x=0, y=0, z=0}
|
entity.passenger_eye_offset = {x=0, y=0, z=0}
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Support for more passengers
|
attach_at = entity.passenger_attach_at
|
||||||
|
eye_offset = entity.passenger_eye_offset
|
||||||
|
|
||||||
|
entity.passenger = player
|
||||||
|
lib_mount.passengers[entity.passenger] = player
|
||||||
|
|
||||||
|
elseif is_passenger == true and passenger_number == 2 then
|
||||||
if not entity.passenger2_attach_at then
|
if not entity.passenger2_attach_at then
|
||||||
entity.passenger2_attach_at = {x=0, y=0, z=0}
|
entity.passenger2_attach_at = {x=0, y=0, z=0}
|
||||||
end
|
end
|
||||||
@ -145,6 +161,13 @@ function lib_mount.attach(entity, player, is_passenger, passenger_number)
|
|||||||
entity.passenger2_eye_offset = {x=0, y=0, z=0}
|
entity.passenger2_eye_offset = {x=0, y=0, z=0}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
attach_at = entity.passenger2_attach_at
|
||||||
|
eye_offset = entity.passenger2_eye_offset
|
||||||
|
|
||||||
|
entity.passenger2 = player
|
||||||
|
lib_mount.passengers[entity.passenger2] = player
|
||||||
|
|
||||||
|
elseif is_passenger == true and passenger_number == 3 then
|
||||||
if not entity.passenger3_attach_at then
|
if not entity.passenger3_attach_at then
|
||||||
entity.passenger3_attach_at = {x=0, y=0, z=0}
|
entity.passenger3_attach_at = {x=0, y=0, z=0}
|
||||||
end
|
end
|
||||||
@ -152,16 +175,11 @@ function lib_mount.attach(entity, player, is_passenger, passenger_number)
|
|||||||
entity.passenger3_eye_offset = {x=0, y=0, z=0}
|
entity.passenger3_eye_offset = {x=0, y=0, z=0}
|
||||||
end
|
end
|
||||||
|
|
||||||
attach_at = entity.passenger_attach_at
|
attach_at = entity.passenger3_attach_at
|
||||||
eye_offset = entity.passenger_eye_offset
|
eye_offset = entity.passenger3_eye_offset
|
||||||
|
|
||||||
attach_at2 = entity.passenger2_attach_at
|
entity.passenger3 = player
|
||||||
eye_offset2 = entity.passenger2_eye_offset
|
lib_mount.passengers[entity.passenger3] = player
|
||||||
|
|
||||||
attach_at3 = entity.passenger3_attach_at
|
|
||||||
eye_offset3 = entity.passenger3_eye_offset
|
|
||||||
|
|
||||||
entity.passenger = player
|
|
||||||
else
|
else
|
||||||
if not entity.driver_attach_at then
|
if not entity.driver_attach_at then
|
||||||
entity.driver_attach_at = {x=0, y=0, z=0}
|
entity.driver_attach_at = {x=0, y=0, z=0}
|
||||||
@ -176,33 +194,13 @@ function lib_mount.attach(entity, player, is_passenger, passenger_number)
|
|||||||
|
|
||||||
force_detach(player)
|
force_detach(player)
|
||||||
|
|
||||||
if passenger_number == 1 or passenger_number == 0 then
|
player:set_attach(entity.object, "", attach_at, entity.player_rotation)
|
||||||
player:set_attach(entity.object, "", attach_at, entity.player_rotation)
|
player_api.player_attached[player:get_player_name()] = true
|
||||||
player_api.player_attached[player:get_player_name()] = true
|
player:set_eye_offset(eye_offset, {x=0, y=0, z=0})
|
||||||
player:set_eye_offset(eye_offset, {x=0, y=0, z=0})
|
minetest.after(0.2, function()
|
||||||
minetest.after(0.2, function()
|
player_api.set_animation(player, "sit", 30)
|
||||||
player_api.set_animation(player, "sit", 30)
|
end)
|
||||||
end)
|
player:set_look_horizontal(entity.object:get_yaw() - rot_view)
|
||||||
player:set_look_horizontal(entity.object:get_yaw() - rot_view)
|
|
||||||
|
|
||||||
elseif passenger_number == 2 then
|
|
||||||
player:set_attach(entity.object, "", attach_at2, entity.player_rotation)
|
|
||||||
player_api.player_attached[player:get_player_name()] = true
|
|
||||||
player:set_eye_offset(eye_offset2, {x=0, y=0, z=0})
|
|
||||||
minetest.after(0.2, function()
|
|
||||||
player_api.set_animation(player, "sit", 30)
|
|
||||||
end)
|
|
||||||
player:set_look_horizontal(entity.object:get_yaw() - rot_view)
|
|
||||||
|
|
||||||
elseif passenger_number == 3 then
|
|
||||||
player:set_attach(entity.object, "", attach_at3, entity.player_rotation)
|
|
||||||
player_api.player_attached[player:get_player_name()] = true
|
|
||||||
player:set_eye_offset(eye_offset3, {x=0, y=0, z=0})
|
|
||||||
minetest.after(0.2, function()
|
|
||||||
player_api.set_animation(player, "sit", 30)
|
|
||||||
end)
|
|
||||||
player:set_look_horizontal(entity.object:get_yaw() - rot_view)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
function lib_mount.detach(player, offset)
|
function lib_mount.detach(player, offset)
|
||||||
@ -378,12 +376,27 @@ function lib_mount.drive(entity, dtime, is_mob, moving_anim, stand_anim, jump_he
|
|||||||
drvr:set_velocity(new_velo)
|
drvr:set_velocity(new_velo)
|
||||||
drvr:set_hp(drvr:get_hp() - intensity)
|
drvr:set_hp(drvr:get_hp() - intensity)
|
||||||
end
|
end
|
||||||
|
|
||||||
if entity.passenger then
|
if entity.passenger then
|
||||||
local pass = entity.passenger
|
local pass = entity.passenger
|
||||||
lib_mount.detach(pass, {x=0, y=0, z=0})
|
lib_mount.detach(pass, {x=0, y=0, z=0})
|
||||||
pass:set_velocity(new_velo)
|
pass:set_velocity(new_velo)
|
||||||
pass:set_hp(pass:get_hp() - intensity)
|
pass:set_hp(pass:get_hp() - intensity)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
if entity.passenger2 then
|
||||||
|
local pass = entity.passenger2
|
||||||
|
lib_mount.detach(pass, {x=0, y=0, z=0})
|
||||||
|
pass:set_velocity(new_velo)
|
||||||
|
pass:set_hp(pass:get_hp() - intensity)
|
||||||
|
end
|
||||||
|
|
||||||
|
if entity.passenger3 then
|
||||||
|
local pass = entity.passenger3
|
||||||
|
lib_mount.detach(pass, {x=0, y=0, z=0})
|
||||||
|
pass:set_velocity(new_velo)
|
||||||
|
pass:set_hp(pass:get_hp() - intensity)
|
||||||
|
end
|
||||||
local pos = entity.object:get_pos()
|
local pos = entity.object:get_pos()
|
||||||
minetest.add_item(pos, entity.drop_on_destroy)
|
minetest.add_item(pos, entity.drop_on_destroy)
|
||||||
entity.removed = true
|
entity.removed = true
|
||||||
|
Loading…
x
Reference in New Issue
Block a user