Arma Reforger Explorer 1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Loading...
Searching...
No Matches
SCR_PlayerSpawnPoint.c
Go to the documentation of this file.
1[EntityEditorProps(category: "GameScripted/GameMode", description: "")]
5
6class SCR_PlayerSpawnPoint : SCR_SpawnPoint
7{
8 [Attribute("1", desc: "How often will the spawn's position be updated to match assigned player's position (in seconds).", category: "Player Spawn Point")]
9 protected float m_fUpdateInterval;
10
11 [Attribute(desc: "Spawn point visualization. Original 'Info' attribute will be ignored.", category: "Player Spawn Point")]
12 protected ref SCR_PlayerUIInfo m_PlayerInfo;
13
14 [RplProp(onRplName: "OnSetPlayerID")]
15 protected int m_iPlayerID;
16
17 [RplProp()]
18 protected bool m_bIsActive;
19
20 protected Faction m_CachedFaction;
21 protected IEntity m_TargetPlayer;
22
23 //------------------------------------------------------------------------------------------------
25 IEntity GetTargetPlayer()
26 {
27 return m_TargetPlayer;
28 }
29
30 //------------------------------------------------------------------------------------------------
34 void SetPlayerID(int playerID)
35 {
36 if (playerID == m_iPlayerID || !Replication.IsServer())
37 return;
38
39 //--- Set and broadcast new player ID
40 m_iPlayerID = playerID;
42 Replication.BumpMe();
43
44 IEntity player = SCR_PossessingManagerComponent.GetPlayerMainEntity(m_iPlayerID);
45 if (player)
46 EnablePoint(m_iPlayerID, player);
47 else
49 }
50
51 //------------------------------------------------------------------------------------------------
55 {
56 return m_iPlayerID;
57 }
58
59 //------------------------------------------------------------------------------------------------
60 protected void OnSetPlayerID()
61 {
62 //--- Link player info
63 if (!m_PlayerInfo)
64 m_PlayerInfo = new SCR_PlayerUIInfo();
65
66 m_PlayerInfo.SetPlayerID(m_iPlayerID);
67 LinkInfo(m_PlayerInfo);
68 }
69
70 //------------------------------------------------------------------------------------------------
71 protected override string GetSpawnPointName()
72 {
73 return SCR_PlayerNamesFilterCache.GetInstance().GetPlayerDisplayName(m_iPlayerID);
74 }
75
76 //------------------------------------------------------------------------------------------------
80 void EnablePoint(int playerId, IEntity playerEntity)
81 {
82 if (playerId != m_iPlayerID)
83 {
84 Print(string.Format("Couldn't enable point, mismatching playerId(s), expected: %1, got: %2", m_iPlayerID, playerId), LogLevel.WARNING);
85 return;
86 }
87
88 m_CachedFaction = SCR_FactionManager.SGetPlayerFaction(m_iPlayerID);
89 m_TargetPlayer = playerEntity;
91 }
92
93 //------------------------------------------------------------------------------------------------
96 void DisablePoint(int playerId)
97 {
98 if (playerId != m_iPlayerID)
99 {
100 Print(string.Format("Couldn't disable point, mismatching playerId(s), expected: %1, got: %2", m_iPlayerID, playerId), LogLevel.WARNING);
101 return;
102 }
103
105
106 m_CachedFaction = null;
107 m_TargetPlayer = null;
108 }
109
110 //------------------------------------------------------------------------------------------------
111 protected void ActivateSpawnPoint()
112 {
113 SetFaction(m_CachedFaction);
114
115 //--- Periodically refresh spawn's position
116 //--- Clients cannot access another player's entity directly, because it may not be streamed for them
117 ClearFlags(EntityFlags.STATIC, false);
118 GetGame().GetCallqueue().CallLater(UpdateSpawnPos, m_fUpdateInterval * 1000, true);
119
120 m_bIsActive = true;
121 Replication.BumpMe();
122 }
123
124 //------------------------------------------------------------------------------------------------
125 override bool IsSpawnPointActive()
126 {
127 return m_bIsActive;
128 }
129
130 //------------------------------------------------------------------------------------------------
131 protected void DeactivateSpawnPoint()
132 {
133 SetFaction(null);
134
135 //--- Stop periodic refresh
136 SetFlags(EntityFlags.STATIC, false);
137 GetGame().GetCallqueue().Remove(UpdateSpawnPos);
138
139 m_bIsActive = false;
140 Replication.BumpMe();
141 }
142
143 //------------------------------------------------------------------------------------------------
144 protected void UpdateSpawnPos()
145 {
146 if (!m_TargetPlayer)
147 return;
148
149 vector pos = m_TargetPlayer.GetOrigin();
151 Rpc(UpdateSpawnPosBroadcast, pos);
152 }
153
154 //------------------------------------------------------------------------------------------------
155 [RplRpc(RplChannel.Reliable, RplRcver.Broadcast)]
156 protected void UpdateSpawnPosBroadcast(vector pos)
157 {
158 SetOrigin(pos);
159 }
160
161 //------------------------------------------------------------------------------------------------
162 override void GetPositionAndRotation(out vector pos, out vector rot)
163 {
164 super.GetPositionAndRotation(pos, rot);
165
166 if (m_TargetPlayer)
167 {
169 IEntity vehicle = compartmentAccessTarget.GetVehicle();
170 if (vehicle)
171 rot = vehicle.GetAngles();
172 else
173 rot = m_TargetPlayer.GetAngles();
174 }
175 }
176
177 //------------------------------------------------------------------------------------------------
179 {
180 if (!m_TargetPlayer)
181 return null;
182
184 if (!compartmentAccessTarget)
185 return null;
186
187 return Vehicle.Cast(compartmentAccessTarget.GetVehicle());
188 }
189
190 //------------------------------------------------------------------------------------------------
191 override bool CanReserveFor_S(int playerId, out SCR_ESpawnResult result = SCR_ESpawnResult.SPAWN_NOT_ALLOWED)
192 {
193 //~ Check if super fails or not if the spawnpoint can be reserved
194 if (!super.CanReserveFor_S(playerId))
195 return false;
196
197 Vehicle targetVehicle = GetTargetVehicle();
198 if (targetVehicle)
199 {
200 // See if there are any slots left
201 BaseCompartmentManagerComponent compartmentManager = BaseCompartmentManagerComponent.Cast(targetVehicle.FindComponent(BaseCompartmentManagerComponent));
202 array<BaseCompartmentSlot> compartments = {};
203 int count = compartmentManager.GetCompartments(compartments);
204 for (int i = 0; i < count; i++)
205 {
206 BaseCompartmentSlot slot = compartments[i];
207 if (!slot.IsOccupied() && !slot.IsReserved())
208 return true;
209 }
210
211 // No slots available
212 result = SCR_ESpawnResult.NOT_ALLOWED_VEHICLE_FULL;
213 return false;
214 }
215
216 // No vehicle and all other tests passed
217 return true;
218 }
219
220 //------------------------------------------------------------------------------------------------
221 override bool PrepareSpawnedEntity_S(SCR_SpawnRequestComponent requestComponent, SCR_SpawnData data, IEntity entity)
222 {
223 #ifdef _ENABLE_RESPAWN_LOGS
224 Print(string.Format("%1::PrepareSpawnedEntity_S(playerId: %2, data: %3, entity: %4)", Type().ToString(),
225 requestComponent.GetPlayerId(), data, entity), LogLevel.NORMAL);
226 #endif
227
228 //~ Check if can prepare spawn from super
229 if (!super.PrepareSpawnedEntity_S(requestComponent, data, entity))
230 return false;
231
232 // Spawned entity must have a compartment access component
234 if (!compartmentAccessPlayer)
235 return false;
236
237 // Spawning on vehicle; resolve vehicle logic
238 Vehicle targetVehicle = GetTargetVehicle();
239 if (targetVehicle)
240 return PrepareSpawnedEntityForVehicle_S(requestComponent, data, entity, targetVehicle);
241
242 // All checks succeed
243 return true;
244 }
245
246 //------------------------------------------------------------------------------------------------
247 protected bool PrepareSpawnedEntityForVehicle_S(SCR_SpawnRequestComponent requestComponent, SCR_SpawnData data, IEntity entity, Vehicle vehicle)
248 {
249 #ifdef _ENABLE_RESPAWN_LOGS
250 Print(string.Format("%1::PrepareSpawnedEntityForVehicle_S(playerId: %2, data: %3, entity: %4, vehicle: %5)", Type().ToString(),
251 requestComponent.GetPlayerId(), data, entity, vehicle), LogLevel.NORMAL);
252 #endif
253
256
257 array<BaseCompartmentSlot> compartments = {};
258 int count = compartmentManager.GetCompartments(compartments);
259 for (int i = 0; i < count; i++)
260 {
261 BaseCompartmentSlot slot = compartments[i];
262 if (!slot.IsOccupied() && (!slot.IsReserved() || slot.IsReservedBy(entity)))
263 {
264 ChimeraWorld world = GetGame().GetWorld();
265 return accessComponent.GetInVehicle(vehicle, slot, true, -1, ECloseDoorAfterActions.INVALID, world.IsGameTimePaused());
266 }
267 }
268
269 return false;
270 }
271
272 //------------------------------------------------------------------------------------------------
273 override bool CanFinalizeSpawn_S(SCR_SpawnRequestComponent requestComponent, SCR_SpawnData data, IEntity entity)
274 {
275 if (!super.CanFinalizeSpawn_S(requestComponent, data, entity))
276 return false;
277
278 // Do not finalize if character is in the middle of entering a vehicle, leave that to be resolved on the authority first
280 if (accessComponent && accessComponent.IsGettingIn())
281 return false;
282
283 return true;
284 }
285
286 //------------------------------------------------------------------------------------------------
287 override void OnFinalizeSpawnDone_S(SCR_SpawnRequestComponent requestComponent, SCR_SpawnData data, IEntity entity)
288 {
289 }
290
291 //------------------------------------------------------------------------------------------------
292 // destructor
294 {
295 GetGame().GetCallqueue().Remove(UpdateSpawnPos);
296 }
297}
ArmaReforgerScripted GetGame()
Definition game.c:1398
SCR_CacheNoteComponentClass ScriptComponentClass RplProp()] protected ref array< string > m_aLines
enum SCR_ECompassType EntityEditorProps(category:"GameScripted/Gadgets", description:"Compass", color:"0 0 255 255")
Prefab data class for compass component.
SCR_ESpawnResult
override int GetPlayerID()
Get all prefabs that have the spawner data
void SCR_FactionManager(IEntitySource src, IEntity parent)
SCR_HintSequenceComponentClass m_bIsActive
void ActivateSpawnPoint()
void DeactivateSpawnPoint()
void UpdateSpawnPosBroadcast(vector pos)
void EnablePoint(int playerId, IEntity playerEntity)
void UpdateSpawnPos()
override bool CanFinalizeSpawn_S(SCR_SpawnRequestComponent requestComponent, SCR_SpawnData data, IEntity entity)
bool PrepareSpawnedEntityForVehicle_S(SCR_SpawnRequestComponent requestComponent, SCR_SpawnData data, IEntity entity, Vehicle vehicle)
override string GetSpawnPointName()
override bool PrepareSpawnedEntity_S(SCR_SpawnRequestComponent requestComponent, SCR_SpawnData data, IEntity entity)
Vehicle GetTargetVehicle()
void ~SCR_PlayerSpawnPoint()
void SetPlayerID(int playerID)
override void OnFinalizeSpawnDone_S(SCR_SpawnRequestComponent requestComponent, SCR_SpawnData data, IEntity entity)
void OnSetPlayerID()
void DisablePoint(int playerId)
UI Textures DeployMenu Briefing conflict_HintBanner_1_UI desc
int Type
proto external Managed FindComponent(typename typeName)
proto external vector GetAngles()
Same as GetYawPitchRoll(), but returns rotation vector around X, Y and Z axis.
proto external vector GetOrigin()
Main replication API.
Definition Replication.c:14
Spawn point entity defines positions on which players can possibly spawn.
bool CanReserveFor_S(int playerId, out SCR_ESpawnResult result=SCR_ESpawnResult.SPAWN_NOT_ALLOWED)
void SetFaction(Faction faction)
bool IsSpawnPointActive()
void GetPositionAndRotation(out vector pos, out vector rot)
enum EPhysicsLayerPresets Vehicle
Definition gameLib.c:24
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
SCR_FieldOfViewSettings Attribute
EntityFlags
Various entity flags.
Definition EntityFlags.c:14
SCR_EditorManagerCore m_iPlayerID
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.
ECloseDoorAfterActions