Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- namespace Oxide.Plugins
- {
- [Info("KillStats", "PsychoTea", "1.0.0")]
- [Description("Tells you your kills/deaths")]
- public sealed class KillStats : RustPlugin
- {
- class StoredData
- {
- public Dictionary<ulong, int> kills = new Dictionary<ulong, int>();
- public Dictionary<ulong, int> deaths = new Dictionary<ulong, int>();
- }
- StoredData storedData;
- void Loaded()
- {
- storedData = Interface.GetMod().DataFileSystem.ReadObject<StoredData>("KillStats");
- }
- void OnEntityDeath(BaseCombatEntity entity, HitInfo hitinfo)
- {
- if (entity != null && entity is BasePlayer)
- {
- BasePlayer victim = entity.ToPlayer();
- ulong vicSteamID = victim.userID;
- if (!storedData.deaths.ContainsKey(victim.userID))
- storedData.deaths.Add(vicSteamID, 1);
- else
- storedData.deaths[vicSteamID] = storedData.deaths[vicSteamID] + 1;
- if (hitinfo != null && hitinfo.Initiator != null && hitinfo.Initiator is BasePlayer)
- {
- BasePlayer attacker = hitinfo.Initiator.ToPlayer();
- ulong attSteamId = attacker.userID;
- if (!storedData.kills.ContainsKey(attacker.userID))
- storedData.kills.Add(attSteamId, 1);
- else
- storedData.kills[attSteamId] = storedData.kills[attSteamId] + 1;
- }
- Interface.GetMod().DataFileSystem.WriteObject("KillStats", storedData);
- }
- }
- [ChatCommand("stats")]
- void statsCmd(BasePlayer player, string cmd, string[] args)
- {
- BasePlayer target = null;
- if (args.Length == 0)
- target = player;
- else if (args.Length > 0)
- {
- target = BasePlayer.Find(args[0]);
- if (target == null)
- player.SendConsoleCommand("chat.add", 76561198206240711, String.Format("<color=red>{0} does not exist.</color>", args[0]));
- }
- if (target != null)
- {
- if (!storedData.kills.ContainsKey(target.userID))
- {
- storedData.kills.Add(target.userID, 0);
- Interface.GetMod().DataFileSystem.WriteObject("KillStats", storedData);
- }
- if (!storedData.deaths.ContainsKey(target.userID))
- {
- storedData.deaths.Add(target.userID, 0);
- Interface.GetMod().DataFileSystem.WriteObject("KillStats", storedData);
- }
- if (player == target)
- player.SendConsoleCommand("chat.add", 76561198206240711, String.Format("You have {0} kills and {1} deaths.", storedData.kills[target.userID].ToString(), storedData.deaths[target.userID].ToString()));
- else
- player.SendConsoleCommand("chat.add", 76561198206240711, String.Format("{0} has {1} kills and {2} deaths.", target.displayName, storedData.kills[target.userID].ToString(), storedData.deaths[target.userID].ToString()));
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement