Dayz Explorer  1.24.157551 (v105080)
Dayz Code Explorer by Zeroy
developerteleport.c
Go to the documentation of this file.
2 {
3  protected static const float TELEPORT_DISTANCE_MAX = 1000;
4 
5  static void TeleportAtCursor()
6  {
7  if ( !DeveloperFreeCamera.IsFreeCameraEnabled() )
8  {
9  PlayerBase player = PlayerBase.Cast( GetGame().GetPlayer() );
10  vector pos_player = player.GetPosition();
11 
12  Object ignore;
13  if (!Class.CastTo(ignore, player.GetParent()))
14  {
15  ignore = player;
16  }
17 
18  vector rayStart = GetGame().GetCurrentCameraPosition();
19  vector rayEnd = rayStart + GetGame().GetCurrentCameraDirection() * 1000;
20  vector hitPos;
21  vector hitNormal;
22  int hitComponentIndex;
23  DayZPhysics.RaycastRV(rayStart, rayEnd, hitPos, hitNormal, hitComponentIndex, NULL, NULL, ignore);
24 
25  float distance = vector.Distance( pos_player, hitPos );
26 
27  if ( distance < TELEPORT_DISTANCE_MAX )
28  {
29  bool breakSync = false;
30 
31  #ifdef DIAG_DEVELOPER
32  breakSync = DiagMenu.GetBool(DiagMenuIDs.MISC_TELEPORT_BREAKS_SYNC);
33  #endif
34 
35  SetPlayerPosition(player, hitPos, breakSync);
36  }
37  else
38  {
39  Debug.LogWarning("Distance for teleportation is too far!");
40  }
41  }
42  }
43 
44  protected static const float TELEPORT_DISTANCE_MAX_EX = 500;
45  static void TeleportAtCursorEx()
46  {
47  PlayerBase player = PlayerBase.Cast( GetGame().GetPlayer() );
48  vector rayStart = GetGame().GetCurrentCameraPosition();
49  vector rayEnd = rayStart + GetGame().GetCurrentCameraDirection() * TELEPORT_DISTANCE_MAX_EX;
50  vector hitPos;
51  vector hitNormal;
52  float hitFraction;
53  Object hitObj;
54 
55  Object ignore;
56  if (!Class.CastTo(ignore, player.GetParent()))
57  {
58  ignore = player;
59  }
60 
61  int layers = 0;
62  layers |= PhxInteractionLayers.TERRAIN;
63  layers |= PhxInteractionLayers.ROADWAY;
64  layers |= PhxInteractionLayers.ITEM_LARGE;
65  layers |= PhxInteractionLayers.BUILDING;
66  layers |= PhxInteractionLayers.VEHICLE;
67  layers |= PhxInteractionLayers.RAGDOLL;
68  if (DayZPhysics.SphereCastBullet(rayStart, rayEnd, 0.01, layers, ignore, hitObj, hitPos, hitNormal, hitFraction))
69  {
70  bool breakSync = false;
71 
72  #ifdef DIAG_DEVELOPER
73  breakSync = DiagMenu.GetBool(DiagMenuIDs.MISC_TELEPORT_BREAKS_SYNC);
74  #endif
75 
76  SetPlayerPosition(player, hitPos, breakSync);
77 
78  if (DeveloperFreeCamera.IsFreeCameraEnabled())
79  {
80  DeveloperTeleport.SetPlayerDirection( player, FreeDebugCamera.GetInstance().GetDirection() );
81  }
82  }
83  }
84 
85  // Set Player Position (MP support)
86  static void SetPlayerPosition(PlayerBase player, vector position, bool breakSync = false)
87  {
88  Object object = player;
89 
90  HumanCommandVehicle vehCmd = player.GetCommand_Vehicle();
91  if (vehCmd)
92  {
93  object = vehCmd.GetTransport();
94  }
95 
96 #ifdef DIAG_DEVELOPER
97  if (GetGame().IsMultiplayer() && breakSync)
98  {
99  vector v;
100  v[0] = Math.RandomFloat(-Math.PI, Math.PI);
101  v[1] = Math.RandomFloat(-Math.PI, Math.PI);
102  v[2] = Math.RandomFloat(-Math.PI, Math.PI);
103  dBodySetAngularVelocity(object, v);
104  SetVelocity(object, vector.Zero);
105 
106  v[0] = Math.RandomFloat(-Math.PI, Math.PI);
107  v[1] = Math.RandomFloat(-Math.PI, Math.PI);
108  v[2] = Math.RandomFloat(-Math.PI, Math.PI);
109  object.SetOrientation(v * Math.RAD2DEG);
110  }
111 #endif
112 
113  if (GetGame().IsServer())
114  {
115  object.SetPosition(position);
116  }
117  else
118  {
119  Param4<float, float, float, bool> params = new Param4<float, float, float, bool>(position[0], position[1], position[2], breakSync);
120  player.RPCSingleParam(ERPCs.DEV_RPC_TELEPORT, params, true);
121  }
122  }
123 
124  // Set Player Direction (MP support)
125  static void SetPlayerDirection(PlayerBase player, vector direction)
126  {
127  if (GetGame().IsServer())
128  {
129  HumanCommandVehicle vehCmd = player.GetCommand_Vehicle();
130  if (vehCmd)
131  {
132  Transport transport = vehCmd.GetTransport();
133  if (transport)
134  transport.SetDirection(direction);
135  }
136  else
137  player.SetDirection(direction);
138  }
139  else
140  {
141  Param3<float, float, float> params = new Param3<float, float, float>(direction[0], direction[1], direction[2]);
142  player.RPCSingleParam(ERPCs.DEV_RPC_SET_PLAYER_DIRECTION, params, true);
143  }
144  }
145 
146  static void OnRPC(PlayerBase player, int rpc_type, ParamsReadContext ctx)
147  {
148  #ifdef DIAG_DEVELOPER
149  if ( rpc_type == ERPCs.DEV_RPC_TELEPORT )
150  {
151  OnRPCSetPlayerPosition(player, ctx);
152  }
153  else if ( rpc_type == ERPCs.DEV_RPC_SET_PLAYER_DIRECTION )
154  {
155  OnRPCSetPlayerDirection(player, ctx);
156  }
157  #endif
158  }
159 
160  static protected void OnRPCSetPlayerPosition(PlayerBase player, ParamsReadContext ctx)
161  {
162  Param4<float, float, float, bool> p = new Param4<float, float, float, bool>(0, 0, 0, false);
163  if (ctx.Read(p))
164  {
165  vector v = "0 0 0";
166  v[0] = p.param1;
167  v[1] = p.param2;
168  v[2] = p.param3;
169  SetPlayerPosition(player, v, p.param4);
170  }
171  }
172 
173  static protected void OnRPCSetPlayerDirection(PlayerBase player, ParamsReadContext ctx)
174  {
176  if (ctx.Read(p))
177  {
178  vector v = "0 0 0";
179  v[0] = p.param1;
180  v[1] = p.param2;
181  v[2] = p.param3;
182  SetPlayerDirection(player, v);
183  }
184  }
185 }
GetGame
proto native CGame GetGame()
SetVelocity
proto native void SetVelocity(notnull IEntity ent, vector vel)
Sets linear velocity (for Rigid bodies)
DeveloperFreeCamera
Definition: developerfreecamera.c:1
DiagMenu
Definition: endebug.c:232
dBodySetAngularVelocity
proto void dBodySetAngularVelocity(notnull IEntity body, vector angvel)
Changed an angular velocity.
Param3< float, float, float >
Serializer
Serialization general interface. Serializer API works with:
Definition: serializer.c:55
DiagMenuIDs
DiagMenuIDs
Definition: ediagmenuids.c:1
PlayerBase
Definition: playerbaseclient.c:1
vector
Definition: enconvert.c:105
Object
Definition: objecttyped.c:1
Transport
Base native class for all motorized wheeled vehicles.
Definition: car.c:79
DeveloperTeleport
Definition: developerteleport.c:1
HumanCommandVehicle
Definition: human.c:689
GetPlayer
protected void GetPlayer()
Definition: crosshairselector.c:127
Debug
Definition: debug.c:13
DayZPhysics
Definition: dayzphysics.c:123
ERPCs
ERPCs
Definition: erpcs.c:1
Math
Definition: enmath.c:6
Class
Super root of all classes in Enforce script.
Definition: enscript.c:10
PhxInteractionLayers
PhxInteractionLayers
Definition: dayzphysics.c:1