generated from AriasCreations/vsmodtemplate
Add max distance argument to rtp
This commit is contained in:
parent
54e8d8a4d5
commit
a9150cf322
5 changed files with 20 additions and 7 deletions
|
@ -210,7 +210,7 @@ namespace AriasServerUtils
|
|||
|
||||
api.ChatCommands.Create("back").RequiresPlayer().RequiresPrivilege(Privilege.chat).WithDescription("Returns you to the last location you were at").HandleWith(Events.HandleBack);
|
||||
|
||||
api.ChatCommands.Create("rtp").RequiresPlayer().RequiresPrivilege(Privilege.chat).WithDescription("Seeks a position possibly thousands of blocks away to teleport to.").HandleWith(Events.HandleRTP);
|
||||
api.ChatCommands.Create("rtp").RequiresPlayer().RequiresPrivilege(Privilege.chat).WithArgs(parsers.Int("maxDist")).WithDescription("Seeks a position possibly thousands of blocks away to teleport to.").HandleWith(Events.HandleRTP);
|
||||
}
|
||||
|
||||
private void OnCheckPlayerCooldowns()
|
||||
|
|
|
@ -54,6 +54,15 @@ namespace AriasServerUtils
|
|||
{
|
||||
if (args.Caller.Player is IServerPlayer isp)
|
||||
{
|
||||
int maxDistance = ServerUtilities.config.MaxRTPBlockDistance;
|
||||
if (args[0] is int ix)
|
||||
{
|
||||
if (ix > maxDistance)
|
||||
{
|
||||
ServerUtilities.SendMessageTo(isp, Lang.Get($"{ServerUtilities.MOD_ID}:rtp-capped", ix, maxDistance));
|
||||
}
|
||||
else maxDistance = ix;
|
||||
}
|
||||
|
||||
PlayerStorage ps = ServerUtilities.GetPlayerData(isp);
|
||||
if (ps.ActiveCooldowns.ContainsKey(CooldownType.RTP))
|
||||
|
@ -67,7 +76,7 @@ namespace AriasServerUtils
|
|||
ps.ActiveCooldowns.Add(CooldownType.RTP, TimeUtil.DecodeTimeNotation(ServerUtilities.config.Cooldowns.Get(CooldownType.RTP)) + TimeUtil.GetUnixEpochTimestamp());
|
||||
ServerUtilities.MarkDirty();
|
||||
|
||||
PlayerPosition pPos = RTPFactory.GetRandomPosition(isp);
|
||||
PlayerPosition pPos = RTPFactory.GetRandomPosition(isp, maxDistance: maxDistance);
|
||||
if (pPos == null)
|
||||
{
|
||||
ServerUtilities.SendMessageTo(isp, Lang.Get($"{ServerUtilities.MOD_ID}:rtp-fail"));
|
||||
|
|
|
@ -16,7 +16,7 @@ public class RTPFactory
|
|||
/// </summary>
|
||||
/// <param name="isp">The player to be teleported</param>
|
||||
/// <returns>A random position +/- max distance from current position.</returns>
|
||||
public static PlayerPosition GetRandomPosition(IServerPlayer isp)
|
||||
public static PlayerPosition GetRandomPosition(IServerPlayer isp, int maxDistance)
|
||||
{
|
||||
Random rng = new Random();
|
||||
EntityPos vPos = isp.Entity.Pos;
|
||||
|
@ -29,10 +29,13 @@ public class RTPFactory
|
|||
while (tries-- > 0)
|
||||
{
|
||||
// Generate random X and Z within max RTP distance
|
||||
bPos.X = (int)vPos.X + rng.Next(-ServerUtilities.config.MaxRTPBlockDistance, ServerUtilities.config.MaxRTPBlockDistance);
|
||||
bPos.Z = (int)vPos.Z + rng.Next(-ServerUtilities.config.MaxRTPBlockDistance, ServerUtilities.config.MaxRTPBlockDistance);
|
||||
bPos.X = (int)vPos.X + rng.Next(0, maxDistance);
|
||||
bPos.Z = (int)vPos.Z + rng.Next(0, maxDistance);
|
||||
bPos.Y = 255;
|
||||
|
||||
if (rng.Next(0, 1) == 1) bPos.X = -bPos.X;
|
||||
if (rng.Next(0, 1) == 1) bPos.Z = -bPos.Z;
|
||||
|
||||
Block lastAboveLast = null;
|
||||
Block lastBlock = null;
|
||||
Block curBlock;
|
||||
|
|
|
@ -36,6 +36,7 @@
|
|||
"rtp-search": "Searching for a random position...",
|
||||
"rtp": "You have been teleported [{0}] blocks away!",
|
||||
"rtp-fail": "Giving up on RTP search. No valid position could be found. Try again later",
|
||||
"rtp-capped": "The distance you tried to go [{0}] is greater than the maximum allowable by the server [{1}]",
|
||||
|
||||
"cmd-cooldown": "[{0}] is currently on cooldown. You can use this command again in [{1}]"
|
||||
}
|
||||
|
|
|
@ -3,8 +3,8 @@
|
|||
"modid": "ariasserverutils",
|
||||
"name": "Aria's Server Utilities",
|
||||
"authors": ["zontreck"],
|
||||
"description": "A collection of server utilities\n\nBuild Date: 03-06-2025 @ 6:37 PM MST",
|
||||
"version": "1.0.4",
|
||||
"description": "A collection of server utilities\n\nBuild Date: 03-07-2025 @ 00:52 AM MST",
|
||||
"version": "1.0.5-dev.1",
|
||||
"dependencies": {
|
||||
"game": ""
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue