Added ability to disable automatic respawn

Prepare for client side scripting.
This commit is contained in:
Sardelka
2022-05-31 02:16:12 -08:00
parent a33f839004
commit b863b7037a
8 changed files with 67 additions and 21 deletions

View File

@ -11,14 +11,15 @@ namespace RageCoop.Client
/// </summary>
public static class COOPAPI
{
#region DELEGATES
/// <summary>
/// ?
/// </summary>
/// <param name="connected"></param>
/// <param name="from">The Lidgren-Network net handle</param>
/// <param name="from">The player's id</param>
/// <param name="reason"></param>
public delegate void ConnectEvent(bool connected, long from, string reason = null);
public delegate void ConnectEvent(bool connected, int from, string reason = null);
/// <summary>
/// ?
/// </summary>
@ -61,9 +62,9 @@ namespace RageCoop.Client
OnConnection?.Invoke(true, playerID);
}
public static void Disconnected(long netHandle)
public static void Disconnected(int playerID)
{
OnConnection?.Invoke(false, netHandle);
OnConnection?.Invoke(false, playerID);
}
public static bool ChatMessageReceived(string from, string message)
@ -113,7 +114,7 @@ namespace RageCoop.Client
/// Get the local player's ID
/// </summary>
/// <returns>PlayerID</returns>
public static long GetPlayerID()
public static int GetPlayerID()
{
return Main.LocalPlayerID;
}

View File

@ -21,8 +21,7 @@ namespace RageCoop.Client
{
private bool _gameLoaded = false;
private static bool _isGoingToCar = false;
private bool _lastDead = false;
public static readonly string CurrentVersion = "V0_3";
public static int LocalPlayerID=0;
@ -108,11 +107,6 @@ namespace RageCoop.Client
CoopMenu.MenuPool.Process();
#endif
if (_isGoingToCar && Game.Player.Character.IsInVehicle())
{
_isGoingToCar = false;
}
DoQueuedActions();
if (!Networking.IsOnServer)
{
@ -162,9 +156,32 @@ namespace RageCoop.Client
MainChat.Tick();
PlayerList.Tick();
if (Settings.DisableAutoRespawn)
{
Function.Call(Hash.PAUSE_DEATH_ARREST_RESTART, true);
Function.Call(Hash.FORCE_GAME_STATE_PLAYING);
var P = Game.Player.Character;
if (P.IsDead)
{
Function.Call(Hash.TERMINATE_ALL_SCRIPTS_WITH_THIS_NAME, "respawn_controller");
Function.Call(Hash.SET_FADE_OUT_AFTER_DEATH, false);
if (P.Health!=1)
{
P.Health=1;
Game.Player.WantedLevel=0;
Main.Logger.Debug("Player died.");
}
GTA.UI.Screen.StopEffects();
}
else
{
Function.Call(Hash.DISPLAY_HUD, true);
}
_lastDead=P.IsDead;
}
Ticked++;
}

View File

@ -79,8 +79,11 @@ namespace RageCoop.Client
{
try
{
Client.FlushSendQueue();
ReceiveMessages();
if (Client!=null)
{
Client.FlushSendQueue();
ReceiveMessages();
}
}
catch (Exception ex)
{

View File

@ -44,6 +44,11 @@ namespace RageCoop.Client
Flag = p.GetPedFlags(),
Heading=p.Heading,
};
if (packet.Health==1&&packet.ID==Main.LocalPlayerID)
{
// Fake death
packet.Health=0;
}
if (packet.Flag.HasFlag(PedDataFlags.IsAiming))
{
packet.AimCoords = p.GetAimCoord();

View File

@ -123,6 +123,7 @@
<ItemGroup>
<Compile Include="DevTools\DevTool.cs" />
<Compile Include="Menus\Sub\DevToolMenu.cs" />
<Compile Include="Scripting\ClientScript.cs" />
<Compile Include="Util\MathExtensions.cs" />
<Compile Include="Util\Util.cs" />
<Compile Include="Util\VehicleExtensions.cs" />

View File

@ -0,0 +1,17 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace RageCoop.Client.Scripting
{
public abstract class ClientScript
{
public class Events
{
}
public abstract void Main();
}
}

View File

@ -54,7 +54,11 @@ namespace RageCoop.Client
/// The game won't spawn more NPC traffic if the limit is exceeded. -1 for unlimited (not recommended).
/// </summary>
public int WorldVehicleSoftLimit { get; set; } = 35;
/// <summary>
/// Disable automatic respawn.
/// </summary>
public bool DisableAutoRespawn { get; set; } = true;
public float HpRechargeMultiplier { get; set; } = 1;
}
}

View File

@ -252,10 +252,8 @@ namespace RageCoop.Client
MainPed.CanBeDraggedOutOfVehicle = true;
MainPed.IsOnlyDamagedByPlayer = false;
MainPed.RelationshipGroup=Main.SyncedPedsGroup;
if (IsPlayer)
{
MainPed.IsInvincible=true;
}
MainPed.IsFireProof=false;
MainPed.IsExplosionProof=false;
SetClothes();
if (IsPlayer)