Dayz Explorer  1.24.157551 (v105080)
Dayz Code Explorer by Zeroy
actioncarhorn.c
Go to the documentation of this file.
2 {
3  static bool ActionCondition(PlayerBase player)
4  {
5  HumanCommandVehicle vehCommand = player.GetCommand_Vehicle();
6 
7  if (vehCommand)
8  {
9  Transport trans = vehCommand.GetTransport();
10  if (trans)
11  {
12  if (!PlayerIsDriver(trans, player))
13  {
14  return false;
15  }
16 
17  CarScript car;
18  if (Class.CastTo(car, trans))
19  {
20  return BatteryIsVital(car.GetBattery());
21  }
22  }
23  }
24 
25  return false;
26  }
27 
28  static void SetCarHornState(CarHornActionData pActionData, int pState)
29  {
30  if (!pActionData.m_Player)
31  return;
32 
33  if (!pActionData.m_Car)
34  return;
35 
36  pActionData.m_Car.SetCarHornState(pState);
37  }
38 
39  protected static bool PlayerIsDriver(Transport trans, PlayerBase player)
40  {
41  return trans.GetSeatAnimationType(trans.CrewMemberIndex(player)) == DayZPlayerConstants.VEHICLESEAT_DRIVER;
42  }
43 
44  protected static bool BatteryIsVital(ItemBase battery)
45  {
46  return battery && battery.GetHealthLevel("Health") <= GameConstants.STATE_DAMAGED;
47  }
48 }
49 
50 class CarHornActionReceiveData : ActionReciveData
51 {
52  bool m_ActionNeedEnd;
54 
55 }
56 
58 {
59  bool m_ActionNeedEnd;
60  CarScript m_Car;
61 }
62 
63 class ActionCarHornShortCB : ActionSingleUseBaseCB {}
64 
66 {
68  {
69  m_CallbackClass = ActionCarHornShortCB;
70  m_CommandUID = DayZPlayerConstants.CMD_ACTIONMOD_TOOTHORN;
71  m_StanceMask = DayZPlayerConstants.STANCEMASK_ALL;
72  }
73 
74  override bool HasTarget()
75  {
76  return false;
77  }
78 
79  override bool HasProgress()
80  {
81  return false;
82  }
83 
84  override bool CanBeUsedInVehicle()
85  {
86  return true;
87  }
88 
89  override bool UseMainItem()
90  {
91  return false;
92  }
93 
94  override void CreateConditionComponents()
95  {
96  m_ConditionItem = new CCINone();
97  m_ConditionTarget = new CCTNone();
98  }
99 
100  override typename GetInputType()
101  {
103  }
104 
106  {
107  ActionData action_data = new CarHornActionData();
108  return action_data;
109  }
110 
111  override bool ActionCondition(PlayerBase player, ActionTarget target, ItemBase item)
112  {
113  return ActionCarHornBase.ActionCondition(player);
114  }
115 
117  override void OnUpdate(ActionData action_data)
118  {
119  super.OnUpdate(action_data);
120 
121  CarHornActionData carHornData = CarHornActionData.Cast(action_data);
122  if (carHornData.m_WasExecuted && carHornData.m_ActionNeedEnd)
123  {
124  carHornData.m_Callback.SetCommand(DayZPlayerConstants.CMD_ACTIONINT_END);
125  carHornData.m_ActionNeedEnd = false;
126  }
127  }
128 
129  override void OnEndInput(ActionData action_data)
130  {
131  super.OnEndInput(action_data);
132 
133  CarHornActionData carHornData = CarHornActionData.Cast(action_data);
134  ActionCarHornBase.SetCarHornState(carHornData, ECarHornState.OFF);
135  }
136 
138  override void OnStart(ActionData action_data)
139  {
140  super.OnStart(action_data);
141 
142  CarHornActionData carHornData = CarHornActionData.Cast(action_data);
143  carHornData.m_ActionNeedEnd = true;
144  carHornData.m_Car = CarScript.Cast(action_data.m_Player.GetCommand_Vehicle().GetTransport());
145  }
146 
147  override void OnStartServer(ActionData action_data)
148  {
149  super.OnStartServer(action_data);
150 
151  CarHornActionData carHornData = CarHornActionData.Cast(action_data);
152  ActionCarHornBase.SetCarHornState(carHornData, ECarHornState.SHORT);
153  }
154 
155  override void OnEndServer(ActionData action_data)
156  {
157  super.OnEndServer(action_data);
158 
159  CarHornActionData carHornData = CarHornActionData.Cast(action_data);
160  ActionCarHornBase.SetCarHornState(carHornData, ECarHornState.OFF);
161  }
162 
163  override void WriteToContext(ParamsWriteContext ctx, ActionData action_data)
164  {
165  super.WriteToContext(ctx, action_data);
166 
167  CarHornActionData carHornData = CarHornActionData.Cast(action_data);
168 
169  ctx.Write(carHornData.m_ActionNeedEnd);
170  ctx.Write(carHornData.m_Car);
171  }
172 
173  override bool ReadFromContext(ParamsReadContext ctx, out ActionReciveData action_recive_data)
174  {
175  if (!action_recive_data)
176  {
177  action_recive_data = new CarHornActionReceiveData();
178  }
179 
180  super.ReadFromContext(ctx, action_recive_data);
181 
182  bool needUpdate;
183  if (!ctx.Read(needUpdate))
184  return false;
185 
186  CarScript carScript;
187  if (!ctx.Read(carScript))
188  return false;
189 
190  CarHornActionReceiveData carHornReceivedData = CarHornActionReceiveData.Cast(action_recive_data);
191  carHornReceivedData.m_ActionNeedEnd = needUpdate;
192  carHornReceivedData.m_Car = carScript;
193 
194  return true;
195  }
196 
197  override void HandleReciveData(ActionReciveData action_recive_data, ActionData action_data)
198  {
199  super.HandleReciveData(action_recive_data, action_data);
200 
201  CarHornActionReceiveData carHornReceivedData = CarHornActionReceiveData.Cast(action_recive_data);
202  CarHornActionData carHornData = CarHornActionData.Cast(action_data);
203  carHornData.m_ActionNeedEnd = carHornReceivedData.m_ActionNeedEnd;
204  carHornData.m_Car = carHornReceivedData.m_Car;
205  }
206 }
207 
209 {
210  void ActionCarHornLong()
211  {
212  m_CommandUID = DayZPlayerConstants.CMD_ACTIONMOD_TOOTHORN;
213  m_StanceMask = DayZPlayerConstants.STANCEMASK_ALL;
214  }
215 
216  override bool HasTarget()
217  {
218  return false;
219  }
220 
221  override bool HasProgress()
222  {
223  return false;
224  }
225 
226  override bool CanBeUsedInVehicle()
227  {
228  return true;
229  }
230 
231  override typename GetInputType()
232  {
233  return CarHornLongActionInput;
234  }
235 
236  override bool UseMainItem()
237  {
238  return false;
239  }
240 
241  override void CreateConditionComponents()
242  {
243  m_ConditionItem = new CCINone();
244  m_ConditionTarget = new CCTNone();
245  }
246 
247  override ActionData CreateActionData()
248  {
249  ActionData action_data = new CarHornActionData();
250  return action_data;
251  }
252 
253  override bool ActionCondition(PlayerBase player, ActionTarget target, ItemBase item)
254  {
255  return ActionCarHornBase.ActionCondition(player);
256  }
257 
259  override void OnUpdate(ActionData action_data)
260  {
261  super.OnUpdate(action_data);
262 
263  CarHornActionData carHornData = CarHornActionData.Cast(action_data);
264  if (carHornData.m_ReciveEndInput && carHornData.m_ActionNeedEnd)
265  {
266  carHornData.m_Callback.SetCommand(DayZPlayerConstants.CMD_ACTIONINT_END);
267  carHornData.m_ActionNeedEnd = false;
268  }
269  }
270 
271  override void OnEndInput(ActionData action_data)
272  {
273  super.OnEndInput(action_data);
274 
275  CarHornActionData carHornData = CarHornActionData.Cast(action_data);
276  ActionCarHornBase.SetCarHornState(carHornData, ECarHornState.OFF);
277  }
278 
279  override void OnStart(ActionData action_data)
280  {
281  super.OnStart(action_data);
282 
283  CarHornActionData carHornData = CarHornActionData.Cast(action_data);
284  carHornData.m_ActionNeedEnd = true;
285  carHornData.m_Car = CarScript.Cast(action_data.m_Player.GetCommand_Vehicle().GetTransport());
286  }
287 
288  override void OnStartServer(ActionData action_data)
289  {
290  super.OnStartServer(action_data);
291 
292  CarHornActionData carHornData = CarHornActionData.Cast(action_data);
293  carHornData.m_ActionNeedEnd = true;
294  ActionCarHornBase.SetCarHornState(carHornData, ECarHornState.LONG);
295  }
296 
297  override void OnEndServer(ActionData action_data)
298  {
299  super.OnEndServer(action_data);
300 
301  CarHornActionData carHornData = CarHornActionData.Cast(action_data);
302  ActionCarHornBase.SetCarHornState(carHornData, ECarHornState.OFF);
303  }
304 
305  override void WriteToContext(ParamsWriteContext ctx, ActionData action_data)
306  {
307  super.WriteToContext(ctx, action_data);
308 
309  CarHornActionData carHornData = CarHornActionData.Cast(action_data);
310 
311  ctx.Write(carHornData.m_ActionNeedEnd);
312  ctx.Write(carHornData.m_Car);
313  }
314 
315  override bool ReadFromContext(ParamsReadContext ctx, out ActionReciveData action_recive_data)
316  {
317  if (!action_recive_data)
318  {
319  action_recive_data = new CarHornActionReceiveData();
320  }
321 
322  super.ReadFromContext(ctx, action_recive_data);
323 
324  bool needUpdate;
325  if (!ctx.Read(needUpdate))
326  return false;
327 
328  CarScript carScript;
329  if (!ctx.Read(carScript))
330  return false;
331 
332  CarHornActionReceiveData carHornReceivedData = CarHornActionReceiveData.Cast(action_recive_data);
333  carHornReceivedData.m_ActionNeedEnd = needUpdate;
334  carHornReceivedData.m_Car = carScript;
335 
336  return true;
337  }
338 
339  override void HandleReciveData(ActionReciveData action_recive_data, ActionData action_data)
340  {
341  super.HandleReciveData(action_recive_data, action_data);
342 
343  CarHornActionReceiveData carHornReceivedData = CarHornActionReceiveData.Cast(action_recive_data);
344  CarHornActionData carHornData = CarHornActionData.Cast(action_data);
345  carHornData.m_ActionNeedEnd = carHornReceivedData.m_ActionNeedEnd;
346  carHornData.m_Car = carHornReceivedData.m_Car;
347  }
348 }
ItemBase
Definition: inventoryitem.c:730
ActionCarHornShort
CarHornActionData ActionData ActionCarHornShort()
Definition: actioncarhorn.c:67
m_Car
CarScript m_Car
Definition: actioncarhorn.c:53
m_ActionNeedEnd
class ActionCarHornBase m_ActionNeedEnd
Definition: actioncarhorn.c:54
CreateActionData
override ActionData CreateActionData()
Definition: actioncarhorn.c:105
CarHornLongActionInput
ToggleLightsActionInput CarHornLongActionInput
CanBeUsedInVehicle
override bool CanBeUsedInVehicle()
Definition: actioncarhorn.c:84
GetInputType
override GetInputType()
Definition: actioncarhorn.c:100
CCINone
Definition: ccinone.c:1
CarHornActionData
Definition: actioncarhorn.c:57
CarScript
Definition: civiliansedan.c:1
CCTNone
Definition: cctnone.c:1
ActionCarHornLong
Definition: actioncarhorn.c:208
OnEndInput
override void OnEndInput(ActionData action_data)
Definition: actioncarhorn.c:129
ActionSingleUseBaseCB
Definition: actionsingleusebase.c:1
ReadFromContext
override bool ReadFromContext(ParamsReadContext ctx, out ActionReciveData action_recive_data)
Definition: actioncarhorn.c:173
Serializer
Serialization general interface. Serializer API works with:
Definition: serializer.c:55
HasProgress
override bool HasProgress()
Definition: actioncarhorn.c:79
UseMainItem
override bool UseMainItem()
Definition: actioncarhorn.c:89
WriteToContext
override void WriteToContext(ParamsWriteContext ctx, ActionData action_data)
Definition: actioncarhorn.c:163
ActionCarHornBase
Definition: actioncarhorn.c:1
PlayerBase
Definition: playerbaseclient.c:1
OnStartServer
override void OnStartServer(ActionData action_data)
Definition: actioncarhorn.c:147
ActionTarget
class ActionTargets ActionTarget
ActionData
Definition: actionbase.c:20
DayZPlayerConstants
DayZPlayerConstants
defined in C++
Definition: dayzplayer.c:601
OnEndServer
override void OnEndServer(ActionData action_data)
Definition: actioncarhorn.c:155
HasTarget
override bool HasTarget()
Definition: actioncarhorn.c:74
Transport
Base native class for all motorized wheeled vehicles.
Definition: car.c:79
HumanCommandVehicle
Definition: human.c:689
OnUpdate
override void OnUpdate(ActionData action_data)
special case - manually ends the action on exec event
Definition: actioncarhorn.c:117
GameConstants
Definition: constants.c:612
ActionSingleUseBase
Definition: actionsingleusebase.c:41
m_ConditionItem
ref CCIBase m_ConditionItem
Definition: actionbase.c:55
ActionCondition
override bool ActionCondition(PlayerBase player, ActionTarget target, ItemBase item)
Definition: actioncarhorn.c:111
HandleReciveData
override void HandleReciveData(ActionReciveData action_recive_data, ActionData action_data)
Definition: actioncarhorn.c:197
ActionContinuousBase
Definition: actioncontinuousbase.c:132
CarHornShortActionInput
void CarHornShortActionInput(PlayerBase player)
Definition: actioninput.c:626
m_ConditionTarget
ref CCTBase m_ConditionTarget
Definition: actionbase.c:56
CreateConditionComponents
override void CreateConditionComponents()
Definition: actioncarhorn.c:94
Class
Super root of all classes in Enforce script.
Definition: enscript.c:10
m_StanceMask
protected int m_StanceMask
Definition: actionbase.c:53
OnStart
override void OnStart(ActionData action_data)
sets the m_ActionNeeded flag on both sides
Definition: actioncarhorn.c:138