KF2-YetAnotherScoreboard/ScoreboardExt/Classes/ScoreboardExtMut.uc

192 lines
5.8 KiB
Ucode
Raw Normal View History

2021-05-31 01:46:53 +00:00
class ScoreboardExtMut extends KFMutator
2021-06-08 21:48:03 +00:00
dependson(CustomRanks, PlayerRankRelations)
2021-05-31 01:46:53 +00:00
config(ScoreboardExt);
const SteamIDLen = 17;
const UniqueIDLen = 18;
const CurrentVersion = 1;
var config int ConfigVersion;
struct SClient
{
var ScoreboardExtRepInfo RepInfo;
var KFPlayerController KFPC;
};
var private array<SClient> RepClients;
2021-06-08 21:48:03 +00:00
var private array<UIDRankRelation> UIDRelations;
2020-01-10 13:14:11 +00:00
function PostBeginPlay()
2020-01-10 13:14:11 +00:00
{
Super.PostBeginPlay();
2021-05-31 01:46:53 +00:00
WorldInfo.Game.HUDType = class'ScoreboardExtHUD';
InitConfig();
2021-06-08 21:48:03 +00:00
LoadPlayerRelations();
2021-05-31 01:46:53 +00:00
}
function NotifyLogin(Controller C)
{
2021-06-08 21:48:03 +00:00
AddPlayer(C);
2021-05-31 01:46:53 +00:00
Super.NotifyLogin(C);
}
function NotifyLogout(Controller C)
{
2021-06-08 21:48:03 +00:00
RemovePlayer(C);
2021-05-31 01:46:53 +00:00
Super.NotifyLogout(C);
}
private function InitConfig()
{
2021-06-08 21:21:28 +00:00
local RankInfo ExampleRank;
2021-06-08 21:48:03 +00:00
local PlayerRankRelation ExamplePlayer;
local SteamGroupRankRelation ExampleSteamGroup;
2021-05-31 01:46:53 +00:00
// Update from config version to current version if needed
switch (ConfigVersion)
{
case 0: // which means there is no config right now
2021-05-31 04:04:26 +00:00
SaveConfig(); // because I want the main settings to be at the beginning of the config :)
// Default admin rank
2021-06-08 21:21:28 +00:00
class'SystemAdminRank'.default.Rank = "Admin";
class'SystemAdminRank'.default.TextColor.R = 250;
class'SystemAdminRank'.default.TextColor.G = 0;
class'SystemAdminRank'.default.TextColor.B = 0;
2021-05-31 01:46:53 +00:00
2021-05-31 04:04:26 +00:00
// Default player rank
2021-06-08 21:21:28 +00:00
class'SystemPlayerRank'.default.Rank = "Player";
class'SystemPlayerRank'.default.TextColor.R = 250;
class'SystemPlayerRank'.default.TextColor.G = 250;
class'SystemPlayerRank'.default.TextColor.B = 250;
2021-05-31 01:46:53 +00:00
2021-05-31 04:04:26 +00:00
// Example rank for player(s)
2021-06-08 21:21:28 +00:00
ExampleRank.ID = 0;
ExampleRank.Rank = "SCE Creator";
ExampleRank.TextColor.R = 130;
ExampleRank.TextColor.G = 250;
ExampleRank.TextColor.B = 235;
ExampleRank.OverrideAdminRank = true;
2021-06-08 21:48:03 +00:00
class'CustomRanks'.default.Rank.AddItem(ExampleRank);
2021-05-31 01:46:53 +00:00
// Example player
2021-06-08 21:48:03 +00:00
ExamplePlayer.PlayerID = "76561198001617867"; // GenZmeY SteamID64
2021-06-08 21:21:28 +00:00
ExamplePlayer.RankID = ExampleRank.ID;
2021-06-08 21:48:03 +00:00
class'PlayerRankRelations'.default.Relation.AddItem(ExamplePlayer);
2021-05-31 04:04:26 +00:00
// Example rank for steam group members
2021-06-08 21:21:28 +00:00
ExampleRank.ID = 1;
ExampleRank.Rank = "[MSK-GS]";
ExampleRank.TextColor.R = 130;
ExampleRank.TextColor.G = 250;
ExampleRank.TextColor.B = 130;
ExampleRank.OverrideAdminRank = false;
2021-06-08 21:48:03 +00:00
class'CustomRanks'.default.Rank.AddItem(ExampleRank);
2021-05-31 04:04:26 +00:00
// Example steam group
2021-06-08 21:48:03 +00:00
ExampleSteamGroup.SteamGroupID = "103582791465384046"; // MSK-GS SteamID64
2021-06-08 21:21:28 +00:00
ExampleSteamGroup.RankID = ExampleRank.ID;
2021-06-08 21:48:03 +00:00
class'SteamGroupRankRelations'.default.Relation.AddItem(ExampleSteamGroup);
2021-05-31 04:04:26 +00:00
2021-06-08 21:21:28 +00:00
class'SystemAdminRank'.static.StaticSaveConfig();
class'SystemPlayerRank'.static.StaticSaveConfig();
2021-06-08 21:48:03 +00:00
class'CustomRanks'.static.StaticSaveConfig();
class'PlayerRankRelations'.static.StaticSaveConfig();
class'SteamGroupRankRelations'.static.StaticSaveConfig();
2021-05-31 01:46:53 +00:00
case 2147483647:
`log("[ScoreboardExt] Config updated to version"@CurrentVersion);
break;
case CurrentVersion:
`log("[ScoreboardExt] Config is up-to-date");
break;
default:
`log("[ScoreboardExt] Warn: The config version is higher than the current version (are you using an old mutator?)");
`log("[ScoreboardExt] Warn: Config version is"@ConfigVersion@"but current version is"@CurrentVersion);
`log("[ScoreboardExt] Warn: The config version will be changed to "@CurrentVersion);
break;
}
2021-06-08 20:31:56 +00:00
if (ConfigVersion != CurrentVersion)
{
ConfigVersion = CurrentVersion;
SaveConfig();
}
2021-05-31 01:46:53 +00:00
}
2021-06-08 21:48:03 +00:00
private function LoadPlayerRelations()
2021-05-31 01:46:53 +00:00
{
2021-06-08 21:21:28 +00:00
local PlayerRankRelation Player;
2021-05-31 01:46:53 +00:00
local OnlineSubsystem steamworks;
2021-06-08 21:21:28 +00:00
local UIDRankRelation UIDInfo;
2021-05-31 01:46:53 +00:00
steamworks = class'GameEngine'.static.GetOnlineSubsystem();
2021-06-08 21:48:03 +00:00
foreach class'PlayerRankRelations'.default.Relation(Player)
2021-05-31 01:46:53 +00:00
{
2021-06-08 21:21:28 +00:00
UIDInfo.RankID = Player.RankID;
2021-05-31 01:46:53 +00:00
if (Len(Player.PlayerID) == UniqueIDLen && steamworks.StringToUniqueNetId(Player.PlayerID, UIDInfo.UID))
{
2021-06-08 21:48:03 +00:00
if (UIDRelations.Find('Uid', UIDInfo.UID) == INDEX_NONE)
UIDRelations.AddItem(UIDInfo);
2021-05-31 01:46:53 +00:00
}
else if (Len(Player.PlayerID) == SteamIDLen && steamworks.Int64ToUniqueNetId(Player.PlayerID, UIDInfo.UID))
{
2021-06-08 21:48:03 +00:00
if (UIDRelations.Find('Uid', UIDInfo.UID) == INDEX_NONE)
UIDRelations.AddItem(UIDInfo);
2021-05-31 01:46:53 +00:00
}
else `Log("[ScoreboardExt] WARN: Can't add player:"@Player.PlayerID);
}
2020-01-10 13:14:11 +00:00
}
2021-06-08 21:48:03 +00:00
function AddPlayer(Controller C)
{
2021-05-31 01:46:53 +00:00
local KFPlayerController KFPC;
local SClient RepClient;
2021-05-31 04:04:26 +00:00
2021-05-31 01:46:53 +00:00
KFPC = KFPlayerController(C);
2021-05-31 04:04:26 +00:00
if (KFPC == None)
2021-05-31 01:46:53 +00:00
return;
RepClient.RepInfo = Spawn(class'ScoreboardExtRepInfo', KFPC);
RepClient.KFPC = KFPC;
RepClients.AddItem(RepClient);
2021-06-08 21:48:03 +00:00
RepClient.RepInfo.PlayerRankRelations = UIDRelations;
RepClient.RepInfo.CustomRanks = class'CustomRanks'.default.Rank;
2021-06-08 21:21:28 +00:00
RepClient.RepInfo.SystemAdminRank = class'SystemAdminRank'.default.Rank;
RepClient.RepInfo.SystemAdminColor = class'SystemAdminRank'.default.TextColor;
RepClient.RepInfo.SystemAdminApplyColorToFields = class'SystemAdminRank'.default.ApplyColorToFields;
RepClient.RepInfo.SystemPlayerRank = class'SystemPlayerRank'.default.Rank;
RepClient.RepInfo.SystemPlayerColor = class'SystemPlayerRank'.default.TextColor;
RepClient.RepInfo.SystemPlayerApplyColorToFields = class'SystemPlayerRank'.default.ApplyColorToFields;
2021-05-31 04:04:26 +00:00
RepClient.RepInfo.ClientStartReplication();
2021-05-31 01:46:53 +00:00
}
2021-06-08 21:48:03 +00:00
function RemovePlayer(Controller C)
2021-05-31 01:46:53 +00:00
{
local KFPlayerController KFPC;
local int Index;
KFPC = KFPlayerController(C);
if (KFPC == None)
return;
Index = RepClients.Find('KFPC', KFPC);
if (Index == INDEX_NONE)
return;
if (RepClients[Index].RepInfo != None)
RepClients[Index].RepInfo.Destroy();
RepClients.Remove(Index, 1);
}
DefaultProperties
{
2020-01-10 13:14:11 +00:00
}