diff --git a/armor.lua b/armor.lua new file mode 100644 index 0000000..6b77967 --- /dev/null +++ b/armor.lua @@ -0,0 +1,9 @@ +if minetest.global_exists("armor") and armor.attributes then + table.insert(armor.attributes, "bullet_res") +end +if minetest.global_exists("armor") and armor.attributes then + table.insert(armor.attributes, "ammo_save") +end +if minetest.global_exists("armor") and armor.attributes then + table.insert(armor.attributes, "ranged_dmg") +end diff --git a/blocks/antigun_block.lua b/blocks/antigun_block.lua new file mode 100644 index 0000000..55b5746 --- /dev/null +++ b/blocks/antigun_block.lua @@ -0,0 +1,6 @@ +minetest.register_node("rangedweapons:antigun_block", { + description = "" ..core.colorize("#35cdff","Anti-gun block\n")..core.colorize("#FFFFFF", "Prevents people from using guns, in 10 node radius to each side from this block"), + tiles = {"textures/blocks/antigun_block.png"}, + groups = {choppy = 3, oddly_breakable_by_hand = 3}, + sounds = default.node_sound_wood_defaults(), +}) diff --git a/bullet_stuff.lua b/bullet_stuff.lua index cc338e5..e2b6d79 100644 --- a/bullet_stuff.lua +++ b/bullet_stuff.lua @@ -1,5 +1,3 @@ - - minetest.register_craftitem("rangedweapons:308shot", { wield_scale = {x=1.0,y=1.0,z=1.0}, inventory_image = "rangedweapons_308_shot.png", diff --git a/colors.lua b/colors.lua new file mode 100644 index 0000000..b8495af --- /dev/null +++ b/colors.lua @@ -0,0 +1,6 @@ +local color = {} + +color.white = "#FFFFFF" + + +return color diff --git a/constants.lua b/constants.lua new file mode 100644 index 0000000..4d48859 --- /dev/null +++ b/constants.lua @@ -0,0 +1,5 @@ +local constants = {} + +constants.mod_name = "rangedweapons" + +return constants diff --git a/init.lua b/init.lua index 6ec121b..1f103ca 100644 --- a/init.lua +++ b/init.lua @@ -1,934 +1,1042 @@ - - local modpath = minetest.get_modpath(minetest.get_current_modname()) -if minetest.global_exists("armor") and armor.attributes then - table.insert(armor.attributes, "bullet_res") -end -if minetest.global_exists("armor") and armor.attributes then - table.insert(armor.attributes, "ammo_save") -end -if minetest.global_exists("armor") and armor.attributes then - table.insert(armor.attributes, "ranged_dmg") +local weapon = dofile(modpath .. "/weapon.lua") + +dofile(modpath .. "/settings.lua") +dofile(modpath .. "/cooldown_stuff.lua") +dofile(modpath .. "/skills.lua") +dofile(modpath .. "/misc.lua") +dofile(modpath .. "/bullet_knockback.lua") +dofile(modpath .. "/ammo.lua") +dofile(modpath .. "/crafting.lua") +dofile(modpath .. "/armor.lua") + +dofile(modpath .. "/blocks/antigun_block.lua") + +-- Load all weapons +for k, v in pairs(weapon.weapons) do + weapon_type = k + + for i, weapon_data in ipairs(v) do + dofile(weapon.get_weapon_path(modpath, weapon_type, weapon_data)) + end end -minetest.register_node("rangedweapons:antigun_block", { - description = "" ..core.colorize("#35cdff","Anti-gun block\n")..core.colorize("#FFFFFF", "Prevents people from using guns, in 10 node radius to each side from this block"), - tiles = {"rangedweapons_antigun_block.png"}, - groups = {choppy = 3, oddly_breakable_by_hand = 3}, - sounds = default.node_sound_wood_defaults(), -}) ---- ---- gun_funcs ---- make_sparks = function(pos) -minetest.sound_play("rengedweapons_ricochet", {pos, gain = 0.75}) - for i=1,9 do - minetest.add_particle({ - pos = pos, - velocity = {x=math.random(-6.0,6.0), y=math.random(-10.0,15.0), z=math.random(-6.0,6.0)}, - acceleration = {x=math.random(-9.0,9.0), y=math.random(-15.0,-3.0), z=math.random(-9.0,9.0)}, - expirationtime = 1.0, - size = math.random(1,2), - collisiondetection = true, - vertical = false, - texture = "rangedweapons_spark.png", - glow = 25, - }) -end -end - - -rangedweapons_gain_skill = function(player,skill,chance) - -if math.random(1, chance) == 1 then - local p_meta = player:get_meta() -local skill_num = p_meta:get_int(skill) -if skill_num < rweapons_max_gun_efficiency then -p_meta:set_int(skill, skill_num + 1) - minetest.chat_send_player(player:get_player_name(), "" ..core.colorize("#25c200","You've improved your skill with this type of gun!")) -end -end - -end - - -rangedweapons_reload_gun = function(itemstack, player) - -GunCaps = itemstack:get_definition().RW_gun_capabilities - -if GunCaps ~= nil then -gun_unload_sound = GunCaps.gun_unload_sound or "" -end - -minetest.sound_play(gun_unload_sound, {player}) - - -local gun_reload = 0.25 - -if GunCaps ~= nil then -gun_reload = GunCaps.gun_reload or 0.25 -end - -local playerMeta = player:get_meta() -local gunMeta = itemstack:get_meta() - -gunMeta:set_float("RW_reload_delay",gun_reload) - -playerMeta:set_float("rw_cooldown",gun_reload) - -local player_has_ammo = 0 -local clipSize = 0 -local reload_ammo = "" - -if GunCaps.suitable_ammo ~= nil then -local inv = player:get_inventory() -for i = 1,inv:get_size("main") do - -for _, ammo in pairs(GunCaps.suitable_ammo) do -if inv:get_stack("main",i):get_name() == ammo[1] then -reload_ammo = inv:get_stack("main",i) -clipSize = ammo[2] - -player_has_ammo = 1 -break -end end - -if player_has_ammo == 1 then -break -end - -end end - -if player_has_ammo == 1 then -local gun_icon = "rangedweapons_emergency_gun_icon.png" - -if GunCaps.gun_icon ~= nil then -gun_icon = GunCaps.gun_icon -end - -local ammo_icon = "rangedweapons_emergency_ammo_icon.png" - -if reload_ammo:get_definition().inventory_image ~= nil then -ammo_icon = reload_ammo:get_definition().inventory_image -end - - player:hud_change(gunimg, "text", gun_icon) - player:hud_change(ammoimg, "text", ammo_icon) - -local gunMeta = itemstack:get_meta() -local ammoCount = gunMeta:get_int("RW_bullets") -local ammoName = gunMeta:get_string("RW_ammo_name") -local inv = player:get_inventory() - -inv:add_item("main",ammoName.." "..ammoCount) - - -if inv:contains_item("main",reload_ammo:get_name().." "..clipSize) then -inv:remove_item("main",reload_ammo:get_name().." "..clipSize) -gunMeta:set_int("RW_bullets",clipSize) -else -gunMeta:set_int("RW_bullets",reload_ammo:get_count()) -inv:remove_item("main",reload_ammo:get_name().." "..reload_ammo:get_count()) -end - -gunMeta:set_string("RW_ammo_name",reload_ammo:get_name()) - -player:hud_change(gunammo, "text", gunMeta:get_int("RW_bullets")) - -if GunCaps.gun_magazine ~= nil then - local pos = player:get_pos() - local dir = player:get_look_dir() - local yaw = player:get_look_horizontal() - if pos and dir and yaw then - pos.y = pos.y + 1.4 -local obj = minetest.add_entity(pos,"rangedweapons:mag") - if obj then -obj:set_properties({textures = {GunCaps.gun_magazine}}) - obj:set_velocity({x=dir.x*2, y=dir.y*2, z=dir.z*2}) - obj:set_acceleration({x=0, y=-5, z=0}) - obj:set_rotation({x=0,y=yaw+math.pi,z=0}) -end end end - -if GunCaps.gun_unloaded ~= nil then -itemstack:set_name(GunCaps.gun_unloaded) -end - - -end -end - - - -rangedweapons_single_load_gun = function(itemstack, player) - -GunCaps = itemstack:get_definition().RW_gun_capabilities - -if GunCaps ~= nil then -gun_unload_sound = GunCaps.gun_unload_sound or "" -end - -minetest.sound_play(gun_unload_sound, {player}) - -local gun_reload = 0.25 - -if GunCaps ~= nil then -gun_reload = GunCaps.gun_reload or 0.25 -end - -local playerMeta = player:get_meta() -local gunMeta = itemstack:get_meta() - -gunMeta:set_float("RW_reload_delay",gun_reload) - -playerMeta:set_float("rw_cooldown",gun_reload) - -local player_has_ammo = 0 -local clipSize = 0 -local reload_ammo = "" - -if GunCaps.suitable_ammo ~= nil then -local inv = player:get_inventory() -for i = 1,inv:get_size("main") do - -for _, ammo in pairs(GunCaps.suitable_ammo) do -if inv:get_stack("main",i):get_name() == ammo[1] then -reload_ammo = inv:get_stack("main",i) -clipSize = ammo[2] - -player_has_ammo = 1 -break -end end - -if player_has_ammo == 1 then -break -end - -end end - -if player_has_ammo == 1 then -local gun_icon = "rangedweapons_emergency_gun_icon.png" - -if GunCaps.gun_icon ~= nil then -gun_icon = GunCaps.gun_icon -end - -local ammo_icon = "rangedweapons_emergency_ammo_icon.png" - -if reload_ammo:get_definition().inventory_image ~= nil then -ammo_icon = reload_ammo:get_definition().inventory_image -end - - player:hud_change(gunimg, "text", gun_icon) - player:hud_change(ammoimg, "text", ammo_icon) - -local gunMeta = itemstack:get_meta() -local ammoCount = gunMeta:get_int("RW_bullets") -local ammoName = gunMeta:get_string("RW_ammo_name") -local inv = player:get_inventory() - -if ammoName ~= reload_ammo:get_name() then -inv:add_item("main",ammoName.." "..ammoCount) -gunMeta:set_int("RW_bullets",0) -end - -if inv:contains_item("main",reload_ammo:get_name()) and -gunMeta:get_int("RW_bullets") < clipSize then -inv:remove_item("main",reload_ammo:get_name()) -gunMeta:set_int("RW_bullets",gunMeta:get_int("RW_bullets")+1) -end - -gunMeta:set_string("RW_ammo_name",reload_ammo:get_name()) - -player:hud_change(gunammo, "text", gunMeta:get_int("RW_bullets")) - -if GunCaps.gun_unloaded ~= nil then -itemstack:set_name(GunCaps.gun_unloaded) -end - -end -end - -rangedweapons_yeet = function(itemstack, player) - -if minetest.find_node_near(player:getpos(), 10,"rangedweapons:antigun_block") -then - minetest.chat_send_player(player:get_player_name(), "" ..core.colorize("#ff0000","throwable weapons are prohibited in this area!")) -else - -ThrowCaps = itemstack:get_definition().RW_throw_capabilities -playerMeta = player:get_meta() - -if ThrowCaps ~= nil then -throw_cooldown = ThrowCaps.throw_cooldown or 0 -end - -if playerMeta:get_float("rw_cooldown") <= 0 then - -playerMeta:set_float("rw_cooldown", throw_cooldown) - -local throw_damage = {fleshy=1} -local throw_sound = "rangedweapons_throw" -local throw_velocity = 20 -local throw_accuracy = 100 -local throw_cooling = 0 -local throw_crit = 0 -local throw_critEffc = 1 -local throw_mobPen = 0 -local throw_nodePen = 0 -local throw_dps = 0 -local throw_gravity = 0 -local throw_door_breaking = 0 -local throw_skill = "" -local throw_skillChance = 0 -local throw_smokeSize = 0 -local throw_ent = "rangedweapons:shot_bullet" -local throw_visual = "wielditem" -local throw_texture = "rangedweapons:shot_bullet_visual" -local throw_glass_breaking = 0 -local throw_particles = {} -local throw_sparks = 0 -local throw_bomb_ignite = 0 -local throw_size = 0 -local throw_glow = 0 - -if ThrowCaps ~= nil then -throw_damage = ThrowCaps.throw_damage or {fleshy=1} -throw_sound = ThrowCaps.throw_sound or "rangedweapons_glock" -throw_velocity = ThrowCaps.throw_velocity or 20 -throw_accuracy = ThrowCaps.throw_accuracy or 100 -throw_cooling = ThrowCaps.throw_cooling or itemstack:get_name() -throw_crit = ThrowCaps.throw_crit or 0 -throw_critEffc = ThrowCaps.throw_critEffc or 1 -throw_projectiles = ThrowCaps.throw_projectiles or 1 -throw_mobPen = ThrowCaps.throw_mob_penetration or 0 -throw_nodePen = ThrowCaps.throw_node_penetration or 0 -throw_dps = ThrowCaps.throw_dps or 0 -throw_gravity = ThrowCaps.throw_gravity or 0 -throw_door_breaking = ThrowCaps.throw_door_breaking or 0 -throw_ent = ThrowCaps.throw_entity or "rangedweapons:shot_bullet" -throw_visual = ThrowCaps.throw_visual or "wielditem" -throw_texture = ThrowCaps.throw_texture or "rangedweapons:shot_bullet_visual" -throw_glass_breaking = ThrowCaps.throw_glass_breaking or 0 -throw_particles = ThrowCaps.throw_particles or nil -throw_sparks = ThrowCaps.throw_sparks or 0 -throw_bomb_ignite = ThrowCaps.ignites_explosives or 0 -throw_size = ThrowCaps.throw_projectile_size or 0 -throw_glow = ThrowCaps.throw_projectile_glow or 0 -OnCollision = ThrowCaps.OnCollision or function()end - -if ThrowCaps.throw_skill ~= nil then -throw_skill = ThrowCaps.throw_skill[1] or "" -throw_skillChance = ThrowCaps.throw_skill[2] or 0 -else -throw_skill = "" -throw_skillChance = 0 -end -end - -if throw_skillChance > 0 and throw_skill ~= "" then -rangedweapons_gain_skill(player,throw_skill,throw_skillChance) -end - -if throw_skill ~= "" then -skill_value = playerMeta:get_int(throw_skill)/100 -else -skill_value = 1 -end - -rangedweapons_launch_projectile(player,throw_projectiles,throw_damage,throw_ent,throw_visual,throw_texture,throw_sound,throw_velocity,throw_accuracy,skill_value,OnCollision,throw_crit,throw_critEffc,throw_mobPen,throw_nodePen,0,"","","",throw_dps,throw_gravity,throw_door_breaking,throw_glass_breaking,throw_particles,throw_sparks,throw_bomb_ignite,throw_size,0,itemstack:get_wear(),throw_glow) - -itemstack:take_item() - -end -end - -end - - -rangedweapons_shoot_gun = function(itemstack, player) - -if minetest.find_node_near(player:getpos(), 10,"rangedweapons:antigun_block") -then -minetest.sound_play("rangedweapons_empty", {player}) - minetest.chat_send_player(player:get_player_name(), "" ..core.colorize("#ff0000","Guns are prohibited in this area!")) - -else - -local gun_cooldown = 0 -local GunCaps = itemstack:get_definition().RW_gun_capabilities -local gun_ammo_save = 0 - -if GunCaps ~= nil then -gun_cooldown = GunCaps.gun_cooldown or 0 -gun_ammo_save = GunCaps.ammo_saving or 0 -end - -local gunMeta = itemstack:get_meta() -local playerMeta = player:get_meta() - -if gunMeta:get_int("RW_bullets") > 0 and -playerMeta:get_float("rw_cooldown") <= 0 then - -playerMeta:set_float("rw_cooldown", gun_cooldown) - -if math.random(1,100) > gun_ammo_save then -gunMeta:set_int("RW_bullets",gunMeta:get_int("RW_bullets")-1) -end - -player:hud_change(gunammo, "text", gunMeta:get_int("RW_bullets")) - -local gun_icon = "rangedweapons_emergency_gun_icon.png" -if GunCaps.gun_icon ~= nil then -gun_icon = GunCaps.gun_icon -end - player:hud_change(gunimg, "text", gun_icon) - -local OnCollision = function() end - -local bulletStack = ItemStack({name = gunMeta:get_string("RW_ammo_name")}) -AmmoCaps = bulletStack:get_definition().RW_ammo_capabilities - -local gun_damage = {fleshy=1} -local gun_sound = "rangedweapons_glock" -local gun_velocity = 20 -local gun_accuracy = 100 -local gun_cooling = 0 -local gun_crit = 0 -local gun_critEffc = 1 -local gun_mobPen = 0 -local gun_nodePen = 0 -local gun_shell = 0 -local gun_durability = 0 -local gun_dps = 0 -local gun_gravity = 0 -local gun_door_breaking = 0 -local gun_skill = "" -local gun_skillChance = 0 -local gun_smokeSize = 0 - -local bullet_damage = {fleshy=0} -local bullet_velocity = 0 -local bullet_ent = "rangedweapons:shot_bullet" -local bullet_visual = "wielditem" -local bullet_texture = "rangedweapons:shot_bullet_visual" -local bullet_crit = 0 -local bullet_critEffc = 0 -local bullet_projMult = 1 -local bullet_mobPen = 0 -local bullet_nodePen = 0 -local bullet_shell_ent = "rangedweapons:empty_shell" -local bullet_shell_visual = "wielditem" -local bullet_shell_texture = "rangedweapons:shelldrop" -local bullet_dps = 0 -local bullet_gravity = 0 -local bullet_glass_breaking = 0 -local bullet_particles = {} -local bullet_sparks = 0 -local bullet_bomb_ignite = 0 -local bullet_size = 0 -local bullet_glow = 20 - - - -if GunCaps ~= nil then -gun_damage = GunCaps.gun_damage or {fleshy=1} -gun_sound = GunCaps.gun_sound or "rangedweapons_glock" -gun_velocity = GunCaps.gun_velocity or 20 -gun_accuracy = GunCaps.gun_accuracy or 100 -gun_cooling = GunCaps.gun_cooling or itemstack:get_name() -gun_crit = GunCaps.gun_crit or 0 -gun_critEffc = GunCaps.gun_critEffc or 1 -gun_projectiles = GunCaps.gun_projectiles or 1 -gun_mobPen = GunCaps.gun_mob_penetration or 0 -gun_nodePen = GunCaps.gun_node_penetration or 0 -gun_shell = GunCaps.has_shell or 0 -gun_durability = GunCaps.gun_durability or 0 -gun_dps = GunCaps.gun_dps or 0 -gun_ammo_save = GunCaps.ammo_saving or 0 -gun_gravity = GunCaps.gun_gravity or 0 -gun_door_breaking = GunCaps.gun_door_breaking or 0 -gun_smokeSize = GunCaps.gun_smokeSize or 0 - -if GunCaps.gun_skill ~= nil then -gun_skill = GunCaps.gun_skill[1] or "" -gun_skillChance = GunCaps.gun_skill[2] or 0 -else -gun_skill = "" -gun_skillChance = 0 -end - -end - -if gun_skillChance > 0 and gun_skill ~= "" then -rangedweapons_gain_skill(player,gun_skill,gun_skillChance) -end - -local ammo_icon = "rangedweapons_emergency_ammo_icon.png" -if bulletStack:get_definition().inventory_image ~= nil then -ammo_icon = bulletStack:get_definition().inventory_image -end -player:hud_change(ammoimg, "text", ammo_icon) - -if AmmoCaps ~= nil then - -OnCollision = AmmoCaps.OnCollision or function()end -bullet_damage = AmmoCaps.ammo_damage or {fleshy=1} -bullet_velocity = AmmoCaps.ammo_velocity or 0 -bullet_ent = AmmoCaps.ammo_entity or "rangedweapons:shot_bullet" -bullet_visual = AmmoCaps.ammo_visual or "wielditem" -bullet_texture = AmmoCaps.ammo_texture or "rangedweapons:shot_bullet_visual" -bullet_crit = AmmoCaps.ammo_crit or 0 -bullet_critEffc = AmmoCaps.ammo_critEffc or 0 -bullet_projMult = AmmoCaps.ammo_projectile_multiplier or 1 -bullet_mobPen = AmmoCaps.ammo_mob_penetration or 0 -bullet_nodePen = AmmoCaps.ammo_node_penetration or 0 -bullet_shell_ent = AmmoCaps.shell_entity or "rangedweapons:empty_shell" -bullet_shell_visual = AmmoCaps.shell_visual or "wielditem" -bullet_shell_texture = AmmoCaps.shell_texture or "rangedweapons:shelldrop" -bullet_dps = AmmoCaps.ammo_dps or 0 -bullet_gravity = AmmoCaps.ammo_gravity or 0 -bullet_glass_breaking = AmmoCaps.ammo_glass_breaking or 0 -bullet_particles = AmmoCaps.ammo_particles or nil -bullet_sparks = AmmoCaps.has_sparks or 0 -bullet_bomb_ignite = AmmoCaps.ignites_explosives or 0 -bullet_size = AmmoCaps.ammo_projectile_size or 0.0025 -bullet_glow = AmmoCaps.ammo_projectile_glow or 20 -end - - -local combined_crit = gun_crit + bullet_crit -local combined_critEffc = gun_critEffc + bullet_critEffc -local combined_velocity = gun_velocity + bullet_velocity -local combined_projNum = math.ceil(gun_projectiles * bullet_projMult) -local combined_mobPen = gun_mobPen + bullet_mobPen -local combined_nodePen = gun_nodePen + bullet_nodePen -local combined_dps = gun_dps + bullet_dps -local combined_dmg = {} -local combined_gravity = gun_gravity + bullet_gravity - -for _, gunDmg in pairs(gun_damage) do -if bullet_damage[_] ~= nil then -combined_dmg[_] = gun_damage[_] + bullet_damage[_] -else -combined_dmg[_] = gun_damage[_] -end -end -for _, bulletDmg in pairs(bullet_damage) do -if gun_damage[_] == nil then -combined_dmg[_] = bullet_damage[_] -end -end - ---minetest.chat_send_all(minetest.serialize(combined_dmg)) - -if gun_skill ~= "" then -skill_value = playerMeta:get_int(gun_skill)/100 -else -skill_value = 1 -end - -rangedweapons_launch_projectile(player,combined_projNum,combined_dmg,bullet_ent,bullet_visual,bullet_texture,gun_sound,combined_velocity,gun_accuracy,skill_value,OnCollision,combined_crit,combined_critEffc,combined_mobPen,combined_nodePen,gun_shell,bullet_shell_ent,bullet_shell_texture,bullet_shell_visual,combined_dps,combined_gravity,gun_door_breaking,bullet_glass_breaking,bullet_particles,bullet_sparks,bullet_bomb_ignite,bullet_size,gun_smokeSize,0,bullet_glow) - -if rweapons_gun_durability == "true" then -itemstack:add_wear(65535/gun_durability) -end -itemstack:set_name(gun_cooling) - -end -end end - - - - -rangedweapons_shoot_powergun = function(itemstack, player) - -if minetest.find_node_near(player:getpos(), 10,"rangedweapons:antigun_block") -then -minetest.sound_play("rangedweapons_empty", {player}) - minetest.chat_send_player(player:get_player_name(), "" ..core.colorize("#ff0000","Guns are prohibited in this area!")) -else -local power_cooldown = 0 - -PowerCaps = itemstack:get_definition().RW_powergun_capabilities - -if PowerCaps ~= nil then -power_cooldown = PowerCaps.power_cooldown or 0 -power_consumption = PowerCaps.power_consumption or 0 -end - -local inv = player:get_inventory() -local playerMeta = player:get_meta() - -if inv:contains_item("main", "rangedweapons:power_particle "..PowerCaps.power_consumption) and -playerMeta:get_float("rw_cooldown") <= 0 then -playerMeta:set_float("rw_cooldown", power_cooldown) - -local OnCollision = function() end - -local power_damage = {fleshy=1} -local power_sound = "rangedweapons_laser" -local power_velocity = 20 -local power_accuracy = 100 -local power_cooling = 0 -local power_crit = 0 -local power_critEffc = 1 -local power_mobPen = 0 -local power_nodePen = 0 -local power_durability = 0 -local power_dps = 0 -local power_gravity = 0 -local power_door_breaking = 0 -local power_skill = "" -local power_skillChance = 0 -local power_ent = "rangedweapons:shot_bullet" -local power_visual = "wielditem" -local power_texture = "rangedweapons:shot_bullet_visual" -local power_glass_breaking = 0 -local power_particles = {} -local power_sparks = 0 -local power_bomb_ignite = 0 -local power_size = 0 -local power_glow = 20 - -if PowerCaps ~= nil then -power_damage = PowerCaps.power_damage or {fleshy=1} -power_sound = PowerCaps.power_sound or "rangedweapons_glock" -power_velocity = PowerCaps.power_velocity or 20 -power_accuracy = PowerCaps.power_accuracy or 100 -power_cooling = PowerCaps.power_cooling or itemstack:get_name() -power_crit = PowerCaps.power_crit or 0 -power_critEffc = PowerCaps.power_critEffc or 1 -power_projectiles = PowerCaps.power_projectiles or 1 -power_mobPen = PowerCaps.power_mob_penetration or 0 -power_nodePen = PowerCaps.power_node_penetration or 0 -power_durability = PowerCaps.power_durability or 0 -power_dps = PowerCaps.power_dps or 0 -power_gravity = PowerCaps.power_gravity or 0 -power_door_breaking = PowerCaps.power_door_breaking or 0 -OnCollision = PowerCaps.OnCollision or function()end -power_ent = PowerCaps.power_entity or "rangedweapons:shot_bullet" -power_visual = PowerCaps.power_visual or "wielditem" -power_texture = PowerCaps.power_texture or "rangedweapons:shot_bullet_visual" -power_glass_breaking = PowerCaps.power_glass_breaking or 0 -power_particles = PowerCaps.power_particles or nil -power_sparks = PowerCaps.has_sparks or 0 -power_bomb_ignite = PowerCaps.ignites_explosives or 0 -power_size = PowerCaps.power_projectile_size or 0.0025 -power_glow = PowerCaps.power_projectile_glow or 20 - -if PowerCaps.power_skill ~= nil then -power_skill = PowerCaps.power_skill[1] or "" -power_skillChance = PowerCaps.power_skill[2] or 0 -else -power_skill = "" -power_skillChance = 0 -end - -end - -if power_skillChance > 0 and power_skill ~= "" then -rangedweapons_gain_skill(player,power_skill,power_skillChance) -end - -if power_skill ~= "" then -skill_value = playerMeta:get_int(power_skill)/100 -else -skill_value = 1 -end - -rangedweapons_launch_projectile(player,power_projectiles,power_damage,power_ent,power_visual,power_texture,power_sound,power_velocity,power_accuracy,skill_value,OnCollision,power_crit,power_critEffc,power_mobPen,power_nodePen,0,"","","",power_dps,power_gravity,power_door_breaking,power_glass_breaking,power_particles,power_sparks,power_bomb_ignite,power_size,0,0,power_glow) - -if rweapons_gun_durability == "true" then -itemstack:add_wear(65535/power_durability) -end -itemstack:set_name(power_cooling) - -inv:remove_item("main", "rangedweapons:power_particle "..PowerCaps.power_consumption) - -end -end end - -rangedweapons_launch_projectile = function(player,projNum,projDmg,projEnt,visualType,texture,shoot_sound,combined_velocity,accuracy,skill_value,ColResult,projCrit,projCritEffc,mobPen,nodePen,has_shell,shellEnt,shellTexture,shellVisual,dps,gravity,door_break,glass_break,bullet_particles,sparks,ignite,size,smokeSize,proj_wear,proj_glow) - ---minetest.chat_send_all(accuracy) - ----------------------------------- - local pos = player:get_pos() - local dir = player:get_look_dir() - local yaw = player:get_look_horizontal() - local svertical = player:get_look_vertical() - - if pos and dir and yaw then - minetest.sound_play(shoot_sound, {player}) - pos.y = pos.y + 1.45 - - if has_shell > 0 then - local shl = minetest.add_entity(pos, shellEnt) -shl:set_velocity({x=dir.x * -10, y=dir.y * -10, z=dir.z * -10}) -shl:set_acceleration({x=dir.x * -5, y= -10, z=dir.z * -5}) -shl:set_rotation({x=0,y=yaw + math.pi,z=-svertical}) -shl:set_properties({ -textures = {shellTexture}, -visual = shellVisual,}) - end -if smokeSize > 0 then - minetest.add_particle({ - pos = pos, - velocity = {x=(dir.x*3)+(math.random(-10,10)/10), y=(dir.y*3)+(math.random(-10,10)/10), z=(dir.z*3)+(math.random(-10,10)/10)} , - acceleration = {x=dir.x * -3, y=2, z=dir.z * -3}, - expirationtime = math.random(5,10)/10, - size = smokeSize, - collisiondetection = false, - vertical = false, - texture = "tnt_smoke.png", - glow = 5, - }) -end - - projectiles = projNum or 1 - for i=1,projectiles do - rndacc = (100 - accuracy) or 0 -local spawnpos_x = pos.x + (math.random(-rndacc,rndacc)/100) -local spawnpos_y = pos.y + (math.random(-rndacc,rndacc)/100) -local spawnpos_z = pos.z + (math.random(-rndacc,rndacc)/100) - - local obj = minetest.add_entity({x=spawnpos_x,y=spawnpos_y,z=spawnpos_z}, projEnt) - local ent = obj:get_luaentity() - -obj:set_properties( -{textures = {texture}, -visual = visualType, -collisionbox = {-size,-size,-size, size,size,size}, -glow = proj_glow,} -) - ent.owner = player:get_player_name() - if obj then - ent.damage = projDmg - ent.crit = projCrit - ent.critEffc = projCritEffc - ent.OnCollision = ColResult - ent.mobPen = mobPen - ent.nodePen = nodePen - ent.dps = dps - ent.door_break = door_break - ent.glass_break = glass_break - ent.skill_value = skill_value - ent.bullet_particles = bullet_particles - ent.sparks = sparks - ent.ignite = ignite - ent.size = size - ent.timer = 0 + (combined_velocity/2000) - ent.wear = proj_wear - obj:set_velocity({x=dir.x * combined_velocity, y=dir.y * combined_velocity, z=dir.z * combined_velocity}) - acc = ((( 100 - accuracy ) / 10) / skill_value ) or 0 - obj:set_acceleration({x=math.random(-acc,acc), y=math.random(-acc,acc)-gravity, z=math.random(-acc,acc)}) -obj:set_rotation({x=0,y=yaw + math.pi,z=-svertical}) - end end end - - -end - -eject_shell = function(itemstack,player,rld_item,rld_time,rldsound,shell) - itemstack:set_name(rld_item) - local meta = player:get_meta() - meta:set_float("rw_cooldown", rld_time) - -local gunMeta = itemstack:get_meta() - -local bulletStack = ItemStack({name = gunMeta:get_string("RW_ammo_name")}) - -minetest.sound_play(rldsound, {player}) - local pos = player:get_pos() - local dir = player:get_look_dir() - local yaw = player:get_look_horizontal() - if pos and dir and yaw then - pos.y = pos.y + 1.6 - local obj = minetest.add_entity(pos, "rangedweapons:empty_shell") - -if AmmoCaps and bulletStack ~= "" then -AmmoCaps = bulletStack:get_definition().RW_ammo_capabilities - -local bullet_shell_visual = "wielditem" -local bullet_shell_texture = "rangedweapons:shelldrop" - -bullet_shell_visual = AmmoCaps.shell_visual or "wielditem" -bullet_shell_texture = AmmoCaps.shell_texture or "rangedweapons:shelldrop" - -obj:set_properties({textures = {bullet_shell_texture}}) -obj:set_properties({visual = bullet_shell_visual}) - -end - if obj then -obj:set_velocity({x=dir.x*-10, y=dir.y*-10, z=dir.z*-10}) -obj:set_acceleration({x=dir.x*-5, y=-10, z=dir.z*-5}) - obj:set_yaw(yaw + math.pi) - end end end ---------------------------------------------------- --- - -function get_weapon_path(modpath, weapons_directory, weapon_type, weapon_name) - return modpath .. "/" .. weapons_directory .. "/" .. weapon_type .. "/" .. weapon_name .. ".lua" -end - - -local weapons = { - handgun = {'glock17', 'luger', 'makarov', 'python', 'deagle', 'taurus', 'beretta', 'm1991'}, - rifle = {'ak47', 'g36', 'm16', 'scar', 'awp', 'm200'}, - shotgun = {'aa12', 'remington', 'spas12', 'benelli', 'jackhammer'}, - machine_gun = {'rpk', 'm60', 'minigun'}, - sub_machine_gun = {'mp40', 'mp5', 'uzi', 'kriss_sv', 'ump', 'tec9', 'thompson', 'tmp'}, - force_weapon = {'forcegun'}, - power_weapon = {'laser_blaster', 'laser_rifle', 'laser_shotgun'}, - throwable = {'shuriken', 'javelin'}, - explosive = {'m79', 'milkor', 'rpg', 'hand_grenade'} -} - -local weapons_directory = "weapons" - -for k, v in pairs(weapons) do - weapon_type = k - - for i, weapon in ipairs(v) do - dofile(get_weapon_path(modpath, weapons_directory, weapon_type, weapon)) + minetest.sound_play("rengedweapons_ricochet", {pos, gain = 0.75}) + for i = 1, 9 do + minetest.add_particle( + { + pos = pos, + velocity = {x = math.random(-6.0, 6.0), y = math.random(-10.0, 15.0), z = math.random(-6.0, 6.0)}, + acceleration = {x = math.random(-9.0, 9.0), y = math.random(-15.0, -3.0), z = math.random(-9.0, 9.0)}, + expirationtime = 1.0, + size = math.random(1, 2), + collisiondetection = true, + vertical = false, + texture = "rangedweapons_spark.png", + glow = 25 + } + ) end end +rangedweapons_gain_skill = function(player, skill, chance) + if math.random(1, chance) == 1 then + local p_meta = player:get_meta() + local skill_num = p_meta:get_int(skill) + if skill_num < rweapons_max_gun_efficiency then + p_meta:set_int(skill, skill_num + 1) + minetest.chat_send_player( + player:get_player_name(), + "" .. core.colorize("#25c200", "You've improved your skill with this type of gun!") + ) + end + end +end -dofile(modpath.."/settings.lua") -dofile(modpath.."/cooldown_stuff.lua") -dofile(modpath.."/skills.lua") -dofile(modpath.."/misc.lua") -dofile(modpath.."/bullet_knockback.lua") -dofile(modpath.."/ammo.lua") -dofile(modpath.."/crafting.lua") +rangedweapons_reload_gun = function(itemstack, player) + GunCaps = itemstack:get_definition().RW_gun_capabilities + + if GunCaps ~= nil then + gun_unload_sound = GunCaps.gun_unload_sound or "" + end + + minetest.sound_play(gun_unload_sound, {player}) + + local gun_reload = 0.25 + + if GunCaps ~= nil then + gun_reload = GunCaps.gun_reload or 0.25 + end + + local playerMeta = player:get_meta() + local gunMeta = itemstack:get_meta() + + gunMeta:set_float("RW_reload_delay", gun_reload) + + playerMeta:set_float("rw_cooldown", gun_reload) + + local player_has_ammo = 0 + local clipSize = 0 + local reload_ammo = "" + + if GunCaps.suitable_ammo ~= nil then + local inv = player:get_inventory() + for i = 1, inv:get_size("main") do + for _, ammo in pairs(GunCaps.suitable_ammo) do + if inv:get_stack("main", i):get_name() == ammo[1] then + reload_ammo = inv:get_stack("main", i) + clipSize = ammo[2] + + player_has_ammo = 1 + break + end + end + + if player_has_ammo == 1 then + break + end + end + end + + if player_has_ammo == 1 then + local gun_icon = "rangedweapons_emergency_gun_icon.png" + + if GunCaps.gun_icon ~= nil then + gun_icon = GunCaps.gun_icon + end + + local ammo_icon = "rangedweapons_emergency_ammo_icon.png" + + if reload_ammo:get_definition().inventory_image ~= nil then + ammo_icon = reload_ammo:get_definition().inventory_image + end + + player:hud_change(gunimg, "text", gun_icon) + player:hud_change(ammoimg, "text", ammo_icon) + + local gunMeta = itemstack:get_meta() + local ammoCount = gunMeta:get_int("RW_bullets") + local ammoName = gunMeta:get_string("RW_ammo_name") + local inv = player:get_inventory() + + inv:add_item("main", ammoName .. " " .. ammoCount) + + if inv:contains_item("main", reload_ammo:get_name() .. " " .. clipSize) then + inv:remove_item("main", reload_ammo:get_name() .. " " .. clipSize) + gunMeta:set_int("RW_bullets", clipSize) + else + gunMeta:set_int("RW_bullets", reload_ammo:get_count()) + inv:remove_item("main", reload_ammo:get_name() .. " " .. reload_ammo:get_count()) + end + + gunMeta:set_string("RW_ammo_name", reload_ammo:get_name()) + + player:hud_change(gunammo, "text", gunMeta:get_int("RW_bullets")) + + if GunCaps.gun_magazine ~= nil then + local pos = player:get_pos() + local dir = player:get_look_dir() + local yaw = player:get_look_horizontal() + if pos and dir and yaw then + pos.y = pos.y + 1.4 + local obj = minetest.add_entity(pos, "rangedweapons:mag") + if obj then + obj:set_properties({textures = {GunCaps.gun_magazine}}) + obj:set_velocity({x = dir.x * 2, y = dir.y * 2, z = dir.z * 2}) + obj:set_acceleration({x = 0, y = -5, z = 0}) + obj:set_rotation({x = 0, y = yaw + math.pi, z = 0}) + end + end + end + + if GunCaps.gun_unloaded ~= nil then + itemstack:set_name(GunCaps.gun_unloaded) + end + end +end + +rangedweapons_single_load_gun = function(itemstack, player) + GunCaps = itemstack:get_definition().RW_gun_capabilities + + if GunCaps ~= nil then + gun_unload_sound = GunCaps.gun_unload_sound or "" + end + + minetest.sound_play(gun_unload_sound, {player}) + + local gun_reload = 0.25 + + if GunCaps ~= nil then + gun_reload = GunCaps.gun_reload or 0.25 + end + + local playerMeta = player:get_meta() + local gunMeta = itemstack:get_meta() + + gunMeta:set_float("RW_reload_delay", gun_reload) + + playerMeta:set_float("rw_cooldown", gun_reload) + + local player_has_ammo = 0 + local clipSize = 0 + local reload_ammo = "" + + if GunCaps.suitable_ammo ~= nil then + local inv = player:get_inventory() + for i = 1, inv:get_size("main") do + for _, ammo in pairs(GunCaps.suitable_ammo) do + if inv:get_stack("main", i):get_name() == ammo[1] then + reload_ammo = inv:get_stack("main", i) + clipSize = ammo[2] + + player_has_ammo = 1 + break + end + end + + if player_has_ammo == 1 then + break + end + end + end + + if player_has_ammo == 1 then + local gun_icon = "rangedweapons_emergency_gun_icon.png" + + if GunCaps.gun_icon ~= nil then + gun_icon = GunCaps.gun_icon + end + + local ammo_icon = "rangedweapons_emergency_ammo_icon.png" + + if reload_ammo:get_definition().inventory_image ~= nil then + ammo_icon = reload_ammo:get_definition().inventory_image + end + + player:hud_change(gunimg, "text", gun_icon) + player:hud_change(ammoimg, "text", ammo_icon) + + local gunMeta = itemstack:get_meta() + local ammoCount = gunMeta:get_int("RW_bullets") + local ammoName = gunMeta:get_string("RW_ammo_name") + local inv = player:get_inventory() + + if ammoName ~= reload_ammo:get_name() then + inv:add_item("main", ammoName .. " " .. ammoCount) + gunMeta:set_int("RW_bullets", 0) + end + + if inv:contains_item("main", reload_ammo:get_name()) and gunMeta:get_int("RW_bullets") < clipSize then + inv:remove_item("main", reload_ammo:get_name()) + gunMeta:set_int("RW_bullets", gunMeta:get_int("RW_bullets") + 1) + end + + gunMeta:set_string("RW_ammo_name", reload_ammo:get_name()) + + player:hud_change(gunammo, "text", gunMeta:get_int("RW_bullets")) + + if GunCaps.gun_unloaded ~= nil then + itemstack:set_name(GunCaps.gun_unloaded) + end + end +end + +rangedweapons_yeet = function(itemstack, player) + if minetest.find_node_near(player:getpos(), 10, "rangedweapons:antigun_block") then + minetest.chat_send_player( + player:get_player_name(), + "" .. core.colorize("#ff0000", "throwable weapons are prohibited in this area!") + ) + else + ThrowCaps = itemstack:get_definition().RW_throw_capabilities + playerMeta = player:get_meta() + + if ThrowCaps ~= nil then + throw_cooldown = ThrowCaps.throw_cooldown or 0 + end + + if playerMeta:get_float("rw_cooldown") <= 0 then + playerMeta:set_float("rw_cooldown", throw_cooldown) + + local throw_damage = {fleshy = 1} + local throw_sound = "rangedweapons_throw" + local throw_velocity = 20 + local throw_accuracy = 100 + local throw_cooling = 0 + local throw_crit = 0 + local throw_critEffc = 1 + local throw_mobPen = 0 + local throw_nodePen = 0 + local throw_dps = 0 + local throw_gravity = 0 + local throw_door_breaking = 0 + local throw_skill = "" + local throw_skillChance = 0 + local throw_smokeSize = 0 + local throw_ent = "rangedweapons:shot_bullet" + local throw_visual = "wielditem" + local throw_texture = "rangedweapons:shot_bullet_visual" + local throw_glass_breaking = 0 + local throw_particles = {} + local throw_sparks = 0 + local throw_bomb_ignite = 0 + local throw_size = 0 + local throw_glow = 0 + + if ThrowCaps ~= nil then + throw_damage = ThrowCaps.throw_damage or {fleshy = 1} + throw_sound = ThrowCaps.throw_sound or "rangedweapons_glock" + throw_velocity = ThrowCaps.throw_velocity or 20 + throw_accuracy = ThrowCaps.throw_accuracy or 100 + throw_cooling = ThrowCaps.throw_cooling or itemstack:get_name() + throw_crit = ThrowCaps.throw_crit or 0 + throw_critEffc = ThrowCaps.throw_critEffc or 1 + throw_projectiles = ThrowCaps.throw_projectiles or 1 + throw_mobPen = ThrowCaps.throw_mob_penetration or 0 + throw_nodePen = ThrowCaps.throw_node_penetration or 0 + throw_dps = ThrowCaps.throw_dps or 0 + throw_gravity = ThrowCaps.throw_gravity or 0 + throw_door_breaking = ThrowCaps.throw_door_breaking or 0 + throw_ent = ThrowCaps.throw_entity or "rangedweapons:shot_bullet" + throw_visual = ThrowCaps.throw_visual or "wielditem" + throw_texture = ThrowCaps.throw_texture or "rangedweapons:shot_bullet_visual" + throw_glass_breaking = ThrowCaps.throw_glass_breaking or 0 + throw_particles = ThrowCaps.throw_particles or nil + throw_sparks = ThrowCaps.throw_sparks or 0 + throw_bomb_ignite = ThrowCaps.ignites_explosives or 0 + throw_size = ThrowCaps.throw_projectile_size or 0 + throw_glow = ThrowCaps.throw_projectile_glow or 0 + OnCollision = ThrowCaps.OnCollision or function() + end + + if ThrowCaps.throw_skill ~= nil then + throw_skill = ThrowCaps.throw_skill[1] or "" + throw_skillChance = ThrowCaps.throw_skill[2] or 0 + else + throw_skill = "" + throw_skillChance = 0 + end + end + + if throw_skillChance > 0 and throw_skill ~= "" then + rangedweapons_gain_skill(player, throw_skill, throw_skillChance) + end + + if throw_skill ~= "" then + skill_value = playerMeta:get_int(throw_skill) / 100 + else + skill_value = 1 + end + + rangedweapons_launch_projectile( + player, + throw_projectiles, + throw_damage, + throw_ent, + throw_visual, + throw_texture, + throw_sound, + throw_velocity, + throw_accuracy, + skill_value, + OnCollision, + throw_crit, + throw_critEffc, + throw_mobPen, + throw_nodePen, + 0, + "", + "", + "", + throw_dps, + throw_gravity, + throw_door_breaking, + throw_glass_breaking, + throw_particles, + throw_sparks, + throw_bomb_ignite, + throw_size, + 0, + itemstack:get_wear(), + throw_glow + ) + + itemstack:take_item() + end + end +end + +rangedweapons_shoot_gun = function(itemstack, player) + if minetest.find_node_near(player:getpos(), 10, "rangedweapons:antigun_block") then + minetest.sound_play("rangedweapons_empty", {player}) + minetest.chat_send_player( + player:get_player_name(), + "" .. core.colorize("#ff0000", "Guns are prohibited in this area!") + ) + else + local gun_cooldown = 0 + local GunCaps = itemstack:get_definition().RW_gun_capabilities + local gun_ammo_save = 0 + + if GunCaps ~= nil then + gun_cooldown = GunCaps.gun_cooldown or 0 + gun_ammo_save = GunCaps.ammo_saving or 0 + end + + local gunMeta = itemstack:get_meta() + local playerMeta = player:get_meta() + + if gunMeta:get_int("RW_bullets") > 0 and playerMeta:get_float("rw_cooldown") <= 0 then + playerMeta:set_float("rw_cooldown", gun_cooldown) + + if math.random(1, 100) > gun_ammo_save then + gunMeta:set_int("RW_bullets", gunMeta:get_int("RW_bullets") - 1) + end + + player:hud_change(gunammo, "text", gunMeta:get_int("RW_bullets")) + + local gun_icon = "rangedweapons_emergency_gun_icon.png" + if GunCaps.gun_icon ~= nil then + gun_icon = GunCaps.gun_icon + end + player:hud_change(gunimg, "text", gun_icon) + + local OnCollision = function() + end + + local bulletStack = ItemStack({name = gunMeta:get_string("RW_ammo_name")}) + AmmoCaps = bulletStack:get_definition().RW_ammo_capabilities + + local gun_damage = {fleshy = 1} + local gun_sound = "rangedweapons_glock" + local gun_velocity = 20 + local gun_accuracy = 100 + local gun_cooling = 0 + local gun_crit = 0 + local gun_critEffc = 1 + local gun_mobPen = 0 + local gun_nodePen = 0 + local gun_shell = 0 + local gun_durability = 0 + local gun_dps = 0 + local gun_gravity = 0 + local gun_door_breaking = 0 + local gun_skill = "" + local gun_skillChance = 0 + local gun_smokeSize = 0 + + local bullet_damage = {fleshy = 0} + local bullet_velocity = 0 + local bullet_ent = "rangedweapons:shot_bullet" + local bullet_visual = "wielditem" + local bullet_texture = "rangedweapons:shot_bullet_visual" + local bullet_crit = 0 + local bullet_critEffc = 0 + local bullet_projMult = 1 + local bullet_mobPen = 0 + local bullet_nodePen = 0 + local bullet_shell_ent = "rangedweapons:empty_shell" + local bullet_shell_visual = "wielditem" + local bullet_shell_texture = "rangedweapons:shelldrop" + local bullet_dps = 0 + local bullet_gravity = 0 + local bullet_glass_breaking = 0 + local bullet_particles = {} + local bullet_sparks = 0 + local bullet_bomb_ignite = 0 + local bullet_size = 0 + local bullet_glow = 20 + + if GunCaps ~= nil then + gun_damage = GunCaps.gun_damage or {fleshy = 1} + gun_sound = GunCaps.gun_sound or "rangedweapons_glock" + gun_velocity = GunCaps.gun_velocity or 20 + gun_accuracy = GunCaps.gun_accuracy or 100 + gun_cooling = GunCaps.gun_cooling or itemstack:get_name() + gun_crit = GunCaps.gun_crit or 0 + gun_critEffc = GunCaps.gun_critEffc or 1 + gun_projectiles = GunCaps.gun_projectiles or 1 + gun_mobPen = GunCaps.gun_mob_penetration or 0 + gun_nodePen = GunCaps.gun_node_penetration or 0 + gun_shell = GunCaps.has_shell or 0 + gun_durability = GunCaps.gun_durability or 0 + gun_dps = GunCaps.gun_dps or 0 + gun_ammo_save = GunCaps.ammo_saving or 0 + gun_gravity = GunCaps.gun_gravity or 0 + gun_door_breaking = GunCaps.gun_door_breaking or 0 + gun_smokeSize = GunCaps.gun_smokeSize or 0 + + if GunCaps.gun_skill ~= nil then + gun_skill = GunCaps.gun_skill[1] or "" + gun_skillChance = GunCaps.gun_skill[2] or 0 + else + gun_skill = "" + gun_skillChance = 0 + end + end + + if gun_skillChance > 0 and gun_skill ~= "" then + rangedweapons_gain_skill(player, gun_skill, gun_skillChance) + end + + local ammo_icon = "rangedweapons_emergency_ammo_icon.png" + if bulletStack:get_definition().inventory_image ~= nil then + ammo_icon = bulletStack:get_definition().inventory_image + end + player:hud_change(ammoimg, "text", ammo_icon) + + if AmmoCaps ~= nil then + OnCollision = AmmoCaps.OnCollision or function() + end + bullet_damage = AmmoCaps.ammo_damage or {fleshy = 1} + bullet_velocity = AmmoCaps.ammo_velocity or 0 + bullet_ent = AmmoCaps.ammo_entity or "rangedweapons:shot_bullet" + bullet_visual = AmmoCaps.ammo_visual or "wielditem" + bullet_texture = AmmoCaps.ammo_texture or "rangedweapons:shot_bullet_visual" + bullet_crit = AmmoCaps.ammo_crit or 0 + bullet_critEffc = AmmoCaps.ammo_critEffc or 0 + bullet_projMult = AmmoCaps.ammo_projectile_multiplier or 1 + bullet_mobPen = AmmoCaps.ammo_mob_penetration or 0 + bullet_nodePen = AmmoCaps.ammo_node_penetration or 0 + bullet_shell_ent = AmmoCaps.shell_entity or "rangedweapons:empty_shell" + bullet_shell_visual = AmmoCaps.shell_visual or "wielditem" + bullet_shell_texture = AmmoCaps.shell_texture or "rangedweapons:shelldrop" + bullet_dps = AmmoCaps.ammo_dps or 0 + bullet_gravity = AmmoCaps.ammo_gravity or 0 + bullet_glass_breaking = AmmoCaps.ammo_glass_breaking or 0 + bullet_particles = AmmoCaps.ammo_particles or nil + bullet_sparks = AmmoCaps.has_sparks or 0 + bullet_bomb_ignite = AmmoCaps.ignites_explosives or 0 + bullet_size = AmmoCaps.ammo_projectile_size or 0.0025 + bullet_glow = AmmoCaps.ammo_projectile_glow or 20 + end + + local combined_crit = gun_crit + bullet_crit + local combined_critEffc = gun_critEffc + bullet_critEffc + local combined_velocity = gun_velocity + bullet_velocity + local combined_projNum = math.ceil(gun_projectiles * bullet_projMult) + local combined_mobPen = gun_mobPen + bullet_mobPen + local combined_nodePen = gun_nodePen + bullet_nodePen + local combined_dps = gun_dps + bullet_dps + local combined_dmg = {} + local combined_gravity = gun_gravity + bullet_gravity + + for _, gunDmg in pairs(gun_damage) do + if bullet_damage[_] ~= nil then + combined_dmg[_] = gun_damage[_] + bullet_damage[_] + else + combined_dmg[_] = gun_damage[_] + end + end + for _, bulletDmg in pairs(bullet_damage) do + if gun_damage[_] == nil then + combined_dmg[_] = bullet_damage[_] + end + end + + --minetest.chat_send_all(minetest.serialize(combined_dmg)) + + if gun_skill ~= "" then + skill_value = playerMeta:get_int(gun_skill) / 100 + else + skill_value = 1 + end + + rangedweapons_launch_projectile( + player, + combined_projNum, + combined_dmg, + bullet_ent, + bullet_visual, + bullet_texture, + gun_sound, + combined_velocity, + gun_accuracy, + skill_value, + OnCollision, + combined_crit, + combined_critEffc, + combined_mobPen, + combined_nodePen, + gun_shell, + bullet_shell_ent, + bullet_shell_texture, + bullet_shell_visual, + combined_dps, + combined_gravity, + gun_door_breaking, + bullet_glass_breaking, + bullet_particles, + bullet_sparks, + bullet_bomb_ignite, + bullet_size, + gun_smokeSize, + 0, + bullet_glow + ) + + if rweapons_gun_durability == "true" then + itemstack:add_wear(65535 / gun_durability) + end + itemstack:set_name(gun_cooling) + end + end +end + +rangedweapons_shoot_powergun = function(itemstack, player) + if minetest.find_node_near(player:getpos(), 10, "rangedweapons:antigun_block") then + minetest.sound_play("rangedweapons_empty", {player}) + minetest.chat_send_player( + player:get_player_name(), + "" .. core.colorize("#ff0000", "Guns are prohibited in this area!") + ) + else + local power_cooldown = 0 + + PowerCaps = itemstack:get_definition().RW_powergun_capabilities + + if PowerCaps ~= nil then + power_cooldown = PowerCaps.power_cooldown or 0 + power_consumption = PowerCaps.power_consumption or 0 + end + + local inv = player:get_inventory() + local playerMeta = player:get_meta() + + if + inv:contains_item("main", "rangedweapons:power_particle " .. PowerCaps.power_consumption) and + playerMeta:get_float("rw_cooldown") <= 0 + then + playerMeta:set_float("rw_cooldown", power_cooldown) + + local OnCollision = function() + end + + local power_damage = {fleshy = 1} + local power_sound = "rangedweapons_laser" + local power_velocity = 20 + local power_accuracy = 100 + local power_cooling = 0 + local power_crit = 0 + local power_critEffc = 1 + local power_mobPen = 0 + local power_nodePen = 0 + local power_durability = 0 + local power_dps = 0 + local power_gravity = 0 + local power_door_breaking = 0 + local power_skill = "" + local power_skillChance = 0 + local power_ent = "rangedweapons:shot_bullet" + local power_visual = "wielditem" + local power_texture = "rangedweapons:shot_bullet_visual" + local power_glass_breaking = 0 + local power_particles = {} + local power_sparks = 0 + local power_bomb_ignite = 0 + local power_size = 0 + local power_glow = 20 + + if PowerCaps ~= nil then + power_damage = PowerCaps.power_damage or {fleshy = 1} + power_sound = PowerCaps.power_sound or "rangedweapons_glock" + power_velocity = PowerCaps.power_velocity or 20 + power_accuracy = PowerCaps.power_accuracy or 100 + power_cooling = PowerCaps.power_cooling or itemstack:get_name() + power_crit = PowerCaps.power_crit or 0 + power_critEffc = PowerCaps.power_critEffc or 1 + power_projectiles = PowerCaps.power_projectiles or 1 + power_mobPen = PowerCaps.power_mob_penetration or 0 + power_nodePen = PowerCaps.power_node_penetration or 0 + power_durability = PowerCaps.power_durability or 0 + power_dps = PowerCaps.power_dps or 0 + power_gravity = PowerCaps.power_gravity or 0 + power_door_breaking = PowerCaps.power_door_breaking or 0 + OnCollision = PowerCaps.OnCollision or function() + end + power_ent = PowerCaps.power_entity or "rangedweapons:shot_bullet" + power_visual = PowerCaps.power_visual or "wielditem" + power_texture = PowerCaps.power_texture or "rangedweapons:shot_bullet_visual" + power_glass_breaking = PowerCaps.power_glass_breaking or 0 + power_particles = PowerCaps.power_particles or nil + power_sparks = PowerCaps.has_sparks or 0 + power_bomb_ignite = PowerCaps.ignites_explosives or 0 + power_size = PowerCaps.power_projectile_size or 0.0025 + power_glow = PowerCaps.power_projectile_glow or 20 + + if PowerCaps.power_skill ~= nil then + power_skill = PowerCaps.power_skill[1] or "" + power_skillChance = PowerCaps.power_skill[2] or 0 + else + power_skill = "" + power_skillChance = 0 + end + end + + if power_skillChance > 0 and power_skill ~= "" then + rangedweapons_gain_skill(player, power_skill, power_skillChance) + end + + if power_skill ~= "" then + skill_value = playerMeta:get_int(power_skill) / 100 + else + skill_value = 1 + end + + rangedweapons_launch_projectile( + player, + power_projectiles, + power_damage, + power_ent, + power_visual, + power_texture, + power_sound, + power_velocity, + power_accuracy, + skill_value, + OnCollision, + power_crit, + power_critEffc, + power_mobPen, + power_nodePen, + 0, + "", + "", + "", + power_dps, + power_gravity, + power_door_breaking, + power_glass_breaking, + power_particles, + power_sparks, + power_bomb_ignite, + power_size, + 0, + 0, + power_glow + ) + + if rweapons_gun_durability == "true" then + itemstack:add_wear(65535 / power_durability) + end + itemstack:set_name(power_cooling) + + inv:remove_item("main", "rangedweapons:power_particle " .. PowerCaps.power_consumption) + end + end +end + +rangedweapons_launch_projectile = function( + player, + projNum, + projDmg, + projEnt, + visualType, + texture, + shoot_sound, + combined_velocity, + accuracy, + skill_value, + ColResult, + projCrit, + projCritEffc, + mobPen, + nodePen, + has_shell, + shellEnt, + shellTexture, + shellVisual, + dps, + gravity, + door_break, + glass_break, + bullet_particles, + sparks, + ignite, + size, + smokeSize, + proj_wear, + proj_glow) + --minetest.chat_send_all(accuracy) + + ---------------------------------- + local pos = player:get_pos() + local dir = player:get_look_dir() + local yaw = player:get_look_horizontal() + local svertical = player:get_look_vertical() + + if pos and dir and yaw then + minetest.sound_play(shoot_sound, {player}) + pos.y = pos.y + 1.45 + + if has_shell > 0 then + local shl = minetest.add_entity(pos, shellEnt) + shl:set_velocity({x = dir.x * -10, y = dir.y * -10, z = dir.z * -10}) + shl:set_acceleration({x = dir.x * -5, y = -10, z = dir.z * -5}) + shl:set_rotation({x = 0, y = yaw + math.pi, z = -svertical}) + shl:set_properties( + { + textures = {shellTexture}, + visual = shellVisual + } + ) + end + if smokeSize > 0 then + minetest.add_particle( + { + pos = pos, + velocity = { + x = (dir.x * 3) + (math.random(-10, 10) / 10), + y = (dir.y * 3) + (math.random(-10, 10) / 10), + z = (dir.z * 3) + (math.random(-10, 10) / 10) + }, + acceleration = {x = dir.x * -3, y = 2, z = dir.z * -3}, + expirationtime = math.random(5, 10) / 10, + size = smokeSize, + collisiondetection = false, + vertical = false, + texture = "tnt_smoke.png", + glow = 5 + } + ) + end + + projectiles = projNum or 1 + for i = 1, projectiles do + rndacc = (100 - accuracy) or 0 + local spawnpos_x = pos.x + (math.random(-rndacc, rndacc) / 100) + local spawnpos_y = pos.y + (math.random(-rndacc, rndacc) / 100) + local spawnpos_z = pos.z + (math.random(-rndacc, rndacc) / 100) + + local obj = minetest.add_entity({x = spawnpos_x, y = spawnpos_y, z = spawnpos_z}, projEnt) + local ent = obj:get_luaentity() + + obj:set_properties( + { + textures = {texture}, + visual = visualType, + collisionbox = {-size, -size, -size, size, size, size}, + glow = proj_glow + } + ) + ent.owner = player:get_player_name() + if obj then + ent.damage = projDmg + ent.crit = projCrit + ent.critEffc = projCritEffc + ent.OnCollision = ColResult + ent.mobPen = mobPen + ent.nodePen = nodePen + ent.dps = dps + ent.door_break = door_break + ent.glass_break = glass_break + ent.skill_value = skill_value + ent.bullet_particles = bullet_particles + ent.sparks = sparks + ent.ignite = ignite + ent.size = size + ent.timer = 0 + (combined_velocity / 2000) + ent.wear = proj_wear + obj:set_velocity( + {x = dir.x * combined_velocity, y = dir.y * combined_velocity, z = dir.z * combined_velocity} + ) + acc = (((100 - accuracy) / 10) / skill_value) or 0 + obj:set_acceleration( + {x = math.random(-acc, acc), y = math.random(-acc, acc) - gravity, z = math.random(-acc, acc)} + ) + obj:set_rotation({x = 0, y = yaw + math.pi, z = -svertical}) + end + end + end +end + +eject_shell = function(itemstack, player, rld_item, rld_time, rldsound, shell) + itemstack:set_name(rld_item) + local meta = player:get_meta() + meta:set_float("rw_cooldown", rld_time) + + local gunMeta = itemstack:get_meta() + + local bulletStack = ItemStack({name = gunMeta:get_string("RW_ammo_name")}) + + minetest.sound_play(rldsound, {player}) + local pos = player:get_pos() + local dir = player:get_look_dir() + local yaw = player:get_look_horizontal() + if pos and dir and yaw then + pos.y = pos.y + 1.6 + local obj = minetest.add_entity(pos, "rangedweapons:empty_shell") + + if AmmoCaps and bulletStack ~= "" then + AmmoCaps = bulletStack:get_definition().RW_ammo_capabilities + + local bullet_shell_visual = "wielditem" + local bullet_shell_texture = "rangedweapons:shelldrop" + + bullet_shell_visual = AmmoCaps.shell_visual or "wielditem" + bullet_shell_texture = AmmoCaps.shell_texture or "rangedweapons:shelldrop" + + obj:set_properties({textures = {bullet_shell_texture}}) + obj:set_properties({visual = bullet_shell_visual}) + end + if obj then + obj:set_velocity({x = dir.x * -10, y = dir.y * -10, z = dir.z * -10}) + obj:set_acceleration({x = dir.x * -5, y = -10, z = dir.z * -5}) + obj:set_yaw(yaw + math.pi) + end + end +end +--------------------------------------------------- if rweapons_explosives == "true" then - dofile(modpath.."/explosives.lua") + dofile(modpath .. "/explosives.lua") end if rweapons_glass_breaking == "true" then - dofile(modpath.."/glass_breaking.lua") + dofile(modpath .. "/glass_breaking.lua") end + if not minetest.settings:get_bool("glass_breaking") then -minetest.register_abm({ - nodenames = {"rangedweapons:broken_glass"}, - interval = 1, - chance = 1, - action = function(pos, node) - if minetest.get_node(pos).name == "rangedweapons:broken_glass" then - node.name = "default:glass" - minetest.set_node(pos, node) - end - end -}) + minetest.register_abm( + { + nodenames = {"rangedweapons:broken_glass"}, + interval = 1, + chance = 1, + action = function(pos, node) + if minetest.get_node(pos).name == "rangedweapons:broken_glass" then + node.name = "default:glass" + minetest.set_node(pos, node) + end + end + } + ) end local rangedweapons_empty_shell = { - physical = false, - timer = 0, - visual = "wielditem", - visual_size = {x=0.3, y=0.3}, - textures = {"rangedweapons:shelldrop"}, - lastpos= {}, - collisionbox = {0, 0, 0, 0, 0, 0}, + physical = false, + timer = 0, + visual = "wielditem", + visual_size = {x = 0.3, y = 0.3}, + textures = {"rangedweapons:shelldrop"}, + lastpos = {}, + collisionbox = {0, 0, 0, 0, 0, 0} } rangedweapons_empty_shell.on_step = function(self, dtime, pos) - self.timer = self.timer + dtime - local pos = self.object:get_pos() - local node = minetest.get_node(pos) - if self.lastpos.y ~= nil then - if minetest.registered_nodes[node.name]~= nil then - if minetest.registered_nodes[node.name].walkable then - local vel = self.object:get_velocity() - local acc = self.object:get_acceleration() - self.object:set_velocity({x=vel.x*-0.3, y=vel.y*-0.75, z=vel.z*-0.3}) - minetest.sound_play("rangedweapons_shellhit", {pos = self.lastpos, gain = 0.8}) - self.object:set_acceleration({x=acc.x, y=acc.y, z=acc.z}) - end end - end - if self.timer > 1.69 then - minetest.sound_play("rangedweapons_bulletdrop", {pos = self.lastpos, gain = 0.8}) - self.object:remove() - - end - self.lastpos= {x = pos.x, y = pos.y, z = pos.z} + self.timer = self.timer + dtime + local pos = self.object:get_pos() + local node = minetest.get_node(pos) + if self.lastpos.y ~= nil then + if minetest.registered_nodes[node.name] ~= nil then + if minetest.registered_nodes[node.name].walkable then + local vel = self.object:get_velocity() + local acc = self.object:get_acceleration() + self.object:set_velocity({x = vel.x * -0.3, y = vel.y * -0.75, z = vel.z * -0.3}) + minetest.sound_play("rangedweapons_shellhit", {pos = self.lastpos, gain = 0.8}) + self.object:set_acceleration({x = acc.x, y = acc.y, z = acc.z}) + end + end + end + if self.timer > 1.69 then + minetest.sound_play("rangedweapons_bulletdrop", {pos = self.lastpos, gain = 0.8}) + self.object:remove() + end + self.lastpos = {x = pos.x, y = pos.y, z = pos.z} end -minetest.register_entity("rangedweapons:empty_shell", rangedweapons_empty_shell ) +minetest.register_entity("rangedweapons:empty_shell", rangedweapons_empty_shell) +minetest.register_abm( + { + nodenames = {"doors:hidden"}, + interval = 1, + chance = 1, + action = function(pos, node) + pos.y = pos.y - 1 + if minetest.get_node(pos).name == "air" then + pos.y = pos.y + 1 + node.name = "air" + minetest.set_node(pos, node) + end + end + } +) -minetest.register_abm({ - nodenames = {"doors:hidden"}, - interval = 1, - chance = 1, - action = function(pos, node) - pos.y = pos.y-1 - if minetest.get_node(pos).name == "air" then - pos.y = pos.y+1 - node.name = "air" - minetest.set_node(pos, node) - end - end -}) +minetest.register_on_joinplayer( + function(player) + gunammo = + player:hud_add( + { + hud_elem_type = "text", + name = "gunammo", + text = "", + number = 0xFFFFFF, + scale = {x = 100, y = 20}, + position = {x = 0.7, y = 0.1}, + offset = {x = 30, y = 100}, + alignment = {x = 0, y = -1} + } + ) + gunimg = + player:hud_add( + { + hud_elem_type = "image", + text = "rangedweapons_empty_icon.png", + scale = {x = 2, y = 2}, + position = {x = 0.7, y = 0.065}, + offset = {x = 30, y = 100}, + alignment = {x = 0, y = -1} + } + ) + ammoimg = + player:hud_add( + { + hud_elem_type = "image", + text = "rangedweapons_empty_icon.png", + scale = {x = 1.5, y = 1.5}, + position = {x = 0.725, y = 0.1}, + offset = {x = 30, y = 100}, + alignment = {x = 0, y = -1} + } + ) + hit = + player:hud_add( + { + hud_elem_type = "image", + text = "rangedweapons_empty_icon.png", + scale = {x = 2, y = 2}, + position = {x = 0.5, y = 0.5}, + offset = {x = 0, y = 0}, + alignment = {x = 0, y = 0} + } + ) + scope_hud = + player:hud_add( + { + hud_elem_type = "image", + position = {x = 0.5, y = 0.5}, + scale = {x = -100, y = -100}, + text = "rangedweapons_empty_icon.png" + } + ) + end +) -minetest.register_on_joinplayer(function(player) - gunammo = - player:hud_add({ - hud_elem_type = "text", - name = "gunammo", - text = "", - number = 0xFFFFFF, - scale = {x = 100, y = 20}, - position = {x = 0.7, y = 0.1}, - offset = {x = 30, y = 100}, - alignment = {x = 0, y = -1} - }) - gunimg = - player:hud_add({ - hud_elem_type = "image", - text = "rangedweapons_empty_icon.png", - scale = {x = 2, y = 2}, - position = {x = 0.7, y = 0.065}, - offset = {x = 30, y = 100}, - alignment = {x = 0, y = -1} - }) - ammoimg = - player:hud_add({ - hud_elem_type = "image", - text = "rangedweapons_empty_icon.png", - scale = {x = 1.5, y = 1.5}, - position = {x = 0.725, y = 0.1}, - offset = {x = 30, y = 100}, - alignment = {x = 0, y = -1} - }) - hit = - player:hud_add({ - hud_elem_type = "image", - text = "rangedweapons_empty_icon.png", - scale = {x = 2, y = 2}, - position = {x = 0.5, y = 0.5}, - offset = {x = 0, y = 0}, - alignment = {x = 0, y = 0} - }) -scope_hud = - player:hud_add({ - hud_elem_type = "image", - position = { x=0.5, y=0.5 }, - scale = { x=-100, y=-100 }, - text = "rangedweapons_empty_icon.png", - }) -end) - - local timer = 0 -minetest.register_globalstep(function(dtime, player) - timer = timer + dtime; - if timer >= 1.0 then - for _, player in pairs(minetest.get_connected_players()) do -player:hud_change(hit, "text", "rangedweapons_empty_icon.png") - timer = 0 - end - end - end) +local timer = 0 +minetest.register_globalstep( + function(dtime, player) + timer = timer + dtime + if timer >= 1.0 then + for _, player in pairs(minetest.get_connected_players()) do + player:hud_change(hit, "text", "rangedweapons_empty_icon.png") + timer = 0 + end + end + end +) diff --git a/item.lua b/item.lua new file mode 100644 index 0000000..7f6408d --- /dev/null +++ b/item.lua @@ -0,0 +1,6 @@ +local item = {} + +item.title_color = "#35cdff" + + +return item diff --git a/scratch b/scratch new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/scratch @@ -0,0 +1 @@ + diff --git a/settings.lua b/settings.lua index 1170aa3..64ce745 100644 --- a/settings.lua +++ b/settings.lua @@ -1,4 +1,3 @@ - rweapons_player_dmg_multiplier = 1.0 rweapons_mob_dmg_multiplier = 1.0 rweapons_headshot_dmg_multiplier = 1.75 @@ -8,20 +7,22 @@ rweapons_bloodyness = 10 rweapons_gun_crafting = "true" rweapons_gun_durability = "true" -rweapons_shurikens = "true" -rweapons_handguns = "true" -rweapons_forceguns = "true" -rweapons_javelins = "true" -rweapons_power_weapons = "true" -rweapons_machine_pistols = "true" -rweapons_shotguns = "true" -rweapons_auto_shotguns = "true" -rweapons_smgs = "true" -rweapons_rifles = "true" -rweapons_assault_rifles = "true" -rweapons_heavy_machineguns = "true" -rweapons_revolvers = "true" -rweapons_explosives = "true" + +-- Enable/Disable types of weapons +rweapons_allow_throwables = "true" +rweapons_allow_handguns = "true" +rweapons_allow_revolvers = "true" +rweapons_allow_sub_machine_gun = "true" +rweapons_allow_machine_pistols = "true" +rweapons_allow_machineguns = "true" +rweapons_allow_shotguns = "true" +rweapons_allow_auto_shotguns = "true" +rweapons_allow_rifles = "true" +rweapons_allow_auto_rifles = "true" +rweapons_allow_explosives = "true" +rweapons_allow_power_weapons = "true" +rweapons_allow_forceguns = "true" + rweapons_glass_breaking = "true" rweapons_door_breaking = "true" rweapons_other_weapon_crafting = "true" diff --git a/textures/rangedweapons_bereta.png b/textures/rangedweapons_bereta.png deleted file mode 100644 index 94ea0fe..0000000 Binary files a/textures/rangedweapons_bereta.png and /dev/null differ diff --git a/textures/rangedweapons_beretta_icon.png b/textures/weapons/handgun/beretta/rangedweapons_handgun_beretta_icon.png similarity index 100% rename from textures/rangedweapons_beretta_icon.png rename to textures/weapons/handgun/beretta/rangedweapons_handgun_beretta_icon.png diff --git a/textures/rangedweapons_beretta_rld.png b/textures/weapons/handgun/beretta/rangedweapons_handgun_beretta_reload.png similarity index 100% rename from textures/rangedweapons_beretta_rld.png rename to textures/weapons/handgun/beretta/rangedweapons_handgun_beretta_reload.png diff --git a/textures/rangedweapons_beretta.png b/textures/weapons/handgun/beretta/rangedweapons_handgun_beretta_texture.png similarity index 100% rename from textures/rangedweapons_beretta.png rename to textures/weapons/handgun/beretta/rangedweapons_handgun_beretta_texture.png diff --git a/weapon.lua b/weapon.lua new file mode 100644 index 0000000..eb4a139 --- /dev/null +++ b/weapon.lua @@ -0,0 +1,66 @@ +local modpath = minetest.get_modpath(minetest.get_current_modname()) +local colors = dofile(modpath.."/colors.lua") +local constants = dofile(modpath.."/constants.lua") + +local weapon = {} + +weapon.weapons = { + handgun = {'glock17', 'luger', 'makarov', 'deagle', 'beretta', 'm1991'}, + revolver = {'python', 'taurus'}, + rifle = {}, + auto_rifle = {'ak47', 'g36', 'm16', 'scar'}, + sniper_rifle = {'awp', 'm200'}, + shotgun = {'remington', 'spas12', 'benelli'}, + auto_shotgun = {'aa12', 'jackhammer'}, + machine_gun = {'rpk', 'm60', 'minigun'}, + machine_pistol = {'tmp', 'uzi', 'tec9'}, + sub_machine_gun = {'mp40', 'mp5', 'kriss_sv', 'ump', 'thompson'}, + force_weapon = {'forcegun'}, + power_weapon = {'laser_blaster', 'laser_rifle', 'laser_shotgun'}, + throwable = {'shuriken', 'javelin'}, + explosive = {'m79', 'milkor', 'rpg', 'hand_grenade'} +} + +weapon.weapons_directory = "weapons" + +function weapon.get_weapon_path(modpath, weapon_type, weapon_name) + return modpath .. "/" .. weapon.weapons_directory .. "/" .. weapon_type .. "/" .. weapon_name .. ".lua" +end + + +function weapon.get_texture_name(weapon_type, weapon_name, texture_name) + return constants.mod_name .. "_" .. weapon_type .. "_" .. weapon_name .. "_" .. texture_name +end + + +function weapon.generate_description(weapon_data) + local description = "" + local text = { + string.format("%s", weapon_data["name"]), + string.format("Damage: %d", weapon_data["damage"]), + string.format("Accuracy: %d", weapon_data["accuracy"]).."%", + string.format("Velocity: %d", weapon_data["velocity"]), + string.format("Knockback: %d", weapon_data["knock_back"]), + string.format("Critical chance: %d", weapon_data["critical_chance"]).."%", + string.format("Critical efficiency: %d", weapon_data["critical_efficiency"]), + string.format("Reload delay: %.2f", weapon_data["reload_delay"]), + string.format("Capacity: %d", weapon_data["capacity"]), + string.format("Ammunition: %s", weapon_data["ammunition_string"]), + string.format("Rate of fire: %.2f", weapon_data["fire_rate"]), + } + + for i,v in ipairs(text) do + if i == 0 then + color_text = core.colorize(item.title_color, v) + else + color_text = core.colorize(colors.white, v) + end + + description = description .. color_text + end + + return description + +end + +return weapon diff --git a/weapons/rifle/ak47.lua b/weapons/auto_rifle/ak47.lua similarity index 100% rename from weapons/rifle/ak47.lua rename to weapons/auto_rifle/ak47.lua diff --git a/weapons/rifle/g36.lua b/weapons/auto_rifle/g36.lua similarity index 100% rename from weapons/rifle/g36.lua rename to weapons/auto_rifle/g36.lua diff --git a/weapons/rifle/m16.lua b/weapons/auto_rifle/m16.lua similarity index 100% rename from weapons/rifle/m16.lua rename to weapons/auto_rifle/m16.lua diff --git a/weapons/rifle/scar.lua b/weapons/auto_rifle/scar.lua similarity index 100% rename from weapons/rifle/scar.lua rename to weapons/auto_rifle/scar.lua diff --git a/weapons/shotgun/aa12.lua b/weapons/auto_shotgun/aa12.lua similarity index 100% rename from weapons/shotgun/aa12.lua rename to weapons/auto_shotgun/aa12.lua diff --git a/weapons/shotgun/jackhammer.lua b/weapons/auto_shotgun/jackhammer.lua similarity index 100% rename from weapons/shotgun/jackhammer.lua rename to weapons/auto_shotgun/jackhammer.lua diff --git a/weapons/handgun/beretta.lua b/weapons/handgun/beretta.lua index a0d1f87..98fc4de 100644 --- a/weapons/handgun/beretta.lua +++ b/weapons/handgun/beretta.lua @@ -1,3 +1,42 @@ +local weapon_type = "handgun" +local weapon_name = "beretta" + +local modpath = minetest.get_modpath(minetest.get_current_modname()) + +local item = dofile(modpath.."/item.lua") +local weapon = dofile(modpath.."/weapon.lua") +local handgun = dofile(modpath.."/weapons".."/handgun".."/handgun.lua") +local colors = dofile(modpath.."/colors.lua") +local constants = dofile(modpath.."/constants.lua") + +local beretta_data = { + name = "Beretta 92", + damage = handgun["damage"], + accuracy = handgun["accuracy"], + velocity = handgun["velocity"], + knock_back = handgun["knockback"], + critical_chance = handgun["critical_chance"], + critical_efficiency = handgun.critical_efficiency, + gun_skill = {"handgun_skill",43}, + capacity = 15, + suitable_ammo = {{"rangedweapons:9mm",capacity}}, + reload_delay = handgun.reload_delay, + cool_down = handgun.cool_down, + ammunition_string = "9mm Ammo", + fire_rate = handgun.fire_rate, + magazine = handgun.magazine, + icon = weapon.get_texture_name(weapon_type, weapon_name, "icon.png"), + texture = weapon.get_texture_name(weapon_type, weapon_name, "texture.png"), + reload_icon = weapon.get_texture_name(weapon_type, weapon_name, "reload.png"), + unloaded = constants.mod_name .. ":beretta_r", + cooling = constants.mod_name .. ":beretta_rld", + fire_sound = "rangedweapons_beretta", + unload_sound = handgun.unload_sound, + gun_projectiles = 1, + has_shell = 1, + gun_durability = 1150, + gun_smokeSize = 5, +} minetest.register_tool("rangedweapons:beretta_rld", { @@ -7,45 +46,26 @@ minetest.register_tool("rangedweapons:beretta_rld", { range = 0, loaded_gun = "rangedweapons:beretta", groups = {not_in_creative_inventory = 1}, - inventory_image = "rangedweapons_beretta_rld.png", + inventory_image = beretta_data["reload_icon"] }) + minetest.register_tool("rangedweapons:beretta_r", { stack_max= 1, wield_scale = {x=1.1,y=1.1,z=1.05}, description = "", rw_next_reload = "rangedweapons:beretta", - load_sound = "rangedweapons_handgun_mag_in", + load_sound = handgun["load_sound"], range = 0, groups = {not_in_creative_inventory = 1}, - inventory_image = "rangedweapons_beretta_rld.png", + inventory_image = beretta_data["reload_icon"] }) minetest.register_tool("rangedweapons:beretta", { - description = "" ..core.colorize("#35cdff","Beretta M9\n") ..core.colorize("#FFFFFF", "Gun damage: 4\n")..core.colorize("#FFFFFF", "Accuracy: 94%\n") ..core.colorize("#FFFFFF", "gun knockback: 4\n") ..core.colorize("#FFFFFF", "Gun crit chance: 13%\n")..core.colorize("#FFFFFF", "Critical efficiency: 2.1x\n") ..core.colorize("#FFFFFF", "Reload delay: 0.5\n")..core.colorize("#FFFFFF", "Clip size: 15\n") ..core.colorize("#FFFFFF", "Ammunition: 9x19mm Parabellum\n") ..core.colorize("#FFFFFF", "Rate of fire: 0.4\n") ..core.colorize("#FFFFFF", "Gun type: Handgun\n") ..core.colorize("#FFFFFF", "Bullet velocity: 25"), + description = weapon.generate_description(beretta_data), wield_scale = {x=1.1,y=1.1,z=1.05}, range = 0, - inventory_image = "rangedweapons_beretta.png", -RW_gun_capabilities = { - gun_damage = {fleshy=4,knockback=4}, - gun_crit = 15, - gun_critEffc = 2.1, - suitable_ammo = {{"rangedweapons:9mm",15}}, - gun_skill = {"handgun_skill",43}, - gun_magazine = "rangedweapons:handgun_mag_black", - gun_icon = "rangedweapons_beretta_icon.png", - gun_unloaded = "rangedweapons:beretta_r", - gun_cooling = "rangedweapons:beretta_rld", - gun_velocity = 25, - gun_accuracy = 94, - gun_cooldown = 0.4, - gun_reload = 0.5, - gun_projectiles = 1, - has_shell = 1, - gun_durability = 1150, - gun_smokeSize = 5, - gun_unload_sound = "rangedweapons_handgun_mag_out", - gun_sound = "rangedweapons_beretta", - }, + inventory_image = beretta_data.texture, + RW_gun_capabilities = beretta_data, on_secondary_use = function(itemstack, user, pointed_thing) rangedweapons_reload_gun(itemstack, user) return itemstack diff --git a/weapons/handgun/handgun.lua b/weapons/handgun/handgun.lua new file mode 100644 index 0000000..be2ebd4 --- /dev/null +++ b/weapons/handgun/handgun.lua @@ -0,0 +1,22 @@ +-- General defaults for a handgun. + +local handgun = { + damage = 4, + knockback=4, + critical_chance = 15, + critical_efficiency = 2, + velocity = 25, + skill = {"handgun_skill",43}, + magazine = "rangedweapons:handgun_mag_black", + accuracy = 94, + fire_rate = 0.9, + cool_down = 0.4, + reload_delay = 0.5, + projectiles = 1, + has_shell = 1, + durability = 1150, + smoke_size = 5, + unload_sound = "rangedweapons_handgun_mag_out", +} + +return handgun diff --git a/weapons/sub_machine_gun/tec9.lua b/weapons/machine_pistol/tec9.lua similarity index 100% rename from weapons/sub_machine_gun/tec9.lua rename to weapons/machine_pistol/tec9.lua diff --git a/weapons/sub_machine_gun/tmp.lua b/weapons/machine_pistol/tmp.lua similarity index 100% rename from weapons/sub_machine_gun/tmp.lua rename to weapons/machine_pistol/tmp.lua diff --git a/weapons/sub_machine_gun/uzi.lua b/weapons/machine_pistol/uzi.lua similarity index 100% rename from weapons/sub_machine_gun/uzi.lua rename to weapons/machine_pistol/uzi.lua diff --git a/weapons/handgun/python.lua b/weapons/revolver/python.lua similarity index 100% rename from weapons/handgun/python.lua rename to weapons/revolver/python.lua diff --git a/weapons/handgun/taurus.lua b/weapons/revolver/taurus.lua similarity index 100% rename from weapons/handgun/taurus.lua rename to weapons/revolver/taurus.lua diff --git a/weapons/rifle/awp.lua b/weapons/sniper_rifle/awp.lua similarity index 100% rename from weapons/rifle/awp.lua rename to weapons/sniper_rifle/awp.lua diff --git a/weapons/rifle/m200.lua b/weapons/sniper_rifle/m200.lua similarity index 100% rename from weapons/rifle/m200.lua rename to weapons/sniper_rifle/m200.lua diff --git a/weapons/rifle/svd.lua b/weapons/sniper_rifle/svd.lua similarity index 100% rename from weapons/rifle/svd.lua rename to weapons/sniper_rifle/svd.lua