Guest User

Untitled

a guest
Aug 2nd, 2015
326
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.58 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.IO;
  4. using Terraria;
  5. using TerrariaApi.Server;
  6. using TShockAPI;
  7.  
  8. namespace Endless_Ammo
  9. {
  10. [ApiVersion(1, 20)]
  11. public class Endless_Ammo : TerrariaPlugin
  12. {
  13. public static List<int> playerList = new List<int>();
  14.  
  15. public override string Name
  16. {
  17. get
  18. {
  19. return "Endless Ammo";
  20. }
  21. }
  22.  
  23. public override string Author
  24. {
  25. get
  26. {
  27. return "by InanZen & DarkunderdoG";
  28. }
  29. }
  30.  
  31. public override string Description
  32. {
  33. get
  34. {
  35. return "Never run out of ammo";
  36. }
  37. }
  38.  
  39. public override Version Version
  40. {
  41. get
  42. {
  43. return new Version("1.0.0");
  44. }
  45. }
  46.  
  47. public override void Initialize()
  48. {
  49. ServerApi.Hooks.NetGetData.Register(this, new HookHandler<GetDataEventArgs>(this.GetData));
  50. ServerApi.Hooks.ServerLeave.Register(this, new HookHandler<LeaveEventArgs>(this.OnLeave));
  51. Commands.ChatCommands.Add(new Command("elite.ambassador", new CommandDelegate(this.EndlessCommand), new string[]
  52. {
  53. "endlessammo"
  54. }));
  55. }
  56.  
  57. protected override void Dispose(bool disposing)
  58. {
  59. if (disposing)
  60. {
  61. ServerApi.Hooks.NetGetData.Deregister(this, new HookHandler<GetDataEventArgs>(this.GetData));
  62. ServerApi.Hooks.ServerLeave.Deregister(this, new HookHandler<LeaveEventArgs>(this.OnLeave));
  63. }
  64. base.Dispose(disposing);
  65. }
  66.  
  67. public Endless_Ammo(Main game) : base(game)
  68. {
  69. Order = 5;
  70. }
  71.  
  72. public void OnLeave(LeaveEventArgs args)
  73. {
  74. lock (Endless_Ammo.playerList)
  75. {
  76. Endless_Ammo.playerList.Remove(args.Who);
  77. }
  78. }
  79.  
  80. public void EndlessCommand(CommandArgs args)
  81. {
  82. if (args.Parameters.Count == 1)
  83. {
  84. if (args.Parameters[0] == "off")
  85. {
  86. lock (Endless_Ammo.playerList)
  87. {
  88. Endless_Ammo.playerList.Remove(args.Player.Index);
  89. }
  90. args.Player.SendMessage("Endless Ammo disabled", Color.BurlyWood);
  91. }
  92. else if (args.Parameters[0] == "on")
  93. {
  94. lock (Endless_Ammo.playerList)
  95. {
  96. if (!Endless_Ammo.playerList.Contains(args.Player.Index))
  97. {
  98. Endless_Ammo.playerList.Add(args.Player.Index);
  99. }
  100. }
  101. args.Player.SendMessage("Endless Ammo enabled", Color.BurlyWood);
  102. }
  103. }
  104. else
  105. {
  106. lock (Endless_Ammo.playerList)
  107. {
  108. if (Endless_Ammo.playerList.Remove(args.Player.Index))
  109. {
  110. args.Player.SendMessage("Endless Ammo disabled", Color.BurlyWood);
  111. }
  112. else
  113. {
  114. Endless_Ammo.playerList.Add(args.Player.Index);
  115. args.Player.SendMessage("Endless Ammo enabled", Color.BurlyWood);
  116. }
  117. }
  118. }
  119. }
  120.  
  121. public void GetData(GetDataEventArgs e)
  122. {
  123. if (e.MsgID == PacketTypes.ProjectileNew)
  124. {
  125. using (MemoryStream memoryStream = new MemoryStream(e.Msg.readBuffer, e.Index, e.Length))
  126. {
  127. BinaryReader binaryReader = new BinaryReader(memoryStream);
  128. byte b = binaryReader.ReadByte();
  129. int num = binaryReader.ReadInt32();
  130. int num2 = binaryReader.ReadInt32();
  131. byte b2 = binaryReader.ReadByte();
  132. bool flag = binaryReader.ReadBoolean();
  133. byte b3 = binaryReader.ReadByte();
  134. binaryReader.Close();
  135. binaryReader.Dispose();
  136. }
  137. if (Endless_Ammo.playerList.Contains(e.Msg.whoAmI))
  138. {
  139. Item[] inventory = TShock.Players[e.Msg.whoAmI].TPlayer.inventory;
  140. for (int i = 0; i < inventory.Length; i++)
  141. {
  142. Item item = inventory[i];
  143. //var ammo = item.ammo;
  144. //TShock.Players[e.Msg.whoAmI].SendMessage(string.Format("Ammo:" + ammo + "i:" + i), Color.Green);
  145. if (item.ammo == 14 || item.ammo == 1 || item.ammo == 71 || item.ammo == 15 || item.ammo == 311 || item.ammo == 949 || item.ammo == 246 || item.ammo == 323 || item.ammo == 23 || item.ammo == 514)
  146. {
  147. Item item2 = item;
  148. if (item.stack < Convert.ToInt32(item.maxStack / 3m) && item2 != null)
  149. {
  150. TShock.Players[e.Msg.whoAmI].GiveItem(item2.type, item2.name, item2.width, item2.height, item2.maxStack - item.stack, 0);
  151. break;
  152. }
  153. }
  154. }
  155. }
  156. }
  157. }
  158. }
  159. }
Advertisement
Add Comment
Please, Sign In to add comment