Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
SCR_EditableCharacterComponent.c
Go to the documentation of this file.
1 [ComponentEditorProps(category: "GameScripted/Editor (Editables)", description: "", icon: "WBData/ComponentEditorProps/componentEditor.png")]
3 {
4  [Attribute(category: "Character", params: "et")]
5  private ResourceName m_PrefabGroup;
6 
7  //------------------------------------------------------------------------------------------------
9  ResourceName GetPrefabGroup()
10  {
11  return m_PrefabGroup;
12  }
13 }
14 
16 
18 class SCR_EditableCharacterComponent : SCR_EditableEntityComponent
19 {
20  protected AIAgent m_Agent;
21  protected AIControlComponent m_AgentControlComponent;
22  protected float m_fPlayerDrawDistance;
23  protected ref ScriptInvoker m_OnUIRefresh = new ScriptInvoker();
24  protected ref ScriptInvoker Event_OnCharacterMovedInVehicle = new ScriptInvoker(); //~ Authority Only, Returns this character and vehicle character is placed in. Is NULL if placing failed
26  protected int m_inDeadPlayerID;
27 
28  [RplProp()]
29  protected bool m_bIsPlayerPending;
30 
32 
34  protected ref array<ECompartmentType> m_aForceVehicleCompartments;
35 
36  //------------------------------------------------------------------------------------------------
38  void SetIsPlayerPending(int playerId)
39  {
40  m_bIsPlayerPending = playerId != 0;
41 
42  RplComponent rplComponent = GetRplComponent();
43  if (rplComponent && rplComponent.Role() == RplRole.Authority)
44  Replication.BumpMe();
45  }
46 
47  //:| This is a similar approach with SCR_ChimeraAIAgent's IsPlayerPending_S method.
48  //:| The reason the similar behavior is also implemented here is that this approach allows us to extend the behavior within Editor if needed.
49  //------------------------------------------------------------------------------------------------
52  {
53  return m_bIsPlayerPending;
54  }
55 
56  //------------------------------------------------------------------------------------------------
59  AIAgent GetAgent()
60  {
61  return m_Agent;
62  }
63 
64  //------------------------------------------------------------------------------------------------
70  {
72  }
73 
74  //------------------------------------------------------------------------------------------------
78  {
79  if (!m_OnDestroyed)
81 
82  return m_OnDestroyed;
83  }
84 
85  //------------------------------------------------------------------------------------------------
89  {
90  if (!m_Agent)
91  return null;
92 
93  GenericEntity owner = GetOwner();
94  if (!owner)
95  return null;
96 
97  //--- Create group
98  SCR_EditableCharacterComponentClass prefabData = SCR_EditableCharacterComponentClass.Cast(GetEditableEntityData());
99  if (!prefabData)
100  return null;
101 
102  EntitySpawnParams params = new EntitySpawnParams();
103  params.Transform[3] = m_Agent.GetControlledEntity().GetOrigin();
104  IEntity groupEntity = GetGame().SpawnEntityPrefab(Resource.Load(prefabData.GetPrefabGroup()), owner.GetWorld(), params);
105  if (!groupEntity)
106  return null;
107 
108  AIGroup group = AIGroup.Cast(groupEntity);
109  if (!group)
110  {
111  Print(string.Format("Cannot create group, prefab '%1' is not AIGroup entity!", prefabData.GetPrefabGroup()), LogLevel.ERROR);
112  delete groupEntity;
113  return null;
114  }
115 
116  SCR_EditableEntityComponent groupEditableEntity = SCR_EditableEntityComponent.GetEditableEntity(groupEntity);
117  if (!groupEditableEntity)
118  {
119  Print(string.Format("Cannot create group, prefab '%1' does not contain SCR_EditableEntityComponent!", prefabData.GetPrefabGroup()), LogLevel.ERROR);
120  delete groupEntity;
121  return null;
122  }
123 
124  //--- Set group's faction
125  SCR_AIGroup groupScripted = SCR_AIGroup.Cast(group);
126  if (groupScripted)
127  {
128  FactionAffiliationComponent factionComponent = FactionAffiliationComponent.Cast(owner.FindComponent(FactionAffiliationComponent));
129  if (factionComponent)
130  {
131  Faction faction = factionComponent.GetAffiliatedFaction();
132  if (faction)
133  groupScripted.InitFactionKey(faction.GetFactionKey());
134  }
135  }
136 
137  //--- Add the entity to the group
138  group.AddAgent(m_Agent);
139 //
140  //group.SetWorldTransform(matrix);
141 
142  return groupEditableEntity;
143  }
144 
145  //------------------------------------------------------------------------------------------------
146  protected bool IsPlayer(IEntity owner = null)
147  {
148  if (m_inDeadPlayerID != 0)
149  return true;
150 
151  if (owner)
152  return SCR_PossessingManagerComponent.GetPlayerIdFromMainEntity(owner) > 0;
153  else if (m_Owner)
154  return SCR_PossessingManagerComponent.GetPlayerIdFromMainEntity(m_Owner) > 0;
155  else
156  return m_Owner == SCR_PlayerController.GetLocalMainEntity();
157  }
158 
159  //------------------------------------------------------------------------------------------------
160  //~ Check if local player is owner of entity
161  protected bool IsLocalPlayerOwner()
162  {
163  //~ Not replicated so always owner
164  if (!IsReplicated())
165  return true;
166 
167  RplComponent rplComp = RplComponent.Cast(GetOwner().FindComponent(RplComponent));
168  return !rplComp || rplComp.IsOwner();
169  }
170 
171  //------------------------------------------------------------------------------------------------
175  {
176  return !m_AgentControlComponent || !m_AgentControlComponent.IsAIActivated();
177  }
178 
179  //------------------------------------------------------------------------------------------------
180  protected void OnLifeStateChanged(ECharacterLifeState previousLifeState, ECharacterLifeState newLifeState)
181  {
182  if (newLifeState != ECharacterLifeState.DEAD)
183  return;
184 
185  //--- Cache player's ID upon death, so we can access it later
186  m_inDeadPlayerID = SCR_PossessingManagerComponent.GetPlayerIdFromMainEntity(GetOwner());
187 
188  m_OnUIRefresh.Invoke();
189 
190  if (m_OnDestroyed)
191  m_OnDestroyed.Invoke(GetOwner());
192  }
193 
194  //------------------------------------------------------------------------------------------------
195  override bool Delete(bool changedByUser = false, bool updateNavmesh = true)
196  {
198  if (compartmentAccess)
199  {
200  BaseCompartmentSlot slot = compartmentAccess.GetCompartment();
201  if (slot)
202  slot.SetCompartmentAccessible(true);
203  }
204 
205  return super.Delete(changedByUser, updateNavmesh);
206  }
207 
208  //------------------------------------------------------------------------------------------------
211  {
212  m_OnUIRefresh.Invoke();
213  }
214 
215  //------------------------------------------------------------------------------------------------
216 // override bool CanSetParent(SCR_EditableEntityComponent parentEntity)
217 // {
218 // if (!parentEntity)
219 // return true;
220 //
221 // EEditableEntityType type = parentEntity.GetEntityType();
222 // return type == EEditableEntityType.GROUP || type == EEditableEntityType.CHARACTER || type == EEditableEntityType.VEHICLE;
223 // }
224 
225  //------------------------------------------------------------------------------------------------
226  [RplRpc(RplChannel.Reliable, RplRcver.Owner)]
227  protected override void SetTransformOwner(vector transform[4])
228  {
229  super.SetTransformOwner(transform);
230 
232  }
233 
234  //------------------------------------------------------------------------------------------------
235  [RplRpc(RplChannel.Reliable, RplRcver.Owner)]
236  protected void PlayerTeleportedFeedback(bool isLongFade)
237  {
238  if (!m_Owner)
239  return;
240 
242  if (!playerController)
243  return;
244 
245  if (m_Owner != playerController.GetLocalControlledEntity())
246  return;
247 
248  SCR_PlayerTeleportedFeedbackComponent playerTeleportedComponent = SCR_PlayerTeleportedFeedbackComponent.Cast(playerController.FindComponent(SCR_PlayerTeleportedFeedbackComponent));
249  if (!playerTeleportedComponent)
250  return;
251 
252  playerTeleportedComponent.PlayerTeleported(GetOwner(), isLongFade, SCR_EPlayerTeleportedReason.EDITOR);
253  }
254 
255  //------------------------------------------------------------------------------------------------
259  void PlayerTeleportedByParentFeedback(bool isLongFade)
260  {
261  if (IsPlayerOrPossessed())
262  Rpc(PlayerTeleportedFeedback, isLongFade);
263  }
264 
265  //------------------------------------------------------------------------------------------------
266  //--- #HACK - when the game is paused, unpause it to ensure that the character is moved in/out of a compartment, which is an operation that needs simulation to be running
267  protected void UpdateCompartment(IEntity newParent)
268  {
269  ChimeraWorld world = GetGame().GetWorld();
270  if (world.IsGameTimePaused())
271  {
272  world.PauseGameTime(false);
273  GetGame().GetCallqueue().CallLater(WaitForCompartmentUpdate, 1, true, newParent);
274  }
275  }
276 
277  //------------------------------------------------------------------------------------------------
278  protected void WaitForCompartmentUpdate(IEntity newParent)
279  {
280  ChimeraWorld world = GetGame().GetWorld();
281  if (world.IsGameTimePaused() || !GetOwner() || CompartmentAccessComponent.GetVehicleIn(GetOwner()) == newParent)
282  {
283  world.PauseGameTime(true);
284  GetGame().GetCallqueue().Remove(WaitForCompartmentUpdate);
285  }
286  }
287 
288  //------------------------------------------------------------------------------------------------
289  override SCR_EditableEntityComponent SetParentEntity(SCR_EditableEntityComponent parentEntity, bool changedByUser = false)
290  {
291  //--- When moving to root or non-AI-compatible layer, create a group for the character in that layer
292  if (changedByUser && IsServer() && !GetOwner().IsDeleted() && !IsDestroyed())
293  {
294  AIControlComponent aiControl = AIControlComponent.Cast(GetOwner().FindComponent(AIControlComponent));
295  if (aiControl && aiControl.IsAIActivated())
296  {
297  EEditableEntityType parentType = EEditableEntityType.GENERIC;
298  if (parentEntity)
299  parentType = parentEntity.GetEntityType();
300 
301  if (parentType == EEditableEntityType.GENERIC)
302  {
303  SCR_EditableEntityComponent parentEntityPrev = parentEntity;
304  parentEntity = CreateGroupForCharacter();
305  parentEntity.SetParentEntity(parentEntityPrev);
306  return parentEntity;
307  }
308  }
309  }
310 
311  return super.SetParentEntity(parentEntity);
312  }
313 
314  //------------------------------------------------------------------------------------------------
315  //~ Authority Only. When spawned will force characters into vehicle position
316  override void ForceVehicleCompartments(notnull array<ECompartmentType> forceVehicleCompartments)
317  {
318  if (forceVehicleCompartments.IsEmpty())
319  return;
320 
322 
323  foreach (ECompartmentType compartment : forceVehicleCompartments)
324  {
325  m_aForceVehicleCompartments.Insert(compartment);
326  }
327  }
328 
329  //------------------------------------------------------------------------------------------------
330  override void OnParentEntityChanged(SCR_EditableEntityComponent parentEntity, SCR_EditableEntityComponent parentEntityPrev, bool changedByUser)
331  {
332  EEditableEntityType parentType;
333  if (parentEntity)
334  parentType = parentEntity.GetEntityType();
335 
336  switch (parentType)
337  {
338  case EEditableEntityType.VEHICLE:
339  {
340  //~ Checks if called for owner and is Player or possessed. Show teleport feedback
343 
344  //--- Execute on server, MoveInVehicle handles distribution to clients
345  if (Replication.IsServer())
346  {
347  Faction characterFaction = GetFaction();
348  Faction vehicleFaction = parentEntity.GetFaction();
349  //Is vehicle hostile? -> if so, do nothing
350  if (vehicleFaction && characterFaction.IsFactionEnemy(vehicleFaction))
351  {
352  Event_OnCharacterMovedInVehicle.Invoke(this, null);
353  break;
354  };
355 
357  if (compartmentAccess)
358  {
359  GenericEntity parentOwner = parentEntity.GetOwner();
360  bool isAi = !IsPlayerOrPossessed();
361 
362  //Add vehicle to group
363  if (isAi)
364  AddUsableVehicle(parentOwner);
365 
366  //~ Try placing character into vehicle
368  {
369  //~ Try to add character to any free vehicle slot
370  if (!isAi && compartmentAccess.MoveInVehicle(parentOwner, ECompartmentType.Pilot))
371  {
372  UpdateCompartment(parentOwner);
373  Event_OnCharacterMovedInVehicle.Invoke(this, parentOwner);
374  break;
375  }
376  if (compartmentAccess.MoveInVehicle(parentOwner, ECompartmentType.Turret))
377  {
378  UpdateCompartment(parentOwner);
379  Event_OnCharacterMovedInVehicle.Invoke(this, parentOwner);
380  break;
381  }
382  if (compartmentAccess.MoveInVehicle(parentOwner, ECompartmentType.Cargo))
383  {
384  UpdateCompartment(parentOwner);
385  Event_OnCharacterMovedInVehicle.Invoke(this, parentOwner);
386  break;
387  }
388  }
389 
390  //~ Force character into vehicle. Will delete the character if it fails to find a valid empty compartment
391  else
392  {
393  if (m_aForceVehicleCompartments.Contains(ECompartmentType.Pilot) && compartmentAccess.MoveInVehicle(parentOwner, ECompartmentType.Pilot))
394  {
395  UpdateCompartment(parentOwner);
396  Event_OnCharacterMovedInVehicle.Invoke(this, parentOwner);
397  break;
398  }
399 
400  if (m_aForceVehicleCompartments.Contains(ECompartmentType.Turret) && compartmentAccess.MoveInVehicle(parentOwner, ECompartmentType.Turret))
401  {
402  UpdateCompartment(parentOwner);
403  Event_OnCharacterMovedInVehicle.Invoke(this, parentOwner);
404  break;
405  }
406 
407  if (m_aForceVehicleCompartments.Contains(ECompartmentType.Cargo) && compartmentAccess.MoveInVehicle(parentOwner, ECompartmentType.Cargo))
408  {
409  UpdateCompartment(parentOwner);
410  Event_OnCharacterMovedInVehicle.Invoke(this, parentOwner);
411  break;
412  }
413 
414  //~ Failed to move in vehicle means delete character
415  Event_OnCharacterMovedInVehicle.Invoke(this, null);
416 
417  //~ Delete the next frame so entity is correctly initialized and delete is valid
418  GetGame().GetCallqueue().CallLater(Delete, param1: false, param2: true);
419  }
420 
421  //~ Failed to move in vehicle
422  Event_OnCharacterMovedInVehicle.Invoke(this, null);
423  }
424  }
425 
426  break;
427  }
428  case EEditableEntityType.GROUP:
429  case EEditableEntityType.CHARACTER:
430  {
431  if (!parentEntity)
432  break;
433 
434  SCR_EditableEntityComponent group = parentEntity.GetAIGroup();
435  super.OnParentEntityChanged(group, parentEntityPrev, changedByUser);
436  m_OnUIRefresh.Invoke(); //--- Update GUI when character moves to another group (in case it's a group of a different faction)
437  break;
438  }
439  default:
440  {
441  //--- Register player
442  super.OnParentEntityChanged(null, parentEntityPrev, changedByUser);
443  }
444  }
445 
448 
449  //--- Create a new group (ToDo: Solve together with entity<->entity interaction)
450  //SCR_EditableEntityComponent newGroup = CreateGroupForCharacter();
451  //SetParentEntity(newGroup);
452  }
453 
454  //------------------------------------------------------------------------------------------------
455  override void SetTransform(vector transform[4], bool changedByUser = false)
456  {
457  //--- Move out of a vehicle
458  CompartmentAccessComponent compartmentAccess = CompartmentAccessComponent.Cast(GetOwner().FindComponent(CompartmentAccessComponent));
459  if (compartmentAccess && compartmentAccess.IsInCompartment())
460  {
461  //~Todo: The delay is not ideal. It would need to be checked if all characters are dragged out of the vehicle in some other way
462  //Unregister from vehicle on next frame (checks with delay as all characters might be dragged out at the same time and it would think the vehicle is still occupied)
463  if (IsServer())
464  GetGame().GetCallqueue().CallLater(RemoveUsableVehicle, 100, false, GetVehicle().GetOwner(), true);
465 
466  //~ If moved out vehicle by GM. Check if player or possessed. If true send teleport feedback request
467  if (changedByUser && IsPlayerOrPossessed())
468  Rpc(PlayerTeleportedFeedback, false);
469 
470  compartmentAccess.MoveOutVehicle(-1, transform);
471 
472  UpdateCompartment(null);
473 
474  return;
475  }
476 
477  //--- Make sure characters don't fall through ground
478  transform[3][1] = Math.Max(transform[3][1], GetOwner().GetWorld().GetSurfaceY(transform[3][0], transform[3][2]));
479 
480  super.SetTransform(transform, changedByUser);
481  }
482 
483  //------------------------------------------------------------------------------------------------
484  override int GetPlayerID()
485  {
486  if (IsDestroyed())
487  return m_inDeadPlayerID;
488  else
489  return SCR_PossessingManagerComponent.GetPlayerIdFromMainEntity(GetOwner());
490  }
491 
492  //------------------------------------------------------------------------------------------------
493  override Faction GetFaction()
494  {
495  //--- Destroyed entities have no faction
496  if (IsDestroyed())
497  return null;
498 
499  //--- Get player faction
500  int playerID = GetPlayerID();
501  if (playerID > 0)
502  {
503  SCR_FactionManager factionManager = SCR_FactionManager.Cast(GetGame().GetFactionManager());
504  if (factionManager)
505  {
506  Faction faction = factionManager.GetPlayerFaction(playerID);
507  if (faction)
508  return faction;
509  }
510  }
511 
512  FactionAffiliationComponent factionAffiliation = FactionAffiliationComponent.Cast(m_Owner.FindComponent(FactionAffiliationComponent));
513  if (factionAffiliation)
514  return factionAffiliation.GetAffiliatedFaction();
515  else
516  return null;
517  }
518 
519  //------------------------------------------------------------------------------------------------
520  override ScriptInvoker GetOnUIRefresh()
521  {
522  return m_OnUIRefresh;
523  }
524 
525  //------------------------------------------------------------------------------------------------
527  {
528  return GetParentEntity();
529  }
530 
531  //------------------------------------------------------------------------------------------------
533  {
534  return this;
535  }
536 
537  //------------------------------------------------------------------------------------------------
539  {
541  if (compartmentAccess)
542  return SCR_EditableEntityComponent.GetEditableEntity(compartmentAccess.GetVehicle());
543  else
544  return null;
545  }
546 
547  //------------------------------------------------------------------------------------------------
548  override int GetCrew(out notnull array<CompartmentAccessComponent> crewCompartmentAccess, bool ignorePlayers = true)
549  {
550  //Ignore player
551  if (ignorePlayers)
552  {
553  if (GetGame().GetPlayerManager().GetPlayerIdFromControlledEntity(GetOwner()) > 0)
554  return 0;
555  }
556 
557  //Check if is in vehicle
558  CompartmentAccessComponent compartmentAccess = CompartmentAccessComponent.Cast(GetOwner().FindComponent(CompartmentAccessComponent));
559  if (compartmentAccess && compartmentAccess.IsInCompartment())
560  crewCompartmentAccess.Insert(compartmentAccess);
561 
562  return crewCompartmentAccess.Count();
563  }
564 
565  //------------------------------------------------------------------------------------------------
568  void AddUsableVehicle(IEntity vehicle)
569  {
570  if (IsPlayer() || !GetAIGroup())
571  return;
572 
574  if (!group)
575  return;
576 
577  SCR_AIGroup aiGroup = group.GetAIGroupComponent();
578  if (!aiGroup)
579  return;
580 
581  array<IEntity> usableVehicles = {};
582  aiGroup.GetUsableVehicles(usableVehicles);
583 
584  if (!usableVehicles.Contains(vehicle))
585  aiGroup.AddUsableVehicle(vehicle);
586  }
587 
588  //------------------------------------------------------------------------------------------------
593  void RemoveUsableVehicle(IEntity vehicle, bool checkIfVehicleStillUsed = true)
594  {
595  if (IsPlayer() || !GetAIGroup())
596  return;
597 
599  if (!group)
600  return;
601 
602  SCR_AIGroup aiGroup = group.GetAIGroupComponent();
603  if (!aiGroup)
604  return;
605 
606  array<IEntity> usableVehicles = {};
607 
608  //Check if vehicle is used by group
609  aiGroup.GetUsableVehicles(usableVehicles);
610  if (!usableVehicles.Contains(vehicle))
611  return;
612 
613  if (checkIfVehicleStillUsed)
614  {
615  set<SCR_EditableEntityComponent> entities = new set<SCR_EditableEntityComponent>();
616  group.GetChildren(entities, true);
617 
618  SCR_EditableVehicleComponent editableVehicle = SCR_EditableVehicleComponent.Cast(vehicle.FindComponent(SCR_EditableVehicleComponent));
619  if (editableVehicle)
620  {
622  array<CompartmentAccessComponent> crewCompartmentAccess = {};
623  editableVehicle.GetCrew(crewCompartmentAccess, true);
624 
625  foreach (CompartmentAccessComponent compartment : crewCompartmentAccess)
626  {
627  crew = SCR_EditableEntityComponent.Cast(compartment.GetOwner().FindComponent(SCR_EditableEntityComponent));
628 
629  if (crew == null || crew == this)
630  continue;
631 
632  //Vehicle is still used by group
633  if (entities.Contains(crew) && !compartment.IsGettingOut())
634  return;
635  }
636  }
637  }
638 
639  //Remove vehicle
640  aiGroup.RemoveUsableVehicle(vehicle);
641  }
642 
643 // //------------------------------------------------------------------------------------------------
644 // //! Remove all useable vehicle from group which unregisters all vehicles from the group. Call on server.
645 // void RemoveAllUsableVehicles()
646 // {
647 // if (IsPlayer() || !GetAIGroup())
648 // return;
649 //
650 // array<IEntity> usableVehicles = new array<IEntity>;
651 // m_Group.GetUsableVehicles(usableVehicles);
652 //
653 // foreach (IEntity vehicle : usableVehicles)
654 // m_Group.RemoveUsableVehicle(vehicle);
655 // }
656 
657  //------------------------------------------------------------------------------------------------
658  override float GetMaxDrawDistanceSq()
659  {
660  if (HasEntityState(EEditableEntityState.PLAYER))
661  {
663  {
665 
667  int playerId = GetPlayerID();
668 
669  bool isPlayerInVehicle = vehicle && playerId > 0;
670  m_fPlayerDrawDistance = core.GetPlayerDrawDistanceSq(isPlayerInVehicle);
671 
673  }
674 
675  return m_fPlayerDrawDistance;
676  }
677  else
678  {
679  return m_fMaxDrawDistance;
680  }
681  }
682 
683  //------------------------------------------------------------------------------------------------
685  void OnPlayerCharacterEnterCompartment(IEntity compartmentEntity)
686  {
688  }
689 
690  //------------------------------------------------------------------------------------------------
692  void OnPlayerCharacterExitCompartment(IEntity compartmentEntity)
693  {
695  }
696 
697  //------------------------------------------------------------------------------------------------
699  {
700  GenericEntity owner = GetOwner();
701 
702  //--- Entity is a player, don't activate AI
703  if (flags & EEditorPlacingFlags.CHARACTER_PLAYER)
704  return this;
705 
706  //--- Activate AI
707  m_AgentControlComponent = AIControlComponent.Cast(owner.FindComponent(AIControlComponent));
709  m_AgentControlComponent.ActivateAI();
710 
711  if (parent && AIGroup.Cast(parent.GetOwner()))
712  {
713  //--- Creating inside of a group - add character to it
714  return this;
715  }
716  else
717  {
718  //--- Creating outside of a group - create one for the character
720  if (group)
721  return group;
722  else
723  return this;
724  }
725  }
726 
727  //------------------------------------------------------------------------------------------------
729  {
730  //--- Activate AI
731  AIControlComponent control = AIControlComponent.Cast(GetOwner().FindComponent(AIControlComponent));
732  if (control)
733  control.ActivateAI();
734  }
735 
736  //------------------------------------------------------------------------------------------------
737  override bool Serialize(out SCR_EditableEntityComponent outTarget = null, out int outTargetIndex = -1, out EEditableEntitySaveFlag outSaveFlags = 0)
738  {
739  //--- Save SP player
740  if (!Replication.IsRunning() && IsPlayer())
741  outSaveFlags |= EEditableEntitySaveFlag.PLAYER;
742 
743  if (super.Serialize(outTarget, outTargetIndex, outSaveFlags))
744  {
746  if (compartmentAccess)
747  outTarget = SCR_EditableEntityComponent.GetEditableEntity(compartmentAccess.GetVehicle(outTargetIndex));
748 
749  return true;
750  }
751  else
752  {
753  return false;
754  }
755  }
756 
757  //------------------------------------------------------------------------------------------------
758  override void Deserialize(SCR_EditableEntityComponent target, int targetValue)
759  {
760  if (!target)
761  return;
762 
763  BaseCompartmentManagerComponent compartmentManager = BaseCompartmentManagerComponent.Cast(target.GetOwner().FindComponent(BaseCompartmentManagerComponent));
764  array<BaseCompartmentSlot> compartments = {};
765  compartmentManager.GetCompartments(compartments);
766 
768  compartmentAccess.MoveInVehicle(target.GetOwner(), compartments[targetValue]);
769  }
770 
771  //------------------------------------------------------------------------------------------------
772  override void OnPostInit(IEntity owner)
773  {
774  if (DiagMenu.GetValue(SCR_DebugMenuID.DEBUGUI_EDITOR_ENTITIES_DISABLE))
775  return;
776 
777  super.OnPostInit(owner);
778 
779  if (SCR_Global.IsEditMode(owner))
780  return;
781 
782  if (Replication.IsServer())
783  {
784  if (GetEntityType() != EEditableEntityType.CHARACTER)
785  {
786  Print(string.Format("SCR_EditableCharacterComponent must have type set to CHARACTER, it's %1!", typename.EnumToString(EEditableEntityType, GetEntityType())), LogLevel.ERROR);
787  return;
788  }
789 
790  m_AgentControlComponent = AIControlComponent.Cast(m_Owner.FindComponent(AIControlComponent));
792  m_Agent = m_AgentControlComponent.GetControlAIAgent();
793  }
794 
795  ChimeraCharacter char = ChimeraCharacter.Cast(owner);
796  if (char)
797  {
799  if (charController)
800  charController.m_OnLifeStateChanged.Insert(OnLifeStateChanged);
801  else
802  Print(string.Format("Failed to insert listened for lifestate changing on SCR_EditableEntityComponent of: " + GetOwner()), LogLevel.ERROR);
803  }
804  }
805 
806  //------------------------------------------------------------------------------------------------
807  // destructor
809  {
810  ChimeraCharacter char = ChimeraCharacter.Cast(GetOwner());
811  if (char)
812  {
814  if (charController)
815  charController.m_OnLifeStateChanged.Remove(OnLifeStateChanged);
816  }
817  }
818 }
GetOnCharacterMovedInVehicle
ScriptInvoker GetOnCharacterMovedInVehicle()
Definition: SCR_EditableCharacterComponent.c:69
ComponentEditorProps
SCR_FragmentEntityClass ComponentEditorProps
m_OnUIRefresh
protected ref ScriptInvoker m_OnUIRefresh
Definition: SCR_EditableCharacterComponent.c:23
SCR_EPlayerTeleportedReason
SCR_EPlayerTeleportedReason
Definition: SCR_PlayerTeleportedFeedbackComponent.c:50
EEditableEntityState
EEditableEntityState
Definition: EEditableEntityState.c:37
GetCrew
override int GetCrew(out notnull array< CompartmentAccessComponent > crewCompartmentAccess, bool ignorePlayers=true)
Definition: SCR_EditableCharacterComponent.c:548
ChimeraWorld
Definition: ChimeraWorld.c:12
m_OnDestroyed
protected ref ScriptInvokerEntity m_OnDestroyed
Definition: SCR_EditableCharacterComponent.c:25
GetFaction
override Faction GetFaction()
Definition: SCR_EditableCharacterComponent.c:493
SCR_EditableEntityCore
Definition: SCR_EditableEntityCore.c:10
GetCharacterController
protected SCR_CharacterControllerComponent GetCharacterController(IEntity from)
Definition: SCR_ItemPlacementComponent.c:50
SCR_PlayerController
Definition: SCR_PlayerController.c:31
SCR_CompartmentAccessComponent
Definition: SCR_CompartmentAccessComponent.c:15
IsDestroyed
override bool IsDestroyed()
Definition: SCR_EditableGroupComponent.c:433
ECharacterLifeState
ECharacterLifeState
Definition: ECharacterLifeState.c:12
UpdateCompartment
protected void UpdateCompartment(IEntity newParent)
Definition: SCR_EditableCharacterComponent.c:267
EOnEditorSessionLoad
override void EOnEditorSessionLoad(SCR_EditableEntityComponent parent)
Definition: SCR_EditableCharacterComponent.c:728
GetAIGroup
override SCR_EditableEntityComponent GetAIGroup()
Definition: SCR_EditableCharacterComponent.c:526
RplProp
SCR_RplTestEntityClass RplProp
Used for handling entity spawning requests for SCR_CatalogEntitySpawnerComponent and inherited classe...
GetGame
ArmaReforgerScripted GetGame()
Definition: game.c:1424
OnFactionChanged
void OnFactionChanged()
Called by SCR_EditableGroupComponent when faction is changed.
Definition: SCR_EditableCharacterComponent.c:210
OnPlayerCharacterExitCompartment
void OnPlayerCharacterExitCompartment(IEntity compartmentEntity)
Definition: SCR_EditableCharacterComponent.c:692
ECompartmentType
ECompartmentType
Definition: ECompartmentType.c:7
SetTransformOwner
protected override void SetTransformOwner(vector transform[4])
Definition: SCR_EditableCharacterComponent.c:227
SCR_EditableGroupComponent
void SCR_EditableGroupComponent(IEntityComponentSource src, IEntity ent, IEntity parent)
Definition: SCR_EditableGroupComponent.c:703
RplRpc
SCR_AchievementsHandlerClass ScriptComponentClass RplRpc(RplChannel.Reliable, RplRcver.Owner)] void UnlockOnClient(AchievementId achievement)
Definition: SCR_AchievementsHandler.c:11
EOnEditorPlace
override SCR_EditableEntityComponent EOnEditorPlace(out SCR_EditableEntityComponent parent, SCR_EditableEntityComponent recipient, EEditorPlacingFlags flags, bool isQueue, int playerID=0)
Definition: SCR_EditableCharacterComponent.c:698
GenericEntity
SCR_GenericBoxEntityClass GenericEntity
GetRplComponent
RplComponent GetRplComponent()
Returns the replication component associated to this entity.
Definition: SCR_RespawnComponent.c:200
func
func
Definition: SCR_AIThreatSystem.c:5
m_bIsPlayerPending
protected bool m_bIsPlayerPending
Definition: SCR_EditableCharacterComponent.c:29
SCR_CharacterControllerComponent
Definition: SCR_CharacterControllerComponent.c:35
GetPlayerController
proto external PlayerController GetPlayerController()
Definition: SCR_PlayerDeployMenuHandlerComponent.c:307
OnPlayerCharacterEnterCompartment
void OnPlayerCharacterEnterCompartment(IEntity compartmentEntity)
Definition: SCR_EditableCharacterComponent.c:685
m_bShouldRecalculateDrawDistance
protected bool m_bShouldRecalculateDrawDistance
Definition: SCR_EditableCharacterComponent.c:31
m_inDeadPlayerID
protected int m_inDeadPlayerID
Definition: SCR_EditableCharacterComponent.c:26
Event_OnCharacterMovedInVehicle
protected ref ScriptInvoker Event_OnCharacterMovedInVehicle
Definition: SCR_EditableCharacterComponent.c:24
IsPlayer
protected bool IsPlayer(IEntity owner=null)
Definition: SCR_EditableCharacterComponent.c:146
AddUsableVehicle
void AddUsableVehicle(IEntity vehicle)
Definition: SCR_EditableCharacterComponent.c:568
GetPlayerID
override int GetPlayerID()
Definition: SCR_EditableCharacterComponent.c:484
RemoveUsableVehicle
void RemoveUsableVehicle(IEntity vehicle, bool checkIfVehicleStillUsed=true)
Definition: SCR_EditableCharacterComponent.c:593
WaitForCompartmentUpdate
protected void WaitForCompartmentUpdate(IEntity newParent)
Definition: SCR_EditableCharacterComponent.c:278
m_aForceVehicleCompartments
protected ref array< ECompartmentType > m_aForceVehicleCompartments
Authority only, Allows character to be forced into a specific vehicle position and will delete it if ...
Definition: SCR_EditableCharacterComponent.c:34
SetIsPlayerPending
void SetIsPlayerPending(int playerId)
Definition: SCR_EditableCharacterComponent.c:38
Delete
override bool Delete(bool changedByUser=false, bool updateNavmesh=true)
Definition: SCR_EditableCharacterComponent.c:195
~SCR_EditableCharacterComponent
void ~SCR_EditableCharacterComponent()
Definition: SCR_EditableCharacterComponent.c:808
GetMaxDrawDistanceSq
override float GetMaxDrawDistanceSq()
Definition: SCR_EditableCharacterComponent.c:658
Attribute
typedef Attribute
Post-process effect of scripted camera.
EEditableEntityType
EEditableEntityType
Defines type of SCR_EditableEntityComponent. Assigned automatically based on IEntity inheritance.
Definition: EEditableEntityType.c:5
PlayerTeleportedByParentFeedback
void PlayerTeleportedByParentFeedback(bool isLongFade)
Definition: SCR_EditableCharacterComponent.c:259
GetAgent
AIAgent GetAgent()
Definition: SCR_EditableCharacterComponent.c:59
ScriptInvokerEntity
ScriptInvokerBase< ScriptInvokerEntityMethod > ScriptInvokerEntity
Definition: SCR_ScriptInvokerHelper.c:92
OnPostInit
override void OnPostInit(IEntity owner)
Called on PostInit when all components are added.
Definition: SCR_EditableCharacterComponent.c:772
EEditorPlacingFlags
EEditorPlacingFlags
Definition: EEditorPlacingFlags.c:1
Serialize
override bool Serialize(out SCR_EditableEntityComponent outTarget=null, out int outTargetIndex=-1, out EEditableEntitySaveFlag outSaveFlags=0)
Definition: SCR_EditableCharacterComponent.c:737
m_fPlayerDrawDistance
protected float m_fPlayerDrawDistance
Definition: SCR_EditableCharacterComponent.c:22
GetOwner
IEntity GetOwner()
Owner entity of the fuel tank.
Definition: SCR_FuelNode.c:128
OnParentEntityChanged
override void OnParentEntityChanged(SCR_EditableEntityComponent parentEntity, SCR_EditableEntityComponent parentEntityPrev, bool changedByUser)
Definition: SCR_EditableCharacterComponent.c:330
SCR_EditableEntityComponent
Definition: SCR_EditableEntityComponent.c:13
GetEntityType
override EEditableEntityType GetEntityType(IEntity owner=null)
Definition: SCR_EditablePlayerDelegateComponent.c:131
Faction
Definition: Faction.c:12
SetTransform
override void SetTransform(vector transform[4], bool changedByUser=false)
Definition: SCR_EditableCharacterComponent.c:455
SCR_Global
Definition: Functions.c:6
SCR_EditableCharacterComponentClass
Definition: SCR_EditableCharacterComponent.c:2
EEditableEntitySaveFlag
EEditableEntitySaveFlag
Definition: EEditableEntitySaveFlag.c:9
ForceVehicleCompartments
override void ForceVehicleCompartments(notnull array< ECompartmentType > forceVehicleCompartments)
Definition: SCR_EditableCharacterComponent.c:316
SCR_AIGroup
Definition: SCR_AIGroup.c:68
SetParentEntity
override SCR_EditableEntityComponent SetParentEntity(SCR_EditableEntityComponent parentEntity, bool changedByUser=false)
Definition: SCR_EditableCharacterComponent.c:289
PlayerTeleportedFeedback
protected void PlayerTeleportedFeedback(bool isLongFade)
Definition: SCR_EditableCharacterComponent.c:236
GetOnUIRefresh
override ScriptInvoker GetOnUIRefresh()
Definition: SCR_EditableCharacterComponent.c:520
params
Configs ServerBrowser KickDialogs params
Definition: SCR_NotificationSenderComponent.c:24
GetVehicle
override SCR_EditableEntityComponent GetVehicle()
Definition: SCR_EditableCharacterComponent.c:538
SCR_FactionManager
void SCR_FactionManager(IEntitySource src, IEntity parent)
Definition: SCR_FactionManager.c:461
CreateGroupForCharacter
SCR_EditableEntityComponent CreateGroupForCharacter()
Definition: SCR_EditableCharacterComponent.c:88
GetIsPlayerPending
bool GetIsPlayerPending()
Definition: SCR_EditableCharacterComponent.c:51
IsLocalPlayerOwner
protected bool IsLocalPlayerOwner()
Definition: SCR_EditableCharacterComponent.c:161
SCR_EditableEntityComponentClass
Definition: SCR_EditableEntityComponentClass.c:2
GetOnDestroyed
ScriptInvokerEntity GetOnDestroyed()
Definition: SCR_EditableCharacterComponent.c:77
SCR_DebugMenuID
SCR_DebugMenuID
This enum contains all IDs for DiagMenu entries added in script.
Definition: DebugMenuID.c:3
m_Agent
SCR_EditableCharacterComponentClass m_Agent
Special configuration for editable character.
OnLifeStateChanged
protected void OnLifeStateChanged(ECharacterLifeState previousLifeState, ECharacterLifeState newLifeState)
Will be called when the life state of the character changes.
Definition: SCR_EditableCharacterComponent.c:180
m_AgentControlComponent
protected AIControlComponent m_AgentControlComponent
Definition: SCR_EditableCharacterComponent.c:21
GetAIEntity
override SCR_EditableEntityComponent GetAIEntity()
Definition: SCR_EditableCharacterComponent.c:532
m_Owner
SCR_AIGroupUtilityComponentClass m_Owner
IsPlayerOrPossessed
bool IsPlayerOrPossessed()
Definition: SCR_EditableCharacterComponent.c:174
Deserialize
override void Deserialize(SCR_EditableEntityComponent target, int targetValue)
Definition: SCR_EditableCharacterComponent.c:758
category
params category
Definition: SCR_VehicleDamageManagerComponent.c:180