Merge branch 'master' of https://github.com/MT-CTF/capturetheflag
This commit is contained in:
commit
63d2b14d37
11 changed files with 151 additions and 40 deletions
|
@ -445,6 +445,15 @@ function ctf.register_on_killedplayer(func)
|
|||
end
|
||||
table.insert(ctf.registered_on_killedplayer, func)
|
||||
end
|
||||
|
||||
ctf.registered_on_punchplayer = {}
|
||||
function ctf.register_on_punchplayer(func)
|
||||
if ctf._mt_loaded then
|
||||
error("You can't register callbacks at game time!")
|
||||
end
|
||||
table.insert(ctf.registered_on_punchplayer, func)
|
||||
end
|
||||
|
||||
local dead_players = {}
|
||||
minetest.register_on_respawnplayer(function(player)
|
||||
dead_players[player:get_player_name()] = nil
|
||||
|
@ -453,7 +462,7 @@ minetest.register_on_joinplayer(function(player)
|
|||
dead_players[player:get_player_name()] = nil
|
||||
end)
|
||||
minetest.register_on_punchplayer(function(player, hitter,
|
||||
time_from_last_punch, tool_capabilities, dir, damage)
|
||||
time_from_last_punch, tool_capabilities, dir, damage, ...)
|
||||
if player and hitter then
|
||||
local pname = player:get_player_name()
|
||||
local hname = hitter:get_player_name()
|
||||
|
@ -487,5 +496,12 @@ minetest.register_on_punchplayer(function(player, hitter,
|
|||
end
|
||||
return false
|
||||
end
|
||||
|
||||
for i = 1, #ctf.registered_on_punchplayer do
|
||||
ctf.registered_on_punchplayer[i](
|
||||
player, hitter, time_from_last_punch,
|
||||
tool_capabilities, dir, damage, ...
|
||||
)
|
||||
end
|
||||
end
|
||||
end)
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
--Inspired from Andrey's bandages mod
|
||||
|
||||
ctf_bandages = {}
|
||||
ctf_bandages.heal_percent = 0.75 --Percentage of total HP to be healed
|
||||
ctf_bandages.heal_percent = 0.75 -- Percentage of total HP to be healed
|
||||
|
||||
minetest.register_craftitem("ctf_bandages:bandage", {
|
||||
description = "Bandage\n\n" ..
|
||||
|
@ -10,26 +10,31 @@ minetest.register_craftitem("ctf_bandages:bandage", {
|
|||
inventory_image = "ctf_bandages_bandage.png",
|
||||
stack_max = 1,
|
||||
on_use = function(itemstack, player, pointed_thing)
|
||||
if pointed_thing.type ~= "object" then
|
||||
return
|
||||
end
|
||||
if pointed_thing.type ~= "object" then return end
|
||||
|
||||
local object = pointed_thing.ref
|
||||
if not object:is_player() then
|
||||
return
|
||||
end
|
||||
if not object:is_player() then return end
|
||||
|
||||
local pname = object:get_player_name()
|
||||
local name = player:get_player_name()
|
||||
|
||||
if ctf.player(pname).team == ctf.player(name).team then
|
||||
local hp = object:get_hp()
|
||||
local limit = ctf_bandages.heal_percent *
|
||||
object:get_properties().hp_max
|
||||
local limit = ctf_bandages.heal_percent * object:get_properties().hp_max
|
||||
|
||||
if hp > 0 and hp < limit then
|
||||
hp = hp + math.random(3,4)
|
||||
local hp_add = math.random(3,4)
|
||||
|
||||
kill_assist.add_heal_assist(pname, hp_add)
|
||||
hp = hp + hp_add
|
||||
|
||||
if hp > limit then
|
||||
hp = limit
|
||||
end
|
||||
|
||||
object:set_hp(hp)
|
||||
minetest.chat_send_player(pname, minetest.colorize("#C1FF44", name .. " has healed you!"))
|
||||
|
||||
return itemstack
|
||||
else
|
||||
minetest.chat_send_player(name, pname .. " has " .. hp .. " HP. You can't heal them.")
|
||||
|
|
|
@ -373,7 +373,7 @@ local function invHasGoodWeapons(inv)
|
|||
return false
|
||||
end
|
||||
|
||||
local function calculateKillReward(victim, killer, toolcaps)
|
||||
function ctf_stats.calculateKillReward(victim, killer, toolcaps)
|
||||
local vmain, victim_match = ctf_stats.player(victim)
|
||||
|
||||
if not vmain or not victim_match then return 5 end
|
||||
|
@ -417,33 +417,9 @@ local function calculateKillReward(victim, killer, toolcaps)
|
|||
return reward
|
||||
end
|
||||
|
||||
ctf.register_on_killedplayer(function(victim, killer, _, toolcaps)
|
||||
-- Suicide is not encouraged here at CTF
|
||||
if victim == killer then
|
||||
return
|
||||
end
|
||||
local main, match = ctf_stats.player(killer)
|
||||
if main and match then
|
||||
local reward = calculateKillReward(victim, killer, toolcaps)
|
||||
main.kills = main.kills + 1
|
||||
main.score = main.score + reward
|
||||
match.kills = match.kills + 1
|
||||
match.score = match.score + reward
|
||||
match.kills_since_death = match.kills_since_death + 1
|
||||
_needs_save = true
|
||||
|
||||
reward = math.floor(reward * 100) / 100
|
||||
|
||||
hud_score.new(killer, {
|
||||
name = "ctf_stats:kill_score",
|
||||
color = "0x00FF00",
|
||||
value = reward
|
||||
})
|
||||
end
|
||||
end)
|
||||
|
||||
minetest.register_on_dieplayer(function(player)
|
||||
local main, match = ctf_stats.player(player:get_player_name())
|
||||
|
||||
if main and match then
|
||||
main.deaths = main.deaths + 1
|
||||
match.deaths = match.deaths + 1
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue