Prevent entity spawning from interfering Tick event

This commit is contained in:
Sardelka
2022-07-15 13:45:43 +08:00
parent 2ad91011c3
commit 30ed509c55
8 changed files with 62 additions and 54 deletions

View File

@ -342,7 +342,7 @@ namespace RageCoop.Client
c.Clothes=packet.Clothes;
c.WeaponComponents=packet.WeaponComponents;
c.WeaponTint=packet.WeaponTint;
c.ModelHash=packet.ModelHash;
c.Model=packet.ModelHash;
c.LastStateSynced = Main.Ticked;
c.BlipColor=packet.BlipColor;
c.BlipSprite=packet.BlipSprite;
@ -377,7 +377,7 @@ namespace RageCoop.Client
v.EngineHealth=packet.EngineHealth;
v.OwnerID=packet.OwnerID;
v.Mods=packet.Mods;
v.ModelHash=packet.ModelHash;
v.Model=packet.ModelHash;
v.Colors=packet.Colors;
v.LandingGear=packet.LandingGear;
v.RoofState=(VehicleRoofState)packet.RoofState;

View File

@ -183,7 +183,7 @@ namespace RageCoop.Client.Scripting
}
}
prop.LastSynced=Main.Ticked+1;
prop.ModelHash= (Model)e.Args[1];
prop.Model= (Model)e.Args[1];
prop.Position=(Vector3)e.Args[2];
prop.Rotation=(Vector3)e.Args[3];
prop.Update();

View File

@ -71,7 +71,7 @@ namespace RageCoop.Client
///
/// </summary>
internal protected bool _lastFrozen=false;
internal int ModelHash { get; set; }
internal Model Model { get; set; }
internal Vector3 Position { get; set; }
internal Vector3 Rotation { get; set; }
internal Quaternion Quaternion { get; set; }

View File

@ -101,12 +101,13 @@ namespace RageCoop.Client
}
bool characterExist = (MainPed != null) && MainPed.Exists();
if (!characterExist)
if (MainPed == null || !MainPed.Exists())
{
CreateCharacter();
return;
if (!CreateCharacter())
{
return;
}
}
@ -135,10 +136,13 @@ namespace RageCoop.Client
if (LastStateSynced>=LastUpdated)
{
if (MainPed!=null&& (ModelHash != MainPed.Model.Hash))
if (MainPed!=null&& (Model != MainPed.Model.Hash))
{
CreateCharacter();
return;
if (!CreateCharacter())
{
return;
}
}
if (!Clothes.SequenceEqual(_lastClothes))
@ -224,7 +228,7 @@ namespace RageCoop.Client
}
private void CreateCharacter()
private bool CreateCharacter()
{
if (MainPed != null)
{
@ -244,20 +248,18 @@ namespace RageCoop.Client
PedBlip.Delete();
PedBlip = null;
}
Model characterModel = ModelHash.ModelRequest();
if (characterModel == null)
if (!Model.IsLoaded)
{
return;
Model.Request();
return false;
}
MainPed = World.CreatePed(characterModel, Position);
characterModel.MarkAsNoLongerNeeded();
if (MainPed == null)
if ((MainPed = Util.CreatePed(Model, Position)) == null)
{
return;
return false;
}
Model.MarkAsNoLongerNeeded();
MainPed.BlockPermanentEvents = true;
@ -292,8 +294,13 @@ namespace RageCoop.Client
}
if (IsInvincible) { MainPed.IsInvincible=true; }
// Add to EntityPool so this Character can be accessed by handle.
EntityPool.Add(this);
lock (EntityPool.PedsLock)
{
// Add to EntityPool so this Character can be accessed by handle.
EntityPool.Add(this);
}
return true;
}
private void SetClothes()
@ -348,7 +355,8 @@ namespace RageCoop.Client
{
if (ParachuteProp == null)
{
Model model = 1740193300.ModelRequest();
Model model = 1740193300;
model.Request(1000);
if (model != null)
{
ParachuteProp = World.CreateProp(model, MainPed.Position, MainPed.Rotation, false, false);

View File

@ -32,7 +32,7 @@ namespace RageCoop.Client
if (!NeedUpdate) { return; }
if (MainProp== null || !MainProp.Exists())
{
MainProp=World.CreateProp(ModelHash,Position,Rotation,false,false);
MainProp=World.CreateProp(Model,Position,Rotation,false,false);
MainProp.IsInvincible=true;
}
MainProp.Position=Position;

View File

@ -116,10 +116,12 @@ namespace RageCoop.Client
if (!NeedUpdate) { return; }
#endregion
#region -- CHECK EXISTENCE --
if ((MainVehicle == null) || (!MainVehicle.Exists()) || (MainVehicle.Model.Hash != ModelHash))
if ((MainVehicle == null) || (!MainVehicle.Exists()) || (MainVehicle.Model.Hash != Model))
{
CreateVehicle();
return;
if (!CreateVehicle())
{
return;
}
}
#endregion
#region -- SYNC CRITICAL --
@ -320,7 +322,7 @@ namespace RageCoop.Client
MainVehicle.SetDeluxoHoverState(true);
}
}
else if(ModelHash==1483171323)
else if(Model==1483171323)
{
if (MainVehicle.IsDeluxoHovering())
{
@ -359,19 +361,23 @@ namespace RageCoop.Client
return r;
}
private void CreateVehicle()
private bool CreateVehicle()
{
MainVehicle?.Delete();
Model vehicleModel = ModelHash.ModelRequest();
if (vehicleModel == null)
MainVehicle = Util.CreateVehicle(Model, Position);
if (!Model.IsInCdImage)
{
//GTA.UI.Notification.Show($"~r~(Vehicle)Model ({CurrentVehicleModelHash}) cannot be loaded!");
return;
// GTA.UI.Notification.Show($"~r~(Vehicle)Model ({CurrentVehicleModelHash}) cannot be loaded!");
return false;
}
else if (MainVehicle==null)
{
Model.Request();
return false;
}
MainVehicle = World.CreateVehicle(vehicleModel, Position);
lock (EntityPool.VehiclesLock)
{
EntityPool.Add( this);
EntityPool.Add(this);
}
MainVehicle.Quaternion = Quaternion;
if (MainVehicle.HasRoof)
@ -379,7 +385,8 @@ namespace RageCoop.Client
MainVehicle.RoofState=RoofState;
}
if (IsInvincible) { MainVehicle.IsInvincible=true; }
vehicleModel.MarkAsNoLongerNeeded();
Model.MarkAsNoLongerNeeded();
return true;
}
#region -- PEDALING --
/*
@ -388,7 +395,7 @@ namespace RageCoop.Client
private string PedalingAnimDict()
{
switch ((VehicleHash)ModelHash)
switch ((VehicleHash)Model)
{
case VehicleHash.Bmx:
return "veh@bicycle@bmx@front@base";

View File

@ -154,7 +154,7 @@ namespace RageCoop.Client {
if (v==null) { return; }
v.OwnerID=p.NewOwnerID;
v.ModelHash=v.MainVehicle.Model;
v.Model=v.MainVehicle.Model;
v.LastSynced=Main.Ticked;
// So this vehicle doesn's get re-spawned
}

View File

@ -177,22 +177,15 @@ namespace RageCoop.Client
return e.Position+e.Velocity*((applyDefault ? SyncParameters.PositioinPredictionDefault : 0)+Networking.Latency);
}
public static Model ModelRequest(this int hash)
public static Vehicle CreateVehicle(Model model, Vector3 position, float heading = 0f)
{
Model model = new Model(hash);
if (!model.IsValid)
{
//GTA.UI.Notification.Show("~y~Not valid!");
return null;
}
if (!model.IsLoaded)
{
return model.Request(1000) ? model : null;
}
return model;
if (!model.IsLoaded) { return null; }
return (Vehicle)Entity.FromHandle(Function.Call<int>(Hash.CREATE_VEHICLE, model.Hash, position.X, position.Y, position.Z, heading, false, false));
}
public static Ped CreatePed(Model model, Vector3 position, float heading = 0f)
{
if (!model.IsLoaded) { return null; }
return (Ped)Entity.FromHandle(Function.Call<int>(Hash.CREATE_PED, 26, model.Hash, position.X, position.Y, position.Z, heading, false, false));
}
public static void SetOnFire(this Entity e, bool toggle)
{