utilities organize

master
Alexsandro Percy 2021-03-12 17:44:44 -03:00
parent 6640f0cfee
commit 5bf9bbfd48
1 changed files with 41 additions and 41 deletions

View File

@ -92,6 +92,47 @@ function trike.attach(self, player)
self.object:set_acceleration(vector.new())
end
function trike.detachPlayer(self, player)
local name = self.driver_name
trike.setText(self)
self._engine_running = false
-- driver clicked the object => driver gets off the vehicle
self.driver_name = nil
-- sound and animation
if self.sound_handle then
minetest.sound_stop(self.sound_handle)
self.sound_handle = nil
end
self.engine:set_animation_frame_speed(0)
-- detach the player
player:set_detach()
player_api.player_attached[name] = nil
player:set_eye_offset({x=0,y=0,z=0},{x=0,y=0,z=0})
player_api.set_animation(player, "stand")
self.driver = nil
self.object:set_acceleration(vector.multiply(trike.vector_up, -trike.gravity))
end
function trike.checkAttach(self)
if self.owner then
local player = minetest.get_player_by_name(self.owner)
if player then
local player_attach = player:get_attach()
if player_attach then
if player_attach == self.object then
return true
end
end
end
end
return false
end
--painting
function trike.paint(self, object, colstr, search_string)
if colstr then
@ -171,22 +212,6 @@ function trike.check_node_below(obj)
return nil, nil
end
function trike.checkAttach(self)
if self.owner then
local player = minetest.get_player_by_name(self.owner)
if player then
local player_attach = player:get_attach()
if player_attach then
if player_attach == self.object then
return true
end
end
end
end
return false
end
function trike.setText(self)
local properties = self.object:get_properties()
local formatted = string.format(
@ -252,31 +277,6 @@ function trike.testImpact(self, velocity)
end
end
function trike.detachPlayer(self, player)
local name = self.driver_name
trike.setText(self)
self._engine_running = false
-- driver clicked the object => driver gets off the vehicle
self.driver_name = nil
-- sound and animation
if self.sound_handle then
minetest.sound_stop(self.sound_handle)
self.sound_handle = nil
end
self.engine:set_animation_frame_speed(0)
-- detach the player
player:set_detach()
player_api.player_attached[name] = nil
player:set_eye_offset({x=0,y=0,z=0},{x=0,y=0,z=0})
player_api.set_animation(player, "stand")
self.driver = nil
self.object:set_acceleration(vector.multiply(trike.vector_up, -trike.gravity))
end
function trike.checkattachBug(self)
-- for some engine error the player can be detached from the submarine, so lets set him attached again
local can_stop = true