Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.IO;
- using Terraria;
- using TerrariaApi.Server;
- using TShockAPI;
- namespace Endless_Ammo
- {
- [ApiVersion(1, 20)]
- public class Endless_Ammo : TerrariaPlugin
- {
- public static List<int> playerList = new List<int>();
- public override string Name
- {
- get
- {
- return "Endless Ammo";
- }
- }
- public override string Author
- {
- get
- {
- return "by InanZen & DarkunderdoG";
- }
- }
- public override string Description
- {
- get
- {
- return "Never run out of ammo";
- }
- }
- public override Version Version
- {
- get
- {
- return new Version("1.0.0");
- }
- }
- public override void Initialize()
- {
- ServerApi.Hooks.NetGetData.Register(this, new HookHandler<GetDataEventArgs>(this.GetData));
- ServerApi.Hooks.ServerLeave.Register(this, new HookHandler<LeaveEventArgs>(this.OnLeave));
- Commands.ChatCommands.Add(new Command("elite.ambassador", new CommandDelegate(this.EndlessCommand), new string[]
- {
- "endlessammo"
- }));
- }
- protected override void Dispose(bool disposing)
- {
- if (disposing)
- {
- ServerApi.Hooks.NetGetData.Deregister(this, new HookHandler<GetDataEventArgs>(this.GetData));
- ServerApi.Hooks.ServerLeave.Deregister(this, new HookHandler<LeaveEventArgs>(this.OnLeave));
- }
- base.Dispose(disposing);
- }
- public Endless_Ammo(Main game) : base(game)
- {
- Order = 5;
- }
- public void OnLeave(LeaveEventArgs args)
- {
- lock (Endless_Ammo.playerList)
- {
- Endless_Ammo.playerList.Remove(args.Who);
- }
- }
- public void EndlessCommand(CommandArgs args)
- {
- if (args.Parameters.Count == 1)
- {
- if (args.Parameters[0] == "off")
- {
- lock (Endless_Ammo.playerList)
- {
- Endless_Ammo.playerList.Remove(args.Player.Index);
- }
- args.Player.SendMessage("Endless Ammo disabled", Color.BurlyWood);
- }
- else if (args.Parameters[0] == "on")
- {
- lock (Endless_Ammo.playerList)
- {
- if (!Endless_Ammo.playerList.Contains(args.Player.Index))
- {
- Endless_Ammo.playerList.Add(args.Player.Index);
- }
- }
- args.Player.SendMessage("Endless Ammo enabled", Color.BurlyWood);
- }
- }
- else
- {
- lock (Endless_Ammo.playerList)
- {
- if (Endless_Ammo.playerList.Remove(args.Player.Index))
- {
- args.Player.SendMessage("Endless Ammo disabled", Color.BurlyWood);
- }
- else
- {
- Endless_Ammo.playerList.Add(args.Player.Index);
- args.Player.SendMessage("Endless Ammo enabled", Color.BurlyWood);
- }
- }
- }
- }
- public void GetData(GetDataEventArgs e)
- {
- if (e.MsgID == PacketTypes.ProjectileNew)
- {
- using (MemoryStream memoryStream = new MemoryStream(e.Msg.readBuffer, e.Index, e.Length))
- {
- BinaryReader binaryReader = new BinaryReader(memoryStream);
- byte b = binaryReader.ReadByte();
- int num = binaryReader.ReadInt32();
- int num2 = binaryReader.ReadInt32();
- byte b2 = binaryReader.ReadByte();
- bool flag = binaryReader.ReadBoolean();
- byte b3 = binaryReader.ReadByte();
- binaryReader.Close();
- binaryReader.Dispose();
- }
- if (Endless_Ammo.playerList.Contains(e.Msg.whoAmI))
- {
- Item[] inventory = TShock.Players[e.Msg.whoAmI].TPlayer.inventory;
- for (int i = 0; i < inventory.Length; i++)
- {
- Item item = inventory[i];
- //var ammo = item.ammo;
- //TShock.Players[e.Msg.whoAmI].SendMessage(string.Format("Ammo:" + ammo + "i:" + i), Color.Green);
- 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)
- {
- Item item2 = item;
- if (item.stack < Convert.ToInt32(item.maxStack / 3m) && item2 != null)
- {
- TShock.Players[e.Msg.whoAmI].GiveItem(item2.type, item2.name, item2.width, item2.height, item2.maxStack - item.stack, 0);
- break;
- }
- }
- }
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment