Move constants to namespaced table, cleanup code, fix line endings
This commit is contained in:
parent
5f4f9233a7
commit
bc414719f1
@ -1,8 +1,7 @@
|
||||
local modpath = minetest.get_modpath(minetest.get_current_modname())
|
||||
local colors = dofile(modpath.."/colors.lua")
|
||||
|
||||
minetest.register_node("rangedweapons:antigun_block", {
|
||||
description = core.colorize(colors["title_color"], "Anti-gun block\n") .. core.colorize(colors.white, "Prevents people from using guns, in 10 node radius to each side from this block"),
|
||||
description = core.colorize(rangedweapons.colors.title_color, "Anti-gun block\n") .. core.colorize(rangedweapons.colors.white, "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(),
|
||||
|
@ -1,8 +1,6 @@
|
||||
local color = {
|
||||
rangedweapons.colors = {
|
||||
white = "#ffffff",
|
||||
turquoise = "#35cdff"
|
||||
turquoise = "35cdff"
|
||||
}
|
||||
|
||||
color.title_color = color["turquoise"]
|
||||
|
||||
return color
|
||||
ranged_weapons.color.title_color = color.turquoise
|
||||
|
@ -1,5 +0,0 @@
|
||||
local constants = {}
|
||||
|
||||
constants.mod_name = "rangedweapons"
|
||||
|
||||
return constants
|
13
crafting.lua
13
crafting.lua
@ -1,5 +1,3 @@
|
||||
----------------------------
|
||||
----------------------------
|
||||
if rweapons_gun_crafting == "true" then
|
||||
|
||||
minetest.register_craft({
|
||||
@ -117,15 +115,6 @@ minetest.register_craft({
|
||||
}
|
||||
})
|
||||
|
||||
minetest.register_craft({
|
||||
output = "rangedweapons:glock17",
|
||||
recipe = {
|
||||
{"rangedweapons:plastic_sheet", "rangedweapons:plastic_sheet", "rangedweapons:plastic_sheet"},
|
||||
{"default:steel_ingot", "default:steel_ingot", "default:steel_ingot"},
|
||||
{"", "default:diamond", "rangedweapons:plastic_sheet"},
|
||||
}
|
||||
})
|
||||
|
||||
minetest.register_craft({
|
||||
output = "rangedweapons:jackhammer",
|
||||
recipe = {
|
||||
@ -638,4 +627,4 @@ minetest.register_craft({
|
||||
}
|
||||
})
|
||||
|
||||
end
|
||||
end
|
||||
|
7
init.lua
7
init.lua
@ -13,6 +13,9 @@ dofile(modpath .. "/armor.lua")
|
||||
|
||||
dofile(modpath .. "/blocks/antigun_block.lua")
|
||||
|
||||
rangedweapons = {}
|
||||
rangedweapons.mod_name = "rangedweapons"
|
||||
|
||||
-- Load all weapons
|
||||
for k, v in pairs(weapon.weapons) do
|
||||
weapon_type = k
|
||||
@ -22,10 +25,6 @@ for k, v in pairs(weapon.weapons) do
|
||||
end
|
||||
end
|
||||
|
||||
----
|
||||
---- gun_funcs
|
||||
----
|
||||
|
||||
make_sparks = function(pos)
|
||||
minetest.sound_play("rengedweapons_ricochet", {pos, gain = 0.75})
|
||||
for i = 1, 9 do
|
||||
|
34
skills.lua
34
skills.lua
@ -44,10 +44,10 @@ minetest.register_chatcommand("gunskills", {
|
||||
for _, player in pairs(minetest.get_connected_players()) do
|
||||
local meta = player:get_meta()
|
||||
local handguns = meta:get_int("handgun_skill")
|
||||
local mps = meta:get_int("mp_skill")
|
||||
local smgs = meta:get_int("smg_skill")
|
||||
local shotguns = meta:get_int("shotgun_skill")
|
||||
local heavy = meta:get_int("heavy_skill")
|
||||
local mps = meta:get_int("mp_skill")
|
||||
local smgs = meta:get_int("smg_skill")
|
||||
local shotguns = meta:get_int("shotgun_skill")
|
||||
local heavy = meta:get_int("heavy_skill")
|
||||
local arifle = meta:get_int("arifle_skill")
|
||||
local revolver = meta:get_int("revolver_skill")
|
||||
local rifle = meta:get_int("rifle_skill")
|
||||
@ -86,65 +86,65 @@ minetest.register_globalstep(function(dtime, player)
|
||||
for _, player in pairs(minetest.get_connected_players()) do
|
||||
local meta = player:get_meta()
|
||||
local handguns = meta:get_int("handgun_skill")
|
||||
local mps = meta:get_int("mp_skill")
|
||||
local smgs = meta:get_int("smg_skill")
|
||||
local shotguns = meta:get_int("shotgun_skill")
|
||||
local heavy = meta:get_int("heavy_skill")
|
||||
local mps = meta:get_int("mp_skill")
|
||||
local smgs = meta:get_int("smg_skill")
|
||||
local shotguns = meta:get_int("shotgun_skill")
|
||||
local heavy = meta:get_int("heavy_skill")
|
||||
local arifle = meta:get_int("arifle_skill")
|
||||
local revolver = meta:get_int("revolver_skill")
|
||||
local rifle = meta:get_int("rifle_skill")
|
||||
local throw = meta:get_int("throw_skill")
|
||||
if math.random(1, 40) == 1 then
|
||||
if handguns > rweapons_min_gun_efficiency then
|
||||
meta:set_int("handgun_skill", handguns - 1)
|
||||
meta:set_int("handgun_skill", handguns - 1)
|
||||
minetest.chat_send_player(player:get_player_name(), "" ..core.colorize("#ff0000","Handgun skill degraded! "))
|
||||
end
|
||||
end
|
||||
if math.random(1, 40) == 1 then
|
||||
if mps > rweapons_min_gun_efficiency then
|
||||
meta:set_int("mp_skill", mps - 1)
|
||||
meta:set_int("mp_skill", mps - 1)
|
||||
minetest.chat_send_player(player:get_player_name(), "" ..core.colorize("#ff0000","Machine Pistol skill degraded! "))
|
||||
end
|
||||
end
|
||||
if math.random(1, 40) == 1 then
|
||||
if smgs > rweapons_min_gun_efficiency then
|
||||
meta:set_int("smg_skill", smgs - 1)
|
||||
meta:set_int("smg_skill", smgs - 1)
|
||||
minetest.chat_send_player(player:get_player_name(), "" ..core.colorize("#ff0000","S.M.G skill degraded! "))
|
||||
end
|
||||
end
|
||||
if math.random(1, 40) == 1 then
|
||||
if shotguns > rweapons_min_gun_efficiency then
|
||||
meta:set_int("shotgun_skill", shotguns - 1)
|
||||
meta:set_int("shotgun_skill", shotguns - 1)
|
||||
minetest.chat_send_player(player:get_player_name(), "" ..core.colorize("#ff0000","Shotgun skill degraded! "))
|
||||
end
|
||||
end
|
||||
if math.random(1, 40) == 1 then
|
||||
if heavy > rweapons_min_gun_efficiency then
|
||||
meta:set_int("heavy_skill", heavy - 1)
|
||||
meta:set_int("heavy_skill", heavy - 1)
|
||||
minetest.chat_send_player(player:get_player_name(), "" ..core.colorize("#ff0000","Heavy.MG skill degraded! "))
|
||||
end
|
||||
end
|
||||
if math.random(1, 40) == 1 then
|
||||
if arifle > rweapons_min_gun_efficiency then
|
||||
meta:set_int("arifle_skill", arifle - 1)
|
||||
meta:set_int("arifle_skill", arifle - 1)
|
||||
minetest.chat_send_player(player:get_player_name(), "" ..core.colorize("#ff0000","A.Rifle skill degraded! "))
|
||||
end
|
||||
end
|
||||
if math.random(1, 40) == 1 then
|
||||
if revolver > rweapons_min_gun_efficiency then
|
||||
meta:set_int("revolver_skill", revolver - 1)
|
||||
meta:set_int("revolver_skill", revolver - 1)
|
||||
minetest.chat_send_player(player:get_player_name(), "" ..core.colorize("#ff0000","Revolver/magnum skill degraded! "))
|
||||
end
|
||||
end
|
||||
if math.random(1, 40) == 1 then
|
||||
if rifle > rweapons_min_gun_efficiency then
|
||||
meta:set_int("rifle_skill", rifle - 1)
|
||||
meta:set_int("rifle_skill", rifle - 1)
|
||||
minetest.chat_send_player(player:get_player_name(), "" ..core.colorize("#ff0000","Rifle skill degraded! "))
|
||||
end
|
||||
end
|
||||
if math.random(1, 40) == 1 then
|
||||
if throw > rweapons_min_gun_efficiency then
|
||||
meta:set_int("throw_skill", throw - 1)
|
||||
meta:set_int("throw_skill", throw - 1)
|
||||
minetest.chat_send_player(player:get_player_name(), "" ..core.colorize("#ff0000","Throwing skill degraded! "))
|
||||
end
|
||||
end
|
||||
|
@ -1,5 +1,4 @@
|
||||
local modpath = minetest.get_modpath(minetest.get_current_modname())
|
||||
local colors = dofile(modpath.."/colors.lua")
|
||||
local constants = dofile(modpath.."/constants.lua")
|
||||
|
||||
local weapon = {}
|
||||
@ -52,7 +51,7 @@ function weapon.generate_description(weapon_data)
|
||||
if i == 0 then
|
||||
color_text = core.colorize(item.title_color, v)
|
||||
else
|
||||
color_text = core.colorize(colors.white, v)
|
||||
color_text = core.colorize(rangedweapons.colors.white, v)
|
||||
end
|
||||
|
||||
description = description .. color_text
|
||||
|
@ -1,13 +1,13 @@
|
||||
local weapon_type = "handgun"
|
||||
local weapon_name = "beretta"
|
||||
|
||||
local weapon_item_name = rangedweapons.mod_name .. ":" .. weapon_name
|
||||
|
||||
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",
|
||||
@ -18,11 +18,9 @@ local beretta_data = {
|
||||
default = weapon.get_texture_name(weapon_type, weapon_name, "texture.png"),
|
||||
reload = weapon.get_texture_name(weapon_type, weapon_name, "reload.png"),
|
||||
},
|
||||
--unloaded = constants.mod_name .. ":beretta_r",
|
||||
unloaded = "rangedweapons:beretta_r",
|
||||
--cooling = constants.mod_name .. ":beretta_rld",
|
||||
cooling = "rangedweapons:beretta_rld",
|
||||
fire_sound = "rangedweapons_beretta",
|
||||
unloaded = rangedweapons.mod_name .. ":beretta_r",
|
||||
cooling = rangedweapons.mod_name .. ":beretta_rld",
|
||||
fire_sound = rangedweapons.mod_name .. "_beretta",
|
||||
}
|
||||
|
||||
beretta_data["suitable_ammo"] = {{"rangedweapons:9mm",beretta_data["capacity"]}}
|
||||
@ -35,11 +33,11 @@ for k,v in pairs(handgun) do
|
||||
end
|
||||
|
||||
minetest.register_tool("rangedweapons:beretta_rld", {
|
||||
stack_max= 1,
|
||||
stack_max=1,
|
||||
wield_scale = {x=1.1,y=1.1,z=1.05},
|
||||
description = "",
|
||||
range = 0,
|
||||
loaded_gun = "rangedweapons:beretta",
|
||||
loaded_gun = weapon_item_name,
|
||||
groups = {not_in_creative_inventory = 1},
|
||||
inventory_image = beretta_data["texture"]["reload"]
|
||||
})
|
||||
@ -48,14 +46,14 @@ 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",
|
||||
rw_next_reload = weapon_item_name,
|
||||
load_sound = handgun["load_sound"],
|
||||
range = 0,
|
||||
groups = {not_in_creative_inventory = 1},
|
||||
inventory_image = beretta_data["texture"]["reload"]
|
||||
})
|
||||
|
||||
minetest.register_tool("rangedweapons:beretta", {
|
||||
minetest.register_tool(weapon_item_name, {
|
||||
description = weapon.generate_description(beretta_data),
|
||||
wield_scale = {x=1.1,y=1.1,z=1.05},
|
||||
range = 0,
|
||||
|
@ -1,14 +1,14 @@
|
||||
local weapon_type = "handgun"
|
||||
local weapon_name = "glock17"
|
||||
local weapon = dofile(modpath.."/weapon.lua")
|
||||
local handgun = dofile(modpath.."/weapons".."/handgun".."/handgun.lua")
|
||||
|
||||
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 weapon_type = "handgun"
|
||||
local weapon_name = "glock17"
|
||||
|
||||
local weapon_item_name = rangedweapons.mod_name .. ":" .. weapon_name
|
||||
|
||||
-- Attributes for the weapon
|
||||
local glock_data = {
|
||||
name = "Glock 17",
|
||||
capacity = 17,
|
||||
@ -19,9 +19,10 @@ local glock_data = {
|
||||
reload = "rangedweapons_glock17_rld.png",
|
||||
},
|
||||
fire_sound = "rangedweapons_glock",
|
||||
wield_scale = {x = 1.2, y = 1.2, z =1.2}
|
||||
}
|
||||
|
||||
glock_data["suitable_ammo"] = {{"rangedweapons:9mm",glock_data["capacity"]}}
|
||||
glock_data.suitable_ammo = {{rangedweapons.mod_name .. ":" .. "9mm", glock_data.capacity}}
|
||||
|
||||
-- Populate any unset values with handgun defaults
|
||||
for k,v in pairs(handgun) do
|
||||
@ -30,58 +31,12 @@ for k,v in pairs(handgun) do
|
||||
end
|
||||
end
|
||||
|
||||
minetest.register_tool("rangedweapons:glock17_rld", {
|
||||
stack_max= 1,
|
||||
wield_scale = {x=1.1,y=1.1,z=1.05},
|
||||
description = "",
|
||||
loaded_gun = "rangedweapons:glock17",
|
||||
range = 0,
|
||||
groups = {not_in_creative_inventory = 1},
|
||||
inventory_image = glock_data["texture"]["reload"],
|
||||
})
|
||||
|
||||
|
||||
minetest.register_tool("rangedweapons:glock17_r", {
|
||||
stack_max= 1,
|
||||
wield_scale = {x=1.2,y=1.2,z=1.2},
|
||||
description = "",
|
||||
rw_next_reload = "rangedweapons:glock17_rr",
|
||||
load_sound = "rangedweapons_handgun_mag_in",
|
||||
range = 0,
|
||||
groups = {not_in_creative_inventory = 1},
|
||||
inventory_image = glock_data["texture"]["default"],
|
||||
})
|
||||
|
||||
minetest.register_tool("rangedweapons:glock17_rr", {
|
||||
stack_max= 1,
|
||||
wield_scale = {x=1.2,y=1.2,z=1.2},
|
||||
description = "",
|
||||
rw_next_reload = "rangedweapons:glock17_rrr",
|
||||
load_sound = "rangedweapons_reload_a",
|
||||
range = 0,
|
||||
groups = {not_in_creative_inventory = 1},
|
||||
inventory_image = glock_data["texture"]["default"],
|
||||
})
|
||||
|
||||
minetest.register_tool("rangedweapons:glock17_rrr", {
|
||||
stack_max= 1,
|
||||
wield_scale = {x=1.2,y=1.2,z=1.2},
|
||||
description = "",
|
||||
rw_next_reload = "rangedweapons:glock17",
|
||||
load_sound = "rangedweapons_reload_b",
|
||||
range = 0,
|
||||
groups = {not_in_creative_inventory = 1},
|
||||
inventory_image = glock_data["texture"]["reload"],
|
||||
})
|
||||
|
||||
|
||||
|
||||
|
||||
-- Define the Glock 17 item
|
||||
minetest.register_tool("rangedweapons:glock17", {
|
||||
description = weapon.generate_description(glock_data),
|
||||
wield_scale = {x=1.2,y=1.2,z=1.2},
|
||||
wield_scale = glock_data.default_wield_scale,
|
||||
range = 0,
|
||||
inventory_image = glock_data["texture"]["default"],
|
||||
inventory_image = glock_data.texture.default,
|
||||
rw_gun_data = glock_data,
|
||||
on_secondary_use = function(itemstack, user, pointed_thing)
|
||||
rangedweapons_reload_gun(itemstack, user)
|
||||
@ -92,3 +47,60 @@ rangedweapons_shoot_gun(itemstack, user)
|
||||
return itemstack
|
||||
end,
|
||||
})
|
||||
|
||||
-- This is a trick that creates multiple in-game items for each step of the
|
||||
-- reload animation.
|
||||
minetest.register_tool("rangedweapons:glock17_rld", {
|
||||
stack_max= 1,
|
||||
wield_scale = {x=1.1,y=1.1,z=1.05},
|
||||
description = "",
|
||||
loaded_gun = weapon_item_name,
|
||||
range = 0,
|
||||
groups = {not_in_creative_inventory = 1},
|
||||
inventory_image = glock_data.texture.reload,
|
||||
})
|
||||
|
||||
minetest.register_tool("rangedweapons:glock17_r", {
|
||||
stack_max= 1,
|
||||
wield_scale = glock_data.wield_scale,
|
||||
description = "",
|
||||
rw_next_reload = "rangedweapons:glock17_rr",
|
||||
load_sound = "rangedweapons_handgun_mag_in",
|
||||
range = 0,
|
||||
groups = {not_in_creative_inventory = 1},
|
||||
inventory_image = glock_data.texture.default,
|
||||
})
|
||||
|
||||
minetest.register_tool("rangedweapons:glock17_rr", {
|
||||
stack_max= 1,
|
||||
wield_scale = glock_data.default_wield_scale,
|
||||
description = "",
|
||||
rw_next_reload = "rangedweapons:glock17_rrr",
|
||||
load_sound = "rangedweapons_reload_a",
|
||||
range = 0,
|
||||
groups = {not_in_creative_inventory = 1},
|
||||
inventory_image = glock_data.texture.default,
|
||||
})
|
||||
|
||||
minetest.register_tool("rangedweapons:glock17_rrr", {
|
||||
stack_max= 1,
|
||||
wield_scale = glock_data.default_wield_scale,
|
||||
description = "",
|
||||
rw_next_reload = "rangedweapons:glock17",
|
||||
load_sound = "rangedweapons_reload_b",
|
||||
range = 0,
|
||||
groups = {not_in_creative_inventory = 1},
|
||||
inventory_image = glock_data.texture.reload,
|
||||
})
|
||||
|
||||
|
||||
|
||||
-- Crafting recipe for the Glock 17
|
||||
minetest.register_craft({
|
||||
output = weapon_item_name,
|
||||
recipe = {
|
||||
{"rangedweapons:plastic_sheet", "rangedweapons:plastic_sheet", "rangedweapons:plastic_sheet"},
|
||||
{"default:steel_ingot", "default:steel_ingot", "default:steel_ingot"},
|
||||
{"", "default:diamond", "rangedweapons:plastic_sheet"},
|
||||
}
|
||||
})
|
||||
|
Loading…
x
Reference in New Issue
Block a user