DayZ Scripts
v1.21.156300 ยท Jun 20, 2023
 
Loading...
Searching...
No Matches
weapon_utils.c
Go to the documentation of this file.
1bool pushToChamberFromAttachedMagazine(Weapon_Base weapon, int muzzleIndex)
2{
3 Magazine mag = weapon.GetMagazine(muzzleIndex);
4 if (mag && !mag.IsDamageDestroyed())
5 {
6 if (LogManager.IsWeaponLogEnable()) { wpnDebugPrint("[wpnfsm] " + Object.GetDebugName(weapon) + " chamberFromAttachedMagazine, using attached magazine mag=" + mag.ToString()); }
7 float damage;
8 string type;
9 if (mag && mag.LocalAcquireCartridge(damage, type))
10 {
11 weapon.SelectionBulletShow();
12 if (LogManager.IsWeaponLogEnable()) { wpnDebugPrint("[wpnfsm] " + Object.GetDebugName(weapon) + " chamberFromAttachedMagazine, ok - cartridge acquired: dmg=" + damage + " type=" + type); }
13 }
14 else
15 Error("[wpnfsm] " + Object.GetDebugName(weapon) + " chamberFromAttachedMagazine, error - cannot take cartridge from magazine");
16
17 if (weapon.PushCartridgeToChamber(muzzleIndex, damage, type))
18 {
19 if (LogManager.IsWeaponLogEnable()) { wpnDebugPrint("[wpnfsm] " + Object.GetDebugName(weapon) + " chamberFromAttachedMagazine, ok - loaded chamber"); }
20 return true;
21 }
22 else
23 Error("[wpnfsm] " + Object.GetDebugName(weapon) + " chamberFromAttachedMagazine, error - cannot load chamber!");
24 }
25 else
26 {
27 if (LogManager.IsWeaponLogEnable()) { wpnDebugPrint("[wpnfsm] " + Object.GetDebugName(weapon) + " chamberFromAttachedMagazine - magazine destroyer or no attached"); }
28 //Error("[wpnfsm] " + Object.GetDebugName(weapon) + " chamberFromAttachedMagazine, error - no magazine attached");
29 }
30 return false;
31}
32
33bool pushToChamberFromInnerMagazine(Weapon_Base weapon, int muzzleIndex)
34{
35
36 if (LogManager.IsWeaponLogEnable()) { wpnDebugPrint("[wpnfsm] " + Object.GetDebugName(weapon) + " chamberFromInnerMagazine, using inner magazine."); }
37 float damage;
38 string type;
39 if (weapon.PopCartridgeFromInternalMagazine(muzzleIndex,damage, type))
40 {
41 weapon.SelectionBulletShow();
42 if (LogManager.IsWeaponLogEnable()) { wpnDebugPrint("[wpnfsm] " + Object.GetDebugName(weapon) + " chamberFromInnerMagazine, ok - cartridge acquired: dmg=" + damage + " type=" + type); }
43 }
44 else
45 Error("[wpnfsm] " + Object.GetDebugName(weapon) + " chamberFromInnerMagazine, error - cannot take cartridge from magazine");
46
47 if (weapon.PushCartridgeToChamber(muzzleIndex, damage, type))
48 {
49 if (LogManager.IsWeaponLogEnable()) { wpnDebugPrint("[wpnfsm] " + Object.GetDebugName(weapon) + " chamberFromInnerMagazine, ok - loaded chamber"); }
50 return true;
51 }
52 else
53 Error("[wpnfsm] " + Object.GetDebugName(weapon) + " chamberFromInnerMagazine, error - cannot load chamber!");
54
55 return false;
56}
57
58void ejectBulletAndStoreInMagazine(Weapon_Base weapon, int muzzleIndex, Magazine mag, DayZPlayer p)
59{
60 float damage = 0;
61 string type = string.Empty;
62 string magazineTypeName = weapon.GetChamberedCartridgeMagazineTypeName(muzzleIndex);
63 if (weapon.EjectCartridge(muzzleIndex, damage, type))
64 {
65 if (LogManager.IsWeaponLogEnable()) { wpnDebugPrint("[wpnfsm] " + Object.GetDebugName(weapon) + " ejectBulletAndStoreInMagazine, ejected chambered cartridge"); }
66 }
67 else
68 Error("[wpnfsm] " + Object.GetDebugName(weapon) + " ejectBulletAndStoreInMagazine, error - cannot eject chambered cartridge!");
69
70 bool is_single_or_server = !GetGame().IsMultiplayer() || GetGame().IsServer();
71 if (is_single_or_server)
72 {
73 if (mag == NULL)
74 {
75 // no magazine configured in parent state, looking in inventory
76 if (DayZPlayerUtils.HandleStoreCartridge(p, weapon, muzzleIndex, damage, type, magazineTypeName))
77 {
78 if (LogManager.IsWeaponLogEnable()) { wpnDebugPrint("[wpnfsm] " + Object.GetDebugName(weapon) + " ejectBulletAndStoreInMagazine, ok - cartridge stored in magazine"); }
79 }
80 else
81 Error("[wpnfsm] " + Object.GetDebugName(weapon) + " ejectBulletAndStoreInMagazine, error - cannot store cartridge!");
82 }
83 else
84 {
85 if (mag.ServerStoreCartridge(damage, type))
86 {
87 mag.SetSynchDirty();
88 if (LogManager.IsWeaponLogEnable()) { wpnDebugPrint("[wpnfsm] " + Object.GetDebugName(weapon) + " ejectBulletAndStoreInMagazine, ok - cartridge stored in user defined magazine"); }
89 }
90 else
91 Error("[wpnfsm] " + Object.GetDebugName(weapon) + " ejectBulletAndStoreInMagazine, error - cannot store cartridge in magazine");
92 }
93 }
94}
95
96bool magazinesHaveEqualSizes(notnull Magazine mag, notnull Magazine mag2)
97{
98 int w, h;
99 GetGame().GetInventoryItemSize(mag, w, h);
100 int w2, h2;
101 GetGame().GetInventoryItemSize(mag2, w2, h2);
102 if (w == w2 && h == h2)
103 {
104 if (LogManager.IsWeaponLogEnable()) { wpnDebugPrint("[wpnfsm] guard - same inventory sizes"); }
105 return true;
106 }
107
108 if (LogManager.IsWeaponLogEnable()) { wpnDebugPrint("[wpnfsm] guard - different inventory sizes"); }
109 return false;
110}
111
void wpnDebugPrint(string s)
Definition Debug.c:9
private void DayZPlayerUtils()
cannot be instantiated
proto void GetInventoryItemSize(InventoryItem item, out int width, out int height)
proto native bool IsServer()
proto native bool IsMultiplayer()
static bool IsWeaponLogEnable()
Definition Debug.c:640
proto native CGame GetGame()
void Error(string err)
Messagebox with error message.
Definition EnDebug.c:90
bool pushToChamberFromInnerMagazine(Weapon_Base weapon, int muzzleIndex)
bool magazinesHaveEqualSizes(notnull Magazine mag, notnull Magazine mag2)
void ejectBulletAndStoreInMagazine(Weapon_Base weapon, int muzzleIndex, Magazine mag, DayZPlayer p)
bool pushToChamberFromAttachedMagazine(Weapon_Base weapon, int muzzleIndex)
Definition weapon_utils.c:1