moved the hook function to it's correspondent

This commit is contained in:
Alexsandro Percy 2024-02-14 21:51:37 -03:00
parent 247419019b
commit ee35aee5af
2 changed files with 52 additions and 50 deletions

View File

@ -1,3 +1,5 @@
local S = airutils.S
local function attach_entity(self, target_obj, dest_pos, relative_pos, entity_name, inv_id)
if not target_obj then return end
if self.object then
@ -110,3 +112,53 @@ function airutils.restore_external_attach(self)
--self._vehicle_custom_data.simple_external_attach_pos = nil
--self._vehicle_custom_data.simple_external_attach_invid = nil
end
minetest.register_chatcommand("remove_hook", {
params = "",
description = S("Dettach current vehicle from another"),
privs = {interact=true},
func = function(name, param)
local colorstring = core.colorize('#ff0000', S(" >>> you are not inside a plane"))
local player = minetest.get_player_by_name(name)
local attached_to = player:get_attach()
if attached_to ~= nil then
local seat = attached_to:get_attach()
if seat ~= nil then
local entity = seat:get_luaentity()
if entity then
if entity.on_step == airutils.on_step then
local rem_obj = entity.object:get_attach()
if not rem_obj then
minetest.chat_send_player(name,core.colorize('#ff0000', S(" >>> no hook found")))
return
end
local rem_ent = rem_obj:get_luaentity()
local pos = rem_ent.object:get_pos()
local rotation = rem_ent.object:get_rotation()
local direction = rotation.y
local velocity = rem_ent.object:get_velocity()
local move = -1*rem_ent._vehicle_custom_data.simple_external_attach_pos.z/10
pos.x = pos.x + move * math.sin(direction)
pos.z = pos.z + move * math.cos(direction)
pos.y = pos.y + rem_ent.initial_properties.collisionbox[2] - entity.initial_properties.collisionbox[2]
entity.object:set_detach()
entity.object:set_pos(pos)
entity.object:set_rotation(rotation)
entity.object:set_velocity(velocity)
--clear
rem_ent._vehicle_custom_data.simple_external_attach_entity = nil
rem_ent._vehicle_custom_data.simple_external_attach_pos = nil
rem_ent._vehicle_custom_data.simple_external_attach_invid = nil
else
minetest.chat_send_player(name,colorstring)
end
end
end
else
minetest.chat_send_player(name,colorstring)
end
end
})

View File

@ -632,56 +632,6 @@ minetest.register_chatcommand("show_lift", {
end
})
minetest.register_chatcommand("remove_hook", {
params = "",
description = S("Dettach current vehicle from another"),
privs = {interact=true},
func = function(name, param)
local colorstring = core.colorize('#ff0000', S(" >>> you are not inside a plane"))
local player = minetest.get_player_by_name(name)
local attached_to = player:get_attach()
if attached_to ~= nil then
local seat = attached_to:get_attach()
if seat ~= nil then
local entity = seat:get_luaentity()
if entity then
if entity.on_step == airutils.on_step then
local rem_obj = entity.object:get_attach()
if not rem_obj then
minetest.chat_send_player(name,core.colorize('#ff0000', S(" >>> no hook found")))
return
end
local rem_ent = rem_obj:get_luaentity()
local pos = rem_ent.object:get_pos()
local rotation = rem_ent.object:get_rotation()
local direction = rotation.y
local velocity = rem_ent.object:get_velocity()
local move = -1*rem_ent._vehicle_custom_data.simple_external_attach_pos.z/10
pos.x = pos.x + move * math.sin(direction)
pos.z = pos.z + move * math.cos(direction)
pos.y = pos.y + rem_ent.initial_properties.collisionbox[2] - entity.initial_properties.collisionbox[2]
entity.object:set_detach()
entity.object:set_pos(pos)
entity.object:set_rotation(rotation)
entity.object:set_velocity(velocity)
--clear
rem_ent._vehicle_custom_data.simple_external_attach_entity = nil
rem_ent._vehicle_custom_data.simple_external_attach_pos = nil
rem_ent._vehicle_custom_data.simple_external_attach_invid = nil
else
minetest.chat_send_player(name,colorstring)
end
end
end
else
minetest.chat_send_player(name,colorstring)
end
end
})
if airutils._use_signs_api then
local function prefix_change(name, param)
local colorstring = core.colorize('#ff0000', S(" >>> you are not inside a vehicle"))