Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
SCR_VehicleSpawnProtectionComponent.c
Go to the documentation of this file.
1 [EntityEditorProps(category: "GameScripted/Campaign", description: "This allows only vehicle requester enther the vehicle as driver for defined period of time.")]
3 {
4 }
5 
6 class SCR_VehicleSpawnProtectionComponent : SCR_BaseLockComponent
7 {
8  protected static const int NO_OWNER = -1;
9  protected static const int NO_TIME_LIMIT = 0;
10 
11  [RplProp()]
12  private int m_iVehicleOwnerID = NO_OWNER;
13 
14  protected int m_iTimeOfProtection;
15  bool m_bOnlyDriverSeat = true;
17 
18  [Attribute(defvalue: "#AR-Campaign_Action_CannotEnterVehicle-UC", desc: "Text that will be displayed on actions telling reason why it cannot be used")];
19  protected string m_sReasonText;
20 
21  //------------------------------------------------------------------------------------------------
22  override void OnPostInit(IEntity owner)
23  {
24  SetEventMask(owner, EntityEvent.INIT);
25  }
26 
27  //------------------------------------------------------------------------------------------------
28  override void EOnInit(IEntity owner)
29  {
30  ClearEventMask(owner, EntityEvent.INIT);
31  }
32 
33  //------------------------------------------------------------------------------------------------
36  {
39  Replication.BumpMe();
40 
41  GetGame().GetCallqueue().Remove(ReleaseProtection);
42  }
43 
44  //------------------------------------------------------------------------------------------------
46  void SetProtectionTime(int protectionTime)
47  {
48  if (protectionTime != NO_TIME_LIMIT)
49  {
50  m_iTimeOfProtection = protectionTime;
51  GetGame().GetCallqueue().CallLater(ReleaseProtection, m_iTimeOfProtection * 1000, false);
52  }
53  }
54 
55  //------------------------------------------------------------------------------------------------
57  void SetVehicleOwner(int playerID)
58  {
59  // -2 == locked for everyone
60  if (playerID == -2)
61  {
62  m_iVehicleOwnerID = playerID;
63  Replication.BumpMe();
64  return;
65  }
66 
67  IEntity playerEnt = GetGame().GetPlayerManager().GetPlayerControlledEntity(playerID);
68  if (!playerEnt)
69  return;
70 
72  if (!m_CharControlComp)
73  return;
74 
75  // Add EH
76  m_CharControlComp.GetOnPlayerDeath().Insert(ReleaseProtection);
77 
79  if (gameMode)
80  gameMode.GetOnPlayerDisconnected().Insert(OnPlayerDisconnected);
81 
82  // Set owner of this vehicle
83  m_iVehicleOwnerID = playerID;
84  Replication.BumpMe();
85  }
86 
87  //------------------------------------------------------------------------------------------------
89  void SetProtectOnlyDriverSeat(bool onlyDriverSeat)
90  {
91  m_bOnlyDriverSeat = onlyDriverSeat;
92  }
93 
94  //------------------------------------------------------------------------------------------------
96  void SetReasonText(string text)
97  {
98  m_sReasonText = text;
99  }
100 
101  //------------------------------------------------------------------------------------------------
104  {
105  return m_iVehicleOwnerID;
106  }
107 
108  //------------------------------------------------------------------------------------------------
113  bool IsProtected(notnull IEntity playerEntering, notnull BaseCompartmentSlot compartmentSlot)
114  {
115  // Test if it is a driver seat or not.
116  if (m_bOnlyDriverSeat && !PilotCompartmentSlot.Cast(compartmentSlot))
117  return false;
118 
119  int testPlayerID = SCR_PossessingManagerComponent.GetPlayerIdFromMainEntity(playerEntering);
120  // Check vehicle owenr ID
121  if (m_iVehicleOwnerID == NO_OWNER || m_iVehicleOwnerID == testPlayerID /*m_Lobby.GetPlayerIdFromControlledEntity(playerEntering)*/)
122  {
123  #ifdef VEHICLE_LOCK
124  Print(string.Format("Player ID is %1, vehicle owner ID is %2. Vehicle is unlocked.", testPlayerID, m_iVehicleOwnerID), LogLevel.NORMAL);
125  #endif
126  return false;
127  }
128  #ifdef VEHICLE_LOCK
129  Print(string.Format("Player ID is %1, vehicle owner ID is %2. Vehicle is LOCKED.", testPlayerID, m_iVehicleOwnerID), LogLevel.NORMAL);
130  #endif
131  return true;
132  }
133 
134  //------------------------------------------------------------------------------------------------
135  [Obsolete("Use OnPlayerDisconnected instead")]
136  protected void OnPlayerDisconected(int playerID)
137  {
138  OnPlayerDisconnected(playerID);
139  }
140 
141  //------------------------------------------------------------------------------------------------
142  protected void OnPlayerDisconnected(int playerID)
143  {
144  if (playerID == m_iVehicleOwnerID)
146  }
147 
148  //------------------------------------------------------------------------------------------------
152  {
153  if (!user)
154  return string.Empty;
155 
156  return m_sReasonText;
157  }
158 
159  //------------------------------------------------------------------------------------------------
162  {
164  if (gameMode)
165  gameMode.GetOnPlayerDisconnected().Remove(OnPlayerDisconnected);
166 
167  if (m_CharControlComp)
168  m_CharControlComp.GetOnPlayerDeath().Remove(ReleaseProtection);
169  }
170 }
NO_OWNER
SCR_VehicleSpawnProtectionComponentClass NO_OWNER
SCR_BaseLockComponentClass
Definition: SCR_BaseLockComponent.c:2
m_bOnlyDriverSeat
bool m_bOnlyDriverSeat
Definition: SCR_VehicleSpawnProtectionComponent.c:15
SCR_BaseGameMode
Definition: SCR_BaseGameMode.c:137
EntityEditorProps
enum EQueryType EntityEditorProps(category:"GameScripted/Sound", description:"THIS IS THE SCRIPT DESCRIPTION.", color:"0 0 255 255")
Definition: SCR_AmbientSoundsComponent.c:12
SetReasonText
void SetReasonText(string text)
Definition: SCR_VehicleSpawnProtectionComponent.c:96
OnPlayerDisconnected
protected void OnPlayerDisconnected(int playerID)
Definition: SCR_VehicleSpawnProtectionComponent.c:142
RplProp
SCR_RplTestEntityClass RplProp
Used for handling entity spawning requests for SCR_CatalogEntitySpawnerComponent and inherited classe...
GetGame
ArmaReforgerScripted GetGame()
Definition: game.c:1424
desc
UI Textures DeployMenu Briefing conflict_HintBanner_1_UI desc
Definition: SCR_RespawnBriefingComponent.c:17
PilotCompartmentSlot
Definition: PilotCompartmentSlot.c:12
SCR_CharacterControllerComponent
Definition: SCR_CharacterControllerComponent.c:35
ReleaseProtection
void ReleaseProtection()
Definition: SCR_VehicleSpawnProtectionComponent.c:35
GetVehicleOwner
int GetVehicleOwner()
Definition: SCR_VehicleSpawnProtectionComponent.c:103
GetGameMode
SCR_BaseGameMode GetGameMode()
Definition: SCR_BaseGameModeComponent.c:15
OnPlayerDisconected
protected void OnPlayerDisconected(int playerID)
Definition: SCR_VehicleSpawnProtectionComponent.c:136
m_iTimeOfProtection
protected int m_iTimeOfProtection
Definition: SCR_VehicleSpawnProtectionComponent.c:14
Attribute
typedef Attribute
Post-process effect of scripted camera.
OnPostInit
override void OnPostInit(IEntity owner)
Called on PostInit when all components are added.
Definition: SCR_VehicleSpawnProtectionComponent.c:22
GetReasonText
LocalizedString GetReasonText(IEntity user)
Definition: SCR_VehicleSpawnProtectionComponent.c:151
SetProtectionTime
void SetProtectionTime(int protectionTime)
Definition: SCR_VehicleSpawnProtectionComponent.c:46
EOnInit
override void EOnInit(IEntity owner)
Definition: SCR_VehicleSpawnProtectionComponent.c:28
SetProtectOnlyDriverSeat
void SetProtectOnlyDriverSeat(bool onlyDriverSeat)
Definition: SCR_VehicleSpawnProtectionComponent.c:89
RemoveEventHandlers
void RemoveEventHandlers()
Definition: SCR_VehicleSpawnProtectionComponent.c:161
m_iVehicleOwnerID
private int m_iVehicleOwnerID
Definition: SCR_VehicleSpawnProtectionComponent.c:12
SCR_VehicleSpawnProtectionComponentClass
Definition: SCR_VehicleSpawnProtectionComponent.c:2
IsProtected
bool IsProtected(notnull IEntity playerEntering, notnull BaseCompartmentSlot compartmentSlot)
Definition: SCR_VehicleSpawnProtectionComponent.c:113
SetVehicleOwner
void SetVehicleOwner(int playerID)
Definition: SCR_VehicleSpawnProtectionComponent.c:57
LocalizedString
Definition: LocalizedString.c:21
m_CharControlComp
private SCR_CharacterControllerComponent m_CharControlComp
Definition: SCR_VehicleSpawnProtectionComponent.c:16
Obsolete
RespawnSystemComponentClass GameComponentClass Obsolete()] proto external GenericEntity DoSpawn(string prefab
RespawnSystemComponent should be attached to a gamemode to handle player spawning and respawning.
m_sReasonText
protected string m_sReasonText
Definition: SCR_VehicleSpawnProtectionComponent.c:18
category
params category
Definition: SCR_VehicleDamageManagerComponent.c:180