DayZ Scripts
v1.21.156300 ยท Jun 20, 2023
 
Loading...
Searching...
No Matches
WeaponStableState.c
Go to the documentation of this file.
1
15{
17 U = -1,
19 E = 0,
21 F = 1,
23 L = 2
25
27{
29
31
32 void WeaponStableState(Weapon_Base w = NULL, WeaponStateBase parent = NULL, int anim_state = -1)
33 {
34 m_animState = anim_state;
37 }
38
40 {
41 int curr = m_weapon.GetWeaponAnimState();
42 if (curr != m_animState)
43 {
44 //fsmDebugSpam("[wpnfsm] " + Object.GetDebugName(m_weapon) + " synchronizing anim state: " + curr + " --> " + m_animState);
45 DayZPlayer p;
46 if (Class.CastTo(p, m_weapon.GetHierarchyParent()))
47 {
48 HumanCommandWeapons hcw = p.GetCommandModifier_Weapons();
49 if (hcw)
50 {
52 m_weapon.SetWeaponAnimState(m_animState);
53 fsmDebugSpam("[wpnfsm] " + Object.GetDebugName(m_weapon) + " state=" + m_weapon.GetCurrentState().Type() + " synchronized anim state: " + typename.EnumToString(PistolAnimState, curr) + " --> " + typename.EnumToString(PistolAnimState, m_animState));
54 }
55 else
56 {
57 Human wpnOwner = Human.Cast(m_weapon.GetHierarchyRootPlayer());
59 m_weapon.SetWeaponAnimState(m_animState);
60 fsmDebugSpam("[wpnfsm] " + Object.GetDebugName(m_weapon) + " state=" + m_weapon.GetCurrentState().Type() + " synchronized remote anim state: " + typename.EnumToString(PistolAnimState, curr) + " --> " + typename.EnumToString(PistolAnimState, m_animState));
61 }
62 }
63 else
64 {
65 m_weapon.SetGroundAnimFrameIndex(m_animState);
66 }
67 }
68 }
69
70 override void OnEntry(WeaponEventBase e)
71 {
72 super.OnEntry(e);
73 m_weapon.SetJammed(false);
74 if (e)
76 }
77 override void OnUpdate(float dt)
78 {
79 super.OnUpdate(dt);
81 }
82 override void OnExit(WeaponEventBase e)
83 {
84 m_weapon.ResetWeaponAnimState();
85 super.OnExit(e);
86 }
87
88 override bool IsIdle() { return true; }
89
90 int GetCurrentStateID() { return 0; }
91
103
112 bool IsRepairEnabled() { return false; }
113
119 bool HasBullet() { return false; }
120
122 bool HasMagazine() { return false; }
123
125 bool IsJammed() { return false; }
126
129
131 bool IsSingleState() { return false; }
132
134
139
142 int GetMuzzleStateCount() { return m_muzzleHasBullet.Count(); }
143 bool IsChamberValid(int idx) { return m_muzzleHasBullet[idx] != MuzzleState.U; }
144 bool IsChamberFiredOut(int idx) { return m_muzzleHasBullet[idx] == MuzzleState.F; }
145 bool IsChamberFull(int idx) { return m_muzzleHasBullet[idx] != MuzzleState.E; }
146
148
151 {
152 // There is only one
153 if (IsSingleState())
154 return;
155
156 bool failed = false;
157
158 if (!failed)
159 {
160 foreach (MuzzleState state : m_muzzleHasBullet)
161 {
162 if ( state == MuzzleState.U )
163 {
164 failed = true;
165 break;
166 }
167 }
168 }
169
170 if (failed)
171 {
172 ErrorExSeverity severity = ErrorExSeverity.ERROR;
173
174 #ifdef DEVELOPER
175 if (DayZGame.m_IsPreviewSpawn)
176 {
177 // we do not want VMEs when spawning the item in order to visualize it for preview in script console
178 severity = ErrorExSeverity.INFO;
179 }
180 #endif
181
182 ErrorEx("Muzzle array validation has failed. Please set up the correct muzzle states by overriding InitMuzzleArray.", severity);
183 }
184 }
185};
186
187
class WeaponGuardIsDestroyed extends WeaponGuardBase m_weapon
void fsmDebugSpam(string s)
Definition HFSMBase.c:5
PistolAnimState
Definition Pistol_Base.c:3
class SSPFireout extends WeaponStableState OnEntry
int GetMuzzleStateCount()
bool IsChamberValid(int idx)
void SyncAnimState()
enum MuzzleState m_animState
MuzzleState
@ E
EMPTY.
@ U
UNKNOWN.
@ L
LOADED.
@ F
FIRED.
void ValidateMuzzleArray()
Safety check and error message in case not set up correctly.
override bool IsIdle()
ref array< MuzzleState > m_muzzleHasBullet
bool IsSingleState()
Special one for when the weapon only has one singular state (like Magnum)
bool IsChamberFiredOut(int idx)
MuzzleState GetMuzzleState(int idx)
Get chamber state of the muzzle at index.
bool IsChamberFull(int idx)
Super root of all classes in Enforce script.
Definition EnScript.c:11
proto native void SetInitState(int pFrameIndex)
proto static native void StaticSetInitState(Human pHuman, int pFrameIdx)
just static version of SetInitState
signalize mechanism manipulation
Definition Events.c:35
represents weapon's stable state (i.e. the basic states that the weapon will spend the most time in)
Definition Crossbow.c:27
override bool IsRepairEnabled()
Definition Crossbow.c:34
override void OnEntry(WeaponEventBase e)
Definition Crossbow.c:28
override int GetCurrentStateID()
Definition Crossbow.c:30
override void OnExit(WeaponEventBase e)
Definition Crossbow.c:29
override bool IsJammed()
Definition Crossbow.c:33
override bool HasBullet()
Definition Crossbow.c:31
override void InitMuzzleArray()
Definition Crossbow.c:35
override bool HasMagazine()
Definition Crossbow.c:32
represent weapon state base
Definition BulletHide.c:2
Result for an object found in CGame.IsBoxCollidingGeometryProxy.
ErrorExSeverity
Definition EnDebug.c:62
enum ShapeType ErrorEx
static proto bool CastTo(out Class to, Class from)
Try to safely down-cast base class to child class.
proto native void OnUpdate()
Definition tools.c:338