Small changes. Small bug fixes
This commit is contained in:
@ -35,7 +35,7 @@ namespace CoopClient
|
||||
public bool IsReloading { get; set; }
|
||||
public int CurrentWeaponHash { get; set; }
|
||||
|
||||
private Blip PedBlip;
|
||||
public Blip PedBlip;
|
||||
|
||||
public void DisplayLocally(string username)
|
||||
{
|
||||
@ -276,8 +276,6 @@ namespace CoopClient
|
||||
Character.CanRagdoll = false;
|
||||
Character.IsInvincible = true;
|
||||
Character.Health = Health;
|
||||
Character.CanBeTargetted = true;
|
||||
Character.IsEnemy = false;
|
||||
|
||||
if (username != null)
|
||||
{
|
||||
@ -286,16 +284,15 @@ namespace CoopClient
|
||||
Character.AttachedBlip.Color = BlipColor.White;
|
||||
Character.AttachedBlip.Scale = 0.8f;
|
||||
Character.AttachedBlip.Name = username;
|
||||
|
||||
Function.Call(Hash.SET_PED_CAN_EVASIVE_DIVE, Character, false);
|
||||
Function.Call(Hash.SET_PED_GET_OUT_UPSIDE_DOWN_VEHICLE, Character, false);
|
||||
}
|
||||
|
||||
foreach (KeyValuePair<int, int> prop in Props)
|
||||
{
|
||||
Function.Call(Hash.SET_PED_COMPONENT_VARIATION, Character.Handle, prop.Key, prop.Value, 0, 0);
|
||||
}
|
||||
|
||||
Function.Call(Hash.SET_PED_CAN_BE_TARGETTED_BY_PLAYER, Character, Game.Player, true);
|
||||
Function.Call(Hash.SET_PED_GET_OUT_UPSIDE_DOWN_VEHICLE, Character, false);
|
||||
Function.Call(Hash.SET_CAN_ATTACK_FRIENDLY, Character, true, true);
|
||||
}
|
||||
|
||||
private bool LastMoving;
|
||||
|
@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
using CoopClient.Entities;
|
||||
|
||||
@ -163,12 +164,29 @@ namespace CoopClient
|
||||
Main.MainMenu.Items[2].Title = "Connect";
|
||||
Main.MainSettingsMenu.Items[0].Enabled = false;
|
||||
|
||||
Main.Players.Clear();
|
||||
Main.Npcs.Clear();
|
||||
foreach (KeyValuePair<string, EntitiesPlayer> player in Main.Players)
|
||||
{
|
||||
if (player.Value.Character != null && player.Value.Character.Exists())
|
||||
{
|
||||
player.Value.Character.Kill();
|
||||
player.Value.Character.Delete();
|
||||
}
|
||||
|
||||
Vector3 pos = Game.Player.Character.Position;
|
||||
Function.Call(Hash.CLEAR_AREA_OF_PEDS, pos.X, pos.Y, pos.Z, 300.0f, 0);
|
||||
Function.Call(Hash.CLEAR_AREA_OF_VEHICLES, pos.X, pos.Y, pos.Z, 300.0f, 0);
|
||||
player.Value.PedBlip?.Delete();
|
||||
}
|
||||
|
||||
Main.Players.Clear();
|
||||
|
||||
foreach (KeyValuePair<string, EntitiesNpc> npc in Main.Npcs)
|
||||
{
|
||||
if (npc.Value.Character != null && npc.Value.Character.Exists())
|
||||
{
|
||||
npc.Value.Character.Kill();
|
||||
npc.Value.Character.Delete();
|
||||
}
|
||||
}
|
||||
|
||||
Main.Npcs.Clear();
|
||||
break;
|
||||
}
|
||||
break;
|
||||
@ -251,10 +269,12 @@ namespace CoopClient
|
||||
player.Character.Delete();
|
||||
}
|
||||
|
||||
Main.Players.Remove(packet.Player);
|
||||
player.PedBlip?.Delete();
|
||||
|
||||
Main.MainPlayerList.Update(Main.Players, Main.MainSettings.Username);
|
||||
Main.Players.Remove(packet.Player);
|
||||
}
|
||||
|
||||
Main.MainPlayerList.Update(Main.Players, Main.MainSettings.Username);
|
||||
}
|
||||
|
||||
private void FullSyncPlayer(FullSyncPlayerPacket packet)
|
||||
|
@ -21,9 +21,6 @@ namespace CoopClient
|
||||
}
|
||||
|
||||
Function.Call((Hash)0xB96B00E976BE977F, 0.0f); // _SET_WAVES_INTENSITY
|
||||
|
||||
Game.Player.Character.CanBeTargetted = true;
|
||||
Function.Call(Hash.SET_CAN_ATTACK_FRIENDLY, Game.Player.Character, true, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -267,30 +267,30 @@ namespace CoopServer
|
||||
}
|
||||
|
||||
// Return a list of all connections but not the local connection
|
||||
private static List<NetConnection> FilterAllLocal(NetConnection local)
|
||||
{
|
||||
return new(MainNetServer.Connections.Where(e => e != local));
|
||||
}
|
||||
private static List<NetConnection> FilterAllLocal(string local)
|
||||
{
|
||||
return new List<NetConnection>(MainNetServer.Connections.FindAll(e => !NetUtility.ToHexString(e.RemoteUniqueIdentifier).Equals(local)));
|
||||
return new(MainNetServer.Connections.Where(e => NetUtility.ToHexString(e.RemoteUniqueIdentifier) != local));
|
||||
}
|
||||
|
||||
// Get all players in range of ...
|
||||
// Return a list of players within range of ...
|
||||
private static List<NetConnection> GetAllInRange(LVector3 position, float range)
|
||||
{
|
||||
return new List<NetConnection>(MainNetServer.Connections.FindAll(e => Players[NetUtility.ToHexString(e.RemoteUniqueIdentifier)].Ped.IsInRangeOf(position, range)));
|
||||
return new(MainNetServer.Connections.FindAll(e => Players[NetUtility.ToHexString(e.RemoteUniqueIdentifier)].Ped.IsInRangeOf(position, range)));
|
||||
}
|
||||
private static List<NetConnection> GetAllInRange(LVector3 position, float range, string local)
|
||||
|
||||
// Return a list of players within range of ... but not the local one
|
||||
private static List<NetConnection> GetAllInRange(LVector3 position, float range, NetConnection local)
|
||||
{
|
||||
return new List<NetConnection>(MainNetServer.Connections.FindAll(e =>
|
||||
{
|
||||
string target = NetUtility.ToHexString(e.RemoteUniqueIdentifier);
|
||||
return target != local && Players[target].Ped.IsInRangeOf(position, range);
|
||||
}));
|
||||
return new(MainNetServer.Connections.Where(e => e != local && Players[NetUtility.ToHexString(e.RemoteUniqueIdentifier)].Ped.IsInRangeOf(position, range)));
|
||||
}
|
||||
|
||||
// Before we approve the connection, we must shake hands
|
||||
private void GetHandshake(NetConnection local, HandshakePacket packet)
|
||||
{
|
||||
string localPlayerID = NetUtility.ToHexString(local.RemoteUniqueIdentifier);
|
||||
|
||||
Logging.Debug("New handshake from: [" + packet.SocialClubName + " | " + packet.Username + "]");
|
||||
|
||||
if (string.IsNullOrWhiteSpace(packet.Username))
|
||||
@ -349,6 +349,8 @@ namespace CoopServer
|
||||
}
|
||||
}
|
||||
|
||||
string localPlayerID = NetUtility.ToHexString(local.RemoteUniqueIdentifier);
|
||||
|
||||
// Add the player to Players
|
||||
Players.Add(localPlayerID,
|
||||
new EntitiesPlayer()
|
||||
@ -384,7 +386,7 @@ namespace CoopServer
|
||||
SendChatMessage(new ChatMessagePacket() { Username = "Server", Message = MainSettings.WelcomeMessage }, new List<NetConnection>() { local });
|
||||
}
|
||||
|
||||
List<NetConnection> playerList = FilterAllLocal(packet.Player);
|
||||
List<NetConnection> playerList = FilterAllLocal(local);
|
||||
if (playerList.Count == 0)
|
||||
{
|
||||
return;
|
||||
@ -422,7 +424,6 @@ namespace CoopServer
|
||||
private static void SendPlayerDisconnectPacket(PlayerDisconnectPacket packet, string reason = "Disconnected")
|
||||
{
|
||||
List<NetConnection> playerList = FilterAllLocal(packet.Player);
|
||||
|
||||
if (playerList.Count != 0)
|
||||
{
|
||||
NetOutgoingMessage outgoingMessage = MainNetServer.CreateMessage();
|
||||
@ -439,7 +440,6 @@ namespace CoopServer
|
||||
Players[packet.Player].Ped.Position = packet.Position;
|
||||
|
||||
List<NetConnection> playerList = FilterAllLocal(packet.Player);
|
||||
|
||||
if (playerList.Count == 0)
|
||||
{
|
||||
return;
|
||||
@ -452,9 +452,7 @@ namespace CoopServer
|
||||
|
||||
private static void FullSyncNpc(NetConnection local, FullSyncNpcPacket packet)
|
||||
{
|
||||
List<NetConnection> playerList = GetAllInRange(packet.Position, 300f, NetUtility.ToHexString(local.RemoteUniqueIdentifier));
|
||||
|
||||
// No connection found in this area
|
||||
List<NetConnection> playerList = GetAllInRange(packet.Position, 300f, local);
|
||||
if (playerList.Count == 0)
|
||||
{
|
||||
return;
|
||||
@ -470,7 +468,6 @@ namespace CoopServer
|
||||
Players[packet.Player].Ped.Position = packet.Position;
|
||||
|
||||
List<NetConnection> playerList = FilterAllLocal(packet.Player);
|
||||
|
||||
if (playerList.Count == 0)
|
||||
{
|
||||
return;
|
||||
|
Reference in New Issue
Block a user