Arma Reforger Explorer 1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Loading...
Searching...
No Matches
LightUserAction.c
Go to the documentation of this file.
2{
4 [Attribute(defvalue: SCR_Enum.GetDefault(ELightType.Head), uiwidget: UIWidgets.ComboBox, enums: ParamEnumArray.FromEnum(ELightType))]
6
8 [Attribute("-1", uiwidget: UIWidgets.ComboBox, enums: { ParamEnum("Either", "-1"), ParamEnum("Left", "0"), ParamEnum("Right", "1")})]
9 protected int m_iLightSide;
10
12 [Attribute("1")]
13 protected bool m_bInteriorOnly;
14
16 [Attribute("1")]
17 protected bool m_bPilotOnly;
18
19 [Attribute("1", "True, if the action should be available to other passengers as long as pilot is not there or unconscious")]
21
22 [Attribute("#AR-UserAction_ControlledByDriver", "Text that will be shown to the passengers when driver of the vehicle is in control of this action")]
24
25 [Attribute(desc: "When anything is defined in here, this action will only be visible if the compartment section of the compartment the player is in is defined in here.")]
26 protected ref array<int> m_aDefinedCompartmentSectionsOnly;
27
28 [Attribute(desc: "When aynthing is defined in here, this action won't be visible if the compartment section of the compartment the player is in is defined in here.")]
29 protected ref array<int> m_aExcludeDefinedCompartmentSections;
30
31 //------------------------------------------------------------------------------------------------
32 override bool CanBePerformedScript(IEntity user)
33 {
34 ChimeraCharacter character = ChimeraCharacter.Cast(user);
35 if (!character)
36 return false;
37
38 //check if user can actually manipulate controls if he is not the pilot
39 if (!SCR_InteractionHandlerComponent.CanBeShownInVehicle(character, this, m_bPilotOnly, m_bPilotUncapableOverride, m_bInteriorOnly, m_aDefinedCompartmentSectionsOnly, m_aExcludeDefinedCompartmentSections))
40 {
42 return false;
43 }
44
45 return true;
46 }
47
48 //------------------------------------------------------------------------------------------------
49 override bool CanBroadcastScript()
50 {
51 return false;
52 }
53
54 //------------------------------------------------------------------------------------------------
55 override bool CanBeShownScript(IEntity user)
56 {
57 if (!GetLightManager())
58 return false;
59
60 ChimeraCharacter character = ChimeraCharacter.Cast(user);
61 if (!character)
62 return false;
63
64 //check only if user is inside same vehicle as long as we require that
65 return SCR_InteractionHandlerComponent.CanBeShownInVehicle(character, this, false, false, m_bInteriorOnly, m_aDefinedCompartmentSectionsOnly, m_aExcludeDefinedCompartmentSections);
66 }
67
68 //------------------------------------------------------------------------------------------------
69 override void PerformAction(IEntity pOwnerEntity, IEntity pUserEntity)
70 {
71 if (!pOwnerEntity || !pUserEntity)
72 return;
73
74 BaseLightManagerComponent lightManager = GetLightManager();
75 if (!lightManager)
76 return;
77
78 bool lightsState;
79
80
81 lightsState = lightManager.GetLightsState(m_eLightType, m_iLightSide);
82
83 if (RplSession.Mode() != RplMode.Client)
84 lightsState = !lightsState;
85
86 lightManager.SetLightsState(m_eLightType, lightsState, m_iLightSide);
87
88 if (lightsState)
89 {
90 // Disable opposite turn signal
91 if (m_iLightSide == 0)
92 lightManager.SetLightsState(m_eLightType, false, 1);
93 else if (m_iLightSide == 1)
94 lightManager.SetLightsState(m_eLightType, false, 0);
95 }
96
97 // Sound
98 PlaySound(pOwnerEntity, lightsState);
99 }
100
101 //------------------------------------------------------------------------------------------------
102 override bool GetActionNameScript(out string outName)
103 {
104 BaseLightManagerComponent lightManager = GetLightManager();
105
106 auto prefix = "";
107 UIInfo actionInfo = GetUIInfo();
108 if(actionInfo)
109 prefix = actionInfo.GetName() + " ";
110
111 if (lightManager && lightManager.GetLightsState(m_eLightType))
112 outName = prefix + "#AR-UserAction_State_Off";
113 else
114 outName = prefix + "#AR-UserAction_State_On";
115
116 return true;
117 }
118
119 //------------------------------------------------------------------------------------------------
121 {
122 UserActionContext userActionContext = GetActiveContext();
123 if (!userActionContext)
124 {
125 return false;
126 }
127 else
128 {
129 pos = GetOwner().CoordToLocal(userActionContext.GetOrigin());
130 return true;
131 }
132 }
133
134 //------------------------------------------------------------------------------------------------
135 void PlaySound(IEntity ownerEntity, bool lightsState)
136 {
137 // Sound
138 SoundComponent soundComponent = SoundComponent.Cast(ownerEntity.FindComponent(SoundComponent));
139 if (!soundComponent)
140 return;
141
142 vector offset;
143 if (GetLightAudioPos(offset))
144 {
145 if (lightsState)
146 soundComponent.SoundEventOffset(SCR_SoundEvent.SOUND_VEHICLE_CLOSE_LIGHT_ON, offset);
147 else
148 soundComponent.SoundEventOffset(SCR_SoundEvent.SOUND_VEHICLE_CLOSE_LIGHT_OFF, offset);
149 }
150 else
151 {
152 if (lightsState)
153 soundComponent.SoundEvent(SCR_SoundEvent.SOUND_VEHICLE_CLOSE_LIGHT_ON);
154 else
155 soundComponent.SoundEvent(SCR_SoundEvent.SOUND_VEHICLE_CLOSE_LIGHT_OFF);
156 }
157 }
158}
ELightType
Definition ELightType.c:8
RplMode
Mode of replication.
Definition RplMode.c:9
UI Textures DeployMenu Briefing conflict_HintBanner_1_UI desc
void SetCannotPerformReason(string reason)
proto external UserActionContext GetActiveContext()
Getter for m_pActiveContext.
proto external IEntity GetOwner()
Returns the parent entity of this action.
proto external UIInfo GetUIInfo()
Returns the UIInfo set for this user action or null if none.
proto external Managed FindComponent(typename typeName)
proto external vector CoordToLocal(vector coord)
int m_iLightSide
Side of turn signals.
ref array< int > m_aExcludeDefinedCompartmentSections
override bool CanBePerformedScript(IEntity user)
override bool GetActionNameScript(out string outName)
ELightType m_eLightType
Type of action instead of 8 different classes.
LocalizedString m_sBlockedByPilotText
ref array< int > m_aDefinedCompartmentSectionsOnly
override bool CanBroadcastScript()
bool m_bPilotOnly
Will action be available for entities seated in pilot compartment only?
bool m_bInteriorOnly
Will only be shown if user is in vehicle?
bool GetLightAudioPos(out vector pos)
void PlaySound(IEntity ownerEntity, bool lightsState)
override bool CanBeShownScript(IEntity user)
override void PerformAction(IEntity pOwnerEntity, IEntity pUserEntity)
UIInfo - allows to define UI elements.
Definition UIInfo.c:14
SCR_FieldOfViewSettings Attribute