Arma Reforger Explorer 1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Loading...
Searching...
No Matches
SCR_RespawnComponent.c
Go to the documentation of this file.
1[ComponentEditorProps(category: "GameScripted/GameMode", description: "Communicator for RespawnSystemComponent. Should be attached to PlayerController.")]
5
7enum ERespawnSelectionResult
8{
9 OK = 0,
10 ERROR = 1,
11
13}
14
17class SCR_RespawnComponent : RespawnComponent
18{
20 protected PlayerController m_PlayerController;
21
23 protected RplComponent m_RplComponent;
24 // RespawnSystemComponent - has to be attached on a gameMode entity
25
29
30 private static ref ScriptInvokerVoid s_OnLocalPlayerSpawned;
31
32 //------------------------------------------------------------------------------------------------
35 static ScriptInvokerVoid SGetOnLocalPlayerSpawned()
36 {
37 if (!s_OnLocalPlayerSpawned)
38 s_OnLocalPlayerSpawned = new ScriptInvokerVoid();
39
40 return s_OnLocalPlayerSpawned;
41 }
42
43 // ON RESPAWN READY (notification from server to e.g. open respawn menu)
45
46 //------------------------------------------------------------------------------------------------
52
53 // ON CAN RESPAWN REQUEST
55
56 //------------------------------------------------------------------------------------------------
62
64
65 //------------------------------------------------------------------------------------------------
71
72 // ON CAN RESPAWN RESPONSE
74
75 //------------------------------------------------------------------------------------------------
82
84
85 //------------------------------------------------------------------------------------------------
92
93 // ON RESPAWN REQUEST
95
96 //------------------------------------------------------------------------------------------------
102
104
105 //------------------------------------------------------------------------------------------------
111
112 // ON RESPAWN RESPONSE
114
115 //------------------------------------------------------------------------------------------------
121
123
124 //------------------------------------------------------------------------------------------------
130
131 //------------------------------------------------------------------------------------------------
132 // ON FINALIZE START
134 //------------------------------------------------------------------------------------------------
142
143 #ifdef DEBUGUI_RESPAWN_REQUEST_COMPONENT_DIAG
144 static bool s_DebugRegistered;
145 #endif
146
147 //------------------------------------------------------------------------------------------------
149 static SCR_RespawnComponent GetInstance()
150 {
151 PlayerController playerController = GetGame().GetPlayerController();
152 if (playerController)
153 return SCR_RespawnComponent.Cast(playerController.FindComponent(SCR_RespawnComponent));
154 else
155 return null;
156 }
157
158 //------------------------------------------------------------------------------------------------
162 static SCR_RespawnComponent SGetLocalRespawnComponent()
163 {
164 PlayerController playerController = GetGame().GetPlayerController();
165 if (!playerController)
166 return null;
167
168 return SCR_RespawnComponent.Cast(playerController.GetRespawnComponent());
169 }
170
171 //------------------------------------------------------------------------------------------------
177 static SCR_RespawnComponent SGetPlayerRespawnComponent(int playerId)
178 {
179 PlayerController playerController = GetGame().GetPlayerManager().GetPlayerController(playerId);
180 if (!playerController)
181 return null;
182
183 return SCR_RespawnComponent.Cast(playerController.GetRespawnComponent());
184 }
185
186 //------------------------------------------------------------------------------------------------
188 RplComponent GetRplComponent()
189 {
190 return m_RplComponent;
191 }
192
193 //------------------------------------------------------------------------------------------------
194 [Obsolete("Use SCR_PlayerFactionAffiliationComponent instead!")]
196
197 //------------------------------------------------------------------------------------------------
198 [Obsolete("Use SCR_PlayerLoadoutComponent instead!")]
200
201 //------------------------------------------------------------------------------------------------
202 [Obsolete("Use SCR_RespawnComponent.RequestSpawn directly instead!")]
204
205 //------------------------------------------------------------------------------------------------
206 [Obsolete("Use SCR_PlayerLoadoutComponent instead!")]
208
209 //------------------------------------------------------------------------------------------------
210 [Obsolete("Use SCR_PlayerFactionAffiliationComponent instead!")]
212
213 //------------------------------------------------------------------------------------------------
214 [Obsolete("Use SCR_RespawnComponent.RequestSpawn directly instead!")]
216
217 //------------------------------------------------------------------------------------------------
220 {
222 return;
223
224 GenericEntity controlledEntity = GenericEntity.Cast(m_PlayerController.GetControlledEntity());
225 if (!controlledEntity)
226 return;
227
228 CharacterControllerComponent characterController = CharacterControllerComponent.Cast(controlledEntity.FindComponent(CharacterControllerComponent));
229 if (characterController)
230 {
231 characterController.ForceDeath();
232 return;
233 }
234 }
235
236 //------------------------------------------------------------------------------------------------
237 [Obsolete("Use SCR_PlayerLoadoutComponent instead!")]
238 protected void RequestPlayerLoadoutIndex(int loadoutIndex);
239
240 //------------------------------------------------------------------------------------------------
241 [Obsolete("Use SCR_PlayerFactionAffiliationComponent instead!")]
242 protected void RequestPlayerFactionIndex(int factionIndex);
243
244 //------------------------------------------------------------------------------------------------
245 [Obsolete("Use SCR_RespawnComponent.RequestSpawn directly instead!")]
246 protected void RequestPlayerSpawnPointIdentity(RplId spawnPointIdentity);
247
248 //------------------------------------------------------------------------------------------------
255
256 //------------------------------------------------------------------------------------------------
257 [RplRpc(RplChannel.Reliable, RplRcver.Owner)]
259 {
260 #ifdef _ENABLE_RESPAWN_LOGS
261 Print(string.Format("%1::Rpc_NotifyReadyForSpawn_O(playerId: %2)", Type().ToString(), GetPlayerController().GetPlayerId()), LogLevel.NORMAL);
262 #endif
263
265
266 #ifdef ENABLE_DIAG
267 if (Diag_IsCLISpawnEnabled())
268 Diag_RequestCLISpawn();
269 #endif
270 }
271
272 //------------------------------------------------------------------------------------------------
273 [Obsolete("Unsupported")]
275
276 //------------------------------------------------------------------------------------------------
277 [Obsolete("Use SCR_RespawnComponent.RequestSpawn instead.")]
278 void RequestRespawn();
279
280 //------------------------------------------------------------------------------------------------
281 #ifdef ENABLE_DIAG
282 override void OnDiag(IEntity owner, float timeSlice)
283 {
284 if (!DiagMenu.GetBool(SCR_DebugMenuID.DEBUGUI_RESPAWN_COMPONENT_DIAG))
285 return;
286
287 foreach (SCR_SpawnRequestComponent requestComponent : m_mRequestComponents)
288 {
289 requestComponent.DrawDiag();
290 }
291 }
292 #endif
293
294 //------------------------------------------------------------------------------------------------
295 override void OnPostInit(IEntity owner)
296 {
297 #ifdef ENABLE_DIAG
298 ConnectToDiagSystem(owner);
299 DiagMenu.RegisterBool(SCR_DebugMenuID.DEBUGUI_RESPAWN_COMPONENT_DIAG, "", "Respawn Component", "GameMode");
300 DiagMenu.RegisterBool(SCR_DebugMenuID.DEBUGUI_RESPAWN_COMPONENT_TIME, "", "Respawn Time Measures", "GameMode");
301 #endif
302
303 m_PlayerController = PlayerController.Cast(owner);
305 {
306 Print("SCR_RespawnComponent must be attached to PlayerController!", LogLevel.ERROR);
307 return;
308 }
309
310 SCR_SpawnLockComponent lockComponent = SCR_SpawnLockComponent.Cast(owner.FindComponent(SCR_SpawnLockComponent));
311 if (!lockComponent)
312 {
313 Print(string.Format("%1 does not have a %2 attached!",
314 Type().ToString(), SCR_SpawnLockComponent),
315 LogLevel.ERROR);
316 }
317
318 m_RplComponent = RplComponent.Cast(owner.FindComponent(RplComponent));
320
322 if (!gameMode)
323 {
324 Print("No game mode found in the world, SCR_RespawnComponent will not function correctly!", LogLevel.ERROR);
325 return;
326 }
327 }
328
329 //------------------------------------------------------------------------------------------------
330 override void OnDelete(IEntity owner)
331 {
332 DisconnectFromDiagSystem(owner);
333
334 super.OnDelete(owner);
335 }
336
337 //------------------------------------------------------------------------------------------------
353 {
354 SCR_SpawnRequestComponent requestComponent = GetRequestComponent(data);
355 if (!requestComponent)
356 {
357 Print(string.Format("%1::RequestRespawn(data: %2) could not find associated %3!",
358 Type().ToString(), data, SCR_SpawnRequestComponent), LogLevel.ERROR);
359 return false;
360 }
361
362 return requestComponent.RequestRespawn(data);
363 }
364
365 //------------------------------------------------------------------------------------------------
381 {
382 SCR_SpawnRequestComponent requestComponent = GetRequestComponent(data);
383 if (!requestComponent)
384 {
385 Print(string.Format("%1::RequestRespawn(data: %2) could not find associated %3!",
386 Type().ToString(), data, SCR_SpawnRequestComponent), LogLevel.ERROR);
387 return false;
388 }
389
390 return requestComponent.CanRequestRespawn(data);
391 }
392
393 //------------------------------------------------------------------------------------------------
397 {
398 array<GenericComponent> components = {};
399 FindComponents(SCR_SpawnRequestComponent, components);
400 foreach (GenericComponent genericComponent : components)
401 {
402 SCR_SpawnRequestComponent requestComponent = SCR_SpawnRequestComponent.Cast(genericComponent);
403 typename dataType = requestComponent.GetDataType();
404 if (m_mRequestComponents.Contains(dataType))
405 {
406 Debug.Error(string.Format("Cannot register %1! %2 already contains a mapping for %3 data type! (old: %4)",
407 requestComponent.Type().ToString(),
408 Type().ToString(),
409 dataType,
410 m_mRequestComponents[dataType].Type().ToString()));
411
412 continue;
413 }
414
415 m_mRequestComponents.Insert(dataType, requestComponent);
416
417 #ifdef _ENABLE_RESPAWN_LOGS
418 string typeName = "null";
419 if (dataType != typename.Empty)
420 typeName = dataType.ToString();
421 Print(string.Format("%1::RegisterRespawnRequestComponents() registered %2 component for requests of %3 type.", Type().ToString(),
422 requestComponent.Type().ToString(),
423 typeName), LogLevel.NORMAL);
424 #endif
425 }
426 }
427
428 //------------------------------------------------------------------------------------------------
432 protected SCR_SpawnRequestComponent GetRequestComponent(SCR_SpawnData data)
433 {
434 if (!data)
435 return null;
436
437 SCR_SpawnRequestComponent component;
438 m_mRequestComponents.Find(data.Type(), component);
439 return component;
440 }
441
442 #ifdef ENABLE_DIAG
443 //------------------------------------------------------------------------------------------------
446 static bool Diag_IsCLISpawnEnabled()
447 {
448 return System.IsCLIParam("autodeployFaction") || System.IsCLIParam("autodeployLoadout") ||
449 System.IsCLIParam("tdmf") || System.IsCLIParam("tdml");
450 }
451
452 //------------------------------------------------------------------------------------------------
454 void Diag_RequestCLISpawn()
455 {
456 int factionId = -1;
457 string fs;
458 if (System.GetCLIParam("autodeployFaction", fs) || System.GetCLIParam("tdmf", fs))
459 {
460 Faction factionFromKey = GetGame().GetFactionManager().GetFactionByKey(fs);
461
462 if (factionFromKey != null)
463 factionId = GetGame().GetFactionManager().GetFactionIndex(factionFromKey);
464 else
465 factionId = fs.ToInt();
466 }
467
468 int loadoutId = -1;
469 string ls;
470 if (System.GetCLIParam("autodeployLoadout", fs) || System.GetCLIParam("tdml", ls))
471 {
472 SCR_BasePlayerLoadout loadoutFromKey = GetGame().GetLoadoutManager().GetLoadoutByName(ls);
473
474 if (loadoutFromKey != null)
475 loadoutId = GetGame().GetLoadoutManager().GetLoadoutIndex(loadoutFromKey);
476 else
477 loadoutId = ls.ToInt();
478 }
479
480 Rpc(Rpc_RequestCLISpawn_S, factionId, loadoutId);
481 }
482
483 //------------------------------------------------------------------------------------------------
484 [RplRpc(RplChannel.Reliable, RplRcver.Server)]
485 protected void Rpc_RequestCLISpawn_S(int factionIdx, int loadoutIdx)
486 {
487 int ok = 0;
488 Faction faction = GetGame().GetFactionManager().GetFactionByIndex(factionIdx);
489 SCR_BasePlayerLoadout loadout = GetGame().GetLoadoutManager().GetLoadoutByIndex(loadoutIdx);
490
491 // backtrack faction index from loadout, if possible
492 if (!faction && loadout)
493 {
494 SCR_FactionPlayerLoadout factionLoadout = SCR_FactionPlayerLoadout.Cast(loadout);
495 if (factionLoadout)
496 faction = GetGame().GetFactionManager().GetFactionByKey(factionLoadout.GetFactionKey());
497 }
498
499 // select loadout at random, faction was given
500 if (faction && !loadout)
501 loadout = GetGame().GetLoadoutManager().GetRandomFactionLoadout(faction);
502
503 SCR_PlayerFactionAffiliationComponent factionComponent = SCR_PlayerFactionAffiliationComponent.Cast(m_PlayerController.FindComponent(SCR_PlayerFactionAffiliationComponent));
504 if (factionComponent)
505 {
506 if (factionComponent.RequestFaction(faction))
507 ok |= (1 << 1);
508 }
509
510 SCR_PlayerLoadoutComponent loadoutComponent = SCR_PlayerLoadoutComponent.Cast(m_PlayerController.FindComponent(SCR_PlayerLoadoutComponent));
511 if (loadoutComponent)
512 {
513 if (loadoutComponent.RequestLoadout(loadout))
514 ok |= (1 << 2);
515 }
516
517 if (loadout)
518 {
519 ResourceName resource = loadout.GetLoadoutResource();
520 SCR_SpawnPoint spawnPoint = SCR_SpawnPoint.GetSpawnPointsForFaction(faction.GetFactionKey()).GetRandomElement();
521 if (!resource.IsEmpty() && spawnPoint)
522 {
523 SCR_SpawnPointSpawnData spsd = new SCR_SpawnPointSpawnData(resource, spawnPoint.GetRplId());
524 if (RequestSpawn(spsd))
525 ok |= (1 << 3);
526 }
527 }
528
529 Rpc(Rpc_ResponseCLISpawn_O, ok);
530 }
531
532 //------------------------------------------------------------------------------------------------
533 [RplRpc(RplChannel.Reliable, RplRcver.Owner)]
534 protected void Rpc_ResponseCLISpawn_O(int response)
535 {
536 bool faction = (response & (1 << 1));
537 bool loadout = (response & (1 << 2));
538 bool spawn = (response & (1 << 3));
539
540 // TODO: check for good const usage
541 const string msg = "Server request to spawn using diagnostics mode processed (-autodeployFaction/-autodeployLoadout), result:\n\tFaction: %1, Loadout: %2, Spawn: %3";
542
543 string fs = "ERR";
544 if (faction)
545 fs = "OK";
546
547 string ls = "ERR";
548 if (loadout)
549 ls = "OK";
550
551 string ss = "ERR";
552 if (spawn)
553 ss = "OK";
554
555 Print(string.Format(msg, fs, ls, ss), LogLevel.NORMAL);
556 }
557
558 #endif
559
560 //------------------------------------------------------------------------------------------------
561 // constructor
566 {
567 }
568}
SCR_DebugMenuID
This enum contains all IDs for DiagMenu entries added in script.
Definition DebugMenuID.c:4
ArmaReforgerScripted GetGame()
Definition game.c:1398
enum EAIGroupCombatMode ComponentEditorProps(category:"GameScripted/AI", description:"Component for utility AI system for groups")
SCR_BaseGameMode GetGameMode()
RplComponent m_RplComponent
Get all prefabs that have the spawner data
Get all prefabs that have the spawner the given labels and are valid in the editor mode param catalogType Type to catalog to get prefabs from param editorMode Editor mode to get valid entries from param faction Faction(Optional)
SCR_FastTravelComponentClass m_PlayerController
bool RequestPlayerSpawnPoint(SCR_SpawnPoint spawnPoint)
void Rpc_NotifyReadyForSpawn_O()
OnRespawnReadyInvoker GetOnRespawnReadyInvoker_O()
OnRespawnRequestInvoker GetOnRespawnRequestInvoker_S()
OnRespawnRequestInvoker GetOnRespawnRequestInvoker_O()
ref OnCanRespawnResponseInvoker m_OnCanRespawnResponseInvoker_O
void RequestRespawn()
Sends a respawn request based on assigned loadout and selected spawn point.
ref OnRespawnResponseInvoker m_OnRespawnResponseInvoker_O
void RequestQuickRespawn()
ref map< typename, SCR_SpawnRequestComponent > m_mRequestComponents
void RequestPlayerFactionIndex(int factionIndex)
OnRespawnResponseInvoker GetOnRespawnResponseInvoker_O()
ref OnRespawnRequestInvoker m_OnRespawnFinalizeBeginInvoker_O
void RequestPlayerSpawnPointIdentity(RplId spawnPointIdentity)
OnRespawnResponseInvoker GetOnRespawnResponseInvoker_S()
OnCanRespawnResponseInvoker GetOnCanRespawnResponseInvoker_O()
void NotifyReadyForSpawn_S()
bool RequestPlayerLoadout(SCR_BasePlayerLoadout loadout)
OnRespawnRequestInvoker GetOnRespawnFinalizeBeginInvoker_O()
SCR_RespawnComponentClass OK
Result code for request/assign response.
Definition EMoveError.c:14
void RequestPlayerSuicide()
void RequestClearPlayerSpawnPoint()
bool RequestClearPlayerLoadout()
ref OnRespawnResponseInvoker m_OnRespawnResponseInvoker_S
bool RequestSpawn(SCR_SpawnData data)
SCR_SpawnRequestComponent GetRequestComponent(SCR_SpawnData data)
OnCanRespawnResponseInvoker GetOnCanRespawnResponseInvoker_S()
void RequestPlayerLoadoutIndex(int loadoutIndex)
ref OnCanRespawnRequestInvoker m_OnCanRespawnRequestInvoker_S
OnCanRespawnRequestInvoker GetOnCanRespawnRequestInvoker_O()
bool CanSpawn(SCR_SpawnData data)
bool RequestPlayerFaction(Faction faction)
SCR_RespawnComponentClass ERROR_FORBIDDEN
Can happen if we are setting a loadout from a faction to which we do not belong to or similar.
void SCR_RespawnComponent(IEntityComponentSource src, IEntity ent, IEntity parent)
ref OnRespawnRequestInvoker m_OnRespawnRequestInvoker_O
OnCanRespawnRequestInvoker GetOnCanRespawnRequestInvoker_S()
ref OnCanRespawnResponseInvoker m_OnCanRespawnResponseInvoker_S
ref OnRespawnRequestInvoker m_OnRespawnRequestInvoker_S
ref OnCanRespawnRequestInvoker m_OnCanRespawnRequestInvoker_O
ref OnRespawnReadyInvoker m_OnRespawnReadyInvoker_O
bool RequestClearPlayerFaction()
void RegisterRespawnRequestComponents(IEntity owner)
ScriptInvokerBase< ScriptInvokerVoidMethod > ScriptInvokerVoid
ScriptInvokerBase< RespawnResponseDelegate > OnRespawnResponseInvoker
ScriptInvokerBase< RespawnReadyDelegate > OnRespawnReadyInvoker
ScriptInvokerBase< CanRespawnRequestDelegate > OnCanRespawnRequestInvoker
ScriptInvokerBase< CanRespawnResponseDelegate > OnCanRespawnResponseInvoker
ScriptInvokerBase< RespawnRequestDelegate > OnRespawnRequestInvoker
int Type
Definition Debug.c:13
Diagnostic and developer menu system.
Definition DiagMenu.c:18
proto external Managed FindComponent(typename typeName)
Replication item identifier.
Definition RplId.c:14
bool RequestLoadout(SCR_BasePlayerLoadout loadout)
Spawn point entity defines positions on which players can possibly spawn.
Definition Types.c:486
void OnDiag(IEntity owner, float timeslice)
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
@ ERROR
Same as DELETE, but global error count for OnAfterLoad is affected.
Definition LogLevel.c:20
RplComponent GetRplComponent()
Returns the replication component associated to this entity.
proto external PlayerController GetPlayerController()
proto external int GetPlayerId()
void RplRpc(RplChannel channel, RplRcver rcver, RplCondition condition=RplCondition.None, string customConditionName="")
Definition EnNetwork.c:95
RplRcver
Definition RplRcver.c:59
RplChannel
Communication channel. Reliable is guaranteed to be delivered. Unreliable not.
Definition RplChannel.c:14
proto external string ToString()
Plain C++ pointer, no weak pointers, no memory management.