Created
October 10, 2020 16:56
-
-
Save Rene-Sackers/6c534b95884f3df5e1b0088359148008 to your computer and use it in GitHub Desktop.
FiveM C# events
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[EventHandler(Events.Client.onClientResourceStart)] | |
private void onClientResourceStart(string resourceName) | |
{ | |
Debug.WriteLine($"{Events.Client.onClientResourceStart}"); | |
} | |
[EventHandler(Events.Client.onClientResourceStop)] | |
public void onClientResourceStop(string resourceName) | |
{ | |
Debug.WriteLine($"{Events.Client.onClientResourceStop}"); | |
} | |
[EventHandler(Events.Shared.onResourceStart)] | |
public void onResourceStart(string resourceName) | |
{ | |
Debug.WriteLine($"{Events.Shared.onResourceStart}"); | |
} | |
[EventHandler(Events.Shared.onResourceStarting)] | |
public void onResourceStarting(string resourceName) | |
{ | |
Debug.WriteLine($"{Events.Shared.onResourceStarting}"); | |
} | |
[EventHandler(Events.Shared.onResourceStop)] | |
public void onResourceStop(string resourceName) | |
{ | |
Debug.WriteLine($"{Events.Shared.onResourceStop}"); | |
} | |
[EventHandler(Events.Client.gameEventTriggered)] | |
public void gameEventTriggered(string name, List<dynamic> args) | |
{ | |
Debug.WriteLine($"{Events.Client.gameEventTriggered}"); | |
} | |
[EventHandler(Events.Client.populationPedCreating)] | |
public void populationPedCreating(float posX, float posY, float posZ, uint model, dynamic setters) | |
{ | |
Debug.WriteLine($"{Events.Client.populationPedCreating}"); | |
} | |
[EventHandler(Events.Shared.rconCommand)] | |
public void rconCommand(string command, List<object> args) | |
{ | |
Debug.WriteLine($"{Events.Shared.rconCommand}"); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static class Events | |
{ | |
public static class Client | |
{ | |
public const string gameEventTriggered = nameof(gameEventTriggered); | |
public const string onClientResourceStart = nameof(onClientResourceStart); | |
public const string onClientResourceStop = nameof(onClientResourceStop); | |
public const string populationPedCreating = nameof(populationPedCreating); | |
} | |
public static class Server | |
{ | |
public const string playerConnecting = nameof(playerConnecting); | |
public const string playerDropped = nameof(playerDropped); | |
public const string onResourceListRefresh = nameof(onResourceListRefresh); | |
public static class OneSync | |
{ | |
public const string weaponDamageEvent = nameof(weaponDamageEvent); | |
public const string vehicleComponentControlEvent = nameof(vehicleComponentControlEvent); | |
public const string respawnPlayerPedEvent = nameof(respawnPlayerPedEvent); | |
public const string explosionEvent = nameof(explosionEvent); | |
public const string entityCreated = nameof(entityCreated); | |
public const string entityCreating = nameof(entityCreating); | |
public const string entityRemoved = nameof(entityRemoved); | |
} | |
} | |
public static class Shared | |
{ | |
public const string rconCommand = nameof(rconCommand); | |
public const string onResourceStart = nameof(onResourceStart); | |
public const string onResourceStarting = nameof(onResourceStarting); | |
public const string onResourceStop = nameof(onResourceStop); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[EventHandler(Events.Shared.onResourceStart)] | |
public void OnResourceStart(string resourceName) | |
{ | |
Debug.WriteLine($"{Events.Shared.onResourceStart}"); | |
} | |
[EventHandler(Events.Shared.onResourceStarting)] | |
public void OnResourceStarting(string resourceName) | |
{ | |
Debug.WriteLine($"{Events.Shared.onResourceStarting}"); | |
} | |
[EventHandler(Events.Shared.onResourceStop)] | |
public void OnResourceStop(string resourceName) | |
{ | |
Debug.WriteLine($"{Events.Shared.onResourceStop}"); | |
} | |
[EventHandler(Events.Server.playerConnecting)] | |
public void playerConnecting([FromSource] Player player, string playerName, dynamic setKickReason, dynamic deferrals) | |
{ | |
Debug.WriteLine($"{Events.Server.playerConnecting}"); | |
} | |
[EventHandler(Events.Server.playerDropped)] | |
public void playerDropped([FromSource] Player player, string reason) | |
{ | |
Debug.WriteLine($"{Events.Server.playerDropped}"); | |
} | |
[EventHandler(Events.Shared.rconCommand)] | |
public void rconCommand(string command, List<object> args) | |
{ | |
Debug.WriteLine($"{Events.Shared.rconCommand}"); | |
} | |
[EventHandler(Events.Server.onResourceListRefresh)] | |
public void onResourceListRefresh() | |
{ | |
Debug.WriteLine($"{Events.Server.onResourceListRefresh}"); | |
} | |
[EventHandler(Events.Server.OneSync.weaponDamageEvent)] | |
public void weaponDamageEvent( | |
string damageType, | |
ExpandoObject expandoObject) | |
{ | |
// damageType | |
// 0= unknown(or incorrect weaponHash) | |
// 1= no damage(flare, snowball, petrolcan) | |
// 2= melee | |
// 3= bullet | |
// 4= force ragdoll fall | |
// 5= explosive(RPG, Railgun, grenade) | |
// 6= fire(molotov) | |
// 8= fall(WEAPON_HELI_CRASH) | |
// 10= electric | |
// 11= barbed wire | |
// 12= extinguisher | |
// 13= gas | |
// 14= water cannon(WEAPON_HIT_BY_WATER_CANNON) | |
Debug.WriteLine($"damageType - {damageType}"); | |
var info = WeaponDamageEventInfo.FromExpandoObject(expandoObject); | |
Debug.WriteLine($"{Events.Server.OneSync.weaponDamageEvent} - {info.weaponType}"); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// <summary> | |
/// https://docs.fivem.net/docs/scripting-reference/events/list/weaponDamageEvent/ | |
/// https://github.com/citizenfx/fivem/blob/c7e1b35b55d4dbd0579b13c63a538501086e60ed/code/components/citizen-server-impl/src/state/ServerGameState.cpp#L2835 | |
/// </summary> | |
public class WeaponDamageEventInfo | |
{ | |
/// <summary> | |
/// weapon's hash | |
/// </summary> | |
public uint weaponType { get; set; } | |
/// <summary> | |
/// if it overrides damage | |
/// </summary> | |
public bool overrideDefaultDamage { get; set; } | |
/// <summary> | |
/// whether the target entity has a weapon or not. | |
/// </summary> | |
public bool hitEntityWeapon { get; set; } | |
/// <summary> | |
/// whether the target entity has attachments or not. | |
/// </summary> | |
public bool hitWeaponAmmoAttachment { get; set; } | |
/// <summary> | |
/// whether the weapon is silenced or not. | |
/// </summary> | |
public bool silenced { get; set; } | |
public uint damageFlags { get; set; } | |
public bool f80_1 { get; set; } | |
public uint f100 { get; set; } | |
public ushort f116 { get; set; } | |
public uint f104 { get; set; } | |
/// <summary> | |
/// damage caused by the weapon. | |
/// </summary> | |
public ushort weaponDamage { get; set; } | |
public bool f135 { get; set; } | |
public ushort f48 { get; set; } | |
public ushort f52 { get; set; } | |
public ushort f56 { get; set; } | |
public bool f112 { get; set; } | |
public uint damageTime { get; set; } | |
/// <summary> | |
/// whether the damage is fatal or not. | |
/// </summary> | |
public bool willKill { get; set; } | |
public uint f120 { get; set; } | |
/// <summary> | |
/// whether it has vehicle data (probably used to check if the target entity is a vehicle). | |
/// </summary> | |
public bool hasVehicleData { get; set; } | |
public ushort f112_1 { get; set; } | |
/// <summary> | |
/// Source entity? | |
/// </summary> | |
public ushort parentGlobalId { get; set; } | |
/// <summary> | |
/// Target entity? | |
/// </summary> | |
public ushort hitGlobalId { get; set; } | |
/// <summary> | |
/// tyreIndex = 0 to 4 on normal vehicles | |
/// '0 = wheel_lf / bike, plane or jet front | |
/// '1 = wheel_rf | |
/// '2 = wheel_lm / in 6 wheels trailer, plane or jet is first one on left | |
/// '3 = wheel_rm / in 6 wheels trailer, plane or jet is first one on right | |
/// '4 = wheel_lr / bike rear / in 6 wheels trailer, plane or jet is last one on left | |
/// '5 = wheel_rr / in 6 wheels trailer, plane or jet is last one on right | |
/// '45 = 6 wheels trailer mid wheel left | |
/// '47 = 6 wheels trailer mid wheel right | |
/// </summary> | |
public byte tyreIndex { get; set; } | |
public byte suspensionIndex { get; set; } | |
public byte hitComponent { get; set; } | |
public bool f133 { get; set; } | |
public bool f125 { get; set; } | |
public ushort f64 { get; set; } | |
public ushort f68 { get; set; } | |
public ushort f72 { get; set; } | |
public static WeaponDamageEventInfo FromExpandoObject(ExpandoObject expandoObject) | |
{ | |
return CastExpandoObject<WeaponDamageEventInfo>(expandoObject); | |
} | |
} | |
private static T CastExpandoObject<T>(ExpandoObject expandoObject) | |
{ | |
var type = typeof(T); | |
var props = type.GetProperties(BindingFlags.Public | BindingFlags.Instance).Where(x => x.GetSetMethod() != null); | |
var values = expandoObject.ToDictionary(kv => kv.Key, kv => kv.Value); | |
var info = Activator.CreateInstance(type); | |
foreach (var prop in props) | |
{ | |
Debug.WriteLine($"Set {prop.Name} - {values[prop.Name].GetType().Name}"); | |
prop.SetValue(info, Convert.ChangeType(values[prop.Name], prop.PropertyType)); | |
} | |
return (T)info; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment