Arma Reforger Explorer 1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Loading...
Searching...
No Matches
SCR_RecoilForceAimModifier.c
Go to the documentation of this file.
1#define SCRIPTED_AIM_MODIFIER_DEBUG
3{
4 [Attribute(desc: "How much rotational force should be applied", params: "0 inf")]
6
7 [Attribute(desc: "If game should check the ground under the gun to determine how much recoil should be applied")]
9
10 protected float m_fRemainingTime;
12 protected int m_iSeed;
13
14 //------------------------------------------------------------------------------------------------
15 override void OnInit(IEntity weaponEnt)
16 {
17 if (m_vRotationOffset == vector.Zero)
18 return;
19
22 if (muzzleEffectComp)
23 muzzleEffectComp.GetOnWeaponFired().Insert(OnProjectileFired);
24 }
25
26 //------------------------------------------------------------------------------------------------
31 void OnProjectileFired(IEntity effectEntity, BaseMuzzleComponent muzzle, IEntity projectileEntity)
32 {
33 RplComponent projectileRpl = RplComponent.Cast(projectileEntity.FindComponent(RplComponent));
34 if (!projectileRpl)
35 return;
36
37 //needed to have the same seed for all clients to adjust the weapon in a same way
38 m_iSeed = projectileRpl.Id().ToString().ToInt();
39 }
40
41 //------------------------------------------------------------------------------------------------
42 protected override void OnWeaponFired()
43 {
44 if (m_vRotationOffset == vector.Zero)
45 return;
46
47 IEntity owner = m_AimingComp.GetOwner();
48 if (!owner)
49 return;
50
51 vector newRotation = m_AimingComp.GetAimingRotation();
52 float surfaceDensityMultiplier = 1;
54 {
55 TraceParam paramGround = new TraceParam();
56 paramGround.Start = owner.GetOrigin() + (vector.Up * 0.1);
57 paramGround.End = paramGround.Start - vector.Up;
58 paramGround.Flags = TraceFlags.WORLD | TraceFlags.ENTS;
59 paramGround.Exclude = owner;
60 paramGround.LayerMask = EPhysicsLayerPresets.Projectile;
61 owner.GetWorld().TraceMove(paramGround, FilterCallback);
62 GameMaterial material = paramGround.SurfaceProps;
63 BallisticInfo ballisticInfo;
64 if (material)
65 ballisticInfo = material.GetBallisticInfo();
66
67 if (ballisticInfo)
68 surfaceDensityMultiplier = Math.AbsFloat(ballisticInfo.GetDensity() - 1) * 0.2 + 1;
69 }
70
71 RandomGenerator randomValueGenerator = new RandomGenerator();
72 randomValueGenerator.SetSeed(m_iSeed);
73 if (!float.AlmostEqual(m_vRotationOffset[0], 0))
74 newRotation[0] = newRotation[0] + (randomValueGenerator.RandFloatXY(-m_vRotationOffset[0], m_vRotationOffset[0]) * surfaceDensityMultiplier);
75
76 if (!float.AlmostEqual(m_vRotationOffset[1], 0))
77 newRotation[1] = newRotation[1] + (randomValueGenerator.RandFloatXY(-m_vRotationOffset[1], m_vRotationOffset[1]) * surfaceDensityMultiplier);
78
79 if (!float.AlmostEqual(m_vRotationOffset[2], 0))
80 newRotation[2] = newRotation[2] + (randomValueGenerator.RandFloatXY(-m_vRotationOffset[2], m_vRotationOffset[2]) * surfaceDensityMultiplier);
81
82 newRotation *= Math.DEG2RAD;
83 m_AimingComp.SetAimingRotation(newRotation);
84 }
85
86 //------------------------------------------------------------------------------------------------
87 protected bool FilterCallback(IEntity e)
88 {
89 if (ChimeraCharacter.Cast(e))
90 return false;
91
92 return true;
93 }
94}
UI Textures DeployMenu Briefing conflict_HintBanner_1_UI desc
proto external Managed FindComponent(typename typeName)
proto external vector GetOrigin()
proto external BaseWorld GetWorld()
Definition Math.c:13
OnItemWeaponFiredInvoker GetOnWeaponFired()
void OnProjectileFired(IEntity effectEntity, BaseMuzzleComponent muzzle, IEntity projectileEntity)
override void OnInit(IEntity weaponEnt)
EPhysicsLayerPresets
Enum is filled by C++ by data in project config PhysicsSettings.LayerPresets.
Definition gameLib.c:19
SCR_FieldOfViewSettings Attribute
TraceFlags
Definition TraceFlags.c:13