6 enum TA_EActivationPresence
14 void ScriptInvokerTriggerUpdated(
float activationCountdownTimer,
float tempWaitTime,
int playersCountByFactionInside,
int playersCountByFaction,
string playerActivationNotificationTitle,
bool triggerConditionsStatus,
float minimumPlayersNeededPercentage);
19 [
Attribute(
desc:
"Faction which is used for area control calculation. Leave empty for any faction.",
category:
"Trigger")]
20 protected FactionKey m_sOwnerFactionKey;
22 [
Attribute(
"0", UIWidgets.ComboBox,
"By whom the trigger is activated",
"", ParamEnumArray.FromEnum(TA_EActivationPresence),
category:
"Trigger")]
23 protected TA_EActivationPresence m_eActivationPresence;
25 [
Attribute(
desc:
"Fill the entity names here for detection. Is combined with other filters using OR.",
category:
"Trigger")]
26 protected ref array<string> m_aSpecificEntityNames;
28 [
Attribute(
desc:
"Fill the class names here for detection. Is combined with other filters using OR.",
category:
"Trigger")]
29 protected ref array<string> m_aSpecificClassNames;
31 [
Attribute(
desc:
"Which Prefabs and if their children will be detected by the trigger. Is combined with other filters using OR.",
category:
"Trigger")]
32 protected ref array<ref SCR_ScenarioFrameworkPrefabFilter> m_aPrefabFilter;
34 [
Attribute(
desc:
"Here you can input custom trigger conditions that you can create by extending the SCR_CustomTriggerConditions", uiwidget: UIWidgets.Object)]
35 protected ref array<ref SCR_CustomTriggerConditions> m_aCustomTriggerConditions;
37 [
Attribute(defvalue:
"1", UIWidgets.CheckBox,
desc:
"If you set some vehicle to be detected by the trigger, it will also search the inventory for vehicle prefabs/classes that are set",
category:
"Trigger")]
38 protected bool m_bSearchVehicleInventory;
40 [
Attribute(defvalue:
"1", UIWidgets.CheckBox,
desc:
"Activate the trigger once or everytime the activation condition is true?",
category:
"Trigger")]
41 protected bool m_bOnce;
43 [
Attribute(defvalue:
"0", UIWidgets.Slider,
desc:
"Minimum players needed to activate this trigger when PLAYER Activation presence is selected",
params:
"0 1 0.01", precision: 2,
category:
"Trigger")]
44 protected float m_fMinimumPlayersNeededPercentage;
46 [
Attribute(defvalue:
"0", UIWidgets.Slider,
desc:
"For how long the trigger conditions must be true in order for the trigger to activate. If conditions become false, timer resets",
params:
"0 86400 1",
category:
"Trigger")]
47 protected float m_fActivationCountdownTimer;
49 [
Attribute(defvalue:
"0", UIWidgets.CheckBox,
desc:
"Whether or not the notification is allowed to be displayed",
category:
"Trigger")]
50 protected bool m_bNotificationEnabled;
52 [
Attribute(defvalue:
"{47864BB47AB0B1F4}UI/layouts/HUD/CampaignMP/CampaignMainHUD.layout",
category:
"Trigger")]
53 protected ResourceName m_sCountdownHUD;
55 [
Attribute(
desc:
"Notification title text that will be displayed when the PLAYER Activation presence is selected",
category:
"Trigger")]
56 protected string m_sPlayerActivationNotificationTitle;
58 [
Attribute(defvalue:
"0", UIWidgets.CheckBox,
desc:
"Whether or not the audio sound is played and affected by the trigger",
category:
"Trigger")]
59 protected bool m_bEnableAudio;
61 [
Attribute(
"", UIWidgets.EditBox,
desc:
"Audio sound that will be playing when countdown is active.",
category:
"Trigger")]
62 protected string m_sCountdownAudio;
64 protected ref set<BaseContainer> m_aPrefabContainerSet =
new set<BaseContainer>();
66 protected ref ScriptInvoker m_OnChange;
69 protected bool m_bInitSequenceDone =
false;
70 protected bool m_bCountdownMusicPlaying;
71 protected ref array<IEntity> m_aEntitiesInside = {};
72 protected ref array<IEntity> m_aPlayersInside = {};
73 protected MusicManager m_MusicManager;
74 protected bool m_bTriggerConditionsStatus;
75 protected bool m_bTimerActive;
76 protected int m_iCountInsideTrigger;
78 static ref ScriptInvokerBase<ScriptInvokerTriggerUpdated> s_OnTriggerUpdated =
new ScriptInvokerBase<ScriptInvokerTriggerUpdated>();
83 void SetActivationPresence(TA_EActivationPresence EActivationPresence)
90 void SetSpecificClassName(array<string> aClassName)
92 foreach (
string className : aClassName)
101 void SetPrefabFilters(array<ref SCR_ScenarioFrameworkPrefabFilter> aPrefabFilter)
112 void SetSearchVehicleInventory(
bool search)
119 void SetOnce(
bool bOnce)
126 void SetNotificationEnabled(
bool notificationEnabled)
133 void SetTriggerConditionsStatus(
bool status)
140 void SetEnableAudio(
bool enableAudio)
147 void SetMinimumPlayersNeeded(
float minimumPlayersNeededPercentage)
154 void SetPlayerActivationNotificationTitle(
string sTitle)
161 void SetActivationCountdownTimer(
float activationCountdownTimer)
168 void SetCountdownAudio(
string sAudioName)
175 void SetCustomTriggerConditions(array<ref SCR_CustomTriggerConditions> triggerConditions)
182 void SetOwnerFaction(FactionKey sFaction)
184 FactionManager factionManager =
GetGame().GetFactionManager();
193 RplComponent comp = RplComponent.Cast(FindComponent(RplComponent));
194 return comp && comp.IsMaster();
206 ResourceName GetCountdownHUD()
213 float GetActivationCountdownTimer()
220 float GetActivationCountdownTimerTemp()
227 float GetMinimumPlayersNeededPercentage()
234 string GetPlayerActivationNotificationTitle()
241 bool GetNotificationEnabled()
248 bool GetTriggerConditionsStatus()
255 int GetCountInsideTrigger()
262 int GetCountEntitiesInside()
270 int GetPlayersCountByFaction()
273 array<int> aPlayerIDs = {};
275 GetGame().GetPlayerManager().GetPlayers(aPlayerIDs);
276 foreach (
int iPlayerID : aPlayerIDs)
285 if (!playerController)
288 if (playerController.GetLocalControlledEntityFaction() ==
m_OwnerFaction)
298 int GetSpecificClassCountInsideTrigger(
string className,
int targetCount = -1)
300 if (className.IsEmpty())
305 array<IEntity> aItemsToAdd = {};
311 if (!Vehicle.Cast(entity))
315 if (!inventoryComponent)
318 array<IEntity> aItems = {};
319 inventoryComponent.GetItems(aItems);
320 if (!aItems.IsEmpty())
321 aItemsToAdd.InsertAll(aItems);
324 if (!aItemsToAdd.IsEmpty())
335 if (entity.IsInherited(className.ToType()))
338 if (iCnt == targetCount)
347 int GetSpecificPrefabCountInsideTrigger(BaseContainer prefabContainer,
int targetCount = -1,
bool includeInheritance =
false)
354 array<IEntity> aItemsToAdd = {};
360 if (!Vehicle.Cast(entity))
364 if (!inventoryComponent)
367 array<IEntity> aItems = {};
368 inventoryComponent.GetItems(aItems);
369 if (!aItems.IsEmpty())
370 aItemsToAdd.InsertAll(aItems);
373 if (!aItemsToAdd.IsEmpty())
382 EntityPrefabData prefabData = entity.GetPrefabData();
386 BaseContainer container = prefabData.GetPrefab();
390 if (!includeInheritance)
392 if (container != prefabContainer)
401 if (container == prefabContainer)
407 container = container.GetAncestor();
411 if (iCnt == targetCount)
420 int GetCharacterCountByFactionInsideTrigger(
Faction faction,
int targetCount = -1)
423 SCR_ChimeraCharacter chimeraCharacter;
430 chimeraCharacter = SCR_ChimeraCharacter.Cast(entity);
431 if (!chimeraCharacter)
434 if (faction && chimeraCharacter.GetFaction() != faction)
438 if (iCnt == targetCount)
447 int GetPlayersCountByFactionInsideTrigger(
Faction faction)
452 SCR_ChimeraCharacter chimeraCharacter;
458 chimeraCharacter = SCR_ChimeraCharacter.Cast(entity);
459 if (!chimeraCharacter)
462 if (faction && chimeraCharacter.GetFaction() != faction)
477 void GetPlayersByFactionInsideTrigger(notnull out array<IEntity> aOut)
479 SCR_ChimeraCharacter chimeraCharacter;
486 chimeraCharacter = SCR_ChimeraCharacter.Cast(entity);
487 if (!chimeraCharacter)
509 void GetPlayersByFaction(notnull out array<IEntity> aOut)
511 array<int> aPlayerIDs = {};
513 GetGame().GetPlayerManager().GetPlayers(aPlayerIDs);
514 foreach (
int iPlayerID : aPlayerIDs)
517 if (!playerController)
520 if (playerController.GetLocalControlledEntityFaction() ==
m_OwnerFaction)
521 aOut.Insert(playerController.GetLocalMainEntity());
527 override bool ScriptedEntityFilterForQuery(IEntity ent)
531 SCR_ChimeraCharacter chimeraCharacter = SCR_ChimeraCharacter.Cast(ent);
532 if (!chimeraCharacter)
548 Vehicle vehicle = Vehicle.Cast(ent);
563 FactionAffiliationComponent factionAffiliation = FactionAffiliationComponent.Cast(ent.FindComponent(FactionAffiliationComponent));
564 if (!factionAffiliation)
567 return factionAffiliation.GetAffiliatedFaction() ==
m_OwnerFaction;
572 void FinishTrigger(IEntity ent)
586 void ActivationPresenceConditions()
604 protected void CustomTriggerConditions()
608 condition.CustomTriggerConditions(
this)
614 protected void HandleNetworkComponentForPlayersInside(IEntity ent)
621 ProcessPlayerNetworkComponent(entity,
false);
626 ProcessPlayerNetworkComponent(ent,
true);
631 protected void ProcessPlayerNetworkComponent(IEntity entity,
bool leftTrigger =
false)
634 int playerId = playerManager.GetPlayerIdFromControlledEntity(entity);
636 if (!playerController)
639 SCR_ScenarioFrameworkTriggerNetworkComponent triggerNetwork = SCR_ScenarioFrameworkTriggerNetworkComponent.Cast(playerController.FindComponent(SCR_ScenarioFrameworkTriggerNetworkComponent));
643 triggerNetwork.ReplicateTriggerState(
this, leftTrigger);
648 protected void HandleTimer()
655 GetGame().GetCallqueue().CallLater(UpdateTimer, 1000,
true);
658 if (GetCountInsideTrigger() == 0)
660 GetGame().GetCallqueue().Remove(UpdateTimer);
668 protected void UpdateTimer()
678 HandleNetworkComponentForPlayersInside(
null);
682 override protected event void OnActivate(IEntity ent)
687 override event protected void OnQueryFinished(
bool bIsEmpty)
689 super.OnQueryFinished(bIsEmpty);
700 ActivationPresenceConditions();
701 CustomTriggerConditions();
712 override protected event void OnDeactivate(IEntity ent)
716 GetGame().GetCallqueue().CallLater(OnDeactivateCalledLater, 100,
false, ent);
720 void OnDeactivateCalledLater(IEntity ent)
727 ActivationPresenceConditions();
728 CustomTriggerConditions();
732 HandleNetworkComponentForPlayersInside(ent);
751 StopMusic(m_sCountdownAudio);
756 void PlayMusic(
string sAudio)
772 Rpc(RpcDo_PlayMusic, sAudio);
776 [
RplRpc(RplChannel.Reliable, RplRcver.Broadcast)]
777 protected void RpcDo_PlayMusic(
string sAudio)
794 void StopMusic(
string sAudio)
809 Rpc(RpcDo_StopMusic, sAudio);
813 [
RplRpc(RplChannel.Reliable, RplRcver.Broadcast)]
814 protected void RpcDo_StopMusic(
string sAudio)
831 void OnChange(IEntity ent)
835 SCR_ScenarioFrameworkParam<IEntity> param =
new SCR_ScenarioFrameworkParam<IEntity>(ent);
841 ScriptInvoker GetOnChange()
851 protected void SetInitSequenceDone()
855 condition.Init(
this);
862 prefabFilter.SetPrefab(prefabFilterInput.m_sSpecificPrefabName);
863 prefabFilter.SetCheckPrefabHierarchy(prefabFilterInput.m_bIncludeChildren);
877 override protected void EOnInit(IEntity owner)
881 GetGame().GetCallqueue().CallLater(SetInitSequenceDone, 1000);
892 class SCR_CustomTriggerConditions
907 protected ref array<ref SCR_ScenarioFrameworkPrefabFilterCount>
m_aPrefabFilter;
913 BaseContainer baseContainer;
918 prefabFilter.SetPrefab(prefabFilterCount.m_sSpecificPrefabName);
919 prefabFilter.SetCheckPrefabHierarchy(prefabFilterCount.m_bIncludeChildren);
920 trigger.AddPrefabFilter(prefabFilter);
922 resource = Resource.Load(prefabFilterCount.m_sSpecificPrefabName);
923 if (!resource.IsValid())
926 prefabFilterCount.m_Resource = resource;
927 prefabFilterCount.m_PrefabContainer = resource.GetResource().ToBaseContainer();
938 if (trigger.GetSpecificPrefabCountInsideTrigger(prefabFilter.m_PrefabContainer, prefabFilter.m_iPrefabCount, prefabFilter.m_bIncludeChildren) >= prefabFilter.m_iPrefabCount)
940 triggerStatus =
true;
944 triggerStatus =
false;
949 trigger.SetTriggerConditionsStatus(triggerStatus);
954 class SCR_CustomTriggerConditionsSpecificClassNameCount : SCR_CustomTriggerConditions
959 [
Attribute(defvalue:
"1",
desc:
"How many entities of specific prefab are requiered to be inside the trigger",
params:
"0 100000 1",
category:
"Trigger")]
960 protected int m_iClassnameCount;
970 type = className.ToType();
972 trigger.AddClassType(
type);
983 if (trigger.GetSpecificClassCountInsideTrigger(className) >= m_iClassnameCount)
985 triggerStatus =
true;
989 triggerStatus =
false;
994 trigger.SetTriggerConditionsStatus(triggerStatus);