diff --git a/automobiles_beetle/crafts.lua b/automobiles_beetle/crafts.lua index 7ca5036..22c1150 100644 --- a/automobiles_beetle/crafts.lua +++ b/automobiles_beetle/crafts.lua @@ -11,24 +11,29 @@ minetest.register_craftitem("automobiles_beetle:beetle_body",{ }) -- beetle -minetest.register_craftitem("automobiles_beetle:beetle", { - description = S("Beetle"), - inventory_image = "automobiles_beetle.png", +minetest.register_tool("automobiles_beetle:beetle", { + description = "Beetle", + inventory_image = "automobiles_beetle.png", liquids_pointable = false, + stack_max = 1, on_place = function(itemstack, placer, pointed_thing) if pointed_thing.type ~= "node" then return end + local stack_meta = itemstack:get_meta() + local staticdata = stack_meta:get_string("staticdata") + local pointed_pos = pointed_thing.above --pointed_pos.y=pointed_pos.y+0.2 - local car = minetest.add_entity(pointed_pos, "automobiles_beetle:beetle") + local car = minetest.add_entity(pointed_pos, "automobiles_beetle:beetle", staticdata) if car and placer then local ent = car:get_luaentity() local owner = placer:get_player_name() if ent then ent.owner = owner + ent.hp = 50 --reset hp --minetest.chat_send_all("owner: " .. ent.owner) car:set_yaw(placer:get_look_horizontal()) itemstack:take_item() diff --git a/automobiles_buggy/buggy_crafts.lua b/automobiles_buggy/buggy_crafts.lua index 7087b53..4024df7 100644 --- a/automobiles_buggy/buggy_crafts.lua +++ b/automobiles_buggy/buggy_crafts.lua @@ -16,24 +16,29 @@ minetest.register_craftitem("automobiles_buggy:wheel",{ }) -- buggy -minetest.register_craftitem("automobiles_buggy:buggy", { +minetest.register_tool("automobiles_buggy:buggy", { description = S("Buggy"), inventory_image = "automobiles_buggy.png", liquids_pointable = false, + stack_max = 1, on_place = function(itemstack, placer, pointed_thing) if pointed_thing.type ~= "node" then return end + local stack_meta = itemstack:get_meta() + local staticdata = stack_meta:get_string("staticdata") + local pointed_pos = pointed_thing.above --pointed_pos.y=pointed_pos.y+0.2 - local car = minetest.add_entity(pointed_pos, "automobiles_buggy:buggy") + local car = minetest.add_entity(pointed_pos, "automobiles_buggy:buggy", staticdata) if car and placer then local ent = car:get_luaentity() local owner = placer:get_player_name() if ent then ent.owner = owner + ent.hp = 50 --reset hp car:set_yaw(placer:get_look_horizontal()) itemstack:take_item() ent.object:set_acceleration({x=0,y=-automobiles_lib.gravity,z=0}) diff --git a/automobiles_buggy/buggy_entities.lua b/automobiles_buggy/buggy_entities.lua index 6eff7fa..ae5848e 100755 --- a/automobiles_buggy/buggy_entities.lua +++ b/automobiles_buggy/buggy_entities.lua @@ -235,7 +235,6 @@ minetest.register_entity("automobiles_buggy:buggy", { _engine_sound = "buggy_engine", _max_fuel = 10, _formspec_function = buggy.driver_formspec, - _destroy_function = buggy.destroy, _vehicle_name = "Buggy", _drive_wheel_pos = {x=-4.26,y=6.01,z=16}, diff --git a/automobiles_buggy/buggy_utilities.lua b/automobiles_buggy/buggy_utilities.lua deleted file mode 100755 index 2296871..0000000 --- a/automobiles_buggy/buggy_utilities.lua +++ /dev/null @@ -1,55 +0,0 @@ ---dofile(minetest.get_modpath("automobiles_buggy") .. DIR_DELIM .. "buggy_global_definitions.lua") ---dofile(minetest.get_modpath("automobiles_buggy") .. DIR_DELIM .. "buggy_hud.lua") - --- destroy the buggy -function buggy.destroy(self, puncher) - automobiles_lib.remove_light(self) - if self.sound_handle then - minetest.sound_stop(self.sound_handle) - self.sound_handle = nil - end - - if self.driver_name then - -- detach the driver first (puncher must be driver) - if puncher then - puncher:set_detach() - puncher:set_eye_offset({x = 0, y = 0, z = 0}, {x = 0, y = 0, z = 0}) - if minetest.global_exists("player_api") then - player_api.player_attached[self.driver_name] = nil - -- player should stand again - player_api.set_animation(puncher, "stand") - end - end - self.driver_name = nil - end - - local pos = self.object:get_pos() - - if self.rag then self.rag:remove() end - if self.front_suspension then self.front_suspension:remove() end - if self.lf_wheel then self.lf_wheel:remove() end - if self.rf_wheel then self.rf_wheel:remove() end - if self.rear_suspension then self.rear_suspension:remove() end - if self.lr_wheel then self.lr_wheel:remove() end - if self.rr_wheel then self.rr_wheel:remove() end - if self.steering then self.steering:remove() end - if self.steering_axis then self.steering_axis:remove() end - if self.driver_seat then self.driver_seat:remove() end - if self.passenger_seat then self.passenger_seat:remove() end - if self.fuel_gauge then self.fuel_gauge:remove() end - if self.lights then self.lights:remove() end - if self.r_lights then self.r_lights:remove() end - - automobiles_lib.destroy_inventory(self) - self.object:remove() - - pos.y=pos.y+2 - - --minetest.add_item({x=pos.x+math.random()-0.5,y=pos.y,z=pos.z+math.random()-0.5},'automobiles_buggy:buggy') - minetest.add_item({x=pos.x+math.random()-0.5,y=pos.y,z=pos.z+math.random()-0.5},'automobiles_lib:engine') - minetest.add_item({x=pos.x+math.random()-0.5,y=pos.y,z=pos.z+math.random()-0.5},'automobiles_buggy:wheel') - minetest.add_item({x=pos.x+math.random()-0.5,y=pos.y,z=pos.z+math.random()-0.5},'automobiles_buggy:wheel') - minetest.add_item({x=pos.x+math.random()-0.5,y=pos.y,z=pos.z+math.random()-0.5},'automobiles_buggy:wheel') - minetest.add_item({x=pos.x+math.random()-0.5,y=pos.y,z=pos.z+math.random()-0.5},'automobiles_buggy:wheel') -end - diff --git a/automobiles_buggy/init.lua b/automobiles_buggy/init.lua index 5c20365..4a8b404 100755 --- a/automobiles_buggy/init.lua +++ b/automobiles_buggy/init.lua @@ -21,7 +21,6 @@ dofile(minetest.get_modpath("automobiles_lib") .. DIR_DELIM .. "control.lua") dofile(minetest.get_modpath("automobiles_lib") .. DIR_DELIM .. "fuel_management.lua") dofile(minetest.get_modpath("automobiles_lib") .. DIR_DELIM .. "ground_detection.lua") dofile(minetest.get_modpath("automobiles_buggy") .. DIR_DELIM .. "buggy_forms.lua") -dofile(minetest.get_modpath("automobiles_buggy") .. DIR_DELIM .. "buggy_utilities.lua") dofile(minetest.get_modpath("automobiles_buggy") .. DIR_DELIM .. "buggy_entities.lua") dofile(minetest.get_modpath("automobiles_buggy") .. DIR_DELIM .. "buggy_crafts.lua") diff --git a/automobiles_catrelle/crafts.lua b/automobiles_catrelle/crafts.lua index ed5316a..8705ac6 100644 --- a/automobiles_catrelle/crafts.lua +++ b/automobiles_catrelle/crafts.lua @@ -11,25 +11,30 @@ minetest.register_craftitem("automobiles_catrelle:catrelle_body",{ }) -- catrelle -minetest.register_craftitem("automobiles_catrelle:catrelle", { +minetest.register_tool("automobiles_catrelle:catrelle", { description = S("Catrelle"), inventory_image = "automobiles_catrelle.png", liquids_pointable = false, + stack_max = 1, on_place = function(itemstack, placer, pointed_thing) if pointed_thing.type ~= "node" then return end + local stack_meta = itemstack:get_meta() + local staticdata = stack_meta:get_string("staticdata") + local pointed_pos = pointed_thing.above --pointed_pos.y=pointed_pos.y+0.2 - local car = minetest.add_entity(pointed_pos, "automobiles_catrelle:catrelle") + local car = minetest.add_entity(pointed_pos, "automobiles_catrelle:catrelle", staticdata) if car and placer then local ent = car:get_luaentity() local owner = placer:get_player_name() if ent then ent.owner = owner - ent._catrelle_type = 0 + ent.hp = 50 --reset hp + ent._catrelle_type = ent._catrelle_type or 0 --minetest.chat_send_all("owner: " .. ent.owner) car:set_yaw(placer:get_look_horizontal()) itemstack:take_item() @@ -44,25 +49,30 @@ minetest.register_craftitem("automobiles_catrelle:catrelle", { }) -- catrelle TL -minetest.register_craftitem("automobiles_catrelle:catrelle_4f", { +minetest.register_tool("automobiles_catrelle:catrelle_4f", { description = S("Catrelle 4F"), inventory_image = "automobiles_catrelle.png", liquids_pointable = false, + stack_max = 1, on_place = function(itemstack, placer, pointed_thing) if pointed_thing.type ~= "node" then return end + local stack_meta = itemstack:get_meta() + local staticdata = stack_meta:get_string("staticdata") + local pointed_pos = pointed_thing.above --pointed_pos.y=pointed_pos.y+0.2 - local car = minetest.add_entity(pointed_pos, "automobiles_catrelle:catrelle_4f") + local car = minetest.add_entity(pointed_pos, "automobiles_catrelle:catrelle_4f", staticdata) if car and placer then local ent = car:get_luaentity() local owner = placer:get_player_name() if ent then ent.owner = owner - ent._catrelle_type = 1 + ent.hp = 50 --reset hp + ent._catrelle_type = ent._catrelle_type or 1 --minetest.chat_send_all("owner: " .. ent.owner) car:set_yaw(placer:get_look_horizontal()) itemstack:take_item() diff --git a/automobiles_catrelle/entities.lua b/automobiles_catrelle/entities.lua index 0b3a943..c1542e5 100755 --- a/automobiles_catrelle/entities.lua +++ b/automobiles_catrelle/entities.lua @@ -5,57 +5,6 @@ function catrelle.extra_parts(self) self.back_seat = back_seat end --- destroy the delorean -function catrelle.destroy(self, puncher) - automobiles_lib.remove_light(self) - if self.sound_handle then - minetest.sound_stop(self.sound_handle) - self.sound_handle = nil - end - - if self.driver_name then - -- detach the driver first (puncher must be driver) - if puncher then - puncher:set_detach() - puncher:set_eye_offset({x = 0, y = 0, z = 0}, {x = 0, y = 0, z = 0}) - if minetest.global_exists("player_api") then - player_api.player_attached[self.driver_name] = nil - -- player should stand again - player_api.set_animation(puncher, "stand") - end - end - self.driver_name = nil - end - - local pos = self.object:get_pos() - - if self.front_suspension then self.front_suspension:remove() end - if self.lf_wheel then self.lf_wheel:remove() end - if self.rf_wheel then self.rf_wheel:remove() end - if self.rear_suspension then self.rear_suspension:remove() end - if self.lr_wheel then self.lr_wheel:remove() end - if self.rr_wheel then self.rr_wheel:remove() end - if self.fuel_gauge then self.fuel_gauge:remove() end - if self.lights then self.lights:remove() end - if self.r_lights then self.r_lights:remove() end - if self.reverse_lights then self.reverse_lights:remove() end - if self.turn_l_light then self.turn_l_light:remove() end - if self.turn_r_light then self.turn_r_light:remove() end - if self.back_seat then self.back_seat:remove() end - - automobiles_lib.seats_destroy(self) - - automobiles_lib.destroy_inventory(self) - self.object:remove() - - pos.y=pos.y+2 - - minetest.add_item({x=pos.x+math.random()-0.5,y=pos.y,z=pos.z+math.random()-0.5},'automobiles_lib:engine') - minetest.add_item({x=pos.x+math.random()-0.5,y=pos.y,z=pos.z+math.random()-0.5},'automobiles_lib:wheel') - minetest.add_item({x=pos.x+math.random()-0.5,y=pos.y,z=pos.z+math.random()-0.5},'automobiles_lib:wheel') - minetest.add_item({x=pos.x+math.random()-0.5,y=pos.y,z=pos.z+math.random()-0.5},'automobiles_lib:wheel') - minetest.add_item({x=pos.x+math.random()-0.5,y=pos.y,z=pos.z+math.random()-0.5},'automobiles_lib:wheel') -end -- -- entity -- @@ -381,7 +330,6 @@ catrelle.car_properties2._seat_pos = {{x=-4.0,y=3,z=15},{x=4.0,y=3,z=15}, {x=-4. catrelle.car_properties2._color = "#0063b0" catrelle.car_properties2._trunk_slots = 16 catrelle.car_properties2._extra_items_function = catrelle.extra_parts -catrelle.car_properties2._destroy_function = catrelle.destroy minetest.register_entity("automobiles_catrelle:catrelle_4f", catrelle.car_properties2) diff --git a/automobiles_coupe/coupe_crafts.lua b/automobiles_coupe/coupe_crafts.lua index e3ee5d9..7938142 100755 --- a/automobiles_coupe/coupe_crafts.lua +++ b/automobiles_coupe/coupe_crafts.lua @@ -11,24 +11,29 @@ minetest.register_craftitem("automobiles_coupe:coupe_body",{ }) -- coupe -minetest.register_craftitem("automobiles_coupe:coupe", { +minetest.register_tool("automobiles_coupe:coupe", { description = S("Coupe"), inventory_image = "automobiles_coupe.png", liquids_pointable = false, + stack_max = 1, on_place = function(itemstack, placer, pointed_thing) if pointed_thing.type ~= "node" then return end + local stack_meta = itemstack:get_meta() + local staticdata = stack_meta:get_string("staticdata") + local pointed_pos = pointed_thing.above --pointed_pos.y=pointed_pos.y+0.2 - local car = minetest.add_entity(pointed_pos, "automobiles_coupe:coupe") + local car = minetest.add_entity(pointed_pos, "automobiles_coupe:coupe", staticdata) if car and placer then local ent = car:get_luaentity() local owner = placer:get_player_name() if ent then ent.owner = owner + ent.hp = 50 --reset hp --minetest.chat_send_all("owner: " .. ent.owner) car:set_yaw(placer:get_look_horizontal()) itemstack:take_item() diff --git a/automobiles_delorean/crafts.lua b/automobiles_delorean/crafts.lua index 46b2d5d..a39642c 100644 --- a/automobiles_delorean/crafts.lua +++ b/automobiles_delorean/crafts.lua @@ -11,25 +11,30 @@ minetest.register_craftitem("automobiles_delorean:delorean_body",{ }) -- delorean -minetest.register_craftitem("automobiles_delorean:delorean", { +minetest.register_tool("automobiles_delorean:delorean", { description = S("Delorean"), inventory_image = "automobiles_delorean.png", liquids_pointable = false, + stack_max = 1, on_place = function(itemstack, placer, pointed_thing) if pointed_thing.type ~= "node" then return end + local stack_meta = itemstack:get_meta() + local staticdata = stack_meta:get_string("staticdata") + local pointed_pos = pointed_thing.above --pointed_pos.y=pointed_pos.y+0.2 - local car = minetest.add_entity(pointed_pos, "automobiles_delorean:delorean") + local car = minetest.add_entity(pointed_pos, "automobiles_delorean:delorean", staticdata) if car and placer then local ent = car:get_luaentity() local owner = placer:get_player_name() if ent then ent.owner = owner - ent._car_type = 0 + ent.hp = 50 --reset hp + ent._car_type = ent._car_type or 0 --minetest.chat_send_all("owner: " .. ent.owner) car:set_yaw(placer:get_look_horizontal()) itemstack:take_item() @@ -44,25 +49,30 @@ minetest.register_craftitem("automobiles_delorean:delorean", { }) -- delorean -minetest.register_craftitem("automobiles_delorean:time_machine", { +minetest.register_tool("automobiles_delorean:time_machine", { description = S("Time Machine"), inventory_image = "automobiles_delorean.png", liquids_pointable = false, + stack_max = 1, on_place = function(itemstack, placer, pointed_thing) if pointed_thing.type ~= "node" then return end + local stack_meta = itemstack:get_meta() + local staticdata = stack_meta:get_string("staticdata") + local pointed_pos = pointed_thing.above --pointed_pos.y=pointed_pos.y+0.2 - local car = minetest.add_entity(pointed_pos, "automobiles_delorean:delorean") + local car = minetest.add_entity(pointed_pos, "automobiles_delorean:delorean", staticdata) if car and placer then local ent = car:get_luaentity() local owner = placer:get_player_name() if ent then ent.owner = owner - ent._car_type = 1 + ent.hp = 50 --reset hp + ent._car_type = ent._car_type or 1 --minetest.chat_send_all("delorean: " .. ent._car_type) --minetest.chat_send_all("owner: " .. ent.owner) car:set_yaw(placer:get_look_horizontal()) diff --git a/automobiles_delorean/entities.lua b/automobiles_delorean/entities.lua index 53c6f4e..776dde0 100755 --- a/automobiles_delorean/entities.lua +++ b/automobiles_delorean/entities.lua @@ -401,14 +401,13 @@ minetest.register_entity("automobiles_delorean:delorean", { _inv_id = "", _change_color = automobiles_lib.paint, _intensity = 4, - _car_type = 0, + _car_type = nil, _car_gravity = -automobiles_lib.gravity, _is_flying = 0, _trunk_slots = 8, _engine_sound = "delorean_engine", _max_fuel = 10, _formspec_function = delorean.driver_formspec, - _destroy_function = delorean.destroy, _vehicle_name = S("Delorean"), _drive_wheel_pos = {x=-4.66, y=6.31, z=15.69}, diff --git a/automobiles_delorean/init.lua b/automobiles_delorean/init.lua index f79631e..08e0db8 100755 --- a/automobiles_delorean/init.lua +++ b/automobiles_delorean/init.lua @@ -23,7 +23,6 @@ dofile(minetest.get_modpath("automobiles_lib") .. DIR_DELIM .. "control.lua") dofile(minetest.get_modpath("automobiles_delorean") .. DIR_DELIM .. "forms.lua") dofile(minetest.get_modpath("automobiles_delorean") .. DIR_DELIM .. "control.lua") dofile(minetest.get_modpath("automobiles_delorean") .. DIR_DELIM .. "flight.lua") -dofile(minetest.get_modpath("automobiles_delorean") .. DIR_DELIM .. "utilities.lua") dofile(minetest.get_modpath("automobiles_delorean") .. DIR_DELIM .. "entities.lua") dofile(minetest.get_modpath("automobiles_delorean") .. DIR_DELIM .. "crafts.lua") diff --git a/automobiles_delorean/utilities.lua b/automobiles_delorean/utilities.lua deleted file mode 100755 index 58b763c..0000000 --- a/automobiles_delorean/utilities.lua +++ /dev/null @@ -1,56 +0,0 @@ - - --- destroy the delorean -function delorean.destroy(self, puncher) - automobiles_lib.remove_light(self) - if self.sound_handle then - minetest.sound_stop(self.sound_handle) - self.sound_handle = nil - end - - if self.driver_name then - -- detach the driver first (puncher must be driver) - if puncher then - puncher:set_detach() - puncher:set_eye_offset({x = 0, y = 0, z = 0}, {x = 0, y = 0, z = 0}) - if minetest.global_exists("player_api") then - player_api.player_attached[self.driver_name] = nil - -- player should stand again - player_api.set_animation(puncher, "stand") - end - end - self.driver_name = nil - end - - local pos = self.object:get_pos() - - if self.front_suspension then self.front_suspension:remove() end - if self.lf_wheel then self.lf_wheel:remove() end - if self.rf_wheel then self.rf_wheel:remove() end - if self.rear_suspension then self.rear_suspension:remove() end - if self.lr_wheel then self.lr_wheel:remove() end - if self.rr_wheel then self.rr_wheel:remove() end - if self.driver_seat then self.driver_seat:remove() end - if self.passenger_seat then self.passenger_seat:remove() end - if self.fuel_gauge then self.fuel_gauge:remove() end - if self.lights then self.lights:remove() end - if self.r_lights then self.r_lights:remove() end - if self.reverse_lights then self.reverse_lights:remove() end - if self.normal_kit then self.normal_kit:remove() end - if self.instruments then self.instruments:remove() end - if self.turn_l_light then self.turn_l_light:remove() end - if self.turn_r_light then self.turn_r_light:remove() end - - automobiles_lib.destroy_inventory(self) - self.object:remove() - - pos.y=pos.y+2 - - --minetest.add_item({x=pos.x+math.random()-0.5,y=pos.y,z=pos.z+math.random()-0.5},'automobiles_delorean:delorean') - minetest.add_item({x=pos.x+math.random()-0.5,y=pos.y,z=pos.z+math.random()-0.5},'automobiles_lib:engine') - minetest.add_item({x=pos.x+math.random()-0.5,y=pos.y,z=pos.z+math.random()-0.5},'automobiles_lib:wheel') - minetest.add_item({x=pos.x+math.random()-0.5,y=pos.y,z=pos.z+math.random()-0.5},'automobiles_lib:wheel') - minetest.add_item({x=pos.x+math.random()-0.5,y=pos.y,z=pos.z+math.random()-0.5},'automobiles_lib:wheel') - minetest.add_item({x=pos.x+math.random()-0.5,y=pos.y,z=pos.z+math.random()-0.5},'automobiles_lib:wheel') -end - diff --git a/automobiles_lib/init.lua b/automobiles_lib/init.lua index d9ddf96..e8f9654 100755 --- a/automobiles_lib/init.lua +++ b/automobiles_lib/init.lua @@ -24,6 +24,7 @@ automobiles_lib.fuel = {['biofuel:biofuel'] = 1,['biofuel:bottle_fuel'] = 1, automobiles_lib.gravity = 9.8 automobiles_lib.ideal_step = 0.2 automobiles_lib.is_creative = minetest.settings:get_bool("creative_mode", false) +automobiles_lib.can_collect_car = minetest.settings:get_bool("collect_automobiles", false) automobiles_lib.is_drift_game = false automobiles_lib.extra_drift = false @@ -505,19 +506,49 @@ function automobiles_lib.destroy(self, puncher) if self.reverse_lights then self.reverse_lights:remove() end if self.turn_l_light then self.turn_l_light:remove() end if self.turn_r_light then self.turn_r_light:remove() end + if self.rag then self.rag:remove() end --for buggy + if self.back_seat then self.back_seat:remove() end --for catrelle + if self.instruments then self.instruments:remove() end --for delorean + if self.normal_kit then self.normal_kit:remove() end + if self.rag_rect then self.rag_rect:remove() end --for roadster + automobiles_lib.seats_destroy(self) - automobiles_lib.destroy_inventory(self) - self.object:remove() pos.y=pos.y+2 - minetest.add_item({x=pos.x+math.random()-0.5,y=pos.y,z=pos.z+math.random()-0.5},'automobiles_lib:engine') - minetest.add_item({x=pos.x+math.random()-0.5,y=pos.y,z=pos.z+math.random()-0.5},'automobiles_lib:wheel') - minetest.add_item({x=pos.x+math.random()-0.5,y=pos.y,z=pos.z+math.random()-0.5},'automobiles_lib:wheel') - minetest.add_item({x=pos.x+math.random()-0.5,y=pos.y,z=pos.z+math.random()-0.5},'automobiles_lib:wheel') - minetest.add_item({x=pos.x+math.random()-0.5,y=pos.y,z=pos.z+math.random()-0.5},'automobiles_lib:wheel') + if automobiles_lib.can_collect_car == false then + minetest.add_item({x=pos.x+math.random()-0.5,y=pos.y,z=pos.z+math.random()-0.5},'automobiles_lib:engine') + minetest.add_item({x=pos.x+math.random()-0.5,y=pos.y,z=pos.z+math.random()-0.5},'automobiles_lib:wheel') + minetest.add_item({x=pos.x+math.random()-0.5,y=pos.y,z=pos.z+math.random()-0.5},'automobiles_lib:wheel') + minetest.add_item({x=pos.x+math.random()-0.5,y=pos.y,z=pos.z+math.random()-0.5},'automobiles_lib:wheel') + minetest.add_item({x=pos.x+math.random()-0.5,y=pos.y,z=pos.z+math.random()-0.5},'automobiles_lib:wheel') + else + local lua_ent = self.object:get_luaentity() + local staticdata = lua_ent:get_staticdata(self) + local obj_name = lua_ent.name + local player = minetest.get_player_by_name(self.owner) + + local stack = ItemStack(obj_name) + local stack_meta = stack:get_meta() + stack_meta:set_string("staticdata", staticdata) + + if player then + local inv = player:get_inventory() + if inv then + if inv:room_for_item("main", stack) then + inv:add_item("main", stack) + else + minetest.add_item({x=pos.x+math.random()-0.5,y=pos.y,z=pos.z+math.random()-0.5}, stack) + end + end + else + minetest.add_item({x=pos.x+math.random()-0.5,y=pos.y,z=pos.z+math.random()-0.5}, stack) + end + end + + self.object:remove() end function automobiles_lib.engine_set_sound_and_animation(self, _longit_speed) diff --git a/automobiles_lib/settingtypes.txt b/automobiles_lib/settingtypes.txt new file mode 100644 index 0000000..0b487c1 --- /dev/null +++ b/automobiles_lib/settingtypes.txt @@ -0,0 +1,5 @@ +# all settings for client menu or in minetest.conf on servers + + +# make cars collectable +collect_automobiles (Collect vehicles to inventory) bool true diff --git a/automobiles_motorcycle/motorcycle_crafts.lua b/automobiles_motorcycle/motorcycle_crafts.lua index ca7e4d0..9008999 100644 --- a/automobiles_motorcycle/motorcycle_crafts.lua +++ b/automobiles_motorcycle/motorcycle_crafts.lua @@ -15,24 +15,29 @@ minetest.register_craftitem("automobiles_motorcycle:wheel",{ }) -- motorcycle -minetest.register_craftitem("automobiles_motorcycle:motorcycle", { +minetest.register_tool("automobiles_motorcycle:motorcycle", { description = S("Motorcycle"), inventory_image = "automobiles_motorcycle.png", liquids_pointable = false, + stack_max = 1, on_place = function(itemstack, placer, pointed_thing) if pointed_thing.type ~= "node" then return end + local stack_meta = itemstack:get_meta() + local staticdata = stack_meta:get_string("staticdata") + local pointed_pos = pointed_thing.above --pointed_pos.y=pointed_pos.y+0.2 - local car = minetest.add_entity(pointed_pos, "automobiles_motorcycle:motorcycle") + local car = minetest.add_entity(pointed_pos, "automobiles_motorcycle:motorcycle", staticdata) if car and placer then local ent = car:get_luaentity() local owner = placer:get_player_name() if ent then ent.owner = owner + ent.hp = 50 --reset hp car:set_yaw(placer:get_look_horizontal()) itemstack:take_item() ent.object:set_acceleration({x=0,y=-automobiles_lib.gravity,z=0}) diff --git a/automobiles_motorcycle/motorcycle_utilities.lua b/automobiles_motorcycle/motorcycle_utilities.lua index 95b880b..94572b2 100755 --- a/automobiles_motorcycle/motorcycle_utilities.lua +++ b/automobiles_motorcycle/motorcycle_utilities.lua @@ -33,13 +33,38 @@ function motorcycle.destroy(self, puncher) if self.pax_mesh then self.pax_mesh:remove() end automobiles_lib.destroy_inventory(self) - self.object:remove() pos.y=pos.y+2 - --minetest.add_item({x=pos.x+math.random()-0.5,y=pos.y,z=pos.z+math.random()-0.5},'automobiles_motorcycle:motorcycle') - minetest.add_item({x=pos.x+math.random()-0.5,y=pos.y,z=pos.z+math.random()-0.5},'automobiles_lib:engine') - minetest.add_item({x=pos.x+math.random()-0.5,y=pos.y,z=pos.z+math.random()-0.5},'automobiles_motorcycle:wheel') - minetest.add_item({x=pos.x+math.random()-0.5,y=pos.y,z=pos.z+math.random()-0.5},'automobiles_motorcycle:wheel') + if automobiles_lib.can_collect_car == false then + --minetest.add_item({x=pos.x+math.random()-0.5,y=pos.y,z=pos.z+math.random()-0.5},'automobiles_motorcycle:motorcycle') + minetest.add_item({x=pos.x+math.random()-0.5,y=pos.y,z=pos.z+math.random()-0.5},'automobiles_lib:engine') + minetest.add_item({x=pos.x+math.random()-0.5,y=pos.y,z=pos.z+math.random()-0.5},'automobiles_motorcycle:wheel') + minetest.add_item({x=pos.x+math.random()-0.5,y=pos.y,z=pos.z+math.random()-0.5},'automobiles_motorcycle:wheel') + else + local lua_ent = self.object:get_luaentity() + local staticdata = lua_ent:get_staticdata(self) + local obj_name = lua_ent.name + local player = minetest.get_player_by_name(self.owner) + + local stack = ItemStack(obj_name) + local stack_meta = stack:get_meta() + stack_meta:set_string("staticdata", staticdata) + + if player then + local inv = player:get_inventory() + if inv then + if inv:room_for_item("main", stack) then + inv:add_item("main", stack) + else + minetest.add_item({x=pos.x+math.random()-0.5,y=pos.y,z=pos.z+math.random()-0.5}, stack) + end + end + else + minetest.add_item({x=pos.x+math.random()-0.5,y=pos.y,z=pos.z+math.random()-0.5}, stack) + end + end + + self.object:remove() end diff --git a/automobiles_roadster/init.lua b/automobiles_roadster/init.lua index 92fc977..12b23e7 100755 --- a/automobiles_roadster/init.lua +++ b/automobiles_roadster/init.lua @@ -25,7 +25,6 @@ dofile(minetest.get_modpath("automobiles_lib") .. DIR_DELIM .. "control.lua") dofile(minetest.get_modpath("automobiles_lib") .. DIR_DELIM .. "fuel_management.lua") dofile(minetest.get_modpath("automobiles_lib") .. DIR_DELIM .. "ground_detection.lua") dofile(minetest.get_modpath("automobiles_roadster") .. DIR_DELIM .. "roadster_forms.lua") -dofile(minetest.get_modpath("automobiles_roadster") .. DIR_DELIM .. "roadster_utilities.lua") dofile(minetest.get_modpath("automobiles_roadster") .. DIR_DELIM .. "roadster_entities.lua") dofile(minetest.get_modpath("automobiles_roadster") .. DIR_DELIM .. "roadster_crafts.lua") diff --git a/automobiles_roadster/roadster_crafts.lua b/automobiles_roadster/roadster_crafts.lua index fd9c90e..e0dc6a5 100644 --- a/automobiles_roadster/roadster_crafts.lua +++ b/automobiles_roadster/roadster_crafts.lua @@ -16,24 +16,29 @@ minetest.register_craftitem("automobiles_roadster:wheel",{ }) -- roadster -minetest.register_craftitem("automobiles_roadster:roadster", { +minetest.register_tool("automobiles_roadster:roadster", { description = S("Roadster"), inventory_image = "automobiles_roadster.png", liquids_pointable = false, + stack_max = 1, on_place = function(itemstack, placer, pointed_thing) if pointed_thing.type ~= "node" then return end + local stack_meta = itemstack:get_meta() + local staticdata = stack_meta:get_string("staticdata") + local pointed_pos = pointed_thing.above --pointed_pos.y=pointed_pos.y+0.2 - local car = minetest.add_entity(pointed_pos, "automobiles_roadster:roadster") + local car = minetest.add_entity(pointed_pos, "automobiles_roadster:roadster", staticdata) if car and placer then local ent = car:get_luaentity() local owner = placer:get_player_name() if ent then ent.owner = owner + ent.hp = 50 --reset hp car:set_yaw(placer:get_look_horizontal()) itemstack:take_item() ent.object:set_acceleration({x=0,y=-automobiles_lib.gravity,z=0}) diff --git a/automobiles_roadster/roadster_utilities.lua b/automobiles_roadster/roadster_utilities.lua deleted file mode 100755 index 84dc998..0000000 --- a/automobiles_roadster/roadster_utilities.lua +++ /dev/null @@ -1,55 +0,0 @@ ---dofile(minetest.get_modpath("automobiles_roadster") .. DIR_DELIM .. "roadster_global_definitions.lua") ---dofile(minetest.get_modpath("automobiles_roadster") .. DIR_DELIM .. "roadster_hud.lua") - --- destroy the roadster -function roadster.destroy(self, puncher) - automobiles_lib.remove_light(self) - if self.sound_handle then - minetest.sound_stop(self.sound_handle) - self.sound_handle = nil - end - - if self.driver_name then - -- detach the driver first (puncher must be driver) - if puncher then - puncher:set_detach() - puncher:set_eye_offset({x = 0, y = 0, z = 0}, {x = 0, y = 0, z = 0}) - if minetest.global_exists("player_api") then - player_api.player_attached[self.driver_name] = nil - -- player should stand again - player_api.set_animation(puncher, "stand") - end - end - self.driver_name = nil - end - - local pos = self.object:get_pos() - - if self.rag_rect then self.rag_rect:remove() end - if self.rag then self.rag:remove() end - if self.front_suspension then self.front_suspension:remove() end - if self.lf_wheel then self.lf_wheel:remove() end - if self.rf_wheel then self.rf_wheel:remove() end - if self.rear_suspension then self.rear_suspension:remove() end - if self.lr_wheel then self.lr_wheel:remove() end - if self.rr_wheel then self.rr_wheel:remove() end - if self.steering then self.steering:remove() end - if self.steering_axis then self.steering_axis:remove() end - if self.driver_seat then self.driver_seat:remove() end - if self.passenger_seat then self.passenger_seat:remove() end - if self.fuel_gauge then self.fuel_gauge:remove() end - if self.lights then self.lights:remove() end - - automobiles_lib.destroy_inventory(self) - self.object:remove() - - pos.y=pos.y+2 - - --minetest.add_item({x=pos.x+math.random()-0.5,y=pos.y,z=pos.z+math.random()-0.5},'automobiles_roadster:roadster') - minetest.add_item({x=pos.x+math.random()-0.5,y=pos.y,z=pos.z+math.random()-0.5},'automobiles_lib:engine') - minetest.add_item({x=pos.x+math.random()-0.5,y=pos.y,z=pos.z+math.random()-0.5},'automobiles_roadster:wheel') - minetest.add_item({x=pos.x+math.random()-0.5,y=pos.y,z=pos.z+math.random()-0.5},'automobiles_roadster:wheel') - minetest.add_item({x=pos.x+math.random()-0.5,y=pos.y,z=pos.z+math.random()-0.5},'automobiles_roadster:wheel') - minetest.add_item({x=pos.x+math.random()-0.5,y=pos.y,z=pos.z+math.random()-0.5},'automobiles_roadster:wheel') -end - diff --git a/automobiles_trans_am/crafts.lua b/automobiles_trans_am/crafts.lua index 1789cad..3e59dbe 100644 --- a/automobiles_trans_am/crafts.lua +++ b/automobiles_trans_am/crafts.lua @@ -11,24 +11,29 @@ minetest.register_craftitem("automobiles_trans_am:trans_am_body",{ }) -- trans_am -minetest.register_craftitem("automobiles_trans_am:trans_am", { +minetest.register_tool("automobiles_trans_am:trans_am", { description = S("Trans Am"), inventory_image = "automobiles_trans_am.png", liquids_pointable = false, + stack_max = 1, on_place = function(itemstack, placer, pointed_thing) if pointed_thing.type ~= "node" then return end + local stack_meta = itemstack:get_meta() + local staticdata = stack_meta:get_string("staticdata") + local pointed_pos = pointed_thing.above --pointed_pos.y=pointed_pos.y+0.2 - local car = minetest.add_entity(pointed_pos, "automobiles_trans_am:trans_am") + local car = minetest.add_entity(pointed_pos, "automobiles_trans_am:trans_am", staticdata) if car and placer then local ent = car:get_luaentity() local owner = placer:get_player_name() if ent then ent.owner = owner + ent.hp = 50 --reset hp ent._trans_am_type = 0 --minetest.chat_send_all("owner: " .. ent.owner) car:set_yaw(placer:get_look_horizontal()) diff --git a/automobiles_vespa/vespa_crafts.lua b/automobiles_vespa/vespa_crafts.lua index 8215774..7958b73 100644 --- a/automobiles_vespa/vespa_crafts.lua +++ b/automobiles_vespa/vespa_crafts.lua @@ -16,24 +16,29 @@ minetest.register_craftitem("automobiles_vespa:wheel",{ }) -- vespa -minetest.register_craftitem("automobiles_vespa:vespa", { +minetest.register_tool("automobiles_vespa:vespa", { description = S("Vespa"), inventory_image = "automobiles_vespa.png", liquids_pointable = false, + stack_max = 1, on_place = function(itemstack, placer, pointed_thing) if pointed_thing.type ~= "node" then return end + local stack_meta = itemstack:get_meta() + local staticdata = stack_meta:get_string("staticdata") + local pointed_pos = pointed_thing.above --pointed_pos.y=pointed_pos.y+0.2 - local car = minetest.add_entity(pointed_pos, "automobiles_vespa:vespa") + local car = minetest.add_entity(pointed_pos, "automobiles_vespa:vespa", staticdata) if car and placer then local ent = car:get_luaentity() local owner = placer:get_player_name() if ent then ent.owner = owner + ent.hp = 50 --reset hp car:set_yaw(placer:get_look_horizontal()) itemstack:take_item() ent.object:set_acceleration({x=0,y=-automobiles_lib.gravity,z=0}) diff --git a/automobiles_vespa/vespa_utilities.lua b/automobiles_vespa/vespa_utilities.lua index cdd69cf..9ef22ad 100755 --- a/automobiles_vespa/vespa_utilities.lua +++ b/automobiles_vespa/vespa_utilities.lua @@ -33,13 +33,38 @@ function vespa.destroy(self, puncher) if self.pax_mesh then self.pax_mesh:remove() end automobiles_lib.destroy_inventory(self) - self.object:remove() pos.y=pos.y+2 - --minetest.add_item({x=pos.x+math.random()-0.5,y=pos.y,z=pos.z+math.random()-0.5},'automobiles_vespa:vespa') - minetest.add_item({x=pos.x+math.random()-0.5,y=pos.y,z=pos.z+math.random()-0.5},'automobiles_lib:engine') - minetest.add_item({x=pos.x+math.random()-0.5,y=pos.y,z=pos.z+math.random()-0.5},'automobiles_vespa:wheel') - minetest.add_item({x=pos.x+math.random()-0.5,y=pos.y,z=pos.z+math.random()-0.5},'automobiles_vespa:wheel') + if automobiles_lib.can_collect_car == false then + --minetest.add_item({x=pos.x+math.random()-0.5,y=pos.y,z=pos.z+math.random()-0.5},'automobiles_vespa:vespa') + minetest.add_item({x=pos.x+math.random()-0.5,y=pos.y,z=pos.z+math.random()-0.5},'automobiles_lib:engine') + minetest.add_item({x=pos.x+math.random()-0.5,y=pos.y,z=pos.z+math.random()-0.5},'automobiles_vespa:wheel') + minetest.add_item({x=pos.x+math.random()-0.5,y=pos.y,z=pos.z+math.random()-0.5},'automobiles_vespa:wheel') + else + local lua_ent = self.object:get_luaentity() + local staticdata = lua_ent:get_staticdata(self) + local obj_name = lua_ent.name + local player = minetest.get_player_by_name(self.owner) + + local stack = ItemStack(obj_name) + local stack_meta = stack:get_meta() + stack_meta:set_string("staticdata", staticdata) + + if player then + local inv = player:get_inventory() + if inv then + if inv:room_for_item("main", stack) then + inv:add_item("main", stack) + else + minetest.add_item({x=pos.x+math.random()-0.5,y=pos.y,z=pos.z+math.random()-0.5}, stack) + end + end + else + minetest.add_item({x=pos.x+math.random()-0.5,y=pos.y,z=pos.z+math.random()-0.5}, stack) + end + end + + self.object:remove() end