mirror of
https://github.com/minetest/minetest_game.git
synced 2024-12-23 07:10:19 +01:00
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,20 +141,19 @@ 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
|
||||||
|
local ctrl = driver_objref:get_player_control()
|
||||||
if ctrl.up and ctrl.down then
|
if ctrl.up and ctrl.down then
|
||||||
if not self.auto then
|
if not self.auto then
|
||||||
self.auto = true
|
self.auto = true
|
||||||
minetest.chat_send_player(driver_name,
|
minetest.chat_send_player(self.driver, "[boats] Cruise on")
|
||||||
"[boats] Cruise on")
|
|
||||||
end
|
end
|
||||||
elseif ctrl.down then
|
elseif ctrl.down then
|
||||||
self.v = self.v - dtime * 1.8
|
self.v = self.v - dtime * 1.8
|
||||||
if self.auto then
|
if self.auto then
|
||||||
self.auto = false
|
self.auto = false
|
||||||
minetest.chat_send_player(driver_name,
|
minetest.chat_send_player(self.driver, "[boats] Cruise off")
|
||||||
"[boats] Cruise off")
|
|
||||||
end
|
end
|
||||||
elseif ctrl.up or self.auto then
|
elseif ctrl.up or self.auto then
|
||||||
self.v = self.v + dtime * 1.8
|
self.v = self.v + dtime * 1.8
|
||||||
@ -164,6 +172,7 @@ function boat.on_step(self, dtime)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
end
|
||||||
local velo = self.object:get_velocity()
|
local velo = self.object:get_velocity()
|
||||||
if self.v == 0 and velo.x == 0 and velo.y == 0 and velo.z == 0 then
|
if self.v == 0 and velo.x == 0 and velo.y == 0 and velo.z == 0 then
|
||||||
self.object:set_pos(self.object:get_pos())
|
self.object:set_pos(self.object:get_pos())
|
||||||
|
Loading…
Reference in New Issue
Block a user