Add PedBlip
This commit is contained in:
@ -23,10 +23,34 @@ namespace RageCoop.Client.Scripting
|
|||||||
API.RegisterCustomEventHandler(CustomEvents.ServerBlipSync, ServerBlipSync);
|
API.RegisterCustomEventHandler(CustomEvents.ServerBlipSync, ServerBlipSync);
|
||||||
API.RegisterCustomEventHandler(CustomEvents.DeleteServerBlip, DeleteServerBlip);
|
API.RegisterCustomEventHandler(CustomEvents.DeleteServerBlip, DeleteServerBlip);
|
||||||
API.RegisterCustomEventHandler(CustomEvents.CreateVehicle, CreateVehicle);
|
API.RegisterCustomEventHandler(CustomEvents.CreateVehicle, CreateVehicle);
|
||||||
|
API.RegisterCustomEventHandler(CustomEvents.UpdatePedBlip, UpdatePedBlip);
|
||||||
API.Events.OnPedDeleted+=(s,p) => { API.SendCustomEvent(CustomEvents.OnPedDeleted,p.ID); };
|
API.Events.OnPedDeleted+=(s,p) => { API.SendCustomEvent(CustomEvents.OnPedDeleted,p.ID); };
|
||||||
API.Events.OnVehicleDeleted+=(s, p) => { API.SendCustomEvent(CustomEvents.OnVehicleDeleted, p.ID); };
|
API.Events.OnVehicleDeleted+=(s, p) => { API.SendCustomEvent(CustomEvents.OnVehicleDeleted, p.ID); };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void UpdatePedBlip(CustomEventReceivedArgs e)
|
||||||
|
{
|
||||||
|
API.QueueAction(() =>
|
||||||
|
{
|
||||||
|
var p = Ped.FromHandle((int)e.Args[0]);
|
||||||
|
if(p == null) { return; }
|
||||||
|
if (p.Handle==Game.Player.Character.Handle)
|
||||||
|
{
|
||||||
|
API.Config.BlipColor=(BlipColor)(byte)e.Args[1];
|
||||||
|
API.Config.BlipSprite=(BlipSprite)(ushort)e.Args[2];
|
||||||
|
API.Config.BlipScale=(float)e.Args[3];
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
var b = p.AttachedBlip;
|
||||||
|
if(b == null) { b=p.AddBlip(); }
|
||||||
|
b.Color=(BlipColor)(byte)e.Args[1];
|
||||||
|
b.Sprite=(BlipSprite)(ushort)e.Args[2];
|
||||||
|
b.Scale=(float)e.Args[3];
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
private void CreateVehicle(CustomEventReceivedArgs e)
|
private void CreateVehicle(CustomEventReceivedArgs e)
|
||||||
{
|
{
|
||||||
API.QueueAction(() =>
|
API.QueueAction(() =>
|
||||||
@ -57,8 +81,8 @@ namespace RageCoop.Client.Scripting
|
|||||||
private void ServerBlipSync(CustomEventReceivedArgs obj)
|
private void ServerBlipSync(CustomEventReceivedArgs obj)
|
||||||
{
|
{
|
||||||
int id= (int)obj.Args[0];
|
int id= (int)obj.Args[0];
|
||||||
var sprite=(BlipSprite)(short)obj.Args[1];
|
var sprite=(BlipSprite)obj.Args[1];
|
||||||
var color = (BlipColor)(byte)obj.Args[2];
|
var color = (BlipColor)obj.Args[2];
|
||||||
var scale=(float)obj.Args[3];
|
var scale=(float)obj.Args[3];
|
||||||
var pos=(Vector3)obj.Args[4];
|
var pos=(Vector3)obj.Args[4];
|
||||||
int rot= (int)obj.Args[5];
|
int rot= (int)obj.Args[5];
|
||||||
|
@ -24,6 +24,7 @@ namespace RageCoop.Core.Scripting
|
|||||||
internal static readonly int ServerBlipSync = Hash("RageCoop.ServerBlipSync");
|
internal static readonly int ServerBlipSync = Hash("RageCoop.ServerBlipSync");
|
||||||
internal static readonly int SetEntity = Hash("RageCoop.SetEntity");
|
internal static readonly int SetEntity = Hash("RageCoop.SetEntity");
|
||||||
internal static readonly int DeleteServerProp = Hash("RageCoop.DeleteServerProp");
|
internal static readonly int DeleteServerProp = Hash("RageCoop.DeleteServerProp");
|
||||||
|
internal static readonly int UpdatePedBlip = Hash("RageCoop.UpdatePedBlip");
|
||||||
internal static readonly int DeleteEntity = Hash("RageCoop.DeleteEntity");
|
internal static readonly int DeleteEntity = Hash("RageCoop.DeleteEntity");
|
||||||
internal static readonly int DeleteServerBlip = Hash("RageCoop.DeleteServerBlip");
|
internal static readonly int DeleteServerBlip = Hash("RageCoop.DeleteServerBlip");
|
||||||
internal static readonly int CreateVehicle = Hash("RageCoop.CreateVehicle");
|
internal static readonly int CreateVehicle = Hash("RageCoop.CreateVehicle");
|
||||||
|
@ -211,6 +211,23 @@ namespace RageCoop.Server
|
|||||||
ped._rot=p.Rotation;
|
ped._rot=p.Rotation;
|
||||||
ped.Owner=sender;
|
ped.Owner=sender;
|
||||||
}
|
}
|
||||||
|
internal void Update(Packets.PedStateSync p, Client sender)
|
||||||
|
{
|
||||||
|
ServerPed ped;
|
||||||
|
if (!Peds.TryGetValue(p.ID, out ped))
|
||||||
|
{
|
||||||
|
Peds.Add(p.ID, ped=new ServerPed(Server));
|
||||||
|
ped.ID=p.ID;
|
||||||
|
}
|
||||||
|
if ((byte)p.BlipColor!=255)
|
||||||
|
{
|
||||||
|
if (ped.AttachedBlip==null) { ped.AttachedBlip=new(ped); }
|
||||||
|
ped.AttachedBlip.Color=p.BlipColor;
|
||||||
|
ped.AttachedBlip.Sprite=p.BlipSprite;
|
||||||
|
ped.AttachedBlip.Scale=p.BlipScale;
|
||||||
|
}
|
||||||
|
ped.Owner=sender;
|
||||||
|
}
|
||||||
internal void Update(Packets.VehicleSync p, Client sender)
|
internal void Update(Packets.VehicleSync p, Client sender)
|
||||||
{
|
{
|
||||||
ServerVehicle veh;
|
ServerVehicle veh;
|
||||||
|
@ -22,7 +22,7 @@ namespace RageCoop.Server
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Server that this object belongs to
|
/// Server that this object belongs to
|
||||||
/// </summary>
|
/// </summary>
|
||||||
protected readonly Server Server;
|
internal readonly Server Server;
|
||||||
internal ServerObject(Server server) { Server=server; }
|
internal ServerObject(Server server) { Server=server; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -175,6 +175,22 @@ namespace RageCoop.Server
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public ServerVehicle LastVehicle { get; internal set; }
|
public ServerVehicle LastVehicle { get; internal set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Get the <see cref="PedBlip"/> attached to this ped.
|
||||||
|
/// </summary>
|
||||||
|
public PedBlip AttachedBlip { get; internal set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Attach a blip to this ped.
|
||||||
|
/// </summary>
|
||||||
|
/// <returns></returns>
|
||||||
|
public PedBlip AddBlip()
|
||||||
|
{
|
||||||
|
AttachedBlip = new PedBlip(this);
|
||||||
|
AttachedBlip.Update();
|
||||||
|
return AttachedBlip;
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Health
|
/// Health
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -245,7 +261,7 @@ namespace RageCoop.Server
|
|||||||
set { _color=value; Update(); }
|
set { _color=value; Update(); }
|
||||||
}
|
}
|
||||||
|
|
||||||
internal BlipSprite _sprite;
|
internal BlipSprite _sprite=BlipSprite.Standard;
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Sprite of this blip
|
/// Sprite of this blip
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -327,4 +343,71 @@ namespace RageCoop.Server
|
|||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Represent a blip attached to ped.
|
||||||
|
/// </summary>
|
||||||
|
public class PedBlip
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Get the <see cref="ServerPed"/> that this blip attached to.
|
||||||
|
/// </summary>
|
||||||
|
public ServerPed Ped { get;internal set; }
|
||||||
|
internal PedBlip(ServerPed ped)
|
||||||
|
{
|
||||||
|
Ped = ped;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
internal BlipColor _color;
|
||||||
|
/// <summary>
|
||||||
|
/// Color of this blip
|
||||||
|
/// </summary>
|
||||||
|
public BlipColor Color
|
||||||
|
{
|
||||||
|
get { return _color; }
|
||||||
|
set { _color=value; Update(); }
|
||||||
|
}
|
||||||
|
|
||||||
|
internal BlipSprite _sprite=BlipSprite.Standard;
|
||||||
|
/// <summary>
|
||||||
|
/// Sprite of this blip
|
||||||
|
/// </summary>
|
||||||
|
public BlipSprite Sprite
|
||||||
|
{
|
||||||
|
get { return _sprite; }
|
||||||
|
set { _sprite=value; Update(); }
|
||||||
|
}
|
||||||
|
|
||||||
|
internal float _scale = 1;
|
||||||
|
/// <summary>
|
||||||
|
/// Scale of this blip
|
||||||
|
/// </summary>
|
||||||
|
public float Scale
|
||||||
|
{
|
||||||
|
get { return _scale; }
|
||||||
|
set { _scale=value; Update(); }
|
||||||
|
}
|
||||||
|
|
||||||
|
private bool _bouncing = false;
|
||||||
|
internal void Update()
|
||||||
|
{
|
||||||
|
// 5ms debounce
|
||||||
|
if (!_bouncing)
|
||||||
|
{
|
||||||
|
_bouncing=true;
|
||||||
|
Task.Run(() =>
|
||||||
|
{
|
||||||
|
Thread.Sleep(5);
|
||||||
|
DoUpdate();
|
||||||
|
_bouncing=false;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
private void DoUpdate()
|
||||||
|
{
|
||||||
|
Ped.Owner.SendCustomEvent(CustomEvents.UpdatePedBlip,Ped.Handle,(byte)Color,(ushort)Sprite,Scale);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user