Arma Reforger Explorer
1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Toggle main menu visibility
Loading...
Searching...
No Matches
SCR_PossessSpawnHandlerComponent.c
Go to the documentation of this file.
1
[
ComponentEditorProps
(
category
:
"GameScripted/Respawn/Handlers"
, description:
"Allows the respawn system to utilize spawning on AI(s). Requires a SCR_OnAIRespawnComponent attached to PlayerController."
)]
2
class
SCR_PossessSpawnHandlerComponentClass
:
SCR_SpawnHandlerComponentClass
3
{
4
}
5
6
class
SCR_PossessSpawnHandlerComponent : SCR_SpawnHandlerComponent
7
{
8
[
Attribute
(
"1"
,
desc
:
"When enabled, conditions like respawn time will not be checked."
)]
9
protected
bool
m_bIgnoreConditions;
10
11
//------------------------------------------------------------------------------------------------
12
protected
override
SCR_ESpawnResult
SpawnEntity_S
(SCR_SpawnRequestComponent requestComponent, notnull
SCR_SpawnData
data
, out
IEntity
spawnedEntity)
13
{
14
int
playerId = requestComponent.GetPlayerController().GetPlayerId();
15
#ifdef _ENABLE_RESPAWN_LOGS
16
Print
(
string
.Format(
"%1::SpawnEntity(playerId: %2, data: %3)"
,
Type
().
ToString
(),
17
playerId,
18
data
),
LogLevel
.NORMAL);
19
#endif
20
21
// We simply use the entity without spawning it
22
spawnedEntity =
GetEntity
(
data
);
23
if
(!spawnedEntity)
24
return
SCR_ESpawnResult
.CANNOT_VALIDATE;
25
26
if
(!
PrepareEntity_S
(requestComponent, spawnedEntity,
data
))
27
return
SCR_ESpawnResult
.CANNOT_PREPARE;
28
29
return
SCR_ESpawnResult
.OK;
30
}
31
32
//------------------------------------------------------------------------------------------------
33
override
SCR_ESpawnResult
CanHandleRequest_S
(SCR_SpawnRequestComponent requestComponent,
SCR_SpawnData
data
)
34
{
35
SCR_ESpawnResult
result = super.CanHandleRequest_S(requestComponent,
data
);
36
if
(result !=
SCR_ESpawnResult
.OK)
37
return
result;
38
39
IEntity
entity =
GetEntity
(
data
);
40
if
(!entity)
41
return
SCR_ESpawnResult
.CANNOT_VALIDATE;
42
43
// Also for now allow only characters, for.. reasons
44
ChimeraCharacter
character =
ChimeraCharacter
.Cast(entity);
45
if
(!character)
46
return
SCR_ESpawnResult
.CANNOT_POSSES;
47
48
// And alive, if possible
49
if
(character.GetCharacterController().IsDead())
50
return
SCR_ESpawnResult
.CANNOT_POSSES;
51
52
// Ensure that entity to be possessed is not already possessed
53
int
controllingPlayerId =
GetGame
().GetPlayerManager().GetPlayerIdFromControlledEntity(entity);
54
if
(controllingPlayerId != 0)
55
return
SCR_ESpawnResult
.CANNOT_POSSES;
56
57
return
SCR_ESpawnResult
.OK;
58
}
59
60
//------------------------------------------------------------------------------------------------
61
protected
IEntity
GetEntity
(
SCR_SpawnData
data
)
62
{
63
SCR_PossessSpawnData
possessData =
SCR_PossessSpawnData
.Cast(
data
);
64
if
(!possessData)
65
return
null;
66
67
RplComponent rplComponent = RplComponent.Cast(
Replication
.FindItem(possessData.
GetRplId
()));
68
if
(!rplComponent)
69
return
null;
70
71
return
rplComponent.GetEntity();
72
}
73
74
//------------------------------------------------------------------------------------------------
75
override
protected
bool
ShouldDeleteEntityOnSpawnFailure_S
(SCR_SpawnRequestComponent requestComponent,
IEntity
entity,
SCR_SpawnData
data
,
SCR_ESpawnResult
reason
)
76
{
77
return
false
;
78
}
79
80
//------------------------------------------------------------------------------------------------
84
protected
override
bool
ValidateData_S
(SCR_SpawnRequestComponent requestComponent,
SCR_SpawnData
data
)
85
{
86
if
(!super.ValidateData_S(requestComponent,
data
))
87
return
false
;
88
89
SCR_PossessSpawnData
possessData =
SCR_PossessSpawnData
.Cast(
data
);
90
if
(!possessData || !possessData.
GetRplId
().IsValid())
91
return
false
;
92
93
Managed rplComponent =
Replication
.FindItem(possessData.
GetRplId
());
94
return
rplComponent != null;
95
}
96
97
//------------------------------------------------------------------------------------------------
98
override
bool
CanRequestSpawn_S
(SCR_SpawnRequestComponent requestComponent,
SCR_SpawnData
data
, out
SCR_ESpawnResult
result)
99
{
100
return
m_bIgnoreConditions || super.CanRequestSpawn_S(requestComponent,
data
, result);
101
}
102
103
//------------------------------------------------------------------------------------------------
104
override
void
OnFinalizeDone_S
(SCR_SpawnRequestComponent requestComponent,
SCR_SpawnData
data
,
IEntity
entity)
105
{
106
// Assign possessed entity's faction to the player
107
PlayerController pc = requestComponent.GetPlayerController();
108
SCR_PlayerFactionAffiliationComponent
playerFactionComp =
SCR_PlayerFactionAffiliationComponent
.Cast(pc.FindComponent(
SCR_PlayerFactionAffiliationComponent
));
109
Faction
targetFaction =
GetFactionFromPrefab
(entity.
GetPrefabData
().GetPrefabName());
110
if
(!targetFaction || targetFaction == playerFactionComp.GetAffiliatedFaction())
111
return
;
112
113
playerFactionComp.SetAffiliatedFaction(targetFaction);
114
115
// Notify faction manager
116
SCR_FactionManager
factionManager =
SCR_FactionManager
.Cast(
GetGame
().GetFactionManager());
117
factionManager.UpdatePlayerFaction_S(playerFactionComp);
118
119
// Notify game mode
120
SCR_BaseGameMode
gameMode =
SCR_BaseGameMode
.Cast(
GetGame
().
GetGameMode
());
121
gameMode.
OnPlayerFactionSet_S
(playerFactionComp, targetFaction);
122
}
123
124
//------------------------------------------------------------------------------------------------
125
protected
Faction
GetFactionFromPrefab
(
ResourceName
prefab)
126
{
127
Resource
res =
Resource
.Load(prefab);
128
IEntityComponentSource
src =
SCR_BaseContainerTools
.FindComponentSource(res, FactionAffiliationComponent);
129
if
(!src)
130
return
null;
131
132
string
factionKey;
133
src.Get(
"faction affiliation"
, factionKey);
134
135
return
GetGame
().GetFactionManager().GetFactionByKey(factionKey);
136
}
137
}
GetGame
ArmaReforgerScripted GetGame()
Definition
game.c:1398
ComponentEditorProps
enum EAIGroupCombatMode ComponentEditorProps(category:"GameScripted/AI", description:"Component for utility AI system for groups")
Definition
SCR_AIGroupUtilityComponent.c:12
GetGameMode
SCR_BaseGameMode GetGameMode()
Definition
SCR_BaseGameModeComponent.c:15
SCR_ESpawnResult
SCR_ESpawnResult
Definition
SCR_ESpawnResult.c:9
data
Get all prefabs that have the spawner data
Definition
SCR_EntityCatalogManagerComponent.c:320
SCR_FactionManager
void SCR_FactionManager(IEntitySource src, IEntity parent)
Definition
SCR_FactionManager.c:498
GetFactionFromPrefab
Faction GetFactionFromPrefab(ResourceName prefab)
Definition
SCR_PossessSpawnHandlerComponent.c:125
desc
UI Textures DeployMenu Briefing conflict_HintBanner_1_UI desc
Definition
SCR_RespawnBriefingComponent.c:17
ValidateData_S
bool ValidateData_S(SCR_SpawnRequestComponent requestComponent, SCR_SpawnData data)
Definition
SCR_SpawnHandlerComponent.c:177
CanHandleRequest_S
SCR_ESpawnResult CanHandleRequest_S(SCR_SpawnRequestComponent requestComponent, SCR_SpawnData data)
Definition
SCR_SpawnHandlerComponent.c:46
OnFinalizeDone_S
void OnFinalizeDone_S(SCR_SpawnRequestComponent requestComponent, SCR_SpawnData data, IEntity entity)
Definition
SCR_PossessSpawnHandlerComponent.c:104
ShouldDeleteEntityOnSpawnFailure_S
bool ShouldDeleteEntityOnSpawnFailure_S(SCR_SpawnRequestComponent requestComponent, IEntity entity, SCR_SpawnData data, SCR_ESpawnResult reason)
Definition
SCR_SpawnHandlerComponent.c:376
CanRequestSpawn_S
bool CanRequestSpawn_S(SCR_SpawnRequestComponent requestComponent, SCR_SpawnData data, out SCR_ESpawnResult result)
Definition
SCR_SpawnHandlerComponent.c:193
SpawnEntity_S
SCR_ESpawnResult SpawnEntity_S(SCR_SpawnRequestComponent requestComponent, notnull SCR_SpawnData data, out IEntity spawnedEntity)
Definition
SCR_SpawnHandlerComponent.c:214
PrepareEntity_S
bool PrepareEntity_S(SCR_SpawnRequestComponent requestComponent, IEntity entity, SCR_SpawnData data)
Definition
SCR_SpawnHandlerComponent.c:305
category
params category
Definition
SCR_VehicleDamageManagerComponent.c:302
Type
int Type
Definition
ScriptCamera.c:17
reason
string reason
Definition
ServerBrowserMenuCallbacks.c:41
ChimeraCharacter
Definition
ChimeraCharacter.c:13
Faction
Definition
Faction.c:13
IEntityComponentSource
Definition
IEntityComponentSource.c:13
IEntity
Definition
IEntity.c:13
IEntity::GetPrefabData
proto external EntityPrefabData GetPrefabData()
Replication
Main replication API.
Definition
Replication.c:14
Resource
Object holding reference to resource. In destructor release the resource.
Definition
Resource.c:25
ResourceName
Definition
ResourceName.c:13
SCR_BaseContainerTools
Definition
SCR_BaseContainerTools.c:4
SCR_BaseGameMode
Definition
SCR_BaseGameMode.c:139
SCR_BaseGameMode::OnPlayerFactionSet_S
void OnPlayerFactionSet_S(SCR_PlayerFactionAffiliationComponent factionComponent, Faction faction)
Definition
SCR_BaseGameMode.c:1556
SCR_PlayerFactionAffiliationComponent
Definition
SCR_PlayerFactionAffiliationComponent.c:21
SCR_PossessSpawnData
Definition
SCR_PossessSpawnData.c:3
SCR_PossessSpawnData::GetRplId
RplId GetRplId()
Definition
SCR_PossessSpawnData.c:10
SCR_PossessSpawnHandlerComponentClass
Definition
SCR_PossessSpawnHandlerComponent.c:3
SCR_SpawnData
Definition
SCR_SpawnData.c:10
SCR_SpawnHandlerComponentClass
Definition
SCR_SpawnHandlerComponent.c:2
GetEntity
IEntity GetEntity()
Definition
SCR_QuickslotBaseContainer.c:34
Print
proto void Print(void var, LogLevel level=LogLevel.NORMAL)
Prints content of variable to console/log.
LogLevel
LogLevel
Enum with severity of the logging message.
Definition
LogLevel.c:14
Attribute
SCR_FieldOfViewSettings Attribute
Definition
SendGoalMessage.c:170
ToString
proto external string ToString()
Plain C++ pointer, no weak pointers, no memory management.
scripts
Game
Respawn
RequestHandling
Implementation
PossessSpawn
SCR_PossessSpawnHandlerComponent.c
Generated by
1.17.0