Bugfix when crashing with no driver

master
tenplus1 2015-01-29 10:15:22 +00:00
parent 3cdead9b9c
commit 9fc7ed8181
1 changed files with 13 additions and 0 deletions

View File

@ -50,6 +50,8 @@ function boat.on_rightclick(self, clicker)
local name = clicker:get_player_name()
if self.driver and clicker == self.driver then
self.driver = nil
self.v = 0
self.v2 = 0
clicker:set_detach()
default.player_attached[name] = false
default.player_set_animation(clicker, "stand" , 30)
@ -71,6 +73,7 @@ function boat.on_activate(self, staticdata, dtime_s)
end
self.last_v = self.v
self.v2 = self.v
self.count = 0
end
function boat.get_staticdata(self)
@ -100,7 +103,15 @@ end
function boat.on_step(self, dtime)
self.v = get_v(self.object:getvelocity()) * get_sign(self.v)
-- count up boat timer, at 100 remove boat and drop boat item
self.count = self.count + 1
if self.count == 100 then
self.object:remove()
local pos = self.object:getpos()
minetest.add_item(pos, "boats:boat")
end
if self.driver then
self.count = 0
local ctrl = self.driver:get_player_control()
local yaw = self.object:getyaw()
if ctrl.up then
@ -184,11 +195,13 @@ function boat.on_step(self, dtime)
-- if boat comes to sudden stop then it has crashed, destroy boat and drop 3x wood
if self.v2 - self.v >= 3 then
print ("VELOCITY ", self.v2 - self.v)
local name = self.driver:get_player_name()
self.driver:set_detach()
self.object:remove()
default.player_attached[name] = false
default.player_set_animation(self.driver, "stand" , 30)
local pos = self.object:getpos()
minetest.add_item(pos, "default:wood 3")
end