Arma Reforger Explorer 1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Loading...
Searching...
No Matches
SCR_ChangeComparmentAction.c
Go to the documentation of this file.
2{
3 [Attribute("0", desc: "If enabled 'Compartment Slot Name' will be ignored and the Pilot compartment will be used")]
4 protected bool m_bUsePilotCompartment;
5
6 [Attribute("SeatsRear", desc: "Name of slot that holds the compartment Prefab we want to access. Found on: SlotManagerComponent.")]
7 protected string m_sCompartmentSlotName;
8
10
11 // Store the last found free compartment slot
13
14 //------------------------------------------------------------------------------------------------
15 override bool CanBeShownScript(IEntity user)
16 {
17 m_Character = ChimeraCharacter.Cast(user);
18
19 // We cannot be pilot nor interior, if we are not seated in vehicle at all.
20 if (!m_Character.IsInVehicle())
21 return false;
22
23 // If the compartment has never been checked before, do it first
26
27 // If no free compartment slot has been found, don't show this action
29 return false;
30
31 // Check if the last stored free compartment this is occupied
32 if (m_NonOccupiedSlot.GetOccupant())
34
35 return m_NonOccupiedSlot && !m_NonOccupiedSlot.GetOccupant();
36 }
37
38 //------------------------------------------------------------------------------------------------
39 override void PerformAction(IEntity pOwnerEntity, IEntity pUserEntity)
40 {
41 if (!pOwnerEntity || !pUserEntity)
42 return;
43
44 m_Character = ChimeraCharacter.Cast(pUserEntity);
45 if (!m_Character)
46 return;
47
48 BaseCompartmentSlot targetCompartment = m_NonOccupiedSlot;
49 if (!targetCompartment)
50 return;
51
52 CompartmentAccessComponent compartmentAccess = m_Character.GetCompartmentAccessComponent();
53 if (!compartmentAccess)
54 return;
55
56 if (!compartmentAccess.GetInVehicle(pOwnerEntity, targetCompartment, false, GetRelevantDoorIndex(pUserEntity), ECloseDoorAfterActions.INVALID, false))
57 return;
58
59 super.PerformAction(pOwnerEntity, pUserEntity);
60 }
61
62 //------------------------------------------------------------------------------------------------
63 override int GetRelevantDoorIndex(IEntity caller)
64 {
67
68 PlayerController playerController = GetGame().GetPlayerController();
69 if (!playerController || playerController.GetControlledEntity() != caller)
70 return -1;
71
72 InteractionHandlerComponent interactionHandler = InteractionHandlerComponent.Cast(playerController.FindComponent(InteractionHandlerComponent));
73 if (!interactionHandler)
74 return -1;
75
76 UserActionContext actionCtx = interactionHandler.GetCurrentContext();
77 if (actionCtx)
78 {
80 return m_NonOccupiedSlot.PickDoorIndexForPoint(actionCtx.GetOrigin());
81 else
82 return GetFreeCompartmentSlot().PickDoorIndexForPoint(actionCtx.GetOrigin());
83 }
84
85 return -1;
86 }
87
88 //------------------------------------------------------------------------------------------------
92 {
93 Vehicle vehicle = Vehicle.Cast(GetOwner().GetRootParent());
94 if (!vehicle)
95 return null;
96
97 SCR_BaseCompartmentManagerComponent compartmentManager;
98
100 {
101 PilotCompartmentSlot pilotCompartmentSlot = GetPilotCompartmentSlot();
102 if (pilotCompartmentSlot)
103 return pilotCompartmentSlot;
104
105 compartmentManager = SCR_BaseCompartmentManagerComponent.Cast(vehicle.FindComponent(SCR_BaseCompartmentManagerComponent));
106 }
107 else
108 {
109 SlotManagerComponent slotManagerComp = SlotManagerComponent.Cast(vehicle.FindComponent(SlotManagerComponent));
110 if (!slotManagerComp)
111 return null;
112
113 EntitySlotInfo slotInfo = slotManagerComp.GetSlotByName(m_sCompartmentSlotName);
114 if (!slotInfo)
115 return null;
116
117 IEntity entity = slotInfo.GetAttachedEntity();
118
119 if (entity)
120 compartmentManager = SCR_BaseCompartmentManagerComponent.Cast(entity.FindComponent(SCR_BaseCompartmentManagerComponent));
121 }
122
123 if (!compartmentManager)
124 return null;
125
126 array<BaseCompartmentSlot> outCompartments = {};
127 compartmentManager.GetCompartments(outCompartments);
128
129 // Get the first CompartmentSlot that is not occupied
130 foreach (BaseCompartmentSlot comp : outCompartments)
131 {
132 if (!comp.GetOccupant())
133 return comp;
134 }
135
136 return null;
137 }
138
139 //------------------------------------------------------------------------------------------------
143 {
144 CompartmentAccessComponent compartmentAccess = m_Character.GetCompartmentAccessComponent();
145 if (!compartmentAccess)
146 return null;
147
148 // Character is in compartment
149 // that belongs to owner of this action
150 BaseCompartmentSlot slot = compartmentAccess.GetCompartment();
151 if (!slot)
152 return null;
153
154 return PilotCompartmentSlot.Cast(slot);
155 }
156}
ArmaReforgerScripted GetGame()
Definition game.c:1398
UI Textures DeployMenu Briefing conflict_HintBanner_1_UI desc
Adds ability to attach an object to a slot.
proto external Managed FindComponent(typename typeName)
BaseCompartmentSlot GetFreeCompartmentSlot()
PilotCompartmentSlot GetPilotCompartmentSlot()
override int GetRelevantDoorIndex(IEntity caller)
override void PerformAction(IEntity pOwnerEntity, IEntity pUserEntity)
override bool CanBeShownScript(IEntity user)
enum EPhysicsLayerPresets Vehicle
Definition gameLib.c:24
IEntity GetOwner()
Owner entity of the fuel tank.
SCR_FieldOfViewSettings Attribute
ECloseDoorAfterActions