2020-03-13 23:26:53 +00:00
|
|
|
local specs_cache = {}
|
2019-03-22 04:01:36 +00:00
|
|
|
|
2020-03-13 23:26:53 +00:00
|
|
|
local function get_shooter_specs(weapon_name, multiplier)
|
|
|
|
local spec = shooter.registered_weapons[weapon_name]
|
2019-03-22 04:01:36 +00:00
|
|
|
if not spec then
|
|
|
|
return nil
|
|
|
|
end
|
|
|
|
spec = spec.spec
|
|
|
|
|
2020-03-13 23:26:53 +00:00
|
|
|
-- this will convert the multipler to a table pointer
|
|
|
|
local idx = ("%s:%s"):format(multiplier or "nil", weapon_name)
|
2019-03-22 04:01:36 +00:00
|
|
|
|
2020-03-13 23:26:53 +00:00
|
|
|
if specs_cache[idx] then
|
|
|
|
return specs_cache[idx]
|
2019-03-22 04:01:36 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
spec = table.copy(spec)
|
2020-03-13 23:26:53 +00:00
|
|
|
specs_cache[idx] = spec
|
2019-03-22 04:01:36 +00:00
|
|
|
|
2020-03-14 17:22:55 +00:00
|
|
|
for key, value in pairs(multiplier) do
|
|
|
|
spec[key] = spec[key] * value
|
|
|
|
end
|
|
|
|
|
2019-03-22 04:01:36 +00:00
|
|
|
return spec
|
|
|
|
end
|
|
|
|
|
2020-03-13 23:26:53 +00:00
|
|
|
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
|
|
|
|
|
2019-03-22 04:01:36 +00:00
|
|
|
|
|
|
|
local function check_grapple(itemname)
|
|
|
|
local def = minetest.registered_items[itemname]
|
|
|
|
local old_func = def.on_use
|
|
|
|
minetest.override_item(itemname, {
|
|
|
|
on_use = function(itemstack, user, ...)
|
2020-03-14 19:37:31 +00:00
|
|
|
if not ctf_classes.get(user).properties.allow_grapples then
|
2019-03-22 04:01:36 +00:00
|
|
|
minetest.chat_send_player(user:get_player_name(),
|
2020-03-13 23:26:53 +00:00
|
|
|
"Your class can't use that weapon! Change your class at spawn")
|
2019-03-22 04:01:36 +00:00
|
|
|
|
|
|
|
return itemstack
|
|
|
|
end
|
|
|
|
|
2020-03-13 21:58:42 +00:00
|
|
|
if ctf_flag.has_flag(user:get_player_name()) then
|
|
|
|
minetest.chat_send_player(user:get_player_name(),
|
|
|
|
"You can't use grapples whilst carrying the flag")
|
|
|
|
|
|
|
|
return itemstack
|
|
|
|
end
|
|
|
|
|
2019-03-22 04:01:36 +00:00
|
|
|
return old_func(itemstack, user, ...)
|
|
|
|
end,
|
|
|
|
})
|
|
|
|
end
|
|
|
|
|
|
|
|
check_grapple("shooter:grapple_gun_loaded")
|
|
|
|
check_grapple("shooter:grapple_gun")
|
2020-03-14 19:37:31 +00:00
|
|
|
check_grapple("shooter:grapple_hook")
|