Arma Reforger Explorer 1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Loading...
Searching...
No Matches
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.")]
5
6class 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;
16 private SCR_CharacterControllerComponent m_CharControlComp;
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 {
38 m_iVehicleOwnerID = NO_OWNER;
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)
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)
166
167 if (m_CharControlComp)
168 m_CharControlComp.GetOnPlayerDeath().Remove(ReleaseProtection);
169 }
170}
ArmaReforgerScripted GetGame()
Definition game.c:1398
SCR_BaseGameMode GetGameMode()
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.
UI Textures DeployMenu Briefing conflict_HintBanner_1_UI desc
void SetVehicleOwner(int playerID)
void OnPlayerDisconected(int playerID)
void SetProtectionTime(int protectionTime)
bool IsProtected(notnull IEntity playerEntering, notnull BaseCompartmentSlot compartmentSlot)
LocalizedString GetReasonText(IEntity user)
void SetProtectOnlyDriverSeat(bool onlyDriverSeat)
void SetReasonText(string text)
SCR_VehicleSpawnProtectionComponentClass NO_OWNER
proto external Managed FindComponent(typename typeName)
Main replication API.
Definition Replication.c:14
ScriptInvokerBase< SCR_BaseGameMode_OnPlayerDisconnected > GetOnPlayerDisconnected()
override void EOnInit(IEntity owner)
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
EntityEvent
Various entity events.
Definition EntityEvent.c:14
override void OnPlayerDisconnected(int playerId, KickCauseCode cause, int timeout)