Arma Reforger Explorer 1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Loading...
Searching...
No Matches
SCR_BaseWeaponAction.c
Go to the documentation of this file.
2{
3 const string PRIMARY_WEAPON_TYPE = "primary";
4 const string SECONDARY_WEAPON_TYPE = "secondary";
5 const string GRENADE_WEAPON_TYPE = "grenade";
6
7 protected bool m_bIsSwappingWeapons = false;
8 protected string m_sWeaponToSwapName = "";
10 protected ref array<WeaponSlotComponent> m_aWeaponSlots = {};
11 protected string m_sWeaponOnGroundType = "";
12 protected int m_iSameTypeSlotsCount = 0;
13
14 //------------------------------------------------------------------------------------------------
15 // Returns true if the equip or equip holster action can be perfomed. Also modifies the text depending on the conditions
17 {
18 ChimeraCharacter user = ChimeraCharacter.Cast( userEntity );
19 if ( !user )
20 return false;
21
22 BaseWeaponManagerComponent weaponManager = user.GetCharacterController().GetWeaponManagerComponent();
23 if ( !weaponManager )
24 return false;
25
29
30 // Eventually the equip actions will be removed for the grenades as whole
31 if ( m_sWeaponOnGroundType == GRENADE_WEAPON_TYPE )
32 return true;
33
34 m_aWeaponSlots.Clear();
35 weaponManager.GetWeaponsSlots( m_aWeaponSlots );
36
37 string weaponSlotType;
38
39 // If there is an empty slot of the same type as the weapon on the ground we are able to equip the weapon without replacing anything
40 foreach ( WeaponSlotComponent weaponSlot: m_aWeaponSlots )
41 {
42 weaponSlotType = weaponSlot.GetWeaponSlotType();
43
44 if ( weaponSlotType != m_sWeaponOnGroundType && !CharacterHandWeaponSlotComponent.Cast(weaponSlot) )
45 continue;
46
48
49 if ( !weaponSlot.GetWeaponEntity() )
50 return true;
51 }
52
53 BaseWeaponComponent weaponToSwap = GetWeaponToSwap( weaponManager );
54
55 if ( !weaponToSwap )
56 return false;
57
59
60 UIInfo weaponToSwapUIInfo = weaponToSwap.GetUIInfo();
61
62 // If the component is missing configuration we can fall back on the weapon slot name.
63 if ( weaponToSwapUIInfo )
64 {
65 string weaponToSwapName = weaponToSwapUIInfo.GetName();
66
67 if ( !weaponToSwapName.IsEmpty() )
68 m_sWeaponToSwapName = weaponToSwapName;
69 }
70 else
72
73 return true;
74 }
75
76 //------------------------------------------------------------------------------------------------
77 // Gets all the variables that are constant for the entire duration.
78 override void Init(IEntity pOwnerEntity, GenericComponent pManagerComponent)
79 {
80 super.Init(pOwnerEntity, pManagerComponent);
81
82 if ( !m_Item )
83 {
84 Print( "Pick up/equip UserAction is attached to an object which is not an item" , LogLevel.WARNING );
85 return;
86 }
87
88 m_pWeaponOnGroundComponent = BaseWeaponComponent.Cast( m_Item.GetOwner().FindComponent( BaseWeaponComponent ) );
89
91 return;
93 }
94
95
96 //------------------------------------------------------------------------------------------------
97 // Returns the weapon that will be swapped.
98 BaseWeaponComponent GetWeaponToSwap( notnull BaseWeaponManagerComponent weaponManager )
99 {
100 BaseWeaponComponent currentWeapon = weaponManager.GetCurrentWeapon();
101
102 // The equipped weapon will be swapped, if it's the same type as the one on the ground.
103 if (currentWeapon)
104 {
105 if ( currentWeapon.GetWeaponSlotType() == m_sWeaponOnGroundType )
106 return currentWeapon;
107 }
108
109 BaseWeaponComponent weaponToSwap;
110 string weaponSlotType;
111
112 // First compatible slot will be used if the equipped weapon doesn't match.
113 foreach ( WeaponSlotComponent weaponSlot: m_aWeaponSlots )
114 {
115 weaponSlotType = weaponSlot.GetWeaponSlotType();
116
117 if ( weaponSlotType == m_sWeaponOnGroundType )
118 {
119 weaponToSwap = BaseWeaponComponent.Cast( weaponSlot.GetWeaponEntity().FindComponent( BaseWeaponComponent ) );
120 if ( weaponToSwap )
121 return weaponToSwap;
122 }
123 }
124
125 return null;
126 }
127};
bool CanEquipOrReplaceWeapon(IEntity userEntity)
BaseWeaponComponent GetWeaponToSwap(notnull BaseWeaponManagerComponent weaponManager)
BaseWeaponComponent m_pWeaponOnGroundComponent
ref array< WeaponSlotComponent > m_aWeaponSlots
override void Init(IEntity pOwnerEntity, GenericComponent pManagerComponent)
modded version for to be used with the inventory 2.0
UIInfo - allows to define UI elements.
Definition UIInfo.c:14
proto void Print(void var, LogLevel level=LogLevel.NORMAL)
Prints content of variable to console/log.
LogLevel
Enum with severity of the logging message.
Definition LogLevel.c:14