Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //'Import' necessary packages
- using System;
- using TShockAPI;
- using Terraria;
- using TerrariaApi.Server;
- using System.Timers;
- namespace Restore
- {
- //Version of TShock API
- [ApiVersion(1,16)]
- public class Restore : TerrariaPlugin
- {
- //Get version of plugin
- public override Version Version
- {
- get { return new Version(1, 0); }
- }
- //Name the plugin
- public override string Name
- {
- get { return "Restore"; }
- }
- //Who created the plugin
- public override string Author
- {
- get { return "MrGgggg243"; }
- }
- //Describe the plugin (not necessary)
- public override string Description
- {
- get { return "[FMG] Designed to refill health and mana"; }
- }
- //Variables
- private Timer restoreTimer = new Timer(1000);
- public TSPlayer player;
- public Boolean HPMode = false;
- public Boolean ManaMode = false;
- public Int32 maxHP = 0;
- public Int32 curHP = 0;
- public Int32 maxMana = 0;
- public Int32 curMana = 0;
- //Will be run first by TShock
- //-x will be run after TShock API loads
- //+x will be run before TShock API loads
- public Restore(Main game)
- : base(game)
- {
- Order = +4;
- }
- //Main code area
- public override void Initialize()
- {
- //Setup hooks
- ServerApi.Hooks.ServerLeave.Register(this, OnLeave);
- //Code for creating a command
- //new Command(permissions, method, command)
- Commands.ChatCommands.Add(new Command("fmg.restore", CallRestore, "restore"));
- restoreTimer.Elapsed += new ElapsedEventHandler(restoreTimer_Elapsed);
- restoreTimer.Interval = 1000;
- restoreTimer.AutoReset = true;
- restoreTimer.Enabled = false;
- }
- private void CallRestore(CommandArgs args)
- {
- string cmd = "help";
- if (args.Parameters.Count > 0)
- {
- cmd = args.Parameters[0].ToLower();
- }
- switch (cmd)
- {
- case "help":
- Help(args);
- break;
- case "hp":
- case "health":
- RestoreHp(args);
- break;
- case "mana":
- RestoreMana(args);
- break;
- default:
- Help(args);
- break;
- }
- }
- private void restoreTimer_Elapsed(object sender, ElapsedEventArgs e)
- {
- player.SendMessage("Timer", Color.Aqua);
- if (ManaMode)
- {
- if (!Main.player[player.Index].hostile)
- {
- if (HPMode || ManaMode)
- {
- maxHP = Main.player[player.Index].statLifeMax;
- curHP = Main.player[player.Index].statLife;
- if (curHP < maxHP)
- {
- Main.player[player.Index].HealEffect(maxHP, false);
- }
- }
- if (ManaMode)
- {
- maxMana = Main.player[player.Index].statManaMax;
- curMana = Main.player[player.Index].statMana;
- if (curMana < maxMana)
- {
- Main.player[player.Index].ManaEffect(maxMana);
- }
- }
- }
- else
- {
- player.SendMessage("FMG Restore - /restore cannot be used while in PVP and his been disabled.", Color.Aqua);
- HPMode = false;
- ManaMode = false;
- }
- }
- //restoreTimer.Enabled = true;
- }
- private void RestoreHp(CommandArgs args)
- {
- var plr = args.Player;
- if (!Main.player[plr.Index].hostile)
- {
- if (!HPMode)
- {
- HPMode = true;
- plr.SendMessage("FMG Success - You now have infinite health.", Color.Aqua);
- restoreTimer.Start();
- }
- else if (HPMode)
- {
- HPMode = false;
- plr.SendMessage("FMG Success - You now no longer have infinite health.", Color.Aqua);
- restoreTimer.Stop();
- }
- }
- else
- {
- plr.SendMessage("FMG Error - /restore cannot be used while in PVP", Color.Aqua);
- }
- }
- private void RestoreMana(CommandArgs args)
- {
- var plr = args.Player;
- if (!Main.player[plr.Index].hostile)
- {
- if (!ManaMode)
- {
- ManaMode = true;
- plr.SendMessage("FMG Success - You now have infinite mana.", Color.Aqua);
- restoreTimer.Start();
- }
- else if (ManaMode)
- {
- ManaMode = false;
- plr.SendMessage("FMG Success - You now no longer have infinite mana.", Color.Aqua);
- restoreTimer.Stop();
- }
- }
- else
- {
- plr.SendMessage("FMG Error - /restore cannot be used while in PVP", Color.Aqua);
- }
- }
- private void OnLeave(LeaveEventArgs args)
- {
- HPMode = false;
- ManaMode = false;
- }
- private void Help(CommandArgs args)
- {
- args.Player.SendMessage("FMG Restore - Help:", Color.Aqua);
- args.Player.SendMessage(" /restore <hp/health-mana> - restore a player's health or mana", Color.Aqua);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement