2018-04-01 11:58:17 +00:00
|
|
|
local bountied_player = nil
|
2018-04-06 10:21:44 +00:00
|
|
|
local bounty_score = 0
|
2018-04-01 11:58:17 +00:00
|
|
|
|
|
|
|
local function announce(name)
|
2021-04-16 17:09:16 +00:00
|
|
|
local bountied = ctf.player(bountied_player)
|
|
|
|
if ctf.player(name).team == bountied.team then
|
|
|
|
return
|
|
|
|
end
|
|
|
|
local tcolor = ctf_colors.get_color(bountied)
|
2018-04-01 11:58:17 +00:00
|
|
|
minetest.chat_send_player(name,
|
2018-06-20 10:17:26 +00:00
|
|
|
minetest.colorize("#fff326", "The next person to kill ") ..
|
2019-04-09 08:31:18 +00:00
|
|
|
minetest.colorize(tcolor.css, bountied_player) ..
|
2021-01-25 18:49:13 +00:00
|
|
|
minetest.colorize("#fff326", " will receive ") ..
|
|
|
|
minetest.colorize("#7efc00", bounty_score) ..
|
|
|
|
minetest.colorize("#fff326", " points!"))
|
2018-04-01 11:58:17 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
local function announce_all()
|
|
|
|
if bountied_player then
|
|
|
|
for _, player in pairs(minetest.get_connected_players()) do
|
2021-04-16 17:09:16 +00:00
|
|
|
announce(player:get_player_name())
|
2018-04-01 11:58:17 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
local function bounty_player(target)
|
2018-12-30 23:27:16 +00:00
|
|
|
local prev = bountied_player
|
2018-04-01 11:58:17 +00:00
|
|
|
bountied_player = target
|
|
|
|
|
2020-12-23 17:29:38 +00:00
|
|
|
-- Players with less than 20000 points --> bounty 50
|
|
|
|
--
|
|
|
|
-- ########################################################
|
|
|
|
--
|
|
|
|
-- Players between 20000 points and 50000 points:
|
|
|
|
--
|
|
|
|
-- Score
|
|
|
|
-- bounty_score = ----------, or 500 (whichever is lesser)
|
|
|
|
-- deaths
|
|
|
|
--
|
|
|
|
-- ########################################################
|
|
|
|
--
|
|
|
|
-- Players with more than 50000 points:
|
|
|
|
--
|
|
|
|
-- Score * 2
|
2018-04-06 13:04:56 +00:00
|
|
|
-- bounty_score = -----------, or 500 (whichever is lesser)
|
2020-12-23 17:29:38 +00:00
|
|
|
-- deaths
|
2018-04-06 13:04:56 +00:00
|
|
|
|
2019-12-05 18:33:38 +00:00
|
|
|
local pstat = ctf_stats.player(target)
|
2018-04-08 14:48:33 +00:00
|
|
|
if pstat.deaths == 0 then
|
|
|
|
pstat.deaths = 1
|
|
|
|
end
|
2020-12-23 17:29:38 +00:00
|
|
|
|
|
|
|
if pstat.score <= 20000 then
|
|
|
|
bounty_score = 50
|
|
|
|
elseif pstat.score <= 50000 then
|
|
|
|
bounty_score = (pstat.score / pstat.deaths)
|
|
|
|
else
|
|
|
|
bounty_score = ((pstat.score * 2) / pstat.deaths)
|
|
|
|
end
|
|
|
|
|
2018-04-06 13:04:56 +00:00
|
|
|
if bounty_score > 500 then
|
|
|
|
bounty_score = 500
|
|
|
|
end
|
2018-04-08 14:48:33 +00:00
|
|
|
if bounty_score < 50 then
|
|
|
|
bounty_score = 50
|
|
|
|
end
|
|
|
|
bounty_score = math.floor(bounty_score)
|
2018-04-06 13:04:56 +00:00
|
|
|
|
2018-12-30 23:27:16 +00:00
|
|
|
if prev then
|
|
|
|
for _, player in pairs(minetest.get_connected_players()) do
|
|
|
|
local name = player:get_player_name()
|
|
|
|
if bountied_player ~= name then
|
2019-12-05 18:33:38 +00:00
|
|
|
local prev_color = ctf_colors.get_color(ctf.player(prev)).css
|
2018-12-30 23:27:16 +00:00
|
|
|
minetest.chat_send_player(player:get_player_name(),
|
|
|
|
minetest.colorize("#fff326", "Player ") ..
|
2019-07-05 16:18:59 +00:00
|
|
|
minetest.colorize(prev_color, prev) ..
|
2018-12-30 23:27:16 +00:00
|
|
|
minetest.colorize("#fff326", " no longer has a bounty on their head!"))
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-04-01 11:58:17 +00:00
|
|
|
minetest.after(0.1, announce_all)
|
|
|
|
end
|
|
|
|
|
|
|
|
local function bounty_find_new_target()
|
|
|
|
local players = {}
|
|
|
|
for _, player in pairs(minetest.get_connected_players()) do
|
|
|
|
local name = player:get_player_name()
|
2019-12-18 05:31:34 +00:00
|
|
|
if ctf_stats.is_pro(name) and name ~= bountied_player then
|
2019-12-05 18:33:38 +00:00
|
|
|
table.insert(players, name)
|
2018-04-01 11:58:17 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
if #players > 0 then
|
2019-12-05 18:33:38 +00:00
|
|
|
bounty_player(players[math.random(1, #players)])
|
2018-04-01 11:58:17 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
minetest.after(math.random(500, 1000), bounty_find_new_target)
|
|
|
|
end
|
|
|
|
minetest.after(math.random(500, 1000), bounty_find_new_target)
|
|
|
|
|
|
|
|
minetest.register_on_joinplayer(function(player)
|
2018-12-30 23:27:16 +00:00
|
|
|
local name = player:get_player_name()
|
2019-12-18 05:31:34 +00:00
|
|
|
if bountied_player and bountied_player ~= name then
|
2018-12-30 23:27:16 +00:00
|
|
|
announce(name)
|
2018-04-01 11:58:17 +00:00
|
|
|
end
|
|
|
|
end)
|
|
|
|
|
|
|
|
ctf.register_on_killedplayer(function(victim, killer)
|
2019-03-17 01:35:51 +00:00
|
|
|
if victim ~= bountied_player or victim == killer then
|
2018-07-12 17:41:56 +00:00
|
|
|
return
|
|
|
|
end
|
2018-04-18 22:00:15 +00:00
|
|
|
|
2019-03-17 01:35:51 +00:00
|
|
|
local main, match = ctf_stats.player(killer)
|
|
|
|
if main and match then
|
|
|
|
main.score = main.score + bounty_score
|
|
|
|
match.score = match.score + bounty_score
|
|
|
|
main.bounty_kills = main.bounty_kills + 1
|
|
|
|
match.bounty_kills = match.bounty_kills + 1
|
2020-05-14 18:25:25 +00:00
|
|
|
|
|
|
|
ctf_stats.request_save()
|
|
|
|
|
|
|
|
hud_score.new(killer, {
|
|
|
|
name = "ctf_bounty:prize",
|
|
|
|
color = 0x4444FF,
|
|
|
|
value = bounty_score
|
|
|
|
})
|
2018-04-01 11:58:17 +00:00
|
|
|
end
|
2019-03-17 01:35:51 +00:00
|
|
|
bountied_player = nil
|
|
|
|
|
2019-12-29 15:17:24 +00:00
|
|
|
local killer_color = ctf_colors.get_color(ctf.player(killer)).css
|
|
|
|
local victim_color = ctf_colors.get_color(ctf.player(victim)).css
|
|
|
|
local msg = minetest.colorize(killer_color, killer) ..
|
|
|
|
minetest.colorize("#fff326", " has killed ") ..
|
|
|
|
minetest.colorize(victim_color, victim) ..
|
2021-01-25 18:49:13 +00:00
|
|
|
minetest.colorize("#fff326", " and received " ) ..
|
|
|
|
minetest.colorize("#7efc00", bounty_score) ..
|
|
|
|
minetest.colorize("#fff326", " points!")
|
2019-12-29 15:17:24 +00:00
|
|
|
minetest.log("action", minetest.strip_colors(msg))
|
2019-03-17 01:35:51 +00:00
|
|
|
minetest.chat_send_all(msg)
|
2018-04-01 11:58:17 +00:00
|
|
|
end)
|
|
|
|
|
|
|
|
minetest.register_privilege("bounty_admin")
|
|
|
|
|
|
|
|
minetest.register_chatcommand("place_bounty", {
|
2020-12-02 18:42:45 +00:00
|
|
|
description = "Place a bounty on a player",
|
|
|
|
params = "<player name>",
|
2018-04-01 11:58:17 +00:00
|
|
|
privs = { bounty_admin = true },
|
|
|
|
func = function(name, target)
|
|
|
|
target = target:trim()
|
|
|
|
if not minetest.get_player_by_name(target) then
|
|
|
|
return false, target .. " is not online"
|
|
|
|
end
|
|
|
|
|
|
|
|
bounty_player(target)
|
2019-10-18 05:52:18 +00:00
|
|
|
minetest.log("action", name .. " places bounty on " .. target)
|
2018-04-01 11:58:17 +00:00
|
|
|
return true, "Put bounty on " .. target
|
|
|
|
end
|
|
|
|
})
|