Yak shaving

pull/5/head
ranguli 2022-01-30 20:44:18 -03:30
parent 17b77262d5
commit 1aeadf965d
30 changed files with 1194 additions and 946 deletions

9
armor.lua Normal file
View File

@ -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

6
blocks/antigun_block.lua Normal file
View File

@ -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(),
})

View File

@ -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",

6
colors.lua Normal file
View File

@ -0,0 +1,6 @@
local color = {}
color.white = "#FFFFFF"
return color

5
constants.lua Normal file
View File

@ -0,0 +1,5 @@
local constants = {}
constants.mod_name = "rangedweapons"
return constants

440
init.lua
View File

@ -1,23 +1,27 @@
local modpath = minetest.get_modpath(minetest.get_current_modname())
if minetest.global_exists("armor") and armor.attributes then
table.insert(armor.attributes, "bullet_res")
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
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
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
----
@ -25,7 +29,8 @@ minetest.register_node("rangedweapons:antigun_block", {
make_sparks = function(pos)
minetest.sound_play("rengedweapons_ricochet", {pos, gain = 0.75})
for i = 1, 9 do
minetest.add_particle({
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)},
@ -34,28 +39,27 @@ minetest.sound_play("rengedweapons_ricochet", {pos, gain = 0.75})
collisiondetection = true,
vertical = false,
texture = "rangedweapons_spark.png",
glow = 25,
})
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!"))
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
@ -64,7 +68,6 @@ end
minetest.sound_play(gun_unload_sound, {player})
local gun_reload = 0.25
if GunCaps ~= nil then
@ -85,7 +88,6 @@ 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)
@ -93,13 +95,14 @@ clipSize = ammo[2]
player_has_ammo = 1
break
end end
end
end
if player_has_ammo == 1 then
break
end
end end
end
end
if player_has_ammo == 1 then
local gun_icon = "rangedweapons_emergency_gun_icon.png"
@ -124,7 +127,6 @@ 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)
@ -149,20 +151,17 @@ 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
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
@ -191,7 +190,6 @@ 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)
@ -199,13 +197,14 @@ clipSize = ammo[2]
player_has_ammo = 1
break
end end
end
end
if player_has_ammo == 1 then
break
end
end end
end
end
if player_has_ammo == 1 then
local gun_icon = "rangedweapons_emergency_gun_icon.png"
@ -233,8 +232,7 @@ 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
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
@ -246,17 +244,16 @@ 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!"))
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()
@ -265,7 +262,6 @@ 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}
@ -316,7 +312,8 @@ 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
OnCollision = ThrowCaps.OnCollision or function()
end
if ThrowCaps.throw_skill ~= nil then
throw_skill = ThrowCaps.throw_skill[1] or ""
@ -337,25 +334,52 @@ 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)
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
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!"))
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
@ -368,9 +392,7 @@ 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
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
@ -385,7 +407,8 @@ gun_icon = GunCaps.gun_icon
end
player:hud_change(gunimg, "text", gun_icon)
local OnCollision = function() end
local OnCollision = function()
end
local bulletStack = ItemStack({name = gunMeta:get_string("RW_ammo_name")})
AmmoCaps = bulletStack:get_definition().RW_ammo_capabilities
@ -430,8 +453,6 @@ 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"
@ -458,7 +479,6 @@ else
gun_skill = ""
gun_skillChance = 0
end
end
if gun_skillChance > 0 and gun_skill ~= "" then
@ -472,8 +492,8 @@ end
player:hud_change(ammoimg, "text", ammo_icon)
if AmmoCaps ~= nil then
OnCollision = AmmoCaps.OnCollision or function()end
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"
@ -497,7 +517,6 @@ 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
@ -529,25 +548,54 @@ 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)
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
end
end
rangedweapons_shoot_powergun = function(itemstack, player)
if minetest.find_node_near(player:getpos(), 10,"rangedweapons:antigun_block")
then
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!"))
minetest.chat_send_player(
player:get_player_name(),
"" .. core.colorize("#ff0000", "Guns are prohibited in this area!")
)
else
local power_cooldown = 0
@ -561,11 +609,14 @@ 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
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 OnCollision = function()
end
local power_damage = {fleshy = 1}
local power_sound = "rangedweapons_laser"
@ -607,7 +658,8 @@ 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
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"
@ -625,7 +677,6 @@ else
power_skill = ""
power_skillChance = 0
end
end
if power_skillChance > 0 and power_skill ~= "" then
@ -638,7 +689,38 @@ 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)
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)
@ -646,12 +728,41 @@ 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)
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)
----------------------------------
@ -669,22 +780,31 @@ rangedweapons_launch_projectile = function(player,projNum,projDmg,projEnt,visual
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({
shl:set_properties(
{
textures = {shellTexture},
visual = shellVisual,})
visual = shellVisual
}
)
end
if smokeSize > 0 then
minetest.add_particle({
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)} ,
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,
})
glow = 5
}
)
end
projectiles = projNum or 1
@ -698,10 +818,12 @@ local spawnpos_z = pos.z + (math.random(-rndacc,rndacc)/100)
local ent = obj:get_luaentity()
obj:set_properties(
{textures = {texture},
{
textures = {texture},
visual = visualType,
collisionbox = {-size, -size, -size, size, size, size},
glow = proj_glow,}
glow = proj_glow
}
)
ent.owner = player:get_player_name()
if obj then
@ -721,13 +843,17 @@ glow = proj_glow,}
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})
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_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
end
end
end
eject_shell = function(itemstack, player, rld_item, rld_time, rldsound, shell)
@ -758,51 +884,15 @@ 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
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))
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")
if rweapons_explosives == "true" then
dofile(modpath .. "/explosives.lua")
@ -811,8 +901,10 @@ end
if rweapons_glass_breaking == "true" then
dofile(modpath .. "/glass_breaking.lua")
end
if not minetest.settings:get_bool("glass_breaking") then
minetest.register_abm({
minetest.register_abm(
{
nodenames = {"rangedweapons:broken_glass"},
interval = 1,
chance = 1,
@ -822,7 +914,8 @@ minetest.register_abm({
minetest.set_node(pos, node)
end
end
})
}
)
end
local rangedweapons_empty_shell = {
@ -832,7 +925,7 @@ local rangedweapons_empty_shell = {
visual_size = {x = 0.3, y = 0.3},
textures = {"rangedweapons:shelldrop"},
lastpos = {},
collisionbox = {0, 0, 0, 0, 0, 0},
collisionbox = {0, 0, 0, 0, 0, 0}
}
rangedweapons_empty_shell.on_step = function(self, dtime, pos)
self.timer = self.timer + dtime
@ -846,20 +939,20 @@ rangedweapons_empty_shell.on_step = function(self, dtime, pos)
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
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_abm({
minetest.register_abm(
{
nodenames = {"doors:hidden"},
interval = 1,
chance = 1,
@ -871,11 +964,14 @@ minetest.register_abm({
minetest.set_node(pos, node)
end
end
})
}
)
minetest.register_on_joinplayer(function(player)
minetest.register_on_joinplayer(
function(player)
gunammo =
player:hud_add({
player:hud_add(
{
hud_elem_type = "text",
name = "gunammo",
text = "",
@ -884,51 +980,63 @@ minetest.register_on_joinplayer(function(player)
position = {x = 0.7, y = 0.1},
offset = {x = 30, y = 100},
alignment = {x = 0, y = -1}
})
}
)
gunimg =
player:hud_add({
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({
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({
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({
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)
text = "rangedweapons_empty_icon.png"
}
)
end
)
local timer = 0
minetest.register_globalstep(function(dtime, player)
timer = timer + dtime;
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)
end
)

6
item.lua Normal file
View File

@ -0,0 +1,6 @@
local item = {}
item.title_color = "#35cdff"
return item

1
scratch Normal file
View File

@ -0,0 +1 @@

View File

@ -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"

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.9 KiB

View File

Before

Width:  |  Height:  |  Size: 3.0 KiB

After

Width:  |  Height:  |  Size: 3.0 KiB

View File

Before

Width:  |  Height:  |  Size: 3.0 KiB

After

Width:  |  Height:  |  Size: 3.0 KiB

View File

Before

Width:  |  Height:  |  Size: 3.0 KiB

After

Width:  |  Height:  |  Size: 3.0 KiB

66
weapon.lua Normal file
View File

@ -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

View File

@ -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

View File

@ -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