Arma Reforger Explorer 1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Loading...
Searching...
No Matches
SCR_BaseFactionCheckUserAction.c
Go to the documentation of this file.
1//------------------------------------------------------------------------------------------------
3{
4 [Attribute("3", desc: "Set faction of user that can use the action, will be ignored if non are selected. Requires a 'FactionAffiliationComponent' on the Owner or parent. It will always allow interaction if user does not have 'FactionAffiliationComponent'. Default faction is the faction associated with the Initial Owner faction. Flags are checked in order. DISALLOW ON NULL is only checked when Default faction check is not set.", uiwidget: UIWidgets.Flags, enums: ParamEnumArray.FromEnum(EActionFactionUsage), category: "Faction Settings")]
6
7 [Attribute("#AR-ActionInvalid_HostileFaction", desc: "Faction invalid faction for the user that tries to use the action (By default this means faction is hostile, replace if there is a diffrent meaning)")]
9
10 [Attribute("0", desc: "If entity itself does not have faction affiliation component then it will try to get the parents faction affiliation component if this is true")]
12
13 protected FactionAffiliationComponent m_OwnerFactionAffiliation;
14
15 //------------------------------------------------------------------------------------------------
16 override protected bool CanBePerformedScript(IEntity user)
17 {
18 //~ Action is invalid. Set cannnot perform reason
19 if (!IsFactionValid(user))
20 {
22 return false;
23 }
24 //~ Action can be performed
25 else
26 {
27 m_sCannotPerformReason = string.Empty;
28 return true;
29 }
30 }
31
32 //------------------------------------------------------------------------------------------------
33 protected bool IsFactionValid(IEntity user)
34 {
35 //~ No flags set so ignore
37 return true;
38
39 FactionAffiliationComponent userFactionAffiliation = FactionAffiliationComponent.Cast(user.FindComponent(FactionAffiliationComponent));
40
41 //~ None have a faction so both return true
42 if (!userFactionAffiliation)
43 return true;
44
45 //~ User is faction less so allow interaction
46 Faction userFaction = userFactionAffiliation.GetAffiliatedFaction();
47 if (!userFaction)
48 return true;
49
50 Faction ownerFaction;
51
52 //~ Checks current faction
53 if (m_eFactionUsageCheck & (EActionFactionUsage.SAME_CURRENT_FACTION | EActionFactionUsage.FRIENDLY_CURRENT_FACTION))
54 {
55 //~ Only check if has current faction
56 ownerFaction = m_OwnerFactionAffiliation.GetAffiliatedFaction();
57 if (ownerFaction)
58 {
59 //~ If faction is the same
60 if (SCR_Enum.HasFlag(m_eFactionUsageCheck, EActionFactionUsage.SAME_CURRENT_FACTION) && ownerFaction.GetFactionKey() == userFaction.GetFactionKey())
61 return true;
62
63 //~ If faction is friendly
64 if (SCR_Enum.HasFlag(m_eFactionUsageCheck, EActionFactionUsage.FRIENDLY_CURRENT_FACTION) && ownerFaction.IsFactionFriendly(userFaction))
65 return true;
66
67 //~ Current faction exists but is not the same (or if friendly is checked and is not friendly)
68 return false;
69 }
70 }
71
72 //~ Checks default faction
73 if (m_eFactionUsageCheck & (EActionFactionUsage.SAME_DEFAULT_FACTION | EActionFactionUsage.FRIENDLY_DEFAULT_FACTION))
74 {
75 //~ No default faction so return true
76 ownerFaction = m_OwnerFactionAffiliation.GetDefaultAffiliatedFaction();
77 if (!ownerFaction)
78 return true;
79
80 //~ If default faction is the same
81 if (SCR_Enum.HasFlag(m_eFactionUsageCheck, EActionFactionUsage.SAME_DEFAULT_FACTION) && ownerFaction.GetFactionKey() == userFaction.GetFactionKey())
82 return true;
83
84 //~ If default faction is friendly
85 if (SCR_Enum.HasFlag(m_eFactionUsageCheck, EActionFactionUsage.FRIENDLY_DEFAULT_FACTION) && ownerFaction.IsFactionFriendly(userFaction))
86 return true;
87
88 //~ Default faction exists but is not the same (or if friendly is checked and is not friendly)
89 return false;
90 }
91
92 //~ Has no current faction and did not check Default faction. So check if it is allowed to be used neutral
93 return !SCR_Enum.HasFlag(m_eFactionUsageCheck, EActionFactionUsage.DISALLOW_USE_ON_CURRENT_FACTION_NULL);
94 }
95
96 //------------------------------------------------------------------------------------------------
97 override void Init(IEntity pOwnerEntity, GenericComponent pManagerComponent)
98 {
99 m_OwnerFactionAffiliation = FactionAffiliationComponent.Cast(GetOwner().FindComponent(FactionAffiliationComponent));
100
102 m_OwnerFactionAffiliation = FactionAffiliationComponent.Cast(GetOwner().GetParent().FindComponent(FactionAffiliationComponent));
103 }
104};
105
@ SAME_CURRENT_FACTION
The user with the same faction as the current faction can interact with the support station.
@ FRIENDLY_DEFAULT_FACTION
he user with a faction that is a friendly faction to the default faction of the support station can i...
@ DISALLOW_USE_ON_CURRENT_FACTION_NULL
If set it disallows the support station to be used if the faction of the Support station is not set....
@ FRIENDLY_CURRENT_FACTION
The user with a faction that is a friendly faction as the current faction can interact with the suppo...
@ SAME_DEFAULT_FACTION
The user with the same faction as the default faction of the support station can interact with the su...
Faction GetParent()
UI Textures DeployMenu Briefing conflict_HintBanner_1_UI desc
string m_sCannotPerformReason
proto external Managed FindComponent(typename typeName)
A scripted action class having optional logic for playing audio as well as checking if the faction is...
override void Init(IEntity pOwnerEntity, GenericComponent pManagerComponent)
FactionAffiliationComponent m_OwnerFactionAffiliation
IEntity GetOwner()
Owner entity of the fuel tank.
SCR_FieldOfViewSettings Attribute