diff --git a/mods/rangedweapons/m16.lua b/mods/rangedweapons/m16.lua new file mode 100644 index 00000000..36914531 --- /dev/null +++ b/mods/rangedweapons/m16.lua @@ -0,0 +1,177 @@ +minetest.register_craft({ + output = 'rangedweapons:m16', + recipe = { + {'default:diamond', 'default:steelblock', 'default:steel_ingot'}, + {'default:steel_ingot', 'default:diamond', 'default:steel_ingot'}, + {'default:steel_ingot', '', 'default:steel_ingot'}, + } +}) + + minetest.register_craftitem("rangedweapons:m16", { + stack_max= 1, + wield_scale = {x=1.75,y=1.75,z=1.3}, + description = "" ..core.colorize("#35cdff","Colt M16\n") ..core.colorize("#FFFFFF", "Ranged damage: 4-10\n") ..core.colorize("#FFFFFF", "Accuracy: 80%\n") ..core.colorize("#FFFFFF", "Mob knockback: 3\n")..core.colorize("#FFFFFF", "Critical chance: 9%\n") ..core.colorize("#FFFFFF", "Critical damage: 9-19\n") ..core.colorize("#FFFFFF", "Ammunition: 5.56mm rounds\n") ..core.colorize("#FFFFFF", "Rate of fire: 0.125\n") ..core.colorize("#FFFFFF", "Gun type: Assault rifle\n") ..core.colorize("#FFFFFF", "Bullet velocity: 35"), + range = 0, + inventory_image = "rangedweapons_m16.png", +}) + +local timer = 0 +minetest.register_globalstep(function(dtime, player) + timer = timer + dtime; + if timer >= 0.125 then + for _, player in pairs(minetest.get_connected_players()) do + local inv = player:get_inventory() + local controls = player:get_player_control() + if controls.LMB then + timer = 0 + local wielded_item = player:get_wielded_item():get_name() + if wielded_item == "rangedweapons:m16" then + if not inv:contains_item("main", "rangedweapons:556mm") then +minetest.sound_play("rangedweapons_empty", {object=player}) + else + if wielded_item == "rangedweapons:m16" then + inv:remove_item("main", "rangedweapons:556mm") + local pos = player:getpos() + local dir = player:get_look_dir() + local yaw = player:get_look_yaw() + if pos and dir and yaw then + pos.y = pos.y + 1.6 + local obj = minetest.add_entity(pos, "rangedweapons:m16shot") + if obj then + minetest.sound_play("rangedweapons_smg", {object=obj}) + obj:setvelocity({x=dir.x * 35, y=dir.y * 35, z=dir.z * 35}) + obj:setacceleration({x=dir.x * math.random(-2.0,2.0), y=math.random(-2.0,2.0), z=dir.z * math.random(-2.0,2.0)}) + obj:setyaw(yaw + math.pi) + pos.y = pos.y + 0 + local obj = minetest.add_entity(pos, "rangedweapons:empty_shell") + minetest.sound_play("", {object=obj}) + obj:setvelocity({x=dir.x * -10, y=dir.y * -10, z=dir.z * -10}) + obj:setacceleration({x=dir.x * -5, y= -10, z=dir.z * -5}) + obj:setyaw(yaw + math.pi) + minetest.add_particle({ + pos = pos, + velocity = {x=dir.x * 3, y=dir.y * 3, z=dir.z * 3} , + acceleration = {x=dir.x * -4, y=2, z=dir.z * -4}, + expirationtime = 0.5, + size = 4, + collisiondetection = false, + vertical = false, + texture = "tnt_smoke.png", + glow = 5, + }) + + local ent = obj:get_luaentity() + if ent then + ent.player = ent.player or player + end + end + end + end +end + +end + end + end + end + end) + +local rangedweapons_m16shot = { + physical = false, + timer = 0, + visual = "sprite", + visual_size = {x=0.3, y=0.3}, + textures = {"rangedweapons_invisible.png"}, + lastpos= {}, + collisionbox = {0, 0, 0, 0, 0, 0}, +} +rangedweapons_m16shot.on_step = function(self, dtime, node, pos) + self.timer = self.timer + dtime + local tiem = 0.002 + local pos = self.object:getpos() + local node = minetest.get_node(pos) + + if self.timer > 0.085 then + local objs = minetest.get_objects_inside_radius({x = pos.x, y = pos.y, z = pos.z}, 1) + for k, obj in pairs(objs) do + if obj:get_luaentity() ~= nil then + if obj:get_luaentity().name ~= "rangedweapons:m16shot" and obj:get_luaentity().name ~= "__builtin:item" then + if math.random(1, 100) <= 9 then + local damage = math.random(9,19) + obj:punch(self.object, 1.0, { + full_punch_interval = 1.0, + damage_groups= {fleshy = damage, knockback=6}, + }, nil) + minetest.sound_play("crit", {pos = self.lastpos, gain = 0.8}) + self.object:remove() + else + local damage = math.random(4,10) + obj:punch(self.object, 1.0, { + full_punch_interval = 1.0, + damage_groups= {fleshy = damage, knockback = 3}, + }, nil) + minetest.sound_play("default_dig_cracky", {pos = self.lastpos, gain = 0.8}) + self.object:remove() + end + end + else + if math.random(1, 100) <= 9 then + local damage = math.random(9,19) + obj:punch(self.object, 1.0, { + full_punch_interval = 1.0, + damage_groups= {fleshy = damage}, + }, nil) + minetest.sound_play("crit", {pos = self.lastpos, gain = 0.8}) + self.object:remove() + else + local damage = math.random(4,10) + obj:punch(self.object, 1.0, { + full_punch_interval = 1.0, + damage_groups= {fleshy = damage}, + }, nil) + minetest.sound_play("default_dig_cracky", {pos = self.lastpos, gain = 0.8}) + self.object:remove() + end + end + if timer >= 0.002 + tiem then + minetest.add_particle({ + pos = pos, + velocity = 0, + acceleration = {x=0, y=0, z=0}, + expirationtime = 0.06, + size = 3, + collisiondetection = false, + vertical = false, + texture = "rangedweapons_bullet_fly.png", + glow = 15, + }) + tiem = tiem + 0.002 + end + if self.timer >= 4.0 then + self.object:remove() + end + if self.lastpos.x ~= nil then + if minetest.registered_nodes[node.name].walkable then + if not minetest.setting_getbool("creative_mode") then + end + minetest.sound_play("default_dig_cracky", {pos = self.lastpos, gain = 0.8}) + if node.name == "rangedweapons:barrel" or + node.name == "doors:door_glass_a" or + node.name == "doors:door_glass_b" or + node.name == "xpanes:pane" or + node.name == "xpanes:pane_flat" or + node.name == "vessels:drinking_glass" or + node.name == "vessels:glass_bottle" or + node.name == "default:glass" then + minetest.get_node_timer(pos):start(0) + end + self.object:remove() + end + end + self.lastpos= {x = pos.x, y = pos.y, z = pos.z} +end +end +end + + + +minetest.register_entity("rangedweapons:m16shot", rangedweapons_m16shot ) \ No newline at end of file diff --git a/mods/rangedweapons/m200.lua b/mods/rangedweapons/m200.lua new file mode 100644 index 00000000..b17f9a5b --- /dev/null +++ b/mods/rangedweapons/m200.lua @@ -0,0 +1,203 @@ +minetest.register_craft({ + output = 'rangedweapons:m200_uld', + recipe = { + {'default:diamondblock', 'default:steel_ingot', 'default:diamondblock'}, + {'default:steel_ingot', 'default:steel_ingot', 'default:steel_ingot'}, + {'default:steel_ingot', 'default:diamond', 'default:steel_ingot'}, + } +}) + +minetest.register_craftitem("rangedweapons:m200_uld", { + stack_max= 1, + wield_scale = {x=2.1,y=2.1,z=1.4}, + range = 0, + description = "" ..core.colorize("#35cdff","M200 Intervention \n") ..core.colorize("#FFFFFF", "Ranged damage: 150/sec of bullet lifetime\n") ..core.colorize("#FFFFFF", "Accuracy: 100%\n") ..core.colorize("#FFFFFF", "Mob knockback: 20\n") ..core.colorize("#FFFFFF", "Critical chance: 50%\n") ..core.colorize("#FFFFFF", "Critical damage: 400/sec of bullet lifetime\n") ..core.colorize("#FFFFFF", "Ammunition: 308.Winchester rounds\n") ..core.colorize("#FFFFFF", "Reload time: 1.75\n") ..core.colorize("#be0d00", "The gun is NOT loaded! (Right-click to load)\n")..core.colorize("#FFFFFF", "Gun type: Rifle\n") ..core.colorize("#FFFFFF", "Bullet velocity: 64"), + inventory_image = "rangedweapons_m200.png", + on_use = function(user) + minetest.sound_play("rangedweapons_empty", {user}) + end, + on_secondary_use = function(itemstack, player, pointed_thing) + local inv = player:get_inventory() + if inv:contains_item("main", "rangedweapons:308winchester") then + inv:remove_item("main", "rangedweapons:308winchester") + local pos = player:getpos() + local dir = player:get_look_dir() + local yaw = player:get_look_yaw() + local wield_index = player:get_wield_index() + if pos and dir and yaw then + pos.y = pos.y + 1.6 + local obj = minetest.add_entity(pos, "rangedweapons:empty_shell") + minetest.sound_play("", {object=obj}) + obj:setvelocity({x=dir.x * -10, y=dir.y * -10, z=dir.z * -10}) + obj:setacceleration({x=dir.x * -5, y= -10, z=dir.z * -5}) + obj:setyaw(yaw + math.pi) + local ent = obj:get_luaentity() + if ent then + ent.player = ent.player or player + end + end + minetest.sound_play("rangedweapons_reload_a", {player}) + minetest.after(1.75, + function(player, wield_index) + player:get_inventory():set_stack("main", wield_index, "rangedweapons:m200") + minetest.sound_play("rangedweapons_reload_b", {player}) + end, + player,wield_index + ) + return ItemStack("rangedweapons:m200_rld") + end + end +}) + +minetest.register_craftitem("rangedweapons:m200_rld", { + stack_max= 1, + range = 0, + wield_scale = {x=2.1,y=2.1,z=1.4}, + description = "**RELOADING M200 INTERVENTION**", + groups = {not_in_creative_inventory = 1}, + inventory_image = "rangedweapons_m200_rld.png", +}) + + +minetest.register_tool("rangedweapons:m200", { + description = "" ..core.colorize("#35cdff","M200 Intervention \n") ..core.colorize("#FFFFFF", "Ranged damage: 150/sec of bullet lifetime\n")..core.colorize("#FFFFFF", "Accuracy: 100%\n") ..core.colorize("#FFFFFF", "Mob knockback: 20\n") ..core.colorize("#FFFFFF", "Critical chance: 50%\n") ..core.colorize("#FFFFFF", "Critical damage: 400/sec of bullet lifetime\n") ..core.colorize("#FFFFFF", "Ammunition: 308.Winchester rounds\n") ..core.colorize("#FFFFFF", "Reload time: 1.75\n") ..core.colorize("#27a600", "The gun is loaded!\n")..core.colorize("#FFFFFF", "Gun type: Rifle\n") ..core.colorize("#FFFFFF", "Bullet velocity: 64"), + range = 0, + groups = {not_in_creative_inventory = 1}, + wield_scale = {x=2.1,y=2.1,z=1.4}, + inventory_image = "rangedweapons_m200.png", + on_use = function(itemstack, user, pointed_thing) + local pos = user:getpos() + local dir = user:get_look_dir() + local yaw = user:get_look_yaw() + if pos and dir and yaw then + pos.y = pos.y + 1.6 + local obj = minetest.add_entity(pos, "rangedweapons:m200shot") + if obj then + minetest.sound_play("rangedweapons_rifle_a", {object=obj}) + obj:setvelocity({x=dir.x * 64, y=dir.y * 64, z=dir.z * 64}) + obj:setacceleration({x=dir.x * 0, y=0, z=dir.z * 0}) + obj:setyaw(yaw + math.pi) + minetest.add_particle({ + pos = pos, + velocity = {x=dir.x * 3, y=dir.y * 3, z=dir.z * 3} , + acceleration = {x=dir.x * -4, y=2, z=dir.z * -4}, + expirationtime = 1.5, + size = 8, + collisiondetection = false, + vertical = false, + texture = "tnt_smoke.png", + glow = 5, + }) + local ent = obj:get_luaentity() + if ent then + ent.player = ent.player or user + itemstack = "rangedweapons:m200_uld" + end + end + end + return itemstack + end, +}) + +local rangedweapons_m200shot = { + physical = false, + timer = 0, + visual = "sprite", + visual_size = {x=0.3, y=0.3}, + textures = {"rangedweapons_invisible.png"}, + lastpos= {}, + collisionbox = {0, 0, 0, 0, 0, 0}, +} +rangedweapons_m200shot.on_step = function(self, dtime, node, pos) + self.timer = self.timer + dtime + local tiem = 0.002 + local pos = self.object:getpos() + local node = minetest.get_node(pos) + + if self.timer > 0.05 then + local objs = minetest.get_objects_inside_radius({x = pos.x, y = pos.y, z = pos.z}, 1.6) + for k, obj in pairs(objs) do + if obj:get_luaentity() ~= nil then + if obj:get_luaentity().name ~= "rangedweapons:m200shot" and obj:get_luaentity().name ~= "__builtin:item" then + if math.random(1, 100) <= 50 then + local damage = 400 * self.timer + obj:punch(self.object, 1.0, { + full_punch_interval = 1.0, + damage_groups= {fleshy = damage, knockback = 40}, + }, nil) + minetest.sound_play("crit", {pos = self.lastpos, gain = 0.8}) + self.object:remove() + else + local damage = 150 * self.timer + obj:punch(self.object, 1.0, { + full_punch_interval = 1.0, + damage_groups= {fleshy = damage, knockback = 20}, + }, nil) + minetest.sound_play("default_dig_cracky", {pos = self.lastpos, gain = 0.8}) + self.object:remove() + end + end + else + if math.random(1, 100) <= 50 then + local damage = 400 * self.timer + obj:punch(self.object, 1.0, { + full_punch_interval = 1.0, + damage_groups= {fleshy = damage}, + }, nil) + minetest.sound_play("crit", {pos = self.lastpos, gain = 0.8}) + self.object:remove() + else + local damage = 150 * self.timer + obj:punch(self.object, 1.0, { + full_punch_interval = 1.0, + damage_groups= {fleshy = damage}, + }, nil) + minetest.sound_play("default_dig_cracky", {pos = self.lastpos, gain = 0.8}) + self.object:remove() + end + end + if self.timer >= 0.002 + tiem then + minetest.add_particle({ + pos = pos, + velocity = 0, + acceleration = {x=0, y=0, z=0}, + expirationtime = 0.06, + size = 3, + collisiondetection = false, + vertical = false, + texture = "rangedweapons_bullet_fly.png", + glow = 15, + }) + tiem = tiem + 0.002 + end + if self.timer >= 4.0 then + self.object:remove() + end + if self.lastpos.x ~= nil then + if minetest.registered_nodes[node.name].walkable then + if not minetest.setting_getbool("creative_mode") then + end + minetest.sound_play("default_dig_cracky", {pos = self.lastpos, gain = 0.8}) + if node.name == "rangedweapons:barrel" or + node.name == "doors:door_glass_a" or + node.name == "doors:door_glass_b" or + node.name == "xpanes:pane" or + node.name == "xpanes:pane_flat" or + node.name == "vessels:drinking_glass" or + node.name == "vessels:glass_bottle" or + node.name == "default:glass" then + minetest.get_node_timer(pos):start(0) + end + self.object:remove() + end + end + self.lastpos= {x = pos.x, y = pos.y, z = pos.z} +end +end +end + + + +minetest.register_entity("rangedweapons:m200shot", rangedweapons_m200shot ) + + diff --git a/mods/rangedweapons/m60.lua b/mods/rangedweapons/m60.lua new file mode 100644 index 00000000..398dac76 --- /dev/null +++ b/mods/rangedweapons/m60.lua @@ -0,0 +1,176 @@ +minetest.register_craft({ + output = 'rangedweapons:m60', + recipe = { + {'default:diamond', 'default:steel_ingot', 'default:mese'}, + {'default:steel_ingot', 'default:steelblock', 'default:steelblock'}, + {'dye:black', 'default:diamond', 'default:steel_ingot'}, + } +}) + + minetest.register_craftitem("rangedweapons:m60", { + stack_max= 1, + wield_scale = {x=2.5,y=2.5,z=1.5}, + description = "" ..core.colorize("#35cdff","M60\n") ..core.colorize("#FFFFFF", "Ranged damage: 2-6\n") ..core.colorize("#FFFFFF", "Accuracy: 55%\n") ..core.colorize("#FFFFFF", "Mob knockback: 2\n") ..core.colorize("#FFFFFF", "Critical chance: 8%\n") ..core.colorize("#FFFFFF", "Critical damage: 5-10\n") ..core.colorize("#FFFFFF", "Ammunition: 7.26mm rounds\n") ..core.colorize("#FFFFFF", "Rate of fire: 0.04\n") ..core.colorize("#FFFFFF", "Gun type: heavy machinegun\n") ..core.colorize("#FFFFFF", "Bullet velocity: 30"), + range = 0, + inventory_image = "rangedweapons_m60.png", +}) + +local timer = 0 +minetest.register_globalstep(function(dtime, player) + timer = timer + dtime; + if timer >= 0.04 then + for _, player in pairs(minetest.get_connected_players()) do + local inv = player:get_inventory() + local controls = player:get_player_control() + if controls.LMB then + timer = 0 + local wielded_item = player:get_wielded_item():get_name() + if wielded_item == "rangedweapons:m60" then + if not inv:contains_item("main", "rangedweapons:726mm") then +minetest.sound_play("rangedweapons_empty", {object=player}) + else + if wielded_item == "rangedweapons:m60" then + inv:remove_item("main", "rangedweapons:726mm") + local pos = player:getpos() + local dir = player:get_look_dir() + local yaw = player:get_look_yaw() + if pos and dir and yaw then + pos.y = pos.y + 1.6 + local obj = minetest.add_entity(pos, "rangedweapons:m60shot") + if obj then + minetest.sound_play("rangedweapons_machinegun", {object=obj}) + obj:setvelocity({x=dir.x * 30, y=dir.y * 30, z=dir.z * 30}) + obj:setacceleration({x=dir.x * math.random(-4.5,4.5), y=math.random(-4.5,4.5), z=dir.z * math.random(-4.5,4.5)}) + obj:setyaw(yaw + math.pi) + pos.y = pos.y + 0 + local obj = minetest.add_entity(pos, "rangedweapons:empty_shell") + minetest.sound_play("", {object=obj}) + obj:setvelocity({x=dir.x * -10, y=dir.y * -10, z=dir.z * -10}) + obj:setacceleration({x=dir.x * -5, y= -10, z=dir.z * -5}) + obj:setyaw(yaw + math.pi) + minetest.add_particle({ + pos = pos, + velocity = {x=dir.x * 3, y=dir.y * 3, z=dir.z * 3} , + acceleration = {x=dir.x * -4, y=2, z=dir.z * -4}, + expirationtime = 0.25, + size = 4, + collisiondetection = false, + vertical = false, + texture = "tnt_smoke.png", + glow = 5, + }) + local ent = obj:get_luaentity() + if ent then + ent.player = ent.player or player + end + end + end + end +end + +end + end + end + end + end) + +local rangedweapons_m60shot = { + physical = false, + timer = 0, + visual = "sprite", + visual_size = {x=0.3, y=0.3}, + textures = {"rangedweapons_invisible.png"}, + lastpos= {}, + collisionbox = {0, 0, 0, 0, 0, 0}, +} +rangedweapons_m60shot.on_step = function(self, dtime, node, pos) + self.timer = self.timer + dtime + local tiem = 0.002 + local pos = self.object:getpos() + local node = minetest.get_node(pos) + + if self.timer > 0.11 then + local objs = minetest.get_objects_inside_radius({x = pos.x, y = pos.y, z = pos.z}, 1) + for k, obj in pairs(objs) do + if obj:get_luaentity() ~= nil then + if obj:get_luaentity().name ~= "rangedweapons:m60shot" and obj:get_luaentity().name ~= "__builtin:item" then + if math.random(1, 100) <= 8 then + local damage = math.random(5,10) + obj:punch(self.object, 1.0, { + full_punch_interval = 1.0, + damage_groups= {fleshy = damage, knockback=4}, + }, nil) + minetest.sound_play("crit", {pos = self.lastpos, gain = 0.8}) + self.object:remove() + else + local damage = math.random(2,6) + obj:punch(self.object, 1.0, { + full_punch_interval = 1.0, + damage_groups= {fleshy = damage, knockback = 2}, + }, nil) + minetest.sound_play("default_dig_cracky", {pos = self.lastpos, gain = 0.8}) + self.object:remove() + end + end + else + if math.random(1, 100) <= 8 then + local damage = math.random(5,10) + obj:punch(self.object, 1.0, { + full_punch_interval = 1.0, + damage_groups= {fleshy = damage}, + }, nil) + minetest.sound_play("crit", {pos = self.lastpos, gain = 0.8}) + self.object:remove() + else + local damage = math.random(2,6) + obj:punch(self.object, 1.0, { + full_punch_interval = 1.0, + damage_groups= {fleshy = damage}, + }, nil) + minetest.sound_play("default_dig_cracky", {pos = self.lastpos, gain = 0.8}) + self.object:remove() + end + end + if timer >= 0.002 + tiem then + minetest.add_particle({ + pos = pos, + velocity = 0, + acceleration = {x=0, y=0, z=0}, + expirationtime = 0.06, + size = 3, + collisiondetection = false, + vertical = false, + texture = "rangedweapons_bullet_fly.png", + glow = 15, + }) + tiem = tiem + 0.002 + end + if self.timer >= 4.0 then + self.object:remove() + end + if self.lastpos.x ~= nil then + if minetest.registered_nodes[node.name].walkable then + if not minetest.setting_getbool("creative_mode") then + end + minetest.sound_play("default_dig_cracky", {pos = self.lastpos, gain = 0.8}) + if node.name == "rangedweapons:barrel" or + node.name == "doors:door_glass_a" or + node.name == "doors:door_glass_b" or + node.name == "xpanes:pane" or + node.name == "xpanes:pane_flat" or + node.name == "vessels:drinking_glass" or + node.name == "vessels:glass_bottle" or + node.name == "default:glass" then + minetest.get_node_timer(pos):start(0) + end + self.object:remove() + end + end + self.lastpos= {x = pos.x, y = pos.y, z = pos.z} +end +end +end + + + +minetest.register_entity("rangedweapons:m60shot", rangedweapons_m60shot ) \ No newline at end of file diff --git a/mods/rangedweapons/m79.lua b/mods/rangedweapons/m79.lua new file mode 100644 index 00000000..5ab2dfe7 --- /dev/null +++ b/mods/rangedweapons/m79.lua @@ -0,0 +1,106 @@ +minetest.register_craft({ + output = 'rangedweapons:m79_uld', + recipe = { + {'default:steel_ingot', '', 'default:mese_crystal'}, + {'default:steelblock', 'default:steelblock', 'default:tree'}, + {'default:tree', 'default:tree', 'default:tree'}, + } +}) + +minetest.register_craftitem("rangedweapons:m79_uld", { + stack_max= 1, + wield_scale = {x=2.0,y=2.0,z=2.5}, + range = 0, + description = "" ..core.colorize("#35cdff","M79\n") ..core.colorize("#FFFFFF", "Explosion radius: 2\n") ..core.colorize("#FFFFFF", "Bullet gravitational pull: 5\n") ..core.colorize("#FFFFFF", "Ammunition: 40mm grenades\n") ..core.colorize("#FFFFFF", "Reload time: 1.25\n") ..core.colorize("#be0d00", "The gun is NOT loaded! (Right-click to load)\n")..core.colorize("#FFFFFF", "Gun type:Grenade launcher\n") ..core.colorize("#FFFFFF", "Bullet velocity: 15"), + inventory_image = "rangedweapons_m79.png", + on_use = function(user) + minetest.sound_play("rangedweapons_empty", {user}) + end, + on_secondary_use = function(itemstack, player, pointed_thing) + local inv = player:get_inventory() + if inv:contains_item("main", "rangedweapons:40mm") then + inv:remove_item("main", "rangedweapons:40mm") + local pos = player:getpos() + local dir = player:get_look_dir() + local yaw = player:get_look_yaw() + local wield_index = player:get_wield_index() + if pos and dir and yaw then + pos.y = pos.y + 1.6 + local obj = minetest.add_entity(pos, "rangedweapons:empty_shell_grenade") + minetest.sound_play("", {object=obj}) + obj:setvelocity({x=dir.x * -10, y=dir.y * -10, z=dir.z * -10}) + obj:setacceleration({x=dir.x * -5, y= -10, z=dir.z * -5}) + obj:setyaw(yaw + math.pi) + local ent = obj:get_luaentity() + if ent then + ent.player = ent.player or player + end + end + minetest.sound_play("rangedweapons_reload_a", {player}) + + minetest.after(1.25, + function(player, wield_index) + player:get_inventory():set_stack("main", wield_index, "rangedweapons:m79") + minetest.sound_play("rangedweapons_reload_b", {player}) + end, + player,wield_index + ) + return ItemStack("rangedweapons:m79_rld") + end + end +}) + + +minetest.register_craftitem("rangedweapons:m79_rld", { + stack_max= 1, + range = 0, + wield_scale = {x=2.0,y=2.0,z=2.5}, + description = "**RELOADING M79**", + groups = {not_in_creative_inventory = 1}, + inventory_image = "rangedweapons_m79_rld.png", +}) + + +minetest.register_tool("rangedweapons:m79", { + description = "" ..core.colorize("#35cdff","M79\n") ..core.colorize("#FFFFFF", "Explosion radius: 2\n") ..core.colorize("#FFFFFF", "Bullet gravitational pull: 5\n") ..core.colorize("#FFFFFF", "Ammunition: 40mm grenades\n") ..core.colorize("#FFFFFF", "Reload time: 1.25\n") ..core.colorize("#27a600", "The gun is loaded!\n")..core.colorize("#FFFFFF", "Gun type:Grenade launcher\n") ..core.colorize("#FFFFFF", "Bullet velocity: 15"), + range = 0, + groups = {not_in_creative_inventory = 1}, + wield_scale = {x=2.0,y=2.0,z=2.5}, + inventory_image = "rangedweapons_m79.png", + on_use = function(itemstack, user, pointed_thing) + local pos = user:getpos() + local dir = user:get_look_dir() + local yaw = user:get_look_yaw() + if pos and dir and yaw then + pos.y = pos.y + 1.6 + local obj = minetest.add_entity(pos, "rangedweapons:he_grenade") + if obj then + minetest.sound_play("rangedweapons_rocket", {object=obj}) + obj:setvelocity({x=dir.x * 15, y=dir.y * 15, z=dir.z * 15}) + obj:setacceleration({x=dir.x * -1, y=-5, z=dir.z * -1}) + obj:setyaw(yaw + math.pi) + minetest.add_particle({ + pos = pos, + velocity = {x=dir.x * 3, y=dir.y * 3, z=dir.z * 3} , + acceleration = {x=dir.x * -4, y=2, z=dir.z * -4}, + expirationtime = 1.5, + size = 10, + collisiondetection = false, + vertical = false, + texture = "tnt_smoke.png", + glow = 5, + }) + local ent = obj:get_luaentity() + if ent then + ent.player = ent.player or user + itemstack = "rangedweapons:m79_uld" + end + end + end + return itemstack + end, +}) + + + + diff --git a/mods/rangedweapons/makarov.lua b/mods/rangedweapons/makarov.lua new file mode 100644 index 00000000..bffc6963 --- /dev/null +++ b/mods/rangedweapons/makarov.lua @@ -0,0 +1,192 @@ + + + local timer = 0 +minetest.register_globalstep(function(dtime, player) + timer = timer + dtime; + if timer >= 0.5 then + for _, player in pairs(minetest.get_connected_players()) do + if player:get_wielded_item():get_name() == "rangedweapons:makarov_rld" then + player:set_wielded_item("rangedweapons:makarov") + minetest.sound_play("", {player}) + + end + + end + end + end) + + +minetest.register_craftitem("rangedweapons:makarov_rld", { + stack_max= 1, + wield_scale = {x=0.9,y=0.9,z=1.0}, + description = "***RELOADING MAKAROV PISTOL***", + range = 0, + groups = {not_in_creative_inventory = 1}, + inventory_image = "rangedweapons_makarov_rld.png", +}) + + +minetest.register_tool("rangedweapons:makarov", { + description = "" ..core.colorize("#35cdff","Makarov pistol\n") ..core.colorize("#FFFFFF", "Ranged damage: 4-6\n")..core.colorize("#FFFFFF", "Accuracy: 90%\n") ..core.colorize("#FFFFFF", "Mob knockback: 3\n") ..core.colorize("#FFFFFF", "Critical chance: 12%\n") ..core.colorize("#FFFFFF", "Critical damage: 8-12\n") ..core.colorize("#FFFFFF", "Ammunition: 9mm rounds\n") ..core.colorize("#FFFFFF", "Rate of fire: 0.5\n") ..core.colorize("#FFFFFF", "Gun type: Handgun\n") ..core.colorize("#FFFFFF", "Bullet velocity: 20"), + range = 0, + wield_scale = {x=0.9,y=0.9,z=1.0}, + inventory_image = "rangedweapons_makarov.png", + on_use = function(itemstack, user, pointed_thing) + timer = 0 + local inv = user:get_inventory() + if not inv:contains_item("main", "rangedweapons:9mm 1") then + minetest.sound_play("rangedweapons_empty", {object=user}) + return itemstack + end + if not minetest.setting_getbool("creative_mode") then + inv:remove_item("main", "rangedweapons:9mm") + end + local pos = user:getpos() + local dir = user:get_look_dir() + local yaw = user:get_look_yaw() + if pos and dir and yaw then + pos.y = pos.y + 1.6 + local obj = minetest.add_entity(pos, "rangedweapons:makarovshot") + if obj then + minetest.sound_play("rangedweapons_makarov", {object=obj}) + obj:setvelocity({x=dir.x * 20, y=dir.y * 20, z=dir.z * 20}) + obj:setacceleration({x=dir.x * math.random(-1.0,1.0), y=math.random(-1.0,1.0), z=dir.z * math.random(-1.0,1.0)}) + obj:setyaw(yaw + math.pi) + pos.y = pos.y + 0 + local obj = minetest.add_entity(pos, "rangedweapons:empty_shell") + minetest.sound_play("", {object=obj}) + obj:setvelocity({x=dir.x * -10, y=dir.y * -10, z=dir.z * -10}) + obj:setacceleration({x=dir.x * -5, y= -10, z=dir.z * -5}) + obj:setyaw(yaw + math.pi) + minetest.add_particle({ + pos = pos, + velocity = {x=dir.x * 3, y=dir.y * 3, z=dir.z * 3} , + acceleration = {x=dir.x * -4, y=2, z=dir.z * -4}, + expirationtime = 0.75, + size = 5, + collisiondetection = false, + vertical = false, + texture = "tnt_smoke.png", + glow = 5, + }) + local ent = obj:get_luaentity() + if ent then + ent.player = ent.player or user + itemstack = "rangedweapons:makarov_rld" + end + end + end + return itemstack + end, +}) +minetest.register_craft({ + output = 'rangedweapons:makarov', + recipe = { + {'', 'default:steel_ingot', 'default:steel_ingot'}, + {'', 'default:mese_crystal_fragment', 'default:tree'}, + {'', '', 'dye:black'}, + } +}) + +local rangedweapons_makarovshot = { + physical = false, + timer = 0, + visual = "sprite", + visual_size = {x=0.3, y=0.3}, + textures = {"rangedweapons_invisible.png"}, + lastpos= {}, + collisionbox = {0, 0, 0, 0, 0, 0}, +} +rangedweapons_makarovshot.on_step = function(self, dtime, node, pos) + self.timer = self.timer + dtime + local tiem = 0.002 + local pos = self.object:getpos() + local node = minetest.get_node(pos) + + if self.timer > 0.165 then + local objs = minetest.get_objects_inside_radius({x = pos.x, y = pos.y, z = pos.z}, 1) + for k, obj in pairs(objs) do + if obj:get_luaentity() ~= nil then + if obj:get_luaentity().name ~= "rangedweapons:makarovshot" and obj:get_luaentity().name ~= "__builtin:item" then + if math.random(1, 100) <= 12 then + local damage = math.random(8,12) + obj:punch(self.object, 1.0, { + full_punch_interval = 1.0, + damage_groups= {fleshy = damage, knockback = 6}, + }, nil) + minetest.sound_play("crit", {pos = self.lastpos, gain = 0.8}) + self.object:remove() + else + local damage = math.random(4,6) + obj:punch(self.object, 1.0, { + full_punch_interval = 1.0, + damage_groups= {fleshy = damage, knockback = 3}, + }, nil) + minetest.sound_play("default_dig_cracky", {pos = self.lastpos, gain = 0.8}) + self.object:remove() + end + end + else + if math.random(1, 100) <= 12 then + local damage = math.random(8,12) + obj:punch(self.object, 1.0, { + full_punch_interval = 1.0, + damage_groups= {fleshy = damage}, + }, nil) + minetest.sound_play("crit", {pos = self.lastpos, gain = 0.8}) + self.object:remove() + else + local damage = math.random(4,6) + obj:punch(self.object, 1.0, { + full_punch_interval = 1.0, + damage_groups= {fleshy = damage}, + }, nil) + minetest.sound_play("default_dig_cracky", {pos = self.lastpos, gain = 0.8}) + self.object:remove() + end + end + if timer >= 0.002 + tiem then + minetest.add_particle({ + pos = pos, + velocity = 0, + acceleration = {x=0, y=0, z=0}, + expirationtime = 0.06, + size = 3, + collisiondetection = false, + vertical = false, + texture = "rangedweapons_bullet_fly.png", + glow = 15, + }) + tiem = tiem + 0.002 + end + if self.timer >= 4.0 then + self.object:remove() + end + if self.lastpos.x ~= nil then + if minetest.registered_nodes[node.name].walkable then + if not minetest.setting_getbool("creative_mode") then + end + minetest.sound_play("default_dig_cracky", {pos = self.lastpos, gain = 0.8}) + if node.name == "rangedweapons:barrel" or + node.name == "doors:door_glass_a" or + node.name == "doors:door_glass_b" or + node.name == "xpanes:pane" or + node.name == "xpanes:pane_flat" or + node.name == "vessels:drinking_glass" or + node.name == "vessels:glass_bottle" or + node.name == "default:glass" then + minetest.get_node_timer(pos):start(0) + end + self.object:remove() + end + end + self.lastpos= {x = pos.x, y = pos.y, z = pos.z} +end +end +end + + + +minetest.register_entity("rangedweapons:makarovshot", rangedweapons_makarovshot ) + +