Skip to content

Commit 8624b02

Browse files
committed
relativeX, Y and Z player properties, TPRelative
1 parent 8545018 commit 8624b02

File tree

3 files changed

+53
-1
lines changed

3 files changed

+53
-1
lines changed
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
using LabApi.Features.Wrappers;
2+
using UnityEngine;
3+
4+
namespace SER.Helpers.Extensions;
5+
6+
public static class PlayerExtensions
7+
{
8+
public static Vector3 RelativeRoomPosition(this Player player)
9+
{
10+
return player.Room == null ? new(0,0,0) : player.Room.Transform.InverseTransformPoint(player.Position) - new Vector3(0, player.Scale.y + 0.01f, 0);
11+
}
12+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
using SER.ArgumentSystem.Arguments;
2+
using SER.ArgumentSystem.BaseArguments;
3+
using SER.Helpers.Extensions;
4+
using SER.MethodSystem.BaseMethods;
5+
using UnityEngine;
6+
7+
namespace SER.MethodSystem.Methods.TeleportMethods;
8+
9+
// ReSharper disable once InconsistentNaming
10+
public class TPRelativeMethod : SynchronousMethod
11+
{
12+
public override string Description => "Teleports players to relative coordinates of a room.";
13+
14+
public override Argument[] ExpectedArguments { get; } =
15+
[
16+
new PlayersArgument("players"),
17+
new RoomArgument("room"),
18+
new FloatArgument("relative x"),
19+
new FloatArgument("relative y"),
20+
new FloatArgument("relative z")
21+
];
22+
23+
public override void Execute()
24+
{
25+
var players = Args.GetPlayers("players");
26+
var room = Args.GetRoom("room");
27+
var pos = room.Transform.TransformPoint(new(
28+
Args.GetFloat("relative x"),
29+
Args.GetFloat("relative y"),
30+
Args.GetFloat("relative z")));
31+
32+
players.ForEach(plr => plr.Position = pos + new Vector3(0, plr.Scale.y + 0.01f, 0));
33+
}
34+
}

TokenSystem/Tokens/ExpressionTokens/PlayerExpressionToken.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,9 @@ public enum PlayerProperty
6161
SizeY,
6262
SizeZ,
6363
AccessTier,
64+
RelativeX,
65+
RelativeY,
66+
RelativeZ,
6467
}
6568

6669
public abstract class Info
@@ -166,7 +169,10 @@ public class Info<T>(Func<Player, T> handler, string? description) : Info
166169
else return -1;
167170
}
168171
else return -1;
169-
}, "Returns the player's Access Tier Level if they are SCP-079, otherwise returns -1")
172+
}, "Returns the player's Access Tier Level if they are SCP-079, otherwise returns -1"),
173+
[PlayerProperty.RelativeX] = new Info<NumberValue>(plr => (decimal)plr.RelativeRoomPosition().x, "Returns the player's x relative to the current room or 0 if in no room"),
174+
[PlayerProperty.RelativeY] = new Info<NumberValue>(plr => (decimal)plr.RelativeRoomPosition().y, "Returns the player's y relative to the current room or 0 if in no room"),
175+
[PlayerProperty.RelativeZ] = new Info<NumberValue>(plr => (decimal)plr.RelativeRoomPosition().z, "Returns the player's z relative to the current room or 0 if in no room"),
170176
};
171177

172178
protected override IParseResult InternalParse(BaseToken[] tokens)

0 commit comments

Comments
 (0)