Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
comdar16 authored Oct 14, 2021
1 parent 5e57d33 commit 931294e
Show file tree
Hide file tree
Showing 14 changed files with 274 additions and 5 deletions.
162 changes: 162 additions & 0 deletions PlayerInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,162 @@
using Microsoft.Xna.Framework;
using System;
using System.Collections.Generic;
using Terraria;
using TerrariaApi.Server;
using TShockAPI;
using System.Linq;

namespace PlayerInfo
{
[ApiVersion(2, 1)]

public class PlayerInfo : TerrariaPlugin
{
public override Version Version
{
get { return new Version(1, 8); }
}

public override string Name
{
get { return "PlayerInfo"; }
}

public override string Author
{
get { return "Comdar"; }
}

public override string Description
{
get { return "Player info plugin"; }
}

public PlayerInfo(Main game)
: base(game)
{
Order = +4;
}

public override void Initialize()
{
Commands.ChatCommands.Add(new Command("playerinfo.hpnmana", SetStats, "stats"));
Commands.ChatCommands.Add(new Command("playerinfo.selfname", SelfName, "nick", "name"));
Commands.ChatCommands.Add(new Command("playerinfo.checkinfo", CheckInfo, "checkinfo", "cinfo"));
}

void CheckInfo(CommandArgs args)
{
TSPlayer plr = args.Player;
if (args.Parameters.Count != 1)
{
plr.SendErrorMessage("Invalid Syntax! Proper Syntax: /checkinfo <player>");
return;
}
var foundPlr = TSPlayer.FindByNameOrID(args.Parameters[0]);
if (foundPlr.Count == 0)
{
args.Player.SendErrorMessage("Invalid player!");
return;
}
else {
var iPlayer = foundPlr[0];
string name = iPlayer.Name;
var hp = iPlayer.TPlayer.statLifeMax2;
var mana = iPlayer.TPlayer.statManaMax2;
var currentHp = iPlayer.TPlayer.statLife;
var currentMana = iPlayer.TPlayer.statMana;
var groupName = iPlayer.Group.Name;
var groupPrefix = iPlayer.Group.Prefix;
string array = "Name: " + name + "\nHP: " + hp + ", Current HP: " + currentHp + "\nMana: " + mana + ", Current Mana: " + currentMana + "\nGroup: " + groupName + ", Group Prefix: " + groupPrefix;
plr.SendMessage(array, Color.LightSteelBlue);
}
}

void SetStats(CommandArgs args)
{
if (args.Parameters.Count < 3 || args.Parameters.Count > 4)
{
args.Player.SendErrorMessage("Invalid syntax! Proper syntax: /stats <player> <health> <mana>");
return;
}
int health = 0;
int mana = 0;
var foundPlr = TSPlayer.FindByNameOrID(args.Parameters[0]);
if (foundPlr.Count == 0)
{
args.Player.SendErrorMessage("Invalid player!");
return;
}
// if (foundplr.Count > 1)
// {
// TShock.Utils.SendMultipleMatchError(args.Player, foundPlr.Select(p => p.Name));
// return;
// }
else
{
var iPlayer = foundPlr[0];
if (!int.TryParse(args.Parameters[1], out health))
{
if (health < 100)
{
args.Player.SendErrorMessage("Invalid Health Amount!");
return;
}
}
if (!int.TryParse(args.Parameters[2], out mana))
{
if (mana < 20)
{
args.Player.SendErrorMessage("Invalid Mana Amount!");
return;
}
}
iPlayer.TPlayer.statLifeMax = health;
iPlayer.TPlayer.statManaMax = mana;
NetMessage.SendData(16, -1, -1, null, iPlayer.Index, 0f, 0f, 0f, 0); // Sends Health Packet
NetMessage.SendData(42, -1, -1, null, iPlayer.Index, 0f, 0f, 0f, 0); // Sends Mana Packet
args.Player.SendSuccessMessage(string.Format("The Player's Stats have been set!"));
iPlayer.SendSuccessMessage(string.Format("Your Stats have been modified!"));
}
}
void SelfName(CommandArgs args)
{
if (args.Player == null) return;

var plr = args.Player;
if (args.Parameters.Count < 1)
{
args.Player.SendErrorMessage("Invalid syntax! Proper syntax: /nick <newname>");
return;
}
string newName = string.Join(" ", args.Parameters).Trim();

#region Checks
if (newName.Length < 2)
{
args.Player.SendMessage("A name must be at least 2 characters long.", Color.DeepPink);
return;
}

if (newName.Length > 20)
{
args.Player.SendMessage("A name must not be longer than 20 characters.", Color.DeepPink);
return;
}

List<TSPlayer> SameName = TShock.Players.Where(player => (player != null && player.Name == newName)).ToList();
if (SameName.Count > 0)
{
args.Player.SendMessage("This name is taken by another player.", Color.DeepPink);
return;
}
#endregion Checks

string oldName = plr.TPlayer.name;
plr.TPlayer.name = newName;
TShock.Utils.Broadcast(string.Format("{0} has changed his name to {1}.", oldName, newName), Color.DeepPink);
plr.SendData(PacketTypes.PlayerInfo, newName, plr.Index);
}
}
}
54 changes: 54 additions & 0 deletions PlayerInfo.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{C04AAE3B-7FAC-4FE0-B3BC-7977008BBAE2}</ProjectGuid>
<OutputType>Library</OutputType>
<RootNamespace>PlayerInfo</RootNamespace>
<AssemblyName>PlayerInfo</AssemblyName>
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>.\</OutputPath>
<DefineConstants>DEBUG;</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<ConsolePause>false</ConsolePause>
<PlatformTarget>x86</PlatformTarget>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<Optimize>true</Optimize>
<OutputPath>D:\Terraria\steamapps\common\Terraria\Legit Terraria Server\ServerPlugins</OutputPath>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<ConsolePause>false</ConsolePause>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="Newtonsoft.Json">
<HintPath>..\Refs\Newtonsoft.Json.dll</HintPath>
</Reference>
<Reference Include="OTAPI">
<HintPath>..\Refs\OTAPI.dll</HintPath>
</Reference>
<Reference Include="TerrariaServer">
<HintPath>..\Refs\TerrariaServer.exe</HintPath>
</Reference>
<Reference Include="TShockAPI">
<HintPath>..\Refs\TShockAPI.dll</HintPath>
</Reference>
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="PlayerInfo.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
</Project>
7 changes: 7 additions & 0 deletions PlayerInfo.csproj.user
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup Condition=" '$(RunConfiguration)' == 'Default' ">
<StartAction>Project</StartAction>
<ConsolePause>true</ConsolePause>
</PropertyGroup>
</Project>
25 changes: 25 additions & 0 deletions PlayerInfo.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.30114.105
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PlayerInfo", "PlayerInfo\PlayerInfo.csproj", "{C04AAE3B-7FAC-4FE0-B3BC-7977008BBAE2}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{C04AAE3B-7FAC-4FE0-B3BC-7977008BBAE2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{C04AAE3B-7FAC-4FE0-B3BC-7977008BBAE2}.Debug|Any CPU.Build.0 = Debug|Any CPU
{C04AAE3B-7FAC-4FE0-B3BC-7977008BBAE2}.Release|Any CPU.ActiveCfg = Release|Any CPU
{C04AAE3B-7FAC-4FE0-B3BC-7977008BBAE2}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {31CA7400-8BB2-4B8C-AC44-8E68D0F9C297}
EndGlobalSection
EndGlobal
Binary file not shown.
Binary file not shown.
26 changes: 26 additions & 0 deletions Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
using System.Reflection;
using System.Runtime.CompilerServices;

// Information about this assembly is defined by the following attributes.
// Change them to the values specific to your project.

[assembly: AssemblyTitle("PlayerInfo")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("PlayerInfo")]
[assembly: AssemblyCopyright("Copyright © Comdar 2021")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

// The assembly version has the format "{Major}.{Minor}.{Build}.{Revision}".
// The form "{Major}.{Minor}.*" will automatically update the build and revision,
// and "{Major}.{Minor}.{Build}.*" will update just the revision.

[assembly: AssemblyVersion("1.0.0.0")]

// The following attributes are used to specify the signing key for the assembly,
// if desired. See the Mono documentation for more information about signing.

//[assembly: AssemblyDelaySign(false)]
//[assembly: AssemblyKeyFile("")]
5 changes: 0 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
# Title
Update for the latest TShock version.


# PlayerInfo
A player info modifier/checker for TShock

Expand All @@ -10,4 +6,3 @@ A player info modifier/checker for TShock
| checkinfo, cinfo | playerinfo.checkinfo | Check another player's max and current HP and mana |
| nick, name | playerinfo.selfname | Change your nickname |
| stats | playerinfo.hpnmana | Set another player's max HP and mana |

Binary file added Refs/Newtonsoft.Json.dll
Binary file not shown.
Binary file added Refs/OTAPI.dll
Binary file not shown.
Binary file added Refs/TShockAPI.dll
Binary file not shown.
Binary file added Refs/TerrariaServer.exe
Binary file not shown.
Binary file not shown.
Binary file not shown.

0 comments on commit 931294e

Please sign in to comment.