diff --git a/mods/ctf/ctf_classes/api.lua b/mods/ctf/ctf_classes/api.lua index b1c4080..be38667 100644 --- a/mods/ctf/ctf_classes/api.lua +++ b/mods/ctf/ctf_classes/api.lua @@ -31,7 +31,7 @@ function ctf_classes.get(player) player = minetest.get_player_by_name(player) end - local cname = player:get_meta():get("ctf_classes:class") or "knight" + local cname = player:get_meta():get("ctf_classes:class") or ctf_classes.default_class return ctf_classes.__classes[cname] end diff --git a/mods/ctf/ctf_classes/gui.lua b/mods/ctf/ctf_classes/gui.lua index 1fd5bae..2cf066f 100644 --- a/mods/ctf/ctf_classes/gui.lua +++ b/mods/ctf/ctf_classes/gui.lua @@ -2,7 +2,7 @@ function ctf_classes.show_gui(name, player) player = player or minetest.get_player_by_name(name) assert(player.get_player_name) if not ctf_classes.can_change(player) then - minetest.chat_send_player(name, "Move closer to the flag to change classes!") + minetest.chat_send_player(name, "Move closer to your flag to change classes!") return end diff --git a/mods/ctf/ctf_classes/init.lua b/mods/ctf/ctf_classes/init.lua index 705957b..f7a90a5 100644 --- a/mods/ctf/ctf_classes/init.lua +++ b/mods/ctf/ctf_classes/init.lua @@ -1,6 +1,8 @@ ctf_classes = { __classes = {}, __classes_ordered = {}, + + default_class = "knight", } dofile(minetest.get_modpath("ctf_classes") .. "/api.lua") @@ -9,6 +11,7 @@ dofile(minetest.get_modpath("ctf_classes") .. "/regen.lua") dofile(minetest.get_modpath("ctf_classes") .. "/ranged.lua") dofile(minetest.get_modpath("ctf_classes") .. "/items.lua") + ctf_classes.register("knight", { description = "Knight", pros = { "+50% Health Points" }, @@ -18,6 +21,12 @@ ctf_classes.register("knight", { max_hp = 30, speed = 0.90, + allowed_guns = { + "shooter:pistol", + "shooter:smg", + "shooter:shotgun", + }, + items = { "default:sword_steel", }, @@ -33,7 +42,19 @@ ctf_classes.register("shooter", { items = { "shooter:rifle", "shooter:grapple_gun_loaded", - } + }, + + allowed_guns = { + "shooter:pistol", + "shooter:rifle", + "shooter:smg", + "shooter:shotgun", + }, + + shooter_multipliers = { + range = 1.5, + full_punch_interval = 0.8, + }, }, }) @@ -48,6 +69,12 @@ ctf_classes.register("medic", { items = { "ctf_bandages:bandage 20", }, + + allowed_guns = { + "shooter:pistol", + "shooter:smg", + "shooter:shotgun", + }, }, }) @@ -76,7 +103,7 @@ minetest.register_chatcommand("class", { end if not ctf_classes.can_change(player) then - return false, "Move closer to the flag to change classes!" + return false, "Move closer to your flag to change classes!" end local cname = params:trim() diff --git a/mods/ctf/ctf_classes/ranged.lua b/mods/ctf/ctf_classes/ranged.lua index 0f4edf4..4d8702f 100644 --- a/mods/ctf/ctf_classes/ranged.lua +++ b/mods/ctf/ctf_classes/ranged.lua @@ -1,50 +1,51 @@ -local shooter_specs = {} +local specs_cache = {} - -shooter.get_weapon_spec = function(_, user, name) - local spec = shooter.registered_weapons[name] +local function get_shooter_specs(weapon_name, multiplier) + local spec = shooter.registered_weapons[weapon_name] if not spec then return nil end spec = spec.spec - spec.name = user:get_player_name() - if not user then - return spec - end + -- this will convert the multipler to a table pointer + local idx = ("%s:%s"):format(multiplier or "nil", weapon_name) - local class = ctf_classes.get(user) - if class.name ~= "shooter" then - if name == "shooter:rifle" then - minetest.chat_send_player(user:get_player_name(), - "Only Shooters are skilled enough for rifles! Change your class at spawn") - return nil - end - return spec - end - - if shooter_specs[name] then - return shooter_specs[name] + if specs_cache[idx] then + return specs_cache[idx] end spec = table.copy(spec) - shooter_specs[name] = spec + specs_cache[idx] = spec spec.range = spec.range * 1.5 spec.tool_caps.full_punch_interval = spec.tool_caps.full_punch_interval * 0.8 return spec end +shooter.get_weapon_spec = function(_, user, weapon_name) + local class = ctf_classes.get(user) + + if table.indexof(class.properties.allowed_guns or {}, weapon_name) == -1 then + minetest.chat_send_player(user:get_player_name(), + "Your class can't use that weapon! Change your class at spawn") + return nil + end + + local spec = get_shooter_specs(weapon_name, class.properties.shooter_multipliers) + spec.name = user and user:get_player_name() + + return spec +end + local function check_grapple(itemname) local def = minetest.registered_items[itemname] local old_func = def.on_use minetest.override_item(itemname, { - description = def.description .. "\n\nCan only be used by Shooters", on_use = function(itemstack, user, ...) if ctf_classes.get(user).name ~= "shooter" then minetest.chat_send_player(user:get_player_name(), - "Only Shooters are skilled enough for grapples! Change your class at spawn") + "Your class can't use that weapon! Change your class at spawn") return itemstack end @@ -63,7 +64,3 @@ end check_grapple("shooter:grapple_gun_loaded") check_grapple("shooter:grapple_gun") - -minetest.override_item("shooter:rifle", { - description = "Rifle\n\nCan only be used by Shooters", -}) diff --git a/mods/other/random_messages/init.lua b/mods/other/random_messages/init.lua index 83345a6..6d0f049 100644 --- a/mods/other/random_messages/init.lua +++ b/mods/other/random_messages/init.lua @@ -75,7 +75,7 @@ function random_messages.read_messages() "Use /summary to check scores of the current match and the previous match.", "Use /maps to view the maps catalog. It also contains license info and attribution details.", "Change your class in your base by right clicking the home flag or typing /class.", - "Medics cause nearby troops to regenerate health faster.", + "Medics cause troops within 10 metres to regenerate health faster.", } end diff --git a/mods/pvp/shooter/grapple.lua b/mods/pvp/shooter/grapple.lua index 4e902fa..2bf62f8 100644 --- a/mods/pvp/shooter/grapple.lua +++ b/mods/pvp/shooter/grapple.lua @@ -89,9 +89,7 @@ minetest.register_tool("shooter:grapple_gun", { end local inv = user:get_inventory() - if inv:contains_item("main", "shooter:grapple_hook") and - true then --inv:contains_item("main", "tnt:gunpowder") then - -- inv:remove_item("main", "tnt:gunpowder") + if inv:contains_item("main", "shooter:grapple_hook") then minetest.sound_play("shooter_reload", {object=user}) local stack = inv:remove_item("main", "shooter:grapple_hook") itemstack = ItemStack("shooter:grapple_gun_loaded 1 "..stack:get_wear())