Arma Reforger Explorer 1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Loading...
Searching...
No Matches
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
18class SCR_EditableCharacterComponent : SCR_EditableEntityComponent
19{
20 protected AIAgent m_Agent;
21 protected AIControlComponent m_AgentControlComponent;
22 protected float m_fPlayerDrawDistance;
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 //------------------------------------------------------------------------------------------------
73
74 //------------------------------------------------------------------------------------------------
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
99 if (!prefabData)
100 return null;
101
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
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
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 // is GM deleting his player character
206 if (changedByUser && IsServer())
207 {
208 int deletedCharacterPlayerId = SCR_PossessingManagerComponent.GetPlayerIdFromMainEntity(GetOwner());
209
210 if (GetGame().GetPlayerManager().HasPlayerRole(deletedCharacterPlayerId, EPlayerRole.GAME_MASTER))
211 {
212 SCR_PlayerControllerGroupComponent groupController = SCR_PlayerControllerGroupComponent.GetPlayerControllerComponent(deletedCharacterPlayerId);
213 if (groupController)
214 {
215 groupController.RequestRemovePlayer(deletedCharacterPlayerId);
216 }
217 }
218 }
219
220 return super.Delete(changedByUser, updateNavmesh);
221 }
222
223 //------------------------------------------------------------------------------------------------
226 {
227 m_OnUIRefresh.Invoke();
228 }
229
230 //------------------------------------------------------------------------------------------------
231// override bool CanSetParent(SCR_EditableEntityComponent parentEntity)
232// {
233// if (!parentEntity)
234// return true;
235//
236// EEditableEntityType type = parentEntity.GetEntityType();
237// return type == EEditableEntityType.GROUP || type == EEditableEntityType.CHARACTER || type == EEditableEntityType.VEHICLE;
238// }
239
240 //------------------------------------------------------------------------------------------------
241 [RplRpc(RplChannel.Reliable, RplRcver.Owner)]
242 protected override void SetTransformOwner(vector transform[4])
243 {
244 super.SetTransformOwner(transform);
245
247 }
248
249 //------------------------------------------------------------------------------------------------
250 [RplRpc(RplChannel.Reliable, RplRcver.Owner)]
251 protected void PlayerTeleportedFeedback(bool isLongFade)
252 {
253 if (!m_Owner)
254 return;
255
257 if (!playerController)
258 return;
259
260 if (m_Owner != playerController.GetLocalControlledEntity())
261 return;
262
263 SCR_PlayerTeleportedFeedbackComponent playerTeleportedComponent = SCR_PlayerTeleportedFeedbackComponent.Cast(playerController.FindComponent(SCR_PlayerTeleportedFeedbackComponent));
264 if (!playerTeleportedComponent)
265 return;
266
267 playerTeleportedComponent.PlayerTeleported(GetOwner(), isLongFade, SCR_EPlayerTeleportedReason.EDITOR);
268 }
269
270 //------------------------------------------------------------------------------------------------
275 {
277 Rpc(PlayerTeleportedFeedback, isLongFade);
278 }
279
280 //------------------------------------------------------------------------------------------------
281 //--- #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
282 protected void UpdateCompartment(IEntity newParent)
283 {
284 ChimeraWorld world = GetGame().GetWorld();
285 if (world.IsGameTimePaused())
286 {
287 world.PauseGameTime(false);
288 GetGame().GetCallqueue().CallLater(WaitForCompartmentUpdate, 1, true, newParent);
289 }
290 }
291
292 //------------------------------------------------------------------------------------------------
293 protected void WaitForCompartmentUpdate(IEntity newParent)
294 {
295 ChimeraWorld world = GetGame().GetWorld();
296 if (world.IsGameTimePaused() || !GetOwner() || CompartmentAccessComponent.GetVehicleIn(GetOwner()) == newParent)
297 {
298 world.PauseGameTime(true);
299 GetGame().GetCallqueue().Remove(WaitForCompartmentUpdate);
300 }
301 }
302
303 //------------------------------------------------------------------------------------------------
304 override SCR_EditableEntityComponent SetParentEntity(SCR_EditableEntityComponent parentEntity, bool changedByUser = false)
305 {
306 //--- When moving to root or non-AI-compatible layer, create a group for the character in that layer
307 if (changedByUser && IsServer() && !GetOwner().IsDeleted() && !IsDestroyed())
308 {
309 AIControlComponent aiControl = AIControlComponent.Cast(GetOwner().FindComponent(AIControlComponent));
310 if (aiControl && aiControl.IsAIActivated())
311 {
312 EEditableEntityType parentType = EEditableEntityType.GENERIC;
313 if (parentEntity)
314 parentType = parentEntity.GetEntityType();
315
316 if (parentType == EEditableEntityType.GENERIC)
317 {
318 SCR_EditableEntityComponent parentEntityPrev = parentEntity;
319 parentEntity = CreateGroupForCharacter();
320 parentEntity.SetParentEntity(parentEntityPrev);
321 return parentEntity;
322 }
323 }
324 }
325
326 return super.SetParentEntity(parentEntity);
327 }
328
329 //------------------------------------------------------------------------------------------------
330 //~ Authority Only. When spawned will force characters into vehicle position
331 override void ForceVehicleCompartments(notnull array<ECompartmentType> forceVehicleCompartments)
332 {
333 if (forceVehicleCompartments.IsEmpty())
334 return;
335
337
338 foreach (ECompartmentType compartment : forceVehicleCompartments)
339 {
340 m_aForceVehicleCompartments.Insert(compartment);
341 }
342 }
343
344 //------------------------------------------------------------------------------------------------
345 override void OnParentEntityChanged(SCR_EditableEntityComponent parentEntity, SCR_EditableEntityComponent parentEntityPrev, bool changedByUser)
346 {
347 EEditableEntityType parentType;
348 if (parentEntity)
349 parentType = parentEntity.GetEntityType();
350
351 switch (parentType)
352 {
353 case EEditableEntityType.VEHICLE:
354 {
355 //~ Checks if called for owner and is Player or possessed. Show teleport feedback
358
359 //--- Execute on server, MoveInVehicle handles distribution to clients
360 if (Replication.IsServer())
361 {
362 Faction characterFaction = GetFaction();
363 Faction vehicleFaction = parentEntity.GetFaction();
364 //Is vehicle hostile? -> if so, do nothing
365 if (vehicleFaction && characterFaction.IsFactionEnemy(vehicleFaction))
366 {
367 Event_OnCharacterMovedInVehicle.Invoke(this, null);
368 break;
369 };
370
372 if (compartmentAccess)
373 {
374 GenericEntity parentOwner = parentEntity.GetOwner();
375 bool isAi = !IsPlayerOrPossessed();
376
377 //Add vehicle to group
378 if (isAi)
379 AddUsableVehicle(parentOwner);
380
381 ChimeraWorld world = GetGame().GetWorld();
382 //~ Try placing character into vehicle
384 {
385 //~ Try to add character to any free vehicle slot
386 if (compartmentAccess.MoveInVehicle(parentOwner, ECompartmentType.PILOT, world.IsGameTimePaused()))
387 {
388 UpdateCompartment(parentOwner);
389 Event_OnCharacterMovedInVehicle.Invoke(this, parentOwner);
390 break;
391 }
392 if (compartmentAccess.MoveInVehicle(parentOwner, ECompartmentType.TURRET, world.IsGameTimePaused()))
393 {
394 UpdateCompartment(parentOwner);
395 Event_OnCharacterMovedInVehicle.Invoke(this, parentOwner);
396 break;
397 }
398 if (compartmentAccess.MoveInVehicle(parentOwner, ECompartmentType.CARGO, world.IsGameTimePaused()))
399 {
400 UpdateCompartment(parentOwner);
401 Event_OnCharacterMovedInVehicle.Invoke(this, parentOwner);
402 break;
403 }
404 }
405
406 //~ Force character into vehicle. Will delete the character if it fails to find a valid empty compartment
407 else
408 {
409 if (m_aForceVehicleCompartments.Contains(ECompartmentType.PILOT) && compartmentAccess.MoveInVehicle(parentOwner, ECompartmentType.PILOT, world.IsGameTimePaused()))
410 {
411 UpdateCompartment(parentOwner);
412 Event_OnCharacterMovedInVehicle.Invoke(this, parentOwner);
413 break;
414 }
415
416 if (m_aForceVehicleCompartments.Contains(ECompartmentType.TURRET) && compartmentAccess.MoveInVehicle(parentOwner, ECompartmentType.TURRET, world.IsGameTimePaused()))
417 {
418 UpdateCompartment(parentOwner);
419 Event_OnCharacterMovedInVehicle.Invoke(this, parentOwner);
420 break;
421 }
422
423 if (m_aForceVehicleCompartments.Contains(ECompartmentType.CARGO) && compartmentAccess.MoveInVehicle(parentOwner, ECompartmentType.CARGO, world.IsGameTimePaused()))
424 {
425 UpdateCompartment(parentOwner);
426 Event_OnCharacterMovedInVehicle.Invoke(this, parentOwner);
427 break;
428 }
429
430 //~ Failed to move in vehicle means delete character
431 Event_OnCharacterMovedInVehicle.Invoke(this, null);
432
433 //~ Delete the next frame so entity is correctly initialized and delete is valid
434 GetGame().GetCallqueue().CallLater(Delete, param1: false, param2: true);
435 }
436
437 //~ Failed to move in vehicle
438 Event_OnCharacterMovedInVehicle.Invoke(this, null);
439 }
440 }
441
442 break;
443 }
444 case EEditableEntityType.GROUP:
445 case EEditableEntityType.CHARACTER:
446 {
447 if (!parentEntity)
448 break;
449
450 SCR_EditableEntityComponent group = parentEntity.GetAIGroup();
451 super.OnParentEntityChanged(group, parentEntityPrev, changedByUser);
452 m_OnUIRefresh.Invoke(); //--- Update GUI when character moves to another group (in case it's a group of a different faction)
453 break;
454 }
455 default:
456 {
457 //--- Register player
458 super.OnParentEntityChanged(null, parentEntityPrev, changedByUser);
459 }
460 }
461
464
465 //--- Create a new group (ToDo: Solve together with entity<->entity interaction)
466 //SCR_EditableEntityComponent newGroup = CreateGroupForCharacter();
467 //SetParentEntity(newGroup);
468 }
469
470 //------------------------------------------------------------------------------------------------
471 override bool SetTransform(vector transform[4], bool changedByUser = false)
472 {
473 //--- Make sure characters don't fall through ground
474 transform[3][1] = Math.Max(transform[3][1], GetOwner().GetWorld().GetSurfaceY(transform[3][0], transform[3][2]));
475
476 //--- Move out of a vehicle
477 CompartmentAccessComponent compartmentAccess = CompartmentAccessComponent.Cast(GetOwner().FindComponent(CompartmentAccessComponent));
478 if (compartmentAccess && compartmentAccess.IsInCompartment())
479 {
480 //~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
481 //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)
482 if (IsServer())
483 GetGame().GetCallqueue().CallLater(RemoveUsableVehicle, 100, false, GetVehicle().GetOwner(), true);
484
485 //~ If moved out vehicle by GM. Check if player or possessed. If true send teleport feedback request
486 if (changedByUser && IsPlayerOrPossessed())
488
489 // Get out of vehicle
490 RplComponent slotRplComponent = RplComponent.Cast(compartmentAccess.GetOwner().FindComponent(RplComponent));
491 RplId slotEntityID = slotRplComponent.Id();
492
493 Rpc(GetOutVehicleOwner, slotEntityID, transform);
494
495 return true;
496 }
497
498 return super.SetTransform(transform, changedByUser);
499 }
500
501 //------------------------------------------------------------------------------------------------
502 [RplRpc(RplChannel.Reliable, RplRcver.Owner)]
503 protected void GetOutVehicleOwner(RplId slotEntityID, vector transform[4])
504 {
505 RplComponent slotRplComponent = RplComponent.Cast(Replication.FindItem(slotEntityID));
506 IEntity slotEntity = slotRplComponent.GetEntity();
507
508 CompartmentAccessComponent compartmentAccess = CompartmentAccessComponent.Cast(slotEntity.FindComponent(CompartmentAccessComponent));
509
510 compartmentAccess.GetOutVehicle_NoDoor(transform, false, true);
511 UpdateCompartment(null);
512 }
513
514 //------------------------------------------------------------------------------------------------
515 override int GetPlayerID()
516 {
517 if (IsDestroyed())
518 return m_inDeadPlayerID;
519 else
520 return SCR_PossessingManagerComponent.GetPlayerIdFromMainEntity(GetOwner());
521 }
522
523 //------------------------------------------------------------------------------------------------
525 {
526 //--- Destroyed entities have no faction
527 if (IsDestroyed())
528 return null;
529
530 //--- Get player faction
531 int playerID = GetPlayerID();
532 if (playerID > 0)
533 {
534 SCR_FactionManager factionManager = SCR_FactionManager.Cast(GetGame().GetFactionManager());
535 if (factionManager)
536 {
537 Faction faction = factionManager.GetPlayerFaction(playerID);
538 if (faction)
539 return faction;
540 }
541 }
542
543 FactionAffiliationComponent factionAffiliation = FactionAffiliationComponent.Cast(m_Owner.FindComponent(FactionAffiliationComponent));
544 if (factionAffiliation)
545 return factionAffiliation.GetAffiliatedFaction();
546 else
547 return null;
548 }
549
550 //------------------------------------------------------------------------------------------------
552 {
553 return m_OnUIRefresh;
554 }
555
556 //------------------------------------------------------------------------------------------------
558 {
559 return GetParentEntity();
560 }
561
562 //------------------------------------------------------------------------------------------------
564 {
565 return this;
566 }
567
568 //------------------------------------------------------------------------------------------------
570 {
572 if (compartmentAccess)
573 return SCR_EditableEntityComponent.GetEditableEntity(compartmentAccess.GetVehicle());
574 else
575 return null;
576 }
577
578 //------------------------------------------------------------------------------------------------
579 override int GetCrew(out notnull array<CompartmentAccessComponent> crewCompartmentAccess, bool ignorePlayers = true)
580 {
581 //Ignore player
582 if (ignorePlayers)
583 {
584 if (GetGame().GetPlayerManager().GetPlayerIdFromControlledEntity(GetOwner()) > 0)
585 return 0;
586 }
587
588 //Check if is in vehicle
589 CompartmentAccessComponent compartmentAccess = CompartmentAccessComponent.Cast(GetOwner().FindComponent(CompartmentAccessComponent));
590 if (compartmentAccess && compartmentAccess.IsInCompartment())
591 crewCompartmentAccess.Insert(compartmentAccess);
592
593 return crewCompartmentAccess.Count();
594 }
595
596 //------------------------------------------------------------------------------------------------
600 {
601 if (IsPlayer() || !GetAIGroup())
602 return;
603
605 if (!group)
606 return;
607
608 SCR_AIGroup aiGroup = group.GetAIGroupComponent();
609 if (!aiGroup)
610 return;
611
613 if (!vehicleUsageComp)
614 return;
615
616 aiGroup.GetGroupUtilityComponent().m_VehicleMgr.TryAddVehicle(vehicleUsageComp);
617 }
618
619 //------------------------------------------------------------------------------------------------
624 void RemoveUsableVehicle(IEntity vehicle, bool checkIfVehicleStillUsed = true)
625 {
626 if (IsPlayer() || !GetAIGroup())
627 return;
628
630 if (!group)
631 return;
632
633 SCR_AIGroup aiGroup = group.GetAIGroupComponent();
634 if (!aiGroup)
635 return;
636
637
639 if (!vehicleUsageComp)
640 return;
641
643 //Check if vehicle is used by group
644 if (vehMgr.FindVehicle(vehicleUsageComp) == null)
645 return;
646
647 if (checkIfVehicleStillUsed)
648 {
649 set<SCR_EditableEntityComponent> entities = new set<SCR_EditableEntityComponent>();
650 group.GetChildren(entities, true);
651
652 SCR_EditableVehicleComponent editableVehicle = SCR_EditableVehicleComponent.Cast(vehicle.FindComponent(SCR_EditableVehicleComponent));
653 if (editableVehicle)
654 {
656 array<CompartmentAccessComponent> crewCompartmentAccess = {};
657 editableVehicle.GetCrew(crewCompartmentAccess, true);
658
659 foreach (CompartmentAccessComponent compartment : crewCompartmentAccess)
660 {
661 crew = SCR_EditableEntityComponent.Cast(compartment.GetOwner().FindComponent(SCR_EditableEntityComponent));
662
663 if (crew == null || crew == this)
664 continue;
665
666 //Vehicle is still used by group
667 if (entities.Contains(crew) && !compartment.IsGettingOut())
668 return;
669 }
670 }
671 }
672
673 //Remove vehicle
674 vehMgr.RemoveVehicle(vehicleUsageComp);
675 }
676
677// //------------------------------------------------------------------------------------------------
678// //! Remove all useable vehicle from group which unregisters all vehicles from the group. Call on server.
679// void RemoveAllUsableVehicles()
680// {
681// if (IsPlayer() || !GetAIGroup())
682// return;
683//
684// array<IEntity> usableVehicles = new array<IEntity>;
685// m_Group.GetUsableVehicles(usableVehicles);
686//
687// foreach (IEntity vehicle : usableVehicles)
688// m_Group.RemoveUsableVehicle(vehicle);
689// }
690
691 //------------------------------------------------------------------------------------------------
692 override float GetMaxDrawDistanceSq()
693 {
695 {
697 {
699
701 int playerId = GetPlayerID();
702
703 bool isPlayerInVehicle = vehicle && playerId > 0;
704 m_fPlayerDrawDistance = core.GetPlayerDrawDistanceSq(isPlayerInVehicle);
705
707 }
708
710 }
711 else
712 {
713 return m_fMaxDrawDistance;
714 }
715 }
716
717 //------------------------------------------------------------------------------------------------
720 {
722 }
723
724 //------------------------------------------------------------------------------------------------
727 {
729 }
730
731 //------------------------------------------------------------------------------------------------
733 {
734 GenericEntity owner = GetOwner();
735
736 //--- Entity is a player, don't activate AI
737 if (flags & EEditorPlacingFlags.CHARACTER_PLAYER)
738 return this;
739
740 //--- Activate AI
741 m_AgentControlComponent = AIControlComponent.Cast(owner.FindComponent(AIControlComponent));
743 m_AgentControlComponent.ActivateAI();
744
745 if (parent && AIGroup.Cast(parent.GetOwner()))
746 {
747 //--- Creating inside of a group - add character to it
748 return this;
749 }
750 else
751 {
752 //--- Creating outside of a group - create one for the character
754 if (group)
755 return group;
756 else
757 return this;
758 }
759 }
760
761 //------------------------------------------------------------------------------------------------
763 {
764 //--- Activate AI
765 AIControlComponent control = AIControlComponent.Cast(GetOwner().FindComponent(AIControlComponent));
766 if (control)
767 control.ActivateAI();
768 }
769
770 /*
771 //------------------------------------------------------------------------------------------------
772 override bool Serialize(out SCR_EditableEntityComponent outTarget = null, out int outTargetIndex = -1, out EEditableEntitySaveFlag outSaveFlags = 0)
773 {
774 //--- Save SP player
775 if (!Replication.IsRunning() && IsPlayer())
776 outSaveFlags |= EEditableEntitySaveFlag.PLAYER;
777
778 if (super.Serialize(outTarget, outTargetIndex, outSaveFlags))
779 {
780 SCR_CompartmentAccessComponent compartmentAccess = SCR_CompartmentAccessComponent.Cast(GetOwner().FindComponent(SCR_CompartmentAccessComponent));
781 if (compartmentAccess)
782 outTarget = SCR_EditableEntityComponent.GetEditableEntity(compartmentAccess.GetVehicle(outTargetIndex));
783
784 return true;
785 }
786 else
787 {
788 return false;
789 }
790 }
791
792 //------------------------------------------------------------------------------------------------
793 override void Deserialize(SCR_EditableEntityComponent target, int targetValue)
794 {
795 if (!target)
796 return;
797
798 BaseCompartmentManagerComponent compartmentManager = BaseCompartmentManagerComponent.Cast(target.GetOwner().FindComponent(BaseCompartmentManagerComponent));
799 array<BaseCompartmentSlot> compartments = {};
800 compartmentManager.GetCompartments(compartments);
801
802 SCR_CompartmentAccessComponent compartmentAccess = SCR_CompartmentAccessComponent.Cast(GetOwner().FindComponent(SCR_CompartmentAccessComponent));
803 compartmentAccess.GetInVehicle(target.GetOwner(), compartments[targetValue], true, -1, ECloseDoorAfterActions.INVALID, true);
804 }
805 */
806
807 //------------------------------------------------------------------------------------------------
808 override void OnPostInit(IEntity owner)
809 {
810 if (DiagMenu.GetValue(SCR_DebugMenuID.DEBUGUI_EDITOR_ENTITIES_DISABLE))
811 return;
812
813 super.OnPostInit(owner);
814
815 if (SCR_Global.IsEditMode(owner))
816 return;
817
818 if (Replication.IsServer())
819 {
820 if (GetEntityType() != EEditableEntityType.CHARACTER)
821 {
822 Print(string.Format("SCR_EditableCharacterComponent must have type set to CHARACTER, it's %1!", typename.EnumToString(EEditableEntityType, GetEntityType())), LogLevel.ERROR);
823 return;
824 }
825
826 m_AgentControlComponent = AIControlComponent.Cast(m_Owner.FindComponent(AIControlComponent));
828 m_Agent = m_AgentControlComponent.GetControlAIAgent();
829 }
830
831 ChimeraCharacter char = ChimeraCharacter.Cast(owner);
832 if (char)
833 {
835 if (charController)
836 charController.m_OnLifeStateChanged.Insert(OnLifeStateChanged);
837 else
838 Print(string.Format("Failed to insert listened for lifestate changing on SCR_EditableEntityComponent of: " + GetOwner()), LogLevel.ERROR);
839 }
840 }
841
842 //------------------------------------------------------------------------------------------------
843 // destructor
845 {
847 if (char)
848 {
850 if (charController)
851 charController.m_OnLifeStateChanged.Remove(OnLifeStateChanged);
852 }
853 }
854}
SCR_EAIThreatSectorFlags flags
SCR_DebugMenuID
This enum contains all IDs for DiagMenu entries added in script.
Definition DebugMenuID.c:4
ECompartmentType
EEditorPlacingFlags
EPlayerRole
Definition EPlayerRole.c:8
ArmaReforgerScripted GetGame()
Definition game.c:1398
SCR_ChimeraAIAgent m_Agent
enum EAIGroupCombatMode ComponentEditorProps(category:"GameScripted/AI", description:"Component for utility AI system for groups")
SCR_CharacterControllerComponent GetCharacterController()
SCR_CacheNoteComponentClass ScriptComponentClass RplProp()] protected ref array< string > m_aLines
void RemoveUsableVehicle(IEntity vehicle, bool checkIfVehicleStillUsed=true)
ref ScriptInvokerEntity m_OnDestroyed
bool GetIsPlayerPending()
ref array< ECompartmentType > m_aForceVehicleCompartments
Authority only, Allows character to be forced into a specific vehicle position and will delete it if ...
bool m_bShouldRecalculateDrawDistance
void UpdateCompartment(IEntity newParent)
void PlayerTeleportedFeedback(bool isLongFade)
float m_fPlayerDrawDistance
void SetIsPlayerPending(int playerId)
bool IsLocalPlayerOwner()
void ~SCR_EditableCharacterComponent()
AIControlComponent m_AgentControlComponent
void AddUsableVehicle(IEntity vehicle)
void OnPlayerCharacterEnterCompartment(IEntity compartmentEntity)
AIAgent GetAgent()
SCR_EditableEntityComponent CreateGroupForCharacter()
ref ScriptInvoker Event_OnCharacterMovedInVehicle
void GetOutVehicleOwner(RplId slotEntityID, vector transform[4])
bool IsPlayer(IEntity owner=null)
ScriptInvoker GetOnCharacterMovedInVehicle()
ScriptInvokerEntity GetOnDestroyed()
void PlayerTeleportedByParentFeedback(bool isLongFade)
void OnPlayerCharacterExitCompartment(IEntity compartmentEntity)
override bool Delete(bool changedByUser=false, bool updateNavmesh=true)
bool IsPlayerOrPossessed()
ref ScriptInvoker m_OnUIRefresh
void WaitForCompartmentUpdate(IEntity newParent)
void SCR_EditableGroupComponent(IEntityComponentSource src, IEntity ent, IEntity parent)
void PlayerTeleportedFeedback()
Add feedback to players that they are teleported when inside of the vehicle.
void SCR_FactionManager(IEntitySource src, IEntity parent)
ScriptInvokerBase< ScriptInvokerEntityMethod > ScriptInvokerEntity
void SetCompartmentAccessible(bool val)
Diagnostic and developer menu system.
Definition DiagMenu.c:18
proto external GenericComponent FindComponent(typename typeName)
void Rpc(func method, void p0=NULL, void p1=NULL, void p2=NULL, void p3=NULL, void p4=NULL, void p5=NULL, void p6=NULL, void p7=NULL)
proto external Managed FindComponent(typename typeName)
proto external BaseWorld GetWorld()
Definition Math.c:13
Main replication API.
Definition Replication.c:14
Object holding reference to resource. In destructor release the resource.
Definition Resource.c:25
Replication item identifier.
Definition RplId.c:14
bool InitFactionKey(string factionKey)
SCR_AIGroupUtilityComponent GetGroupUtilityComponent()
ref SCR_AIGroupVehicleManager m_VehicleMgr
SCR_AIGroupVehicle FindVehicle(IEntity vehicleEntity)
SCR_AIGroupVehicle TryAddVehicle(notnull SCR_AIVehicleUsageComponent vehicleUsageComp)
bool RemoveVehicle(notnull SCR_AIVehicleUsageComponent vehicleUsageComp)
static SCR_AIVehicleUsageComponent FindOnNearestParent(notnull IEntity ent, out IEntity componentOwner)
ref OnLifeStateChangedInvoker m_OnLifeStateChanged
bool MoveInVehicle(IEntity vehicle, ECompartmentType compartmentType, bool performWhenPaused=false, BaseCompartmentSlot customSlot=null)
SCR_EditableEntityComponentClass GetEditableEntityData(IEntity owner=null)
bool SetTransform(vector transform[4], bool changedByUser=false)
SCR_EditableEntityComponent EOnEditorPlace(out SCR_EditableEntityComponent parent, SCR_EditableEntityComponent recipient, EEditorPlacingFlags flags, bool isQueue, int playerID=0)
void ForceVehicleCompartments(notnull array< ECompartmentType > forceVehicleCompartments)
void SetTransformOwner(vector transform[4])
void OnParentEntityChanged(SCR_EditableEntityComponent parentEntity, SCR_EditableEntityComponent parentEntityPrev, bool changedByUser)
SCR_EditableEntityComponent GetAIEntity()
bool HasEntityState(EEditableEntityState state)
SCR_EditableEntityComponent GetVehicle()
bool Delete(bool changedByUser=false, bool updateNavmesh=false)
static SCR_EditableEntityComponent GetEditableEntity(IEntity owner)
void EOnEditorSessionLoad(SCR_EditableEntityComponent parent)
EEditableEntityType GetEntityType(IEntity owner=null)
SCR_EditableEntityComponent SetParentEntity(SCR_EditableEntityComponent parentEntity, bool changedByUser=false)
int GetCrew(out notnull array< CompartmentAccessComponent > crewCompartmentAccess, bool ignorePlayers=true)
bool IsReplicated(out RplId replicationID=-1)
SCR_EditableEntityComponent GetParentEntity()
SCR_EditableEntityComponent GetAIGroup()
static bool IsEditMode()
Definition Functions.c:1566
static IEntity GetLocalControlledEntity()
static IEntity GetLocalMainEntity()
proto external GenericEntity GetOwner()
Get owner entity.
void EntitySpawnParams()
Definition gameLib.c:130
IEntity GetOwner()
Owner entity of the fuel tank.
ECharacterLifeState
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
EEditableEntityType
Defines type of SCR_EditableEntityComponent. Assigned automatically based on IEntity inheritance.
EEditableEntityState
SCR_FieldOfViewSettings Attribute
proto external PlayerController GetPlayerController()
RplRole
Role of replicated node (and all items in it) within the replication system.
Definition RplRole.c:14
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
T2 param2
Definition tuple.c:92
Tuple param1
ScriptInvokerBase< func > ScriptInvoker
Definition tools.c:134