From acc2814c581a432e64052dde38cecd4678f89cbc Mon Sep 17 00:00:00 2001 From: D00Med Date: Wed, 5 Oct 2016 07:10:56 +1000 Subject: [PATCH] vehicle owner can remove it --- api.lua | 11 ++++++++++ init.lua | 62 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 73 insertions(+) diff --git a/api.lua b/api.lua index 463bdce..8982fef 100644 --- a/api.lua +++ b/api.lua @@ -664,13 +664,24 @@ minetest.register_tool(vehicle.."_spawner", { local playerpos = placer:getpos(); if pointed_thing.type == "node" and not is_boat then local obj = minetest.env:add_entity(pointed_thing.above, vehicle) + local object = obj:get_luaentity() + object.owner = placer item:take_item() return item elseif pointed_thing.type == "node" and minetest.get_item_group(pointed_thing.name, "water")then local obj = minetest.env:add_entity(pointed_thing.under, vehicle) + obj.owner = placer item:take_item() return item end end, }) +end + +function vehicle_drop(ent, player, name) + if ent.owner == player then + local pos = ent.object:getpos() + minetest.env:add_item(pos, name.."_spawner") + ent.object:remove() + end end \ No newline at end of file diff --git a/init.lua b/init.lua index fb2e1e3..01c8048 100644 --- a/init.lua +++ b/init.lua @@ -16,6 +16,8 @@ dofile(minetest.get_modpath("vehicles").."/api.lua") -- end -- end) + + minetest.register_entity("vehicles:missile", { visual = "mesh", mesh = "missile.b3d", @@ -221,6 +223,9 @@ minetest.register_entity("vehicles:tank", { object_attach(self, clicker, {x=0, y=5, z=4}, false, {x=0, y=2, z=4}) end end, + on_punch = function(self, puncher) + vehicle_drop(self, puncher, "vehicles:tank") + end, on_step = function(self, dtime) if self.driver then object_drive(self, dtime, 6, 0.5, true, "vehicles:missile_2", 1, nil, nil, false) @@ -247,6 +252,9 @@ minetest.register_entity("vehicles:turret", { object_attach(self, clicker, {x=0, y=5, z=4}, true, {x=0, y=2, z=4}) end end, + on_punch = function(self, puncher) + vehicle_drop(self, puncher, "vehicles:turret") + end, on_step = function(self, dtime) self.object:setvelocity({x=0, y=-1, z=0}) if self.driver then @@ -277,6 +285,9 @@ minetest.register_entity("vehicles:firetruck", { object_attach(self, clicker, {x=0, y=5, z=4}, false, {x=0, y=2, z=4}) end end, + on_punch = function(self, puncher) + vehicle_drop(self, puncher, "vehicles:firetruck") + end, on_step = function(self, dtime) if self.driver then object_drive(self, dtime, 7, 0.5, true, "vehicles:water", 0.2, nil, nil, false) @@ -311,6 +322,9 @@ minetest.register_entity("vehicles:ute", { object_attach(self, clicker, {x=0, y=5, z=4}, false, {x=0, y=2, z=4}) end end, + on_punch = function(self, puncher) + vehicle_drop(self, puncher, "vehicles:ute") + end, on_activate = function(self) self.nitro = true end, @@ -365,6 +379,9 @@ minetest.register_entity("vehicles:ute2", { object_attach(self, clicker, {x=0, y=5, z=4}, false, {x=0, y=2, z=4}) end end, + on_punch = function(self, puncher) + vehicle_drop(self, puncher, "vehicles:ute2") + end, on_activate = function(self) self.nitro = true end, @@ -396,6 +413,9 @@ minetest.register_entity("vehicles:astonmaaton", { object_attach(self, clicker, {x=0, y=5, z=4}, false, {x=0, y=2, z=4}) end end, + on_punch = function(self, puncher) + vehicle_drop(self, puncher, "vehicles:astonmaaton") + end, on_activate = function(self) self.nitro = true end, @@ -427,6 +447,9 @@ minetest.register_entity("vehicles:nizzan", { object_attach(self, clicker, {x=0, y=5, z=4}, false, {x=0, y=2, z=4}) end end, + on_punch = function(self, puncher) + vehicle_drop(self, puncher, "vehicles:nizzan") + end, on_activate = function(self) self.nitro = true end, @@ -478,6 +501,9 @@ minetest.register_entity("vehicles:nizzan2", { on_activate = function(self) self.nitro = true end, + on_punch = function(self, puncher) + vehicle_drop(self, puncher, "vehicles:nizzan2") + end, on_step = function(self, dtime) if self.driver then object_drive_car(self, dtime, 14, 0.8, 5) @@ -523,6 +549,9 @@ minetest.register_entity("vehicles:lambogoni", { object_attach(self, clicker, {x=0, y=5, z=4}, false, {x=0, y=2, z=4}) end end, + on_punch = function(self, puncher) + vehicle_drop(self, puncher, "vehicles:lambogoni") + end, on_activate = function(self) self.nitro = true end, @@ -554,6 +583,9 @@ minetest.register_entity("vehicles:masda", { object_attach(self, clicker, {x=0, y=5, z=4}, false, {x=0, y=2, z=4}) end end, + on_punch = function(self, puncher) + vehicle_drop(self, puncher, "vehicles:masda") + end, on_activate = function(self) self.nitro = true end, @@ -588,6 +620,9 @@ minetest.register_entity("vehicles:musting", { on_activate = function(self) self.nitro = true end, + on_punch = function(self, puncher) + vehicle_drop(self, puncher, "vehicles:musting") + end, on_step = function(self, dtime) if self.driver then object_drive_car(self, dtime, 15, 0.95, 4) @@ -616,6 +651,9 @@ minetest.register_entity("vehicles:musting2", { object_attach(self, clicker, {x=0, y=5, z=4}, false, {x=0, y=2, z=4}) end end, + on_punch = function(self, puncher) + vehicle_drop(self, puncher, "vehicles:musting2") + end, on_activate = function(self) self.nitro = true end, @@ -658,6 +696,9 @@ minetest.register_entity("vehicles:fewawi", { end end end, + on_punch = function(self, puncher) + vehicle_drop(self, puncher, "vehicles:fewawi") + end, on_activate = function(self) self.nitro = true end, @@ -700,6 +741,9 @@ minetest.register_entity("vehicles:fewawi2", { end end end, + on_punch = function(self, puncher) + vehicle_drop(self, puncher, "vehicles:fewawi2") + end, on_activate = function(self) self.nitro = true end, @@ -734,6 +778,9 @@ minetest.register_entity("vehicles:pooshe", { on_activate = function(self) self.nitro = true end, + on_punch = function(self, puncher) + vehicle_drop(self, puncher, "vehicles:pooshe") + end, on_step = function(self, dtime) if self.driver then object_drive_car(self, dtime, 15, 0.95, 4) @@ -762,6 +809,9 @@ minetest.register_entity("vehicles:pooshe2", { object_attach(self, clicker, {x=0, y=5, z=4}, false, {x=0, y=2, z=4}) end end, + on_punch = function(self, puncher) + vehicle_drop(self, puncher, "vehicles:pooshe2") + end, on_activate = function(self) self.nitro = true end, @@ -796,6 +846,9 @@ minetest.register_entity("vehicles:masda2", { on_activate = function(self) self.nitro = true end, + on_punch = function(self, puncher) + vehicle_drop(self, puncher, "vehicles:masda2") + end, on_step = function(self, dtime) if self.driver then object_drive_car(self, dtime, 15, 0.85, 4) @@ -824,6 +877,9 @@ minetest.register_entity("vehicles:boat", { object_attach(self, clicker, {x=0, y=5, z=4}, false, {x=0, y=2, z=4}) end end, + on_punch = function(self, puncher) + vehicle_drop(self, puncher, "vehicles:boat") + end, on_step = function(self, dtime) if self.driver then object_float(self, dtime, 10, 0.85) @@ -857,6 +913,9 @@ minetest.register_entity("vehicles:jet", { object_attach(self, clicker, {x=0, y=5, z=5}, false, {x=0, y=3, z=4}) end end, + on_punch = function(self, puncher) + vehicle_drop(self, puncher, "vehicles:jet") + end, on_step = function(self, dtime) if self.driver then object_fly(self, dtime, 14, 0.2, 0.95, true, "vehicles:missile_2", 1, {x=1, y=1}, {x=10, y=10}) @@ -889,6 +948,9 @@ minetest.register_entity("vehicles:plane", { object_attach(self, clicker, {x=0, y=8, z=3}, false, {x=0, y=9, z=0}) end end, + on_punch = function(self, puncher) + vehicle_drop(self, puncher, "vehicles:plane") + end, on_step = function(self, dtime) if self.anim and not self.driver then self.object:set_animation({x=1, y=1}, 5, 0)