Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using Rocket.Core.Logging;
- using Rocket.Core.Plugins;
- using Rocket.Core.Steam;
- using Rocket.Unturned;
- using Rocket.Unturned.Chat;
- using Rocket.Unturned.Effects;
- using Rocket.Unturned.Enumerations;
- using Rocket.Unturned.Events;
- using Rocket.Unturned.Commands;
- using Rocket.Unturned.Items;
- using Rocket.Unturned.Player;
- using SDG.Unturned;
- using UnityEngine;
- using Steamworks;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.IO;
- namespace Ster.Test
- {
- class Testing : RocketPlugin<Configuration> //Here we are creating our "main" class, which will be deriving from "RocketPlugin".
- {
- public static Testing Instance; //we create our "Testing" Instance here.
- protected override void Load() //this is our Load method, it will be called when the plugin is loaded.
- {
- Instance = this;
- if (Testing.Instance.Configuration.Instance.Enabled) //we are checking the value of the variable "Enabled" in our configuration.
- {
- UnturnedPlayerEvents.OnPlayerDeath += PlayerDied; //here we are subscribing the OnPlayerDeath event to our PlayerDied method.
- Logger.Log("[Admin-Death-Announcer] Log: Plugin Loaded.");
- }
- else //this code is run when Enabled = false
- {
- Logger.Log("[Admin-Death-Announcer] Log: Plugin Unloading because Enabled = 'false'.");
- Unload(); //the method to unload our plugin. Runs all code in the unload method.
- }
- }
- private void PlayerDied(UnturnedPlayer player, EDeathCause cause, ELimb limb, CSteamID murderer) //creating our PlayerDied method with the proper parameters from the event.
- {
- if (player.IsAdmin) //checks if the player who died is an admin.
- {
- foreach (SteamPlayer plr in Provider.Players) //we are grabbing all users online and executing the below code for each of them.
- {
- UnturnedPlayer looped = UnturnedPlayer.FromSteamPlayer(plr); //we are converting the SteamPlayer into an UnturnedPlayer.
- UnturnedChat.Say(looped, "The Admin '" + player.CharacterName + "' has died!", Color.cyan); //our message that will be sent to the looped player.
- }
- UnturnedChat.Say(murderer, "Oh dear. You killed an Admin!", Color.red); //this message is only sent to the player who killed the admin.
- }
- }
- //Advertising - FearRising.com
- //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.
- 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)
- {
- UnturnedPlayerEvents.OnPlayerDeath -= PlayerDied; //unsubscribing the OnPlayerDeath event from our PlayerDied method.
- Logger.Log("[Admin-Death-Announcer] Log: Plugin Unloaded.");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement