Skip to content

Commit

Permalink
merge dev
Browse files Browse the repository at this point in the history
  • Loading branch information
Doxoh committed Aug 23, 2024
2 parents 78ac38d + f743610 commit 345ca2b
Show file tree
Hide file tree
Showing 43 changed files with 601 additions and 126 deletions.
26 changes: 26 additions & 0 deletions api/AltV.Net.Async/AltAsync.RegisterEvents.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,32 @@ public static void RegisterEvents(object target)
ScriptFunction scriptFunction;
switch (scriptEventType)
{
case ScriptEventType.BaseObjectCreate:
{
scriptFunction = ScriptFunction.Create(eventMethodDelegate,
new[] { typeof(IBaseObject) }, isAsync: true);
if (scriptFunction == null) return;
OnBaseObjectCreate += (baseObject) =>
{
var currScriptFunction = scriptFunction.Clone();
currScriptFunction.Set(baseObject);
return currScriptFunction.CallAsync();
};
break;
}
case ScriptEventType.BaseObjectRemove:
{
scriptFunction = ScriptFunction.Create(eventMethodDelegate,
new[] { typeof(IBaseObject) }, isAsync: true);
if (scriptFunction == null) return;
OnBaseObjectRemove += (baseObject) =>
{
var currScriptFunction = scriptFunction.Clone();
currScriptFunction.Set(baseObject);
return currScriptFunction.CallAsync();
};
break;
}
case ScriptEventType.Checkpoint:
{
scriptFunction = ScriptFunction.Create(eventMethodDelegate,
Expand Down
12 changes: 12 additions & 0 deletions api/AltV.Net.Async/AltAsync.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,18 @@ public static event CheckpointAsyncDelegate OnCheckpoint
remove => Core.CheckpointAsyncEventHandler.Remove(value);
}

public static event BaseObjectCreateAsyncDelegate OnBaseObjectCreate
{
add => Core.BaseObjectCreateAsyncEventHandler.Add(value);
remove => Core.BaseObjectCreateAsyncEventHandler.Remove(value);
}

public static event BaseObjectRemoveAsyncDelegate OnBaseObjectRemove
{
add => Core.BaseObjectRemoveAsyncEventHandler.Add(value);
remove => Core.BaseObjectRemoveAsyncEventHandler.Remove(value);
}

public static event PlayerConnectAsyncDelegate OnPlayerConnect
{
add => Core.PlayerConnectAsyncEventHandler.Add(value);
Expand Down
27 changes: 27 additions & 0 deletions api/AltV.Net.Async/AsyncCore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,12 @@ internal readonly AsyncEventHandler<PlayerChangeVehicleSeatAsyncDelegate>
internal readonly AsyncEventHandler<PlayerDisconnectAsyncDelegate> PlayerDisconnectAsyncEventHandler =
new(EventType.PLAYER_DISCONNECT);

internal readonly AsyncEventHandler<BaseObjectCreateAsyncDelegate> BaseObjectCreateAsyncEventHandler =
new();

internal readonly AsyncEventHandler<BaseObjectRemoveAsyncDelegate> BaseObjectRemoveAsyncEventHandler =
new();

internal readonly AsyncEventHandler<PlayerRemoveAsyncDelegate> PlayerRemoveAsyncEventHandler =
new();

Expand Down Expand Up @@ -357,6 +363,27 @@ await PlayerDisconnectAsyncEventHandler.CallAsync(@delegate =>
);
}

public override void OnCreateBaseObjectEvent(IBaseObject baseObject)
{
base.OnCreateBaseObjectEvent(baseObject);
if (!BaseObjectCreateAsyncEventHandler.HasEvents()) return;
Task.Run(async () =>
{
await BaseObjectCreateAsyncEventHandler.CallAsync(@delegate =>
@delegate(baseObject));
});
}
public override void OnRemoveBaseObjectEvent(IBaseObject baseObject)
{
base.OnRemoveBaseObjectEvent(baseObject);
if (!BaseObjectRemoveAsyncEventHandler.HasEvents()) return;
Task.Run(async () =>
{
await BaseObjectRemoveAsyncEventHandler.CallAsync(@delegate =>
@delegate(baseObject));
});
}

public override void OnPlayerRemoveEvent(IPlayer player)
{
base.OnPlayerRemoveEvent(player);
Expand Down
18 changes: 18 additions & 0 deletions api/AltV.Net.Async/Elements/Entities/AsyncPlayer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -580,6 +580,24 @@ public void Spawn(Position position, uint delayMs = 0)
Player.Spawn(position, delayMs);
}
}

public void Spawn(uint model, Position position, uint delayMs = 0)
{
lock (Player)
{
if (!AsyncContext.CheckIfExistsNullable(Player)) return;
Player.Spawn(model, position, delayMs);
}
}

public void Spawn(PedModel model, Position position, uint delayMs = 0)
{
lock (Player)
{
if (!AsyncContext.CheckIfExistsNullable(Player)) return;
Player.Spawn(model, position, delayMs);
}
}

public void Despawn()
{
Expand Down
2 changes: 2 additions & 0 deletions api/AltV.Net.Async/Events/Events.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ public delegate Task PlayerHealAsyncDelegate(IPlayer target, ushort oldHealth, u

public delegate Task PlayerDisconnectAsyncDelegate(IPlayer player, string reason);

public delegate Task BaseObjectCreateAsyncDelegate(IBaseObject baseObject);
public delegate Task BaseObjectRemoveAsyncDelegate(IBaseObject baseObject);
public delegate Task PlayerRemoveAsyncDelegate(IPlayer player);

public delegate Task VehicleRemoveAsyncDelegate(IVehicle vehicle);
Expand Down
Loading

0 comments on commit 345ca2b

Please sign in to comment.