1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79
|
/*--
Modular scoreboard: Deaths
Author: Maikel
This script can be included to create a death count column in the scoreboard.
Make sure that the following functions return _inherited(...);
* Initialize();
* InitializePlayer(int plr);
* OnClonkDeath(object clonk, int killer);
* RemovePlayer(int plr);
--*/
local score_death_list; // Here the death count of all players is stored, access through plrid.
/*-- Callbacks --*/
// called by the scoreboard, assigns a symbol to the scoreboard field
// used by Scoreboard_Relaunch too
public func ScoreboardCondition(x)
{
if(GetType(x) != C4V_Int) return x;
if(x == -1) return Rule_KillLogs;
return x;
}
protected func Initialize()
{
// Make sure it is a list.
score_death_list = [];
// init scoreboard
Scoreboard->Init(
[{key = "deaths", title = Scoreboard_Death, sorted = true, desc = true, default = 0, priority = 75, conditional = Scoreboard_Death.ScoreboardCondition}]
);
return _inherited(...);
}
protected func InitializePlayer(int plr)
{
var plrid = GetPlayerID(plr);
// Create scoreboard entry for this player, will only do it once
score_death_list[plrid] = 0;
Scoreboard->NewPlayerEntry(plr);
return _inherited(plr, ...);
}
protected func OnClonkDeath(object clonk, int killer)
{
var plr = clonk->GetOwner();
var plrid = GetPlayerID(plr);
// Modify scoreboard death count entry for this player.
score_death_list[plrid]++;
Scoreboard->SetPlayerData(plr, "deaths", score_death_list[plrid]);
return _inherited(clonk, killer, ...);
}
protected func RemovePlayer(int plr)
{
return _inherited(plr, ...);
}
/*-- Misc --*/
public func SetDeathCount(int plr)
{
var plrid = GetPlayerID(plr);
score_death_list[plrid] = 0;
Scoreboard->SetPlayerData(plr, "deaths", score_death_list[plrid]);
return;
}
public func GetDeathCount(int plr)
{
var plrid = GetPlayerID(plr);
return score_death_list[plrid];
}
local Name = "Scoreboard Deaths";
|