Skip to content

Commit e843836

Browse files
TomGrobbesir-lord-pizza
authored andcommitted
fix(online players): tell the summoner when the player is already next to them or in their vehicle
1 parent 8d6b686 commit e843836

8 files changed

Lines changed: 76 additions & 7 deletions

File tree

assets/enhanced/language/de.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -876,6 +876,7 @@
876876
"onlineplayers.summon.by": "Du wurdest von ~y~{player}~s~ herbeigerufen.",
877877
"onlineplayers.summon.desc": "Holt diesen Spieler dorthin, wo du stehst.",
878878
"onlineplayers.summon.done": "~g~{player}~s~ herbeigerufen.",
879+
"onlineplayers.summon.nearby": "~y~{player}~s~ steht schon direkt neben dir.",
879880
"onlineplayers.summon.riding": "~y~{player}~s~ sitzt schon in deinem Fahrzeug.",
880881
"onlineplayers.summonvehicle": "Spieler ins Fahrzeug holen",
881882
"onlineplayers.summonvehicle.by": "Du wurdest ins Fahrzeug von ~y~{player}~s~ geholt.",

assets/enhanced/language/es.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -876,6 +876,7 @@
876876
"onlineplayers.summon.by": "~y~{player}~s~ te ha traído hasta él.",
877877
"onlineplayers.summon.desc": "Trae a este jugador hasta donde estás.",
878878
"onlineplayers.summon.done": "Has traído a ~g~{player}~s~.",
879+
"onlineplayers.summon.nearby": "~y~{player}~s~ ya está justo a tu lado.",
879880
"onlineplayers.summon.riding": "~y~{player}~s~ ya está en tu vehículo.",
880881
"onlineplayers.summonvehicle": "Traer jugador al vehículo",
881882
"onlineplayers.summonvehicle.by": "~y~{player}~s~ te ha traído a su vehículo.",

assets/enhanced/language/fr.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -876,6 +876,7 @@
876876
"onlineplayers.summon.by": "Vous avez été amené par ~y~{player}~s~.",
877877
"onlineplayers.summon.desc": "Amène ce joueur là où vous vous trouvez.",
878878
"onlineplayers.summon.done": "~g~{player}~s~ a été amené.",
879+
"onlineplayers.summon.nearby": "~y~{player}~s~ se tient déjà juste à côté de vous.",
879880
"onlineplayers.summon.riding": "~y~{player}~s~ est déjà dans votre véhicule.",
880881
"onlineplayers.summonvehicle": "Faire venir le joueur dans le véhicule",
881882
"onlineplayers.summonvehicle.by": "Vous avez été amené dans le véhicule de ~y~{player}~s~.",

assets/enhanced/language/nl.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -876,6 +876,7 @@
876876
"onlineplayers.summon.by": "Je bent opgeroepen door ~y~{player}~s~.",
877877
"onlineplayers.summon.desc": "Haalt deze speler naar de plek waar jij staat.",
878878
"onlineplayers.summon.done": "~g~{player}~s~ opgeroepen.",
879+
"onlineplayers.summon.nearby": "~y~{player}~s~ staat al vlak naast je.",
879880
"onlineplayers.summon.riding": "~y~{player}~s~ zit al in je voertuig.",
880881
"onlineplayers.summonvehicle": "Speler in voertuig oproepen",
881882
"onlineplayers.summonvehicle.by": "Je bent in het voertuig van ~y~{player}~s~ geplaatst.",

src/Client/vMenu.Enhanced.MenuFramework/Localization/Languages/EnglishStrings.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
namespace vMenu.Enhanced.MenuFramework.Localization.Languages;
1+
namespace vMenu.Enhanced.MenuFramework.Localization.Languages;
22

33
/// <summary>The English strings, and the fallback for every other language.</summary>
44
/// <remarks>Every other language lives in a JSON file under <c>assets/enhanced/language/</c>. If you
@@ -373,6 +373,7 @@ internal static class EnglishStrings
373373
[Loc.OnlinePlayers.SummonDescription] = "Bring this player to where you are standing.",
374374
[Loc.OnlinePlayers.SummonDone] = "Summoned ~g~{player}~s~.",
375375
[Loc.OnlinePlayers.SummonedBy] = "You have been summoned by ~y~{player}~s~.",
376+
[Loc.OnlinePlayers.SummonNearby] = "~y~{player}~s~ is already standing right next to you.",
376377
[Loc.OnlinePlayers.SummonRiding] = "~y~{player}~s~ is already in your vehicle.",
377378
[Loc.OnlinePlayers.SummonIntoVehicle] = "Summon Player Into Vehicle",
378379
[Loc.OnlinePlayers.SummonIntoVehicleDescription] = "Bring this player straight into a free seat of the vehicle you are in. Nothing happens if you are not in a vehicle, or if every seat is taken.",

src/Client/vMenu.Enhanced.MenuFramework/Localization/Loc.OnlinePlayers.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,8 @@ public static class OnlinePlayers
6464

6565
public const string SummonedBy = "onlineplayers.summon.by";
6666

67+
public const string SummonNearby = "onlineplayers.summon.nearby";
68+
6769
public const string SummonRiding = "onlineplayers.summon.riding";
6870

6971
public const string SummonIntoVehicle = "onlineplayers.summonvehicle";

src/Client/vMenu.Enhanced.Menus/OnlinePlayersMenu.cs

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ public sealed class OnlinePlayersMenu : MenuDefinition
4646

4747
private const string SummonMoved = "0";
4848

49+
private const string SummonNearby = "1";
50+
4951
private const string SummonRiding = "2";
5052

5153
private const string SummonNoVehicle = "3";
@@ -330,7 +332,7 @@ private void BuildActions(MenuBuilder actions)
330332
Text = MenuText.Key(Loc.OnlinePlayers.Summon),
331333
Description = MenuText.Key(Loc.OnlinePlayers.SummonDescription),
332334
Gate = OnlinePlayersPermissions.Summon,
333-
OnSelectedAsync = _ => SendAsync(ActionIds.OnlinePlayers.Summon, Loc.OnlinePlayers.SummonDone, allowSelf: false),
335+
OnSelectedAsync = _ => SummonAsync(),
334336
});
335337

336338
actions.Entries.Add(new ButtonEntry
@@ -787,6 +789,43 @@ private async Task TeleportIntoVehicleAsync()
787789
Notifications.Success(MenuText.Key(Loc.OnlinePlayers.TeleportIntoVehicleDone, ("player", name)));
788790
}
789791

792+
private async Task SummonAsync()
793+
{
794+
if (Target() is not { } player)
795+
{
796+
return;
797+
}
798+
799+
var name = MenuText.Literal(player.Name);
800+
801+
var result = await ServerActions.InvokeAsync(ActionIds.OnlinePlayers.Summon, Id(player));
802+
803+
if (result.Status != ActionStatus.Ok || result.Data.Length < 1)
804+
{
805+
Report(result, name);
806+
807+
return;
808+
}
809+
810+
switch (result.Data[0])
811+
{
812+
case SummonNearby:
813+
Notifications.Info(MenuText.Key(Loc.OnlinePlayers.SummonNearby, ("player", name)));
814+
815+
break;
816+
817+
case SummonRiding:
818+
Notifications.Info(MenuText.Key(Loc.OnlinePlayers.SummonRiding, ("player", name)));
819+
820+
break;
821+
822+
default:
823+
Notifications.Success(MenuText.Key(Loc.OnlinePlayers.SummonDone, ("player", name)));
824+
825+
break;
826+
}
827+
}
828+
790829
private async Task SummonIntoVehicleAsync()
791830
{
792831
if (Target() is not { } player)

src/Server/vMenu.Enhanced.Actions.Server/Handlers/OnlinePlayerActions.cs

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System.Globalization;
2+
using System.Numerics;
23

34
using CitizenFX.FiveM.Server;
45
using CitizenFX.FiveM.Server.Entities;
@@ -57,10 +58,14 @@ public static class OnlinePlayerActions
5758

5859
private const string StatusUnknown = "?";
5960

61+
private const float NearbyDistance = 5f;
62+
6063
private const int MaxSeat = 16;
6164

6265
private const string SummonMoved = "0";
6366

67+
private const string SummonNearby = "1";
68+
6469
private const string SummonRiding = "2";
6570

6671
private const string SummonNoVehicle = "3";
@@ -582,20 +587,28 @@ private static ActionResponse Summon(Player source, string[] args)
582587

583588
// Somebody still on the loading screen has no character to move, and their client is not listening
584589
// for this yet either.
585-
if (PedOf(target) is null)
590+
if (PedOf(target) is not { } targetPed)
586591
{
587592
return ActionResponse.NotReady();
588593
}
589594

590-
var ped = source.PedIndex;
591-
592-
if (ped <= 0 || !Native.DoesEntityExist(ped))
595+
if (SourcePedOf(source) is not { } ped)
593596
{
594597
return ActionResponse.NotFound();
595598
}
596599

600+
if (SharesVehicle(ped, targetPed))
601+
{
602+
return ActionResponse.Ok(SummonRiding);
603+
}
604+
597605
var coords = Native.GetEntityCoords(ped);
598606

607+
if (IsNearby(coords, Native.GetEntityCoords(targetPed)))
608+
{
609+
return ActionResponse.Ok(SummonNearby);
610+
}
611+
599612
MatchBucket(target, source.Handle);
600613

601614
Log.Info($"[OnlinePlayers] {source.Name} summoned {Native.GetPlayerName(target.ToString())}.");
@@ -610,7 +623,7 @@ private static ActionResponse Summon(Player source, string[] args)
610623
coords.Y.ToString(CultureInfo.InvariantCulture),
611624
coords.Z.ToString(CultureInfo.InvariantCulture));
612625

613-
return ActionResponse.Ok();
626+
return ActionResponse.Ok(SummonMoved);
614627
}
615628

616629
private static ActionResponse SummonIntoVehicle(Player source, string[] args)
@@ -686,6 +699,16 @@ private static ActionResponse SummonIntoVehicle(Player source, string[] args)
686699
return ped > 0 && Native.DoesEntityExist(ped) ? ped : null;
687700
}
688701

702+
private static bool SharesVehicle(int ped, int other)
703+
{
704+
var vehicle = Native.GetVehiclePedIsIn(ped, false);
705+
706+
return vehicle != 0 && Native.DoesEntityExist(vehicle) && Native.GetVehiclePedIsIn(other, false) == vehicle;
707+
}
708+
709+
private static bool IsNearby(Vector3 from, Vector3 to) =>
710+
Vector3.DistanceSquared(from, to) <= NearbyDistance * NearbyDistance;
711+
689712
// The sender is not answered until the other player's client says it put the message on screen.
690713
// "Sent" when the other end never showed it is the one thing a sender actually wants to know.
691714
private static async Task<ActionResponse> SendMessage(Player source, string[] args)

0 commit comments

Comments
 (0)