Update framework.lua

add ownership
This commit is contained in:
shivajiva101 2016-07-06 02:08:43 +01:00 committed by GitHub
parent c0e5099957
commit b670c45a30

View File

@ -96,6 +96,10 @@ function vehicle_mash:register_vehicle(name, def)
if not clicker or not clicker:is_player() then if not clicker or not clicker:is_player() then
return return
end end
-- owner set to the player?
if not self.owner or self.owner == "" then
self.owner = clicker:get_player_name()
end
-- if there is already a driver -- if there is already a driver
if self.driver then if self.driver then
-- if clicker is driver detach passenger and driver -- if clicker is driver detach passenger and driver
@ -123,7 +127,9 @@ function vehicle_mash:register_vehicle(name, def)
-- if there is no driver -- if there is no driver
else else
-- attach driver -- attach driver
self.driver = AttachPlayer(self, clicker, true) if self.owner == clicker:get_player_name() then
self.driver = AttachPlayer(self, clicker, true)
end
end end
end, end,
on_activate = function(self, staticdata, dtime_s) on_activate = function(self, staticdata, dtime_s)
@ -140,12 +146,14 @@ function vehicle_mash:register_vehicle(name, def)
if not puncher or not puncher:is_player() or self.removed or self.driver then if not puncher or not puncher:is_player() or self.removed or self.driver then
return return
end end
self.removed = true if self.owner == puncher:get_player_name() then
-- delay remove to ensure player is detached self.removed = true
minetest.after(0.1, function() -- delay remove to ensure player is detached
self.object:remove() minetest.after(0.1, function()
end) self.object:remove()
puncher:get_inventory():add_item("main", self.name) end)
puncher:get_inventory():add_item("main", self.name)
end
end, end,
on_step = function(self, dtime) on_step = function(self, dtime)
-- Acelerating, braking, and rotating -- Acelerating, braking, and rotating