Re-organize weapons file structure

pull/5/head
ranguli 2022-01-30 16:26:45 -03:30
parent 59eec8584b
commit 17b77262d5
43 changed files with 42 additions and 229 deletions

132
init.lua
View File

@ -26,7 +26,7 @@ make_sparks = function(pos)
minetest.sound_play("rengedweapons_ricochet", {pos, gain = 0.75})
for i=1,9 do
minetest.add_particle({
pos = pos,
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,
@ -140,7 +140,7 @@ 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_yaw()
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")
@ -233,7 +233,7 @@ inv:add_item("main",ammoName.." "..ammoCount)
gunMeta:set_int("RW_bullets",0)
end
if inv:contains_item("main",reload_ammo:get_name()) and
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)
@ -368,7 +368,7 @@ end
local gunMeta = itemstack:get_meta()
local playerMeta = player:get_meta()
if gunMeta:get_int("RW_bullets") > 0 and
if gunMeta:get_int("RW_bullets") > 0 and
playerMeta:get_float("rw_cooldown") <= 0 then
playerMeta:set_float("rw_cooldown", gun_cooldown)
@ -561,7 +561,7 @@ end
local inv = player:get_inventory()
local playerMeta = player:get_meta()
if inv:contains_item("main", "rangedweapons:power_particle "..PowerCaps.power_consumption) and
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)
@ -657,7 +657,7 @@ rangedweapons_launch_projectile = function(player,projNum,projDmg,projEnt,visual
----------------------------------
local pos = player:get_pos()
local dir = player:get_look_dir()
local yaw = player:get_look_yaw()
local yaw = player:get_look_horizontal()
local svertical = player:get_look_vertical()
if pos and dir and yaw then
@ -666,13 +666,13 @@ rangedweapons_launch_projectile = function(player,projNum,projDmg,projEnt,visual
if has_shell > 0 then
local shl = minetest.add_entity(pos, shellEnt)
shl:setvelocity({x=dir.x * -10, y=dir.y * -10, z=dir.z * -10})
shl:setacceleration({x=dir.x * -5, y= -10, z=dir.z * -5})
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
end
if smokeSize > 0 then
minetest.add_particle({
pos = pos,
@ -742,7 +742,7 @@ 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_yaw()
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")
@ -766,7 +766,34 @@ 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))
end
end
dofile(modpath.."/settings.lua")
@ -777,85 +804,10 @@ dofile(modpath.."/bullet_knockback.lua")
dofile(modpath.."/ammo.lua")
dofile(modpath.."/crafting.lua")
if rweapons_shurikens == "true" then
dofile(modpath.."/shurikens.lua")
end
if rweapons_handguns == "true" then
dofile(modpath.."/makarov.lua")
dofile(modpath.."/luger.lua")
dofile(modpath.."/beretta.lua")
dofile(modpath.."/m1991.lua")
dofile(modpath.."/glock17.lua")
dofile(modpath.."/deagle.lua")
end
if rweapons_forceguns == "true" then
dofile(modpath.."/forcegun.lua")
end
if rweapons_javelins == "true" then
dofile(modpath.."/javelin.lua")
end
if rweapons_power_weapons == "true" then
dofile(modpath.."/generator.lua")
dofile(modpath.."/laser_blaster.lua")
dofile(modpath.."/laser_rifle.lua")
dofile(modpath.."/laser_shotgun.lua")
end
if rweapons_machine_pistols == "true" then
dofile(modpath.."/tmp.lua")
dofile(modpath.."/tec9.lua")
dofile(modpath.."/uzi.lua")
dofile(modpath.."/kriss_sv.lua")
end
if rweapons_shotguns == "true" then
dofile(modpath.."/remington.lua")
dofile(modpath.."/spas12.lua")
dofile(modpath.."/benelli.lua")
end
if rweapons_auto_shotguns == "true" then
dofile(modpath.."/jackhammer.lua")
dofile(modpath.."/aa12.lua")
end
if rweapons_smgs == "true" then
dofile(modpath.."/mp5.lua")
dofile(modpath.."/ump.lua")
dofile(modpath.."/mp40.lua")
dofile(modpath.."/thompson.lua")
end
if rweapons_rifles == "true" then
dofile(modpath.."/awp.lua")
dofile(modpath.."/svd.lua")
dofile(modpath.."/m200.lua")
end
if rweapons_heavy_machineguns == "true" then
dofile(modpath.."/m60.lua")
dofile(modpath.."/rpk.lua")
dofile(modpath.."/minigun.lua")
end
if rweapons_revolvers == "true" then
dofile(modpath.."/python.lua")
dofile(modpath.."/taurus.lua")
end
if rweapons_assault_rifles == "true" then
dofile(modpath.."/m16.lua")
dofile(modpath.."/g36.lua")
dofile(modpath.."/ak47.lua")
dofile(modpath.."/scar.lua")
end
if rweapons_explosives == "true" then
dofile(modpath.."/explosives.lua")
dofile(modpath.."/m79.lua")
dofile(modpath.."/milkor.lua")
dofile(modpath.."/rpg.lua")
dofile(modpath.."/hand_grenade.lua")
end
if rweapons_glass_breaking == "true" then
dofile(modpath.."/glass_breaking.lua")
end
@ -922,7 +874,7 @@ minetest.register_abm({
})
minetest.register_on_joinplayer(function(player)
gunammo =
gunammo =
player:hud_add({
hud_elem_type = "text",
name = "gunammo",
@ -933,7 +885,7 @@ minetest.register_on_joinplayer(function(player)
offset = {x = 30, y = 100},
alignment = {x = 0, y = -1}
})
gunimg =
gunimg =
player:hud_add({
hud_elem_type = "image",
text = "rangedweapons_empty_icon.png",
@ -942,7 +894,7 @@ minetest.register_on_joinplayer(function(player)
offset = {x = 30, y = 100},
alignment = {x = 0, y = -1}
})
ammoimg =
ammoimg =
player:hud_add({
hud_elem_type = "image",
text = "rangedweapons_empty_icon.png",
@ -951,7 +903,7 @@ minetest.register_on_joinplayer(function(player)
offset = {x = 30, y = 100},
alignment = {x = 0, y = -1}
})
hit =
hit =
player:hud_add({
hud_elem_type = "image",
text = "rangedweapons_empty_icon.png",
@ -960,7 +912,7 @@ minetest.register_on_joinplayer(function(player)
offset = {x = 0, y = 0},
alignment = {x = 0, y = 0}
})
scope_hud =
scope_hud =
player:hud_add({
hud_elem_type = "image",
position = { x=0.5, y=0.5 },

View File

@ -1,139 +0,0 @@
minetest.register_craftitem("rangedweapons:thrown_javelin", {
wield_scale = {x=2.0,y=2.0,z=1.0},
inventory_image = "rangedweapons_thrown_javelin.png",
})
minetest.register_craftitem("rangedweapons:javelin", {
description = "" ..core.colorize("#35cdff","Javelin\n") ..core.colorize("#FFFFFF", "Mele damage: 9\n") ..core.colorize("#FFFFFF", "Mele range: 5\n")..core.colorize("#FFFFFF", "Full punch interval: 1.25\n") ..core.colorize("#FFFFFF", "Ranged damage: 4-16\n") ..core.colorize("#FFFFFF", "Accuracy: 100%\n") ..core.colorize("#FFFFFF", "Mob knockback: 10\n") ..core.colorize("#FFFFFF", "Critical chance: 15%\n") ..core.colorize("#FFFFFF", "Critical damage: 25-45\n") ..core.colorize("#FFFFFF", "javelin survival rate: 95%\n")..core.colorize("#FFFFFF", "Projectile gravity: 4\n") ..core.colorize("#FFFFFF", "Projectile velocity: 20\n")..core.colorize("#ffc000", "Right-click to throw, Left-click to stab") ,
wield_scale = {x=2.0,y=2.0,z=1.0},
range = 5,
stack_max= 10,
inventory_image = "rangedweapons_javelin.png",
on_secondary_use = function(itemstack, user, pointed_thing)
if not minetest.setting_getbool("creative_mode") then itemstack:take_item()
end
if pointed_thing.type ~= "nothing" then
local pointed = minetest.get_pointed_thing_position(pointed_thing)
if vector.distance(user:getpos(), pointed) < 8 then
return itemstack
end
end
local pos = user:getpos()
local dir = user:get_look_dir()
local yaw = user:get_look_yaw()
if pos and dir then
pos.y = pos.y + 1.5
local obj = minetest.add_entity(pos, "rangedweapons:javelin")
if obj then
minetest.sound_play("rangedweapons_throw", {object=obj})
obj:setvelocity({x=dir.x * 20, y=dir.y * 20, z=dir.z * 20})
obj:setacceleration({x=dir.x * -1, y=-4, z=dir.z * -1})
obj:setyaw(yaw + math.pi)
local ent = obj:get_luaentity()
if ent then
ent.player = ent.player or user
end
end
end
return itemstack
end,
tool_capabilities = {
full_punch_interval = 1.25,
max_drop_level = 0,
groupcaps = {
stabby = {times={[1]=0.25, [2]=0.50, [3]=0.75}, uses=0, maxlevel=1},
},
damage_groups = {fleshy=9,knockback=10},
}
})
local rangedweapons_javelin = {
physical = false,
timer = 0,
visual = "wielditem",
visual_size = {x=0.5, y=0.5,},
textures = {"rangedweapons:thrown_javelin"},
lastpos= {},
collisionbox = {0, 0, 0, 0, 0, 0},
}
rangedweapons_javelin.on_step = function(self, dtime)
self.timer = self.timer + dtime
local pos = self.object:getpos()
local node = minetest.get_node(pos)
if self.timer > 0.15 then
local objs = minetest.get_objects_inside_radius({x = pos.x, y = pos.y, z = pos.z}, 1)
for k, obj in pairs(objs) do
if obj:get_luaentity() ~= nil then
if obj:get_luaentity().name ~= "rangedweapons:javelin" and obj:get_luaentity().name ~= "__builtin:item" then
if math.random(1, 100) <= 15 then
local damage = math.random(25,45)
obj:punch(self.object, 1.0, {
full_punch_interval = 1.0,
damage_groups= {fleshy = damage, knockback=20},
}, nil)
minetest.sound_play("crit", {pos = self.lastpos, gain = 0.8})
self.object:remove()
if not minetest.setting_getbool("creative_mode") and math.random(1, 100) <= 95 then
minetest.add_item(self.lastpos, "rangedweapons:javelin")
end
else
local damage = math.random(4,16)
obj:punch(self.object, 1.0, {
full_punch_interval = 1.0,
damage_groups= {fleshy = damage, knockback=10},
}, nil)
minetest.sound_play("default_dig_cracky", {pos = self.lastpos, gain = 0.8})
self.object:remove()
if not minetest.setting_getbool("creative_mode") and math.random(1, 100) <= 95 then
minetest.add_item(self.lastpos, "rangedweapons:javelin")
end
end
end
else
if math.random(1, 100) <= 15 then
local damage = math.random(25,45)
obj:punch(self.object, 1.0, {
full_punch_interval = 1.0,
damage_groups= {fleshy = damage},
}, nil)
minetest.sound_play("crit", {pos = self.lastpos, gain = 0.8})
self.object:remove()
if not minetest.setting_getbool("creative_mode") and math.random(1, 100) <= 95 then
minetest.add_item(self.lastpos, "rangedweapons:javelin")
end
else
local damage = math.random(4,16)
obj:punch(self.object, 1.0, {
full_punch_interval = 1.0,
damage_groups= {fleshy = damage},
}, nil)
minetest.sound_play("default_dig_cracky", {pos = self.lastpos, gain = 0.8})
self.object:remove()
if not minetest.setting_getbool("creative_mode") and math.random(1, 100) <= 95 then
minetest.add_item(self.lastpos, "rangedweapons:javelin")
end
end
end
end
end
if self.lastpos.x ~= nil then
if minetest.registered_nodes[node.name].walkable then
if not minetest.setting_getbool("creative_mode") and math.random(1, 100) <= 95 then
minetest.add_item(self.lastpos, "rangedweapons:javelin")
end
minetest.sound_play("default_dig_cracky", {pos = self.lastpos, gain = 0.8})
self.object:remove()
end
end
self.lastpos= {x = pos.x, y = pos.y, z = pos.z}
end
minetest.register_entity("rangedweapons:javelin", rangedweapons_javelin)