DayZ Scripts
v1.21.156300 ยท Jun 20, 2023
 
Loading...
Searching...
No Matches
ActionGetOutTransport.c
Go to the documentation of this file.
2{
3 Car m_Car;
5 float m_CarSpeed;
6 bool m_WasJumpingOut = false;
7 float m_DmgTaken = 0; // Damage taken by the player when jumping out of vehicle
8 float m_ShockTaken = 0; // Shock inflicted to the player when jumping out of vehicle
9}
10
12{
13 //For the two following variables -> The HIGHER the value, the LOWER the output
14 int m_DmgFactor = 60; //value used to translate impact strength into actual damage (impact strength -> velocity squared)
15 int m_ShockFactor = 15; //Value used to translate impact strength into actual shock
16
17 //Variables used to determine the different speed levels for bleeding checks
18 const int LOW_SPEED_VALUE = 20;
19 const int HIGH_SPEED_VALUE = 30;
20
22 {
23 m_StanceMask = DayZPlayerConstants.STANCEMASK_ALL;
24 m_Text = "#leave_vehicle";
25 }
26
28 {
29 ActionData action_data = new GetOutTransportActionData();
30 return action_data;
31 }
32
33
35 {
38 }
39
40 override typename GetInputType()
41 {
43 }
44
45 override bool HasProgress()
46 {
47 return false;
48 }
49
50 override bool ActionCondition( PlayerBase player, ActionTarget target, ItemBase item )
51 {
52 Transport trans = null;
53 int crew_index = -1;
54
55 HumanCommandVehicle vehCommand = player.GetCommand_Vehicle();
56 if (vehCommand)
57 {
58 trans = vehCommand.GetTransport();
59 if (trans)
60 {
61 crew_index = trans.CrewMemberIndex(player);
62 return crew_index >= 0 && trans.CrewCanGetThrough(crew_index) && trans.IsAreaAtDoorFree(crew_index);
63 }
64 }
65
66 return false;
67 }
68
70 {
71 got_action_data.m_StartLocation = got_action_data.m_Player.GetPosition();
72 got_action_data.m_Car = car;
73 float speed = car.GetSpeedometerAbsolute();
74 got_action_data.m_CarSpeed = speed;
75 got_action_data.m_DmgTaken = (got_action_data.m_CarSpeed * got_action_data.m_CarSpeed) / m_DmgFactor; //When using multiplications, wrong value is returned
76 got_action_data.m_ShockTaken = (got_action_data.m_CarSpeed * got_action_data.m_CarSpeed) / m_ShockFactor;
77 got_action_data.m_WasJumpingOut = speed > 8.0;
78 }
79
80 override void OnStart(ActionData action_data)
81 {
82 super.OnStart(action_data);
83
84 HumanCommandVehicle vehCommand = action_data.m_Player.GetCommand_Vehicle();
85 if (vehCommand)
86 {
87 Transport trans = vehCommand.GetTransport();
88
89 if (trans)
90 {
91 GetOutTransportActionData got_action_data = GetOutTransportActionData.Cast(action_data);
92
93 Car car;
94 if (Class.CastTo(car, trans))
95 {
96 ProcessGetOutActionData( car, got_action_data );
97 }
98
99 if ( !got_action_data.m_WasJumpingOut )
100 {
101 vehCommand.GetOutVehicle();
102 }
103 else
104 {
105 vehCommand.JumpOutVehicle();
106 }
107
108 if (car)
109 {
110 GetDayZGame().GetBacklit().OnLeaveCar();
111 }
112
113 if ( action_data.m_Player.GetInventory() )
114 action_data.m_Player.GetInventory().LockInventory(LOCK_FROM_SCRIPT);
115 }
116 }
117 }
118
119 override void OnStartServer(ActionData action_data)
120 {
121 HumanCommandVehicle vehCommand = action_data.m_Player.GetCommand_Vehicle();
122 if (vehCommand)
123 {
124 Transport trans = vehCommand.GetTransport();
125
126 if (trans)
127 {
128 CarScript car;
129 if (Class.CastTo(car, trans))
130 {
131 car.ForceUpdateLightsStart();
132 }
133 }
134 }
135 }
136
137 void Unhide(PlayerBase player);
138
139 override void OnUpdate(ActionData action_data)
140 {
141 if (action_data.m_State == UA_START)
142 {
143 if (!action_data.m_Player.GetCommand_Vehicle())
144 {
145 End(action_data);
146 }
147 }
148 }
149
150 override bool CanBeUsedInRestrain()
151 {
152 return true;
153 }
154
155 override bool CanBeUsedInVehicle()
156 {
157 return true;
158 }
159
160 override int GetActionCategory()
161 {
162 return AC_INTERACT;
163 }
164
165 override void OnEnd( ActionData action_data )
166 {
167 if ( action_data.m_Player.GetInventory() )
168 action_data.m_Player.GetInventory().UnlockInventory(LOCK_FROM_SCRIPT);
169 }
170
171 override void OnEndServer( ActionData action_data )
172 {
173 GetOutTransportActionData got_action_data = GetOutTransportActionData.Cast(action_data);
174
175 if (got_action_data.m_WasJumpingOut)
176 {
177 got_action_data.m_Player.OnJumpOutVehicleFinish(got_action_data.m_CarSpeed);
178
179 PlayerBase player = got_action_data.m_Player;
180
181 ApplyJumpOutDmg(action_data);
182
183 vector posMS = player.WorldToModel(player.GetPosition());
184 player.DamageAllLegs(got_action_data.m_DmgTaken); //Additionnal leg specific damage dealing
185 player.ProcessDirectDamage(DT_CUSTOM, player, "", "FallDamage", posMS, got_action_data.m_DmgTaken);
186 }
187
188 if ( got_action_data.m_Car )
189 {
190 CarScript car;
191 if ( Class.CastTo(car, got_action_data.m_Car) )
192 {
193 car.ForceUpdateLightsEnd();
194 }
195 }
196 }
197
198 //Manage all jumping out of vehicle damage logic
199 void ApplyJumpOutDmg(ActionData action_data)
200 {
201 GetOutTransportActionData got_action_data = GetOutTransportActionData.Cast(action_data);
202 PlayerBase player = got_action_data.m_Player;
203
204 //Get all currently equipped clothing
205 // ---------------------------------------------
206
207 ClothingBase trousers = ClothingBase.Cast(player.GetItemOnSlot("LEGS"));
208 ClothingBase bag = ClothingBase.Cast(player.GetItemOnSlot("BACK"));
209 ClothingBase vest = ClothingBase.Cast(player.GetItemOnSlot("VEST"));
210 ClothingBase headGear = ClothingBase.Cast(player.GetItemOnSlot("HeadGear"));
211 ClothingBase mask = ClothingBase.Cast(player.GetItemOnSlot("Mask"));
212 ClothingBase shirt = ClothingBase.Cast(player.GetItemOnSlot("BODY"));
213 ClothingBase shoes = ClothingBase.Cast(player.GetItemOnSlot("FEET"));
214 ClothingBase gloves = ClothingBase.Cast(player.GetItemOnSlot("GLOVES"));
215
216 //Array used to find all relevant information about currently equipped clothes
217 array<ClothingBase> equippedClothes = new array<ClothingBase>;
218
219 equippedClothes.Insert(trousers);
220 equippedClothes.Insert(bag);
221 equippedClothes.Insert(vest);
222 equippedClothes.Insert(headGear);
223 equippedClothes.Insert(mask);
224 equippedClothes.Insert(shirt);
225 equippedClothes.Insert(shoes);
226 equippedClothes.Insert(gloves);
227
228 // -----------------------------------------------
229
230 //Lower shock taken if player uses a helmet
231 headGear = ClothingBase.Cast(player.GetItemOnHead());
232 HelmetBase helmet;
233 if (Class.CastTo(helmet, headGear))
234 got_action_data.m_ShockTaken *= 0.5;
235
236 // -----------------------------------------------
237
238 int randNum; //value used for probability evaluation
239 randNum = Math.RandomInt(0, 100);
240 if (got_action_data.m_CarSpeed < LOW_SPEED_VALUE)
241 {
242 if (randNum < 20)
243 player.GiveShock(-got_action_data.m_ShockTaken); //To inflict shock, a negative value must be passed
244
245 randNum = Math.RandomIntInclusive(0, PlayerBase.m_BleedingSourcesLow.Count() - 1);
246
247 player.m_BleedingManagerServer.AttemptAddBleedingSourceBySelection(PlayerBase.m_BleedingSourcesLow[randNum]);
248 }
249 else if (got_action_data.m_CarSpeed >= LOW_SPEED_VALUE && got_action_data.m_CarSpeed < HIGH_SPEED_VALUE)
250 {
251 if (randNum < 50)
252 player.GiveShock(-got_action_data.m_ShockTaken);
253
254 randNum = Math.RandomInt(0, PlayerBase.m_BleedingSourcesUp.Count() - 1);
255
256 player.m_BleedingManagerServer.AttemptAddBleedingSourceBySelection(PlayerBase.m_BleedingSourcesUp[randNum]);
257 }
258 else if (got_action_data.m_CarSpeed >= HIGH_SPEED_VALUE)
259 {
260 headGear = ClothingBase.Cast(player.GetItemOnHead());
261 if (!Class.CastTo(helmet, headGear))
262 player.m_BleedingManagerServer.AttemptAddBleedingSourceBySelection("Head");
263
264 if (randNum < 75)
265 player.GiveShock(-got_action_data.m_ShockTaken);
266 }
267
268 int nbClothes = 0;
269
270 //Damage all currently equipped clothes
271 for (int i = 0; i < equippedClothes.Count(); i++)
272 {
273 //If no item is equipped on slot, slot is ignored
274 if (equippedClothes[i] == null)
275 continue;
276
277 equippedClothes[i].DecreaseHealth(got_action_data.m_DmgTaken, false);
278 nbClothes++;
279 }
280 }
281};
const int AC_INTERACT
Definition _constants.c:4
ActionData CreateActionData()
Definition ActionBase.c:213
void CreateConditionComponents()
Definition ActionBase.c:218
void OnEndServer(ActionData action_data)
int GetActionCategory()
Definition ActionBase.c:266
GetInputType()
Definition ActionBase.c:203
ref CCIBase m_ConditionItem
Definition ActionBase.c:55
void OnStartServer(ActionData action_data)
ref CCTBase m_ConditionTarget
Definition ActionBase.c:56
void ActionBase()
Definition ActionBase.c:73
protected bool ActionCondition(PlayerBase player, ActionTarget target, ItemBase item)
Definition ActionBase.c:372
bool HasProgress()
For UI: hiding of progress bar.
Definition ActionBase.c:238
bool CanBeUsedInRestrain()
Definition ActionBase.c:306
protected string m_Text
Definition ActionBase.c:49
bool CanBeUsedInVehicle()
Definition ActionBase.c:311
protected int m_StanceMask
Definition ActionBase.c:53
int m_ShockFactor
GetOutTransportActionData m_DmgFactor
void ProcessGetOutActionData(Car car, GetOutTransportActionData got_action_data)
const int LOW_SPEED_VALUE
void ApplyJumpOutDmg(ActionData action_data)
void Unhide(PlayerBase player)
void ActionGetOutTransport()
const int HIGH_SPEED_VALUE
class ActionTargets ActionTarget
DayZGame GetDayZGame()
Definition DayZGame.c:3656
void End()
called on surrender end request end
override void OnEnd()
Definition JumpEvents.c:57
protected void OnStart(Param par=null)
PlayerBase m_Player
Definition ActionBase.c:33
Super root of all classes in Enforce script.
Definition EnScript.c:11
proto native Transport GetTransport()
proto native void GetOutVehicle()
proto native void JumpOutVehicle()
Definition EnMath.c:7
Base native class for all motorized wheeled vehicles.
Definition Car.c:80
override bool IsAreaAtDoorFree(int currentSeat, float maxAllowedObjHeight=0.5, float horizontalExtents=0.5, float playerHeight=1.7)
Definition Car.c:93
Result for an object found in CGame.IsBoxCollidingGeometryProxy.
DayZPlayerConstants
defined in C++
Definition dayzplayer.c:602
static proto bool CastTo(out Class to, Class from)
Try to safely down-cast base class to child class.
static proto int RandomInt(int min, int max)
Returns a random int number between and min [inclusive] and max [exclusive].
static int RandomIntInclusive(int min, int max)
Returns a random int number between and min [inclusive] and max [inclusive].
Definition EnMath.c:53
proto native void OnUpdate()
Definition tools.c:338
const int UA_START
Definition constants.c:423