C#:
using System;
using System.Collections.Generic;
using Oxide.Core.Libraries.Covalence;
namespace Oxide.Plugins
{
[Info("Team Shifter", "Zeeuss", "0.1.1")]
[Description("Gives player ability to move other players to someone's team")]
public class TeamShifter : RustPlugin
{
#region Fields
private const string permUse = "teamshifter.use";
private const string permBypass = "teamshifter.bypass";
#endregion
#region Init
void Init()
{
permission.RegisterPermission(permUse, this);
permission.RegisterPermission(permBypass, this);
AddCovalenceCommand("tshift", "shiftCmd", permUse);
}
#endregion
#region Localization
protected override void LoadDefaultMessages()
{
lang.RegisterMessages(new Dictionary<string, string>
{
["NoPerms"] = "You don't have permission to use this!",
["Syntax"] = "Syntax: /tshift (player_to_move) (player_of_new_team)",
["NoPlayerToMove"] = "Couldn't find the player to move",
["NoPlayerOfNewTeam"] = "Couldn't find the player of new team",
["MoveMessage"] = "Moved {0} to {1}'s team",
["AlreadyInThatTeam"] = "{0} already is in {1}'s team",
["NeedsDifferentPlayers"] = "This command needs 2 different players and not the same one",
["CannotBeShifted"] = "{0} cannot be shifted by anyone into other teams",
}, this);
}
#endregion
#region Shift Command
void shiftCmd(IPlayer player, string command, string[] args)
{
if (!permission.UserHasPermission(player.Id, permUse))
{
player.Message(lang.GetMessage("NoPerms", this, player.Id));
return;
}
if(args.Length < 2)
{
player.Message(lang.GetMessage("Syntax", this, player.Id));
return;
}
//BasePlayer playerToMove = BasePlayer.FindAwakeOrSleeping(args[0]);
//BasePlayer playerOfNewTeam = BasePlayer.FindAwakeOrSleeping(args[1]);
IPlayer iplayerToMove = covalence.Players.FindPlayer(args[0]);
BasePlayer playerToMove = RelationshipManager.FindByID(Convert.ToUInt64(iplayerToMove.Id));
IPlayer iplayerOfNewTeam = covalence.Players.FindPlayer(args[1]);
BasePlayer playerOfNewTeam = RelationshipManager.FindByID(Convert.ToUInt64(iplayerOfNewTeam.Id));
//null check
if (playerToMove == null)
{
player.Message(lang.GetMessage("NoPlayerToMove", this, player.Id));
return;
}
//null check
if (playerOfNewTeam == null)
{
player.Message(lang.GetMessage("NoPlayerOfNewTeam", this, player.Id));
return;
}
//if pl to move has bypass perm he can't be shifted
if (permission.UserHasPermission(playerToMove.UserIDString, permBypass))
{
player.Message(string.Format(lang.GetMessage("CannotBeShifted", this, player.Id), playerToMove.displayName));
return;
}
//self explanatory? D:
if (playerToMove.userID == playerOfNewTeam.userID)
{
player.Message(lang.GetMessage("NeedsDifferentPlayers", this, player.Id));
return;
}
//If player to move already is in that team then return
if (playerToMove.currentTeam == playerOfNewTeam.currentTeam && playerToMove.currentTeam != 0UL)
{
player.Message(string.Format(lang.GetMessage("AlreadyInThatTeam", this, player.Id), playerToMove.displayName, playerOfNewTeam.displayName));
return;
}
//If player to move is in any team then leave it
if (playerToMove.currentTeam != 0UL)
{
RelationshipManager.PlayerTeam toMoveTeam = RelationshipManager.ServerInstance.FindTeam(playerToMove.Team.teamID);
toMoveTeam.RemovePlayer(playerToMove.userID);
}
//If the player of new team is not in team yet then create
if (playerOfNewTeam.currentTeam == 0UL)
{
RelationshipManager.PlayerTeam plTeam = RelationshipManager.ServerInstance.CreateTeam();
plTeam.AddPlayer(playerOfNewTeam);
if(plTeam.members.Count <= 1)
{
plTeam.SetTeamLeader(playerOfNewTeam.userID);
}
}
RelationshipManager.PlayerTeam newPlayersTeam = RelationshipManager.ServerInstance.FindTeam(playerOfNewTeam.Team.teamID);
newPlayersTeam.AddPlayer(playerToMove);
player.Message(string.Format(lang.GetMessage("MoveMessage", this, player.Id), playerToMove.displayName, playerOfNewTeam.displayName));
}
#endregion
}
}