Add hud_score mod API

Fixes #72
This commit is contained in:
ANAND 2019-03-17 07:05:51 +05:30 committed by rubenwardy
parent f8b90c60a2
commit 5643fdf802
6 changed files with 178 additions and 17 deletions

View file

@ -1,3 +1,3 @@
ctf
ctf_stats
irc?
hud_score

View file

@ -86,26 +86,27 @@ minetest.register_on_joinplayer(function(player)
end)
ctf.register_on_killedplayer(function(victim, killer)
-- Suicide is not encouraged here at CTF
if victim == killer then
if victim ~= bountied_player or victim == killer then
return
end
if victim == bountied_player then
local main, match = ctf_stats.player(killer)
if main and match then
main.score = main.score + bounty_score
match.score = match.score + bounty_score
ctf.needs_save = true
end
bountied_player = nil
local msg = killer .. " has killed " .. victim .. " and received the prize!"
minetest.chat_send_all(msg)
local pstats, mstats = ctf_stats.player(killer)
pstats.bounty_kills = pstats.bounty_kills + 1
mstats.bounty_kills = mstats.bounty_kills + 1
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
ctf.needs_save = true
end
bountied_player = nil
local msg = killer .. " has killed " .. victim .. " and received the prize!"
minetest.chat_send_all(msg)
hud_score.new(killer, {
name = "ctf_bounty:prize",
color = 0x4444FF,
value = bounty_score
})
end)
minetest.register_privilege("bounty_admin")

View file

@ -299,6 +299,14 @@ ctf.register_on_killedplayer(function(victim, killer)
match.score = match.score + reward
match.kills_since_death = match.kills_since_death + 1
ctf.needs_save = true
reward = math.floor(reward * 100) / 100
hud_score.new(killer, {
name = "ctf_stats:kill_score",
color = "0x00FF00",
value = reward
})
end
end)