Advertisement
Guest User

Untitled

a guest
Oct 18th, 2015
129
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.31 KB | None | 0 0
  1. namespace Oxide.Plugins
  2. {
  3. [Info("KillStats", "PsychoTea", "1.0.0")]
  4. [Description("Tells you your kills/deaths")]
  5.  
  6. public sealed class KillStats : RustPlugin
  7. {
  8. class StoredData
  9. {
  10. public Dictionary<ulong, int> kills = new Dictionary<ulong, int>();
  11. public Dictionary<ulong, int> deaths = new Dictionary<ulong, int>();
  12. }
  13. StoredData storedData;
  14.  
  15. void Loaded()
  16. {
  17. storedData = Interface.GetMod().DataFileSystem.ReadObject<StoredData>("KillStats");
  18. }
  19.  
  20.  
  21. void OnEntityDeath(BaseCombatEntity entity, HitInfo hitinfo)
  22. {
  23. if (entity != null && entity is BasePlayer)
  24. {
  25. BasePlayer victim = entity.ToPlayer();
  26. ulong vicSteamID = victim.userID;
  27.  
  28. if (!storedData.deaths.ContainsKey(victim.userID))
  29. storedData.deaths.Add(vicSteamID, 1);
  30. else
  31. storedData.deaths[vicSteamID] = storedData.deaths[vicSteamID] + 1;
  32.  
  33. if (hitinfo != null && hitinfo.Initiator != null && hitinfo.Initiator is BasePlayer)
  34. {
  35. BasePlayer attacker = hitinfo.Initiator.ToPlayer();
  36. ulong attSteamId = attacker.userID;
  37.  
  38. if (!storedData.kills.ContainsKey(attacker.userID))
  39. storedData.kills.Add(attSteamId, 1);
  40. else
  41. storedData.kills[attSteamId] = storedData.kills[attSteamId] + 1;
  42. }
  43. Interface.GetMod().DataFileSystem.WriteObject("KillStats", storedData);
  44. }
  45. }
  46.  
  47. [ChatCommand("stats")]
  48. void statsCmd(BasePlayer player, string cmd, string[] args)
  49. {
  50. BasePlayer target = null;
  51.  
  52. if (args.Length == 0)
  53. target = player;
  54. else if (args.Length > 0)
  55. {
  56. target = BasePlayer.Find(args[0]);
  57.  
  58. if (target == null)
  59. player.SendConsoleCommand("chat.add", 76561198206240711, String.Format("<color=red>{0} does not exist.</color>", args[0]));
  60. }
  61.  
  62. if (target != null)
  63. {
  64. if (!storedData.kills.ContainsKey(target.userID))
  65. {
  66. storedData.kills.Add(target.userID, 0);
  67. Interface.GetMod().DataFileSystem.WriteObject("KillStats", storedData);
  68. }
  69.  
  70. if (!storedData.deaths.ContainsKey(target.userID))
  71. {
  72. storedData.deaths.Add(target.userID, 0);
  73. Interface.GetMod().DataFileSystem.WriteObject("KillStats", storedData);
  74. }
  75.  
  76. if (player == target)
  77. player.SendConsoleCommand("chat.add", 76561198206240711, String.Format("You have {0} kills and {1} deaths.", storedData.kills[target.userID].ToString(), storedData.deaths[target.userID].ToString()));
  78. else
  79. 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()));
  80. }
  81. }
  82. }
  83. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement