forked from minetest/minetest_game
Boats: Use driver name string instead of objectref
This commit is contained in:
parent
57db3f748c
commit
ee72bc722c
@ -54,7 +54,7 @@ function boat.on_rightclick(self, clicker)
|
|||||||
return
|
return
|
||||||
end
|
end
|
||||||
local name = clicker:get_player_name()
|
local name = clicker:get_player_name()
|
||||||
if self.driver and clicker == self.driver then
|
if self.driver and name == self.driver then
|
||||||
self.driver = nil
|
self.driver = nil
|
||||||
self.auto = false
|
self.auto = false
|
||||||
clicker:set_detach()
|
clicker:set_detach()
|
||||||
@ -74,7 +74,7 @@ function boat.on_rightclick(self, clicker)
|
|||||||
end
|
end
|
||||||
clicker:set_detach()
|
clicker:set_detach()
|
||||||
end
|
end
|
||||||
self.driver = clicker
|
self.driver = name
|
||||||
clicker:set_attach(self.object, "",
|
clicker:set_attach(self.object, "",
|
||||||
{x = 0.5, y = 1, z = -3}, {x = 0, y = 0, z = 0})
|
{x = 0.5, y = 1, z = -3}, {x = 0, y = 0, z = 0})
|
||||||
player_api.player_attached[name] = true
|
player_api.player_attached[name] = true
|
||||||
@ -86,6 +86,13 @@ function boat.on_rightclick(self, clicker)
|
|||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
-- If driver leaves server while driving boat
|
||||||
|
function boat.on_detach_child(self, child)
|
||||||
|
self.driver = nil
|
||||||
|
self.auto = false
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
function boat.on_activate(self, staticdata, dtime_s)
|
function boat.on_activate(self, staticdata, dtime_s)
|
||||||
self.object:set_armor_groups({immortal = 1})
|
self.object:set_armor_groups({immortal = 1})
|
||||||
if staticdata then
|
if staticdata then
|
||||||
@ -104,16 +111,18 @@ function boat.on_punch(self, puncher)
|
|||||||
if not puncher or not puncher:is_player() or self.removed then
|
if not puncher or not puncher:is_player() or self.removed then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
if self.driver and puncher == self.driver then
|
|
||||||
|
local name = puncher:get_player_name()
|
||||||
|
if self.driver and name == self.driver then
|
||||||
self.driver = nil
|
self.driver = nil
|
||||||
puncher:set_detach()
|
puncher:set_detach()
|
||||||
player_api.player_attached[puncher:get_player_name()] = false
|
player_api.player_attached[name] = false
|
||||||
end
|
end
|
||||||
if not self.driver then
|
if not self.driver then
|
||||||
self.removed = true
|
self.removed = true
|
||||||
local inv = puncher:get_inventory()
|
local inv = puncher:get_inventory()
|
||||||
if not (creative and creative.is_enabled_for
|
if not (creative and creative.is_enabled_for
|
||||||
and creative.is_enabled_for(puncher:get_player_name()))
|
and creative.is_enabled_for(name))
|
||||||
or not inv:contains_item("main", "boats:boat") then
|
or not inv:contains_item("main", "boats:boat") then
|
||||||
local leftover = inv:add_item("main", "boats:boat")
|
local leftover = inv:add_item("main", "boats:boat")
|
||||||
-- if no room in inventory add a replacement boat to the world
|
-- if no room in inventory add a replacement boat to the world
|
||||||
@ -132,35 +141,35 @@ end
|
|||||||
function boat.on_step(self, dtime)
|
function boat.on_step(self, dtime)
|
||||||
self.v = get_v(self.object:get_velocity()) * get_sign(self.v)
|
self.v = get_v(self.object:get_velocity()) * get_sign(self.v)
|
||||||
if self.driver then
|
if self.driver then
|
||||||
local driver_name = self.driver:get_player_name()
|
local driver_objref = minetest.get_player_by_name(self.driver)
|
||||||
local ctrl = self.driver:get_player_control()
|
if driver_objref then
|
||||||
if ctrl.up and ctrl.down then
|
local ctrl = driver_objref:get_player_control()
|
||||||
if not self.auto then
|
if ctrl.up and ctrl.down then
|
||||||
self.auto = true
|
if not self.auto then
|
||||||
minetest.chat_send_player(driver_name,
|
self.auto = true
|
||||||
"[boats] Cruise on")
|
minetest.chat_send_player(self.driver, "[boats] Cruise on")
|
||||||
|
end
|
||||||
|
elseif ctrl.down then
|
||||||
|
self.v = self.v - dtime * 1.8
|
||||||
|
if self.auto then
|
||||||
|
self.auto = false
|
||||||
|
minetest.chat_send_player(self.driver, "[boats] Cruise off")
|
||||||
|
end
|
||||||
|
elseif ctrl.up or self.auto then
|
||||||
|
self.v = self.v + dtime * 1.8
|
||||||
end
|
end
|
||||||
elseif ctrl.down then
|
if ctrl.left then
|
||||||
self.v = self.v - dtime * 1.8
|
if self.v < -0.001 then
|
||||||
if self.auto then
|
self.object:set_yaw(self.object:get_yaw() - dtime * 0.9)
|
||||||
self.auto = false
|
else
|
||||||
minetest.chat_send_player(driver_name,
|
self.object:set_yaw(self.object:get_yaw() + dtime * 0.9)
|
||||||
"[boats] Cruise off")
|
end
|
||||||
end
|
elseif ctrl.right then
|
||||||
elseif ctrl.up or self.auto then
|
if self.v < -0.001 then
|
||||||
self.v = self.v + dtime * 1.8
|
self.object:set_yaw(self.object:get_yaw() + dtime * 0.9)
|
||||||
end
|
else
|
||||||
if ctrl.left then
|
self.object:set_yaw(self.object:get_yaw() - dtime * 0.9)
|
||||||
if self.v < -0.001 then
|
end
|
||||||
self.object:set_yaw(self.object:get_yaw() - dtime * 0.9)
|
|
||||||
else
|
|
||||||
self.object:set_yaw(self.object:get_yaw() + dtime * 0.9)
|
|
||||||
end
|
|
||||||
elseif ctrl.right then
|
|
||||||
if self.v < -0.001 then
|
|
||||||
self.object:set_yaw(self.object:get_yaw() + dtime * 0.9)
|
|
||||||
else
|
|
||||||
self.object:set_yaw(self.object:get_yaw() - dtime * 0.9)
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user