Arma Reforger Explorer 1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Loading...
Searching...
No Matches
SCR_CaptureAndHoldSpawnArea.c
Go to the documentation of this file.
1[EntityEditorProps(category: "GameScripted/GameMode/CaptureAndHold", description: "This area trigger detects enemies not belonging to assigned faction, and raises callbacks which allow penalizing abusive behaviour.")]
5
8class SCR_CaptureAndHoldSpawnArea : SCR_SpawnArea
9{
10 [Attribute("#AR-CAH-SpawnArea_LocalPlayer_Alert_Title", UIWidgets.EditBox, "The string that is shown as the main message to the local player upon entering this area as enemy faction.")]
11 protected LocalizedString m_sLocalPlayerAlertTitle;
12
13 [Attribute("#AR-CAH-SpawnArea_LocalPlayer_Alert_Text", UIWidgets.EditBox, "The additional string that is shown as the main message to the local player upon entering this area as enemy faction.")]
15
16 [Attribute("10.0", UIWidgets.EditBox, "Time spent in the are in seconds for an enemy to be killed after.")]
17 protected float m_fPenaltyTime;
18
21
24
26 protected RplComponent m_pRplComponent;
27
28 //------------------------------------------------------------------------------------------------
30 protected override void OnInit(IEntity owner)
31 {
32 super.OnInit(owner);
33
34 // Supress messages out of playmode, order of things is not quite guaranteed here
35 if (!GetGame().InPlayMode())
36 return;
37
38 m_pRplComponent = RplComponent.Cast(owner.FindComponent(RplComponent));
39 if (!m_pRplComponent)
40 Print("SCR_CaptureAndHoldSpawnArea cannot find RplComponent! Functionality will be limited!", LogLevel.WARNING);
41
42 // Register self in manager
43 SCR_CaptureAndHoldManager parentManager = SCR_CaptureAndHoldManager.GetAreaManager();
44 if (!parentManager)
45 {
46 Print("SCR_CaptureAndHoldSpawnArea cannot find SCR_CaptureAndHoldManager! Functionality might be limited!", LogLevel.WARNING);
47 return;
48 }
49
50 parentManager.RegisterSpawnArea(this);
51
52 // Authority only
53 if (!m_pRplComponent || !m_pRplComponent.IsMaster())
54 return;
55
57 SetEventMask(EntityEvent.FRAME);
58 }
59
60 //------------------------------------------------------------------------------------------------
63 protected override void OnFrame(IEntity owner, float timeSlice)
64 {
65 // Authority only
66 if (!m_pRplComponent || !m_pRplComponent.IsMaster() || !m_mTimeStamps)
67 return;
68
69 array<IEntity> toRemove = {};
70 float now = GetWorld().GetWorldTime();
71 ChimeraCharacter character;
72 CharacterControllerComponent controller;
73 foreach (IEntity occupant, float timeStamp : m_mTimeStamps)
74 {
75 if (now >= timeStamp + (m_fPenaltyTime * 1000.0))
76 {
77 character = ChimeraCharacter.Cast(occupant);
78 if (!character) // ???
79 {
80 toRemove.Insert(occupant);
81 continue;
82 }
83
84 controller = character.GetCharacterController();
85 if (!controller.IsDead())
86 {
87 controller.ForceDeath();
88 toRemove.Insert(character);
89 }
90 }
91 }
92
93 // Remove killer occupants
94 foreach (IEntity occupant : toRemove)
95 {
96 if (!occupant)
97 continue;
98
99 if (m_mTimeStamps.Contains(occupant))
100 m_mTimeStamps.Remove(occupant);
101 }
102 }
103
104 //------------------------------------------------------------------------------------------------
106 protected override event void OnCharacterEnter(IEntity character, bool isFriendly)
107 {
108 super.OnCharacterEnter(character, isFriendly);
109
110 // Raise callback for local player
112 OnLocalPlayerEnter(character, isFriendly);
113
114 // Authority only
115 if (!m_pRplComponent || !m_pRplComponent.IsMaster())
116 return;
117
118 // Enemy occupants only
119 if (isFriendly)
120 return;
121
122 if (!m_mTimeStamps.Contains(character))
123 m_mTimeStamps.Insert(character, GetWorld().GetWorldTime());
124 }
125
126 //------------------------------------------------------------------------------------------------
128 protected event void OnLocalPlayerEnter(IEntity character, bool isFriendly)
129 {
130 // Store the local player entity,
131 // death occuring and similar things come unexpectedly,
132 // this way we can always make sure we clear the previous state
133 m_pLastLocalEntity = character;
134
135 if (isFriendly)
136 return;
137
139 if (!popupNotifications)
140 return;
141
142 popupNotifications.PopupMsg(text: m_sLocalPlayerAlertTitle, duration: m_fPenaltyTime, text2: m_sLocalPlayerAlertText);
143 }
144
145 //------------------------------------------------------------------------------------------------
147 protected override event void OnCharacterExit(IEntity character, bool isFriendly)
148 {
149 super.OnCharacterExit(character, isFriendly);
150
151 // Raise callback for local player
152 if (character == m_pLastLocalEntity || character == SCR_PlayerController.GetLocalControlledEntity())
153 {
154 m_pLastLocalEntity = null;
155 OnLocalPlayerExit(character, isFriendly);
156 }
157
158 // Authority only
159 if (!m_pRplComponent || !m_pRplComponent.IsMaster())
160 return;
161
162 // Enemy occupants only
163 if (isFriendly)
164 return;
165
166 if (m_mTimeStamps.Contains(character))
167 m_mTimeStamps.Remove(character);
168 }
169
170 //------------------------------------------------------------------------------------------------
172 protected event void OnLocalPlayerExit(IEntity character, bool isFriendly)
173 {
174 if (isFriendly)
175 return;
176
178 if (!popupNotifications)
179 return;
180
181 if (popupNotifications.GetCurrentMsg())
182 popupNotifications.HideCurrentMsg();
183 }
184
185 //------------------------------------------------------------------------------------------------
188 {
189 // Far from ideal, OnDelete would be better
190
191 // Register self in manager
192 SCR_CaptureAndHoldManager parentManager = SCR_CaptureAndHoldManager.GetAreaManager();
193 if (!parentManager)
194 return;
195
196 parentManager.UnregisterSpawnArea(this);
197 }
198}
ArmaReforgerScripted GetGame()
Definition game.c:1398
void ~SCR_CaptureAndHoldSpawnArea()
Unregister self from parent manager.
LocalizedString m_sLocalPlayerAlertText
event void OnLocalPlayerEnter(IEntity character, bool isFriendly)
Called when the local character enters this area.
RplComponent m_pRplComponent
RplComponent attached to this are or null if none.
float m_fPenaltyTime
IEntity m_pLastLocalEntity
Last entity stored as the "local offender" or null if none.
event void OnLocalPlayerExit(IEntity character, bool isFriendly)
Called when the local character leaves this area.
ref map< IEntity, float > m_mTimeStamps
Authority map for time spent in the trigger for individual entities (offending ones).
enum SCR_ECompassType EntityEditorProps(category:"GameScripted/Gadgets", description:"Compass", color:"0 0 255 255")
Prefab data class for compass component.
proto external Managed FindComponent(typename typeName)
static IEntity GetLocalControlledEntity()
Takes care of dynamic and static onscreen popups.
void PopupMsg(string text, float duration=DEFAULT_DURATION, string text2="", int prio=-1, string param1="", string param2="", string param3="", string param4="", string text2param1="", string text2param2="", string text2param3="", string text2param4="", string sound="", SCR_EPopupMsgFilter category=SCR_EPopupMsgFilter.ALL, WorldTimestamp progressStart=null, WorldTimestamp progressEnd=null)
static SCR_PopUpNotification GetInstance()
SCR_PopupMessage GetCurrentMsg()
event void OnCharacterExit(IEntity character, bool isFriendly)
event void OnCharacterEnter(IEntity character, bool isFriendly)
Definition Types.c:486
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
EntityEvent
Various entity events.
Definition EntityEvent.c:14