Arma Reforger Explorer 1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Loading...
Searching...
No Matches
SCR_RestrictedDeployableSpawnPoint.c
Go to the documentation of this file.
1[EntityEditorProps(category: "GameScripted/DeployableItems", description: "", visible: false)]
5
6//------------------------------------------------------------------------------------------------
9{
10 [RplProp()]
12
13 [RplProp()]
14 protected int m_iGroupID = -1;
15
17
18 protected int m_iMaxRespawns;
19
20 protected int m_iRespawnCount;
21
22 protected bool m_bLoadoutAllowed;
23
24 //------------------------------------------------------------------------------------------------
25 protected bool CanSpawn(notnull array<SCR_ChimeraCharacter> characters, Faction spawnPointFaction, vector spawnPointOrigin)
26 {
28 if (!restrictedDeployableSpawnPointComp)
29 return false;
30
31 if (restrictedDeployableSpawnPointComp.GetIgnoreEnemyCharacters())
32 return true;
33
34 int friendlyCharactersCount, enemyCharactersCount = 0;
35
36 foreach (SCR_ChimeraCharacter character : characters)
37 {
38 if (character.GetCharacterController().IsDead())
39 continue;
40
41 float distanceToItemSq = (spawnPointOrigin - character.GetOrigin()).LengthSq();
42 float queryRadius = restrictedDeployableSpawnPointComp.GetQueryRadiusCharacters();
43 float queryRadiusSq = queryRadius * queryRadius;
44
45 if (distanceToItemSq > queryRadiusSq)
46 continue;
47
48 SCR_Faction faction = SCR_Faction.Cast(SCR_Faction.GetEntityFaction(character));
49
50 if (faction.DoCheckIfFactionFriendly(spawnPointFaction))
51 friendlyCharactersCount++;
52 else
53 enemyCharactersCount++;
54 }
55
56 return friendlyCharactersCount - enemyCharactersCount >= 0;
57 }
58
59 //------------------------------------------------------------------------------------------------
60 override bool IsSpawnPointVisibleForPlayer(int pid)
61 {
63 return true;
64
65 SCR_PlayerControllerGroupComponent playerControllerGroupComp = SCR_PlayerControllerGroupComponent.GetPlayerControllerComponent(pid);
66 if (!playerControllerGroupComp)
67 return false;
68
69 int localPlayerGroupID = playerControllerGroupComp.GetGroupID();
70
71 return m_iGroupID == localPlayerGroupID;
72 }
73
74 //------------------------------------------------------------------------------------------------
75 override void OnFinalizeSpawnDone_S(SCR_SpawnRequestComponent requestComponent, SCR_SpawnData data, IEntity entity)
76 {
77 super.OnFinalizeSpawnDone_S(requestComponent, data, entity);
78
80 {
82
84 if (!restrictedDeployableSpawnPointComp)
85 return;
86
87 restrictedDeployableSpawnPointComp.SetRespawnCount(m_iRespawnCount);
88 }
89 }
90
91 //------------------------------------------------------------------------------------------------
92 override bool CanReserveFor_S(int playerId, out SCR_ESpawnResult result = SCR_ESpawnResult.SPAWN_NOT_ALLOWED)
93 {
94 if (!super.CanReserveFor_S(playerId, result))
95 return false;
96
97 // Deny spawning when respawn limit is reached and supply usage is disabled
99 {
100 result = SCR_ESpawnResult.NOT_ALLOWED_SPAWNPOINT_DISABLED_OUT_OF_RESPAWNS;
101 return false;
102 }
103
104 // Deny spawning if custom loadouts are disabled and player is trying to spawn with one
106 {
107 IEntity playerController = GetGame().GetPlayerManager().GetPlayerController(playerId);
108 if (!playerController)
109 return false;
110
112 if (!loadoutComp)
113 return false;
114
116 if (loadout)
117 {
118 result = SCR_ESpawnResult.NOT_ALLOWED_CUSTOM_LOADOUT;
119 return false;
120 }
121 }
122
123 // Deny spawning when enemies are near spawnpoint
124 array<SCR_ChimeraCharacter> characters = SCR_CharacterRegistrationComponent.GetChimeraCharacters();
125
126 FactionManager factionManager = GetGame().GetFactionManager();
127 if (!factionManager)
128 return false;
129
130 SCR_Faction faction = SCR_Faction.Cast(factionManager.GetFactionByKey(GetFactionKey()));
131
132 if (!CanSpawn(characters, faction, GetOrigin()))
133 {
134 result = SCR_ESpawnResult.NOT_ALLOWED_SPAWNING_DISABLED_ENEMIES_NEARBY;
135 return false;
136 }
137
138 return true;
139 }
140
141 //------------------------------------------------------------------------------------------------
142 void SetAllowAllGroupsToSpawn(bool allowAllGroupsToSpawn)
143 {
144 m_bAllowAllGroupsToSpawn = allowAllGroupsToSpawn;
145 Replication.BumpMe();
146 }
147
148 //------------------------------------------------------------------------------------------------
150 {
151 m_eRespawnBudgetType = budgetType;
152 }
153
154 //------------------------------------------------------------------------------------------------
155 void SetGroupID(int groupID)
156 {
157 m_iGroupID = groupID;
158 Replication.BumpMe();
159 }
160
161 //------------------------------------------------------------------------------------------------
163 {
164 return m_iMaxRespawns;
165 }
166
167 //------------------------------------------------------------------------------------------------
168 void SetMaxRespawns(int maxRespawns)
169 {
170 m_iMaxRespawns = maxRespawns;
171 }
172
173 //------------------------------------------------------------------------------------------------
175 {
176 return m_iRespawnCount;
177 }
178
179 //------------------------------------------------------------------------------------------------
180 void SetRespawnCount(int respawnCount)
181 {
182 m_iRespawnCount = respawnCount;
183 }
184
185 //------------------------------------------------------------------------------------------------
187 {
188 return m_bLoadoutAllowed;
189 }
190
191 //------------------------------------------------------------------------------------------------
192 void SetLoadoutAllowed(bool allow)
193 {
194 m_bLoadoutAllowed = allow;
195 }
196}
ArmaReforgerScripted GetGame()
Definition game.c:1398
vector GetOrigin()
SCR_CacheNoteComponentClass ScriptComponentClass RplProp()] protected ref array< string > m_aLines
void SCR_CharacterRegistrationComponent(IEntityComponentSource src, IEntity ent, IEntity parent)
enum SCR_ECompassType EntityEditorProps(category:"GameScripted/Gadgets", description:"Compass", color:"0 0 255 255")
Prefab data class for compass component.
SCR_ESpawnResult
Get all prefabs that have the spawner data
proto external Managed FindComponent(typename typeName)
Main replication API.
Definition Replication.c:14
SCR_BaseDeployableSpawnPointComponent m_DeployableSpawnPointComp
override bool DoCheckIfFactionFriendly(Faction faction)
static Faction GetEntityFaction(notnull IEntity entity)
Deployable spawn point with configurable conditions.
Basically SCR_SpawnPoint with the ability to limit respawn amount.
void SetAllowAllGroupsToSpawn(bool allowAllGroupsToSpawn)
bool CanSpawn(notnull array< SCR_ChimeraCharacter > characters, Faction spawnPointFaction, vector spawnPointOrigin)
override void OnFinalizeSpawnDone_S(SCR_SpawnRequestComponent requestComponent, SCR_SpawnData data, IEntity entity)
override bool CanReserveFor_S(int playerId, out SCR_ESpawnResult result=SCR_ESpawnResult.SPAWN_NOT_ALLOWED)
void SetBudgetType(SCR_ESpawnPointBudgetType budgetType)
string GetFactionKey()