Arma Reforger Explorer 1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Loading...
Searching...
No Matches
SCR_ScenarioFrameworkActionBase.c
Go to the documentation of this file.
2class SCR_ScenarioFrameworkActionBase : BaseContainerObject
3{
4 [Attribute(desc: "If set to true, when this action gets activated, it will break the breakpoint in the Script Editor in CanActivate method from which you can step out to the OnActivate method and debug this specific action. This can be also set during runtime via Debug Menu > ScenarioFramework > Action Inspector")]
5 bool m_bDebug;
6
7 [Attribute(defvalue: "-1", uiwidget: UIWidgets.Graph, params: "-1 10000 1", desc: "How many times this action can be performed if this gets triggered? Value -1 for infinity")]
8 int m_iMaxNumberOfActivations;
9
10 IEntity m_Entity;
11 int m_iNumberOfActivations;
12
13 //------------------------------------------------------------------------------------------------
16 void Init(IEntity entity)
17 {
18 m_Entity = entity;
19
20 if (!SCR_BaseTriggerEntity.Cast(entity))
21 {
22 OnActivate(entity);
23 return;
24 }
25
26 ScriptInvoker pOnActivateInvoker = SCR_BaseTriggerEntity.Cast(entity).GetOnActivate();
27 if (pOnActivateInvoker)
28 pOnActivateInvoker.Insert(OnActivate);
29
30 ScriptInvoker pOnDeactivateInvoker = SCR_BaseTriggerEntity.Cast(entity).GetOnDeactivate();
31 if (pOnDeactivateInvoker)
32 pOnDeactivateInvoker.Insert(OnActivate); //registering OnDeactivate to OnActivate - we need both changes
33 }
34
35 //------------------------------------------------------------------------------------------------
38 bool CanActivate()
39 {
40 // Here you can step out to the OnActivate method and debug this specific action if m_bDebug attribute is set to true.
41 // This can be also adjusted during runtime via Debug Menu > ScenarioFramework > Action Inspector
42 if (m_bDebug)
43 Print("[SCR_ScenarioFrameworkActionBase.CanActivate] debug line (" + __FILE__ + " L" + __LINE__ + ")", LogLevel.WARNING);
44
45 if (m_iMaxNumberOfActivations != -1 && m_iNumberOfActivations >= m_iMaxNumberOfActivations)
46 {
47 if (m_bDebug)
48 {
49 if (m_Entity)
50 Print(string.Format("ScenarioFramework Action: Maximum number of activations reached for Action %1 attached on %2. Action won't do anything.", this, m_Entity.GetName()), LogLevel.ERROR);
51 else
52 Print(string.Format("ScenarioFramework Action: Maximum number of activations reached for Action %1. Action won't do anything.", this), LogLevel.ERROR);
53 }
54
55 return false;
56 }
57
58 m_iNumberOfActivations++;
59 return true;
60 }
61
62 //------------------------------------------------------------------------------------------------
68 bool ValidateInputEntity(IEntity object, SCR_ScenarioFrameworkGet getter, out IEntity entity)
69 {
70 if (!getter && object)
71 {
73 if (!layer)
74 {
75 Print(string.Format("ScenarioFramework Action: Action %1 attached on %2 is not called from layer and won't do anything.", this, object.GetName()), LogLevel.ERROR);
76 return false;
77 }
78
79 entity = layer.GetSpawnedEntity();
80 }
81 else
82 {
83 SCR_ScenarioFrameworkParam<IEntity> entityWrapper = SCR_ScenarioFrameworkParam<IEntity>.Cast(getter.Get());
84 if (!entityWrapper)
85 {
86 if (object)
87 Print(string.Format("ScenarioFramework Action: Issue with Getter detected for Action %1 attached on %2.", this, object.GetName()), LogLevel.ERROR);
88 else
89 Print(string.Format("ScenarioFramework Action: Issue with Getter detected for Action %1.", this), LogLevel.ERROR);
90
91 return false;
92 }
93
94 entity = entityWrapper.GetValue();
95 }
96
97 if (!entity)
98 {
99 if (object)
100 Print(string.Format("ScenarioFramework Action: Entity not found for Action %1 attached on %2.", this, object.GetName()), LogLevel.ERROR);
101 else
102 Print(string.Format("ScenarioFramework Action: Entity not found for Action %1.", this), LogLevel.ERROR);
103
104 return false;
105 }
106
107 return true;
108 }
109
110 //------------------------------------------------------------------------------------------------
112 void OnActivate(IEntity object);
113
114 //------------------------------------------------------------------------------------------------
116 array<ref SCR_ScenarioFrameworkActionBase> GetSubActions();
117
118 //------------------------------------------------------------------------------------------------
120 void RestoreToDefault()
121 {
122 m_iNumberOfActivations = 0;
123 array<ref SCR_ScenarioFrameworkActionBase> subActions = GetSubActions();
124 if (subActions && !subActions.IsEmpty())
125 {
126 foreach (SCR_ScenarioFrameworkActionBase subAction : subActions)
127 {
128 subAction.RestoreToDefault();
129 }
130 }
131 }
132
133 //------------------------------------------------------------------------------------------------
137 void SpawnObjects(notnull array<string> aObjectsNames, SCR_ScenarioFrameworkEActivationType eActivationType)
138 {
139 IEntity object;
141
142 foreach (string sObjectName : aObjectsNames)
143 {
144 object = GetGame().GetWorld().FindEntityByName(sObjectName);
145 if (!object)
146 {
147 Print(string.Format("ScenarioFramework Action: Can't spawn object set in slot %1. Slot doesn't exist", sObjectName), LogLevel.ERROR);
148 continue;
149 }
150
152 if (!layer)
153 {
154 Print(string.Format("Can't spawn object %1 - the slot doesn't have SCR_ScenarioFrameworkLayerBase component", sObjectName), LogLevel.ERROR);
155 continue;
156 }
157
158 if (layer.GetActivationType() != eActivationType)
159 {
160 Print(string.Format("Can't spawn object %1 - the slot has %2 activation type set instead of %3", sObjectName, layer.GetActivationType(), eActivationType), LogLevel.ERROR);
161 continue;
162 }
163
164 layer.Init(null, eActivationType);
165 layer.SetActivationType(SCR_ScenarioFrameworkEActivationType.SAME_AS_PARENT);
166 }
167 }
168}
override void Init()
ArmaReforgerScripted GetGame()
Definition game.c:1398
LayerPresets layer
SCR_AIAnimation_Loitering BaseContainerProps
Commanding menu commanding element class.
override void OnActivate()
UI Textures DeployMenu Briefing conflict_HintBanner_1_UI desc
void SCR_ScenarioFrameworkLayerBase(IEntityComponentSource src, IEntity ent, IEntity parent)
void RestoreToDefault()
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
SCR_FieldOfViewSettings Attribute
ScriptInvokerBase< func > ScriptInvoker
Definition tools.c:134