Skip to content

Commit 48fe386

Browse files
committed
Merge branch 'dev' into rc
2 parents 04a2c8a + 2abafb3 commit 48fe386

File tree

6 files changed

+25
-5
lines changed

6 files changed

+25
-5
lines changed

api/AltV.Net.Example/SampleResource.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,18 @@ public override void OnStart()
2222
long currentTraceSize = 0;
2323
AltTrace.OnTraceFileSizeChange += size => { currentTraceSize = size; };
2424

25+
Alt.OnWeaponDamage += (player, target, weapon, damage, offset, part) =>
26+
{
27+
//Do Something
28+
return "asdsad";
29+
};
30+
31+
Alt.OnWeaponDamage += (player, target, weapon, damage, offset, part) =>
32+
{
33+
//Do Something
34+
return false;
35+
};
36+
2537
Alt.OnConsoleCommand += (name, args) =>
2638
{
2739
Console.WriteLine("Command name: " + name);

api/AltV.Net/Alt.Events.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ public static event ExplosionDelegate OnExplosion
8181
/// Alt.OnWeaponDamage += (player, target, weapon, damage, shotOffset, bodyPart) => {
8282
/// Console.WriteLine($"{player.Name} got damaged.");
8383
/// return true; // return false will cancel the weapon damage event and player won't receive damage.
84+
/// return 5; // return a number will set the new damage
8485
/// };
8586
/// </code>
8687
/// </example>

api/AltV.Net/Alt.RegisterEvents.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -327,7 +327,7 @@ public static void RegisterEvents(object target)
327327
{
328328
typeof(IPlayer), typeof(IEntity), typeof(uint), typeof(ushort),
329329
typeof(Position), typeof(BodyPart)
330-
}, new[] {typeof(uint), typeof(bool)});
330+
}, new[] {typeof(WeaponDamageResponse)});
331331
if (scriptFunction == null) return;
332332
OnWeaponDamage +=
333333
(player, targetEntity, weapon, damage, shotOffset, damageOffset) =>

api/AltV.Net/Core.Events.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -519,13 +519,14 @@ public virtual void OnWeaponDamageEvent(IntPtr eventPointer, IPlayer sourcePlaye
519519
{
520520
var result = @delegate(sourcePlayer, targetEntity, weapon, damage, shotOffset, bodyPart);
521521

522-
if (result is bool and false)
522+
if (result.Cancel)
523523
{
524524
cancel = true;
525525
}
526-
else if (uint.TryParse(result, out uint newDamage))
526+
527+
if (result.Damage.HasValue)
527528
{
528-
weaponDamage ??= newDamage;
529+
weaponDamage ??= result.Damage.Value;
529530
}
530531
}
531532
catch (TargetInvocationException exception)
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
namespace AltV.Net.Data;
2+
3+
public record WeaponDamageResponse(bool Cancel, uint? Damage) {
4+
public static implicit operator WeaponDamageResponse(bool val) => new WeaponDamageResponse(val, null);
5+
public static implicit operator WeaponDamageResponse(uint val) => new WeaponDamageResponse(false, val);
6+
};

api/AltV.Net/Events/Events.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ public delegate void PlayerHealDelegate(IPlayer target, ushort oldHealth, ushort
5959
public delegate bool ExplosionDelegate(IPlayer player, ExplosionType explosionType, Position position,
6060
uint explosionFx, IEntity targetEntity);
6161

62-
public delegate dynamic WeaponDamageDelegate(IPlayer player, IEntity target, uint weapon, ushort damage,
62+
public delegate WeaponDamageResponse WeaponDamageDelegate(IPlayer player, IEntity target, uint weapon, ushort damage,
6363
Position shotOffset, BodyPart bodyPart);
6464

6565
public delegate void VehicleDestroyDelegate(IVehicle vehicle);

0 commit comments

Comments
 (0)