Advertisement
Guest User

Testing.cs

a guest
Jul 12th, 2016
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.13 KB | None | 0 0
  1. using Rocket.Core.Logging;
  2. using Rocket.Core.Plugins;
  3. using Rocket.Core.Steam;
  4. using Rocket.Unturned;
  5. using Rocket.Unturned.Chat;
  6. using Rocket.Unturned.Effects;
  7. using Rocket.Unturned.Enumerations;
  8. using Rocket.Unturned.Events;
  9. using Rocket.Unturned.Commands;
  10. using Rocket.Unturned.Items;
  11. using Rocket.Unturned.Player;
  12. using SDG.Unturned;
  13. using UnityEngine;
  14. using Steamworks;
  15. using System;
  16. using System.Collections.Generic;
  17. using System.Linq;
  18. using System.Text;
  19. using System.IO;
  20.  
  21. namespace Ster.Test
  22. {
  23.     class Testing : RocketPlugin<Configuration> //Here we are creating our "main" class, which will be deriving from "RocketPlugin".
  24.     {
  25.         public static Testing Instance; //we create our "Testing" Instance here.
  26.         protected override void Load() //this is our Load method, it will be called when the plugin is loaded.
  27.         {
  28.             Instance = this;
  29.             if (Testing.Instance.Configuration.Instance.Enabled) //we are checking the value of the variable "Enabled" in our configuration.
  30.             {
  31.                 UnturnedPlayerEvents.OnPlayerDeath += PlayerDied; //here we are subscribing the OnPlayerDeath event to our PlayerDied method.
  32.                 Logger.Log("[Admin-Death-Announcer] Log:  Plugin Loaded.");
  33.             }
  34.             else //this code is run when Enabled = false
  35.             {
  36.                 Logger.Log("[Admin-Death-Announcer] Log:  Plugin Unloading because Enabled = 'false'.");
  37.                 Unload(); //the method to unload our plugin. Runs all code in the unload method.
  38.             }
  39.         }
  40.  
  41.         private void PlayerDied(UnturnedPlayer player, EDeathCause cause, ELimb limb, CSteamID murderer) //creating our PlayerDied method with the proper parameters from the event.
  42.         {
  43.             if (player.IsAdmin) //checks if the player who died is an admin.
  44.             {
  45.                 foreach (SteamPlayer plr in Provider.Players) //we are grabbing all users online and executing the below code for each of them.
  46.                 {
  47.                     UnturnedPlayer looped = UnturnedPlayer.FromSteamPlayer(plr); //we are converting the SteamPlayer into an UnturnedPlayer.
  48.                     UnturnedChat.Say(looped, "The Admin '" + player.CharacterName + "' has died!", Color.cyan); //our message that will be sent to the looped player.
  49.                 }
  50.                 UnturnedChat.Say(murderer, "Oh dear. You killed an Admin!", Color.red); //this message is only sent to the player who killed the admin.
  51.             }
  52.         }
  53.  
  54.         //Advertising - FearRising.com
  55.         //Note - I am referencing a lot of libs here so I don't need to reference them later. Feel free to clean the ones that are not in use if you release your plugin.
  56.  
  57.         protected override void Unload() //This is our unload method. All code inside will be executed when the server stops, the plugin is unloaded, or if we call this method (like earlier)
  58.         {
  59.             UnturnedPlayerEvents.OnPlayerDeath -= PlayerDied; //unsubscribing the OnPlayerDeath event from our PlayerDied method.
  60.             Logger.Log("[Admin-Death-Announcer] Log:  Plugin Unloaded.");
  61.         }
  62.     }
  63. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement