Some tweaks
This commit is contained in:
@ -124,7 +124,8 @@ namespace RageCoop.Client
|
||||
/// <summary>
|
||||
/// Player Latency in second.
|
||||
/// </summary>
|
||||
public float Latency { get; internal set; }
|
||||
public float Latency { get; set; }
|
||||
|
||||
public bool DisplayNameTag { get; set; } = true;
|
||||
}
|
||||
}
|
||||
|
@ -14,6 +14,7 @@ namespace RageCoop.Client.Scripting
|
||||
public override void OnStart()
|
||||
{
|
||||
API.RegisterCustomEventHandler(CustomEvents.SetAutoRespawn,SetAutoRespawn);
|
||||
API.RegisterCustomEventHandler(CustomEvents.SetDisplayNameTag,SetDisplayNameTag);
|
||||
API.RegisterCustomEventHandler(CustomEvents.NativeCall,NativeCall);
|
||||
API.RegisterCustomEventHandler(CustomEvents.ServerPropSync, ServerObjectSync);
|
||||
API.RegisterCustomEventHandler(CustomEvents.DeleteServerProp, DeleteServerProp);
|
||||
@ -27,6 +28,12 @@ namespace RageCoop.Client.Scripting
|
||||
API.Events.OnVehicleDeleted+=(s, p) => { API.SendCustomEvent(CustomEvents.OnVehicleDeleted, p.ID); };
|
||||
}
|
||||
|
||||
private void SetDisplayNameTag(CustomEventReceivedArgs e)
|
||||
{
|
||||
var p = PlayerList.GetPlayer((int)e.Args[0]);
|
||||
if(p != null) { p.DisplayNameTag=(bool)e.Args[1]; }
|
||||
}
|
||||
|
||||
private void UpdatePedBlip(CustomEventReceivedArgs e)
|
||||
{
|
||||
var p = Ped.FromHandle((int)e.Args[0]);
|
||||
@ -51,7 +58,12 @@ namespace RageCoop.Client.Scripting
|
||||
{
|
||||
var vehicleModel = (Model)e.Args[1];
|
||||
vehicleModel.Request(1000);
|
||||
var veh = World.CreateVehicle(vehicleModel, (Vector3)e.Args[2], (float)e.Args[3]);
|
||||
Vehicle veh= World.CreateVehicle(vehicleModel, (Vector3)e.Args[2], (float)e.Args[3]);
|
||||
while (veh==null)
|
||||
{
|
||||
veh = World.CreateVehicle(vehicleModel, (Vector3)e.Args[2], (float)e.Args[3]);
|
||||
System.Threading.Thread.Sleep(10);
|
||||
}
|
||||
veh.CanPretendOccupants=false;
|
||||
var v = new SyncedVehicle()
|
||||
{
|
||||
@ -104,7 +116,7 @@ namespace RageCoop.Client.Scripting
|
||||
}
|
||||
private void SetNameTag(CustomEventReceivedArgs e)
|
||||
{
|
||||
var p = EntityPool.GetPedByID((int)e.Args[0]);
|
||||
var p =PlayerList.GetPlayer((int)e.Args[0]);
|
||||
if(p!= null)
|
||||
{
|
||||
p.DisplayNameTag=(bool)e.Args[1];
|
||||
|
@ -32,7 +32,7 @@ namespace RageCoop.Client
|
||||
|
||||
Function.Call(Hash._SET_PED_CAN_PLAY_INJURED_ANIMS, false);
|
||||
MainPed.SetConfigFlag((int)PedConfigFlags.CPED_CONFIG_FLAG_DisableHurt, true);
|
||||
MainPed.SetConfigFlag((int)PedConfigFlags.CPED_CONFIG_FLAG_DisableMelee, true);
|
||||
// MainPed.SetConfigFlag((int)PedConfigFlags.CPED_CONFIG_FLAG_DisableMelee, true);
|
||||
|
||||
}
|
||||
|
||||
@ -46,12 +46,11 @@ namespace RageCoop.Client
|
||||
}
|
||||
#endregion
|
||||
#region PLAYER -- ONLY
|
||||
internal string Username = "N/A";
|
||||
internal Blip PedBlip = null;
|
||||
internal BlipColor BlipColor = (BlipColor)255;
|
||||
internal BlipSprite BlipSprite = (BlipSprite)0;
|
||||
internal float BlipScale=1;
|
||||
internal bool DisplayNameTag { get; set; } = true;
|
||||
internal PlayerData Player;
|
||||
#endregion
|
||||
|
||||
/// <summary>
|
||||
@ -84,14 +83,10 @@ namespace RageCoop.Client
|
||||
{
|
||||
if (IsPlayer)
|
||||
{
|
||||
if (Username=="N/A")
|
||||
if (Player==null)
|
||||
{
|
||||
var p = PlayerList.GetPlayer(this);
|
||||
if (p!=null)
|
||||
{
|
||||
Username=p.Username;
|
||||
}
|
||||
|
||||
Player = PlayerList.GetPlayer(this);
|
||||
return;
|
||||
}
|
||||
RenderNameTag();
|
||||
}
|
||||
@ -123,20 +118,10 @@ namespace RageCoop.Client
|
||||
else if (((byte)BlipColor != 255) && PedBlip==null)
|
||||
{
|
||||
PedBlip=MainPed.AddBlip();
|
||||
|
||||
if (IsPlayer)
|
||||
{
|
||||
Main.QueueAction(() =>
|
||||
{
|
||||
if (Username=="N/A")
|
||||
{
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
PedBlip.Name=Username;
|
||||
return true;
|
||||
}
|
||||
});
|
||||
PedBlip.Name=Player.Username;
|
||||
}
|
||||
PedBlip.Color=BlipColor;
|
||||
PedBlip.Sprite=BlipSprite;
|
||||
@ -159,6 +144,17 @@ namespace RageCoop.Client
|
||||
{
|
||||
SetClothes();
|
||||
}
|
||||
var b = MainPed.AttachedBlip;
|
||||
if (b==null || b.Color!=BlipColor || b.Sprite!=BlipSprite)
|
||||
{
|
||||
PedBlip=MainPed.AddBlip();
|
||||
PedBlip.Color=BlipColor;
|
||||
PedBlip.Sprite =BlipSprite;
|
||||
if (IsPlayer)
|
||||
{
|
||||
b.Name=Player.Username;
|
||||
}
|
||||
}
|
||||
|
||||
CheckCurrentWeapon();
|
||||
}
|
||||
@ -206,12 +202,12 @@ namespace RageCoop.Client
|
||||
|
||||
private void RenderNameTag()
|
||||
{
|
||||
if (!DisplayNameTag || (MainPed==null) || !MainPed.IsVisible || !MainPed.IsInRange(Game.Player.Character.Position, 20f))
|
||||
if (!Player.DisplayNameTag || (MainPed==null) || !MainPed.IsVisible || !MainPed.IsInRange(Game.Player.Character.Position, 20f))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
string renderText = IsOutOfSync ? "~r~AFK" : Username;
|
||||
string renderText = IsOutOfSync ? "~r~AFK" : Player.Username;
|
||||
Vector3 targetPos = MainPed.Bones[Bone.IKHead].Position + new Vector3(0, 0, 0.35f);
|
||||
|
||||
Function.Call(Hash.SET_DRAW_ORIGIN, targetPos.X, targetPos.Y, targetPos.Z, 0);
|
||||
@ -263,13 +259,6 @@ namespace RageCoop.Client
|
||||
}
|
||||
|
||||
|
||||
Function.Call(Hash.SET_PED_CAN_EVASIVE_DIVE, MainPed.Handle, false);
|
||||
Function.Call(Hash.SET_PED_DROPS_WEAPONS_WHEN_DEAD, MainPed.Handle, false);
|
||||
Function.Call(Hash.SET_PED_CAN_BE_TARGETTED, MainPed.Handle, true);
|
||||
Function.Call(Hash.SET_PED_CAN_BE_TARGETTED_BY_PLAYER, MainPed.Handle, Game.Player, true);
|
||||
Function.Call(Hash.SET_PED_GET_OUT_UPSIDE_DOWN_VEHICLE, MainPed.Handle, false);
|
||||
Function.Call(Hash.SET_CAN_ATTACK_FRIENDLY, MainPed.Handle, true, true);
|
||||
Function.Call(Hash._SET_PED_CAN_PLAY_INJURED_ANIMS, false);
|
||||
|
||||
MainPed.BlockPermanentEvents = true;
|
||||
MainPed.CanWrithe=false;
|
||||
@ -279,8 +268,16 @@ namespace RageCoop.Client
|
||||
MainPed.IsFireProof=false;
|
||||
MainPed.IsExplosionProof=false;
|
||||
|
||||
Function.Call(Hash.SET_PED_DROPS_WEAPONS_WHEN_DEAD, MainPed.Handle, false);
|
||||
Function.Call(Hash.SET_PED_CAN_BE_TARGETTED, MainPed.Handle, true);
|
||||
Function.Call(Hash.SET_PED_CAN_BE_TARGETTED_BY_PLAYER, MainPed.Handle, Game.Player, true);
|
||||
Function.Call(Hash.SET_PED_GET_OUT_UPSIDE_DOWN_VEHICLE, MainPed.Handle, false);
|
||||
Function.Call(Hash.SET_CAN_ATTACK_FRIENDLY, MainPed.Handle, true, true);
|
||||
Function.Call(Hash._SET_PED_CAN_PLAY_INJURED_ANIMS, false);
|
||||
Function.Call(Hash.SET_PED_CAN_EVASIVE_DIVE, MainPed.Handle, false);
|
||||
|
||||
|
||||
MainPed.SetConfigFlag((int)PedConfigFlags.CPED_CONFIG_FLAG_DrownsInWater,false);
|
||||
MainPed.SetConfigFlag((int)PedConfigFlags.CPED_CONFIG_FLAG_DisableMelee, true);
|
||||
MainPed.SetConfigFlag((int)PedConfigFlags.CPED_CONFIG_FLAG_DisableHurt, true);
|
||||
MainPed.SetConfigFlag((int)PedConfigFlags.CPED_CONFIG_FLAG_DisableExplosionReactions, true);
|
||||
MainPed.SetConfigFlag((int)PedConfigFlags.CPED_CONFIG_FLAG_AvoidTearGas, false);
|
||||
|
@ -54,7 +54,7 @@ namespace RageCoop.Server
|
||||
public bool EnableAutoRespawn {
|
||||
get { return _autoRespawn; }
|
||||
set {
|
||||
Server.BaseScript.SetAutoRespawn(this,value);
|
||||
BaseScript.SetAutoRespawn(this,value);
|
||||
_autoRespawn=value;
|
||||
}
|
||||
}
|
||||
|
@ -155,9 +155,9 @@ namespace RageCoop.Server.Scripting
|
||||
/// Get a list of all Clients
|
||||
/// </summary>
|
||||
/// <returns>All clients as a dictionary indexed by NetID</returns>
|
||||
public Dictionary<long, Client> GetAllClients()
|
||||
public Dictionary<string, Client> GetAllClients()
|
||||
{
|
||||
return new(Server.Clients);
|
||||
return new(Server.ClientsByName);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -25,7 +25,7 @@ namespace RageCoop.Server.Scripting
|
||||
public override void OnStop()
|
||||
{
|
||||
}
|
||||
public void SetAutoRespawn(Client c,bool toggle)
|
||||
public static void SetAutoRespawn(Client c,bool toggle)
|
||||
{
|
||||
c.SendCustomEvent(CustomEvents.SetAutoRespawn, toggle );
|
||||
}
|
||||
|
@ -43,6 +43,7 @@ namespace RageCoop.Server
|
||||
|
||||
internal readonly Dictionary<Command, Action<CommandContext>> Commands = new();
|
||||
internal readonly Dictionary<long,Client> Clients = new();
|
||||
internal readonly Dictionary<string, Client> ClientsByName = new();
|
||||
|
||||
private Dictionary<int,FileTransfer> InProgressFileTransfers=new();
|
||||
private Resources Resources;
|
||||
@ -617,7 +618,8 @@ namespace RageCoop.Server
|
||||
Username=packet.Username,
|
||||
Player = player
|
||||
}
|
||||
);;
|
||||
);
|
||||
ClientsByName.Add(packet.Username, tmpClient);
|
||||
}
|
||||
|
||||
Logger?.Debug($"Handshake sucess, Player:{packet.Username} PedID:{packet.PedID}");
|
||||
@ -690,6 +692,7 @@ namespace RageCoop.Server
|
||||
_worker.QueueJob(() => API.Events.InvokePlayerDisconnected(localClient));
|
||||
Logger?.Info($"Player {localClient.Username} disconnected! ID:{localClient.Player.ID}");
|
||||
Clients.Remove(localClient.NetID);
|
||||
ClientsByName.Remove(localClient.Username);
|
||||
Security.RemoveConnection(localClient.Connection.RemoteEndPoint);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user