This commit is contained in:
2021-04-06 21:19:44 +02:00
parent b993485906
commit be78edd912
5 changed files with 73 additions and 24 deletions

View File

@@ -1,5 +1,4 @@

using System;
using System;
using System.Collections.Generic;
using System.Linq;
using GTANetworkAPI;
@@ -12,7 +11,7 @@ public static class AttachmentSync
/// <param name="entity">The entity to attach the object to</param>
/// <param name="attachment">The attachment, should be in string or long type</param>
/// <param name="remove">Pass true to remove the specified attachment, false otherwise.</param>
public static void AddAttachment(this Entity entity, dynamic attachment, bool remove)
{
if (!entity.HasData("Attachments"))
@@ -109,6 +108,29 @@ public static class AttachmentSync
{
return string.Join('|', attachments.Select(a => Base36Extensions.ToBase36(a)).ToArray());
}
public static void AttachPlayer(this Player player, Player attachTo)
{
attachTo.DetachPlayer();
if (!attachTo.HasData("attachedPlayer"))
attachTo.SetData<Player>("attachedPlayer", null);
if (attachTo.GetData<Player>("attachedPlayer") == player)
return;
attachTo.SetData("attachedPlayer", attachTo);
attachTo.SetSharedData("attachToPlayer", player);
}
public static void DetachPlayer(this Player player)
{
if (!player.HasData("attachedPlayer"))
return;
player.ResetData("attachedPlayer");
player.ResetSharedData("attachToPlayer");
}
}
public class AttachmentSyncExample : Script
@@ -154,7 +176,4 @@ public class AttachmentSyncExample : Script
player.ClearAttachments();
}
}
}