Dayz Explorer 1.28.160049
Loading...
Searching...
No Matches
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
86 {
87 Object playerRoot = player;
88
89 HumanCommandVehicle hcv = player.GetCommand_Vehicle();
90 if (hcv)
91 {
92 playerRoot = hcv.GetTransport();
93 }
94
95 HumanCommandUnconscious hcu = player.GetCommand_Unconscious();
96 if (hcu)
97 {
98 Class.CastTo(playerRoot, player.GetParent());
99
100 if (playerRoot != player.GetTransportCache())
101 {
102 playerRoot = null;
103 }
104 }
105
106 if (playerRoot == null)
107 {
108 playerRoot = player;
109 }
110
111 return playerRoot;
112 }
113
114 // Set Player Position (MP support)
115 static void SetPlayerPosition(PlayerBase player, vector position, bool breakSync = false)
116 {
117 Object playerRoot = GetPlayerRootForTeleporting(player);
118
119#ifdef DIAG_DEVELOPER
120 if (GetGame().IsMultiplayer() && breakSync)
121 {
122 vector v;
123 v[0] = Math.RandomFloat(-Math.PI, Math.PI);
124 v[1] = Math.RandomFloat(-Math.PI, Math.PI);
125 v[2] = Math.RandomFloat(-Math.PI, Math.PI);
126 dBodySetAngularVelocity(playerRoot, v);
127 SetVelocity(playerRoot, vector.Zero);
128
129 v[0] = Math.RandomFloat(-Math.PI, Math.PI);
130 v[1] = Math.RandomFloat(-Math.PI, Math.PI);
131 v[2] = Math.RandomFloat(-Math.PI, Math.PI);
132 playerRoot.SetOrientation(v * Math.RAD2DEG);
133 }
134#endif
135
136 if (position[1] < GetGame().SurfaceGetSeaLevel())
137 {
138 position[1] = GetGame().SurfaceGetSeaLevel();
139 }
140
141 if (GetGame().IsServer())
142 {
143 playerRoot.SetPosition(position);
144 }
145 else
146 {
147 Param4<float, float, float, bool> params = new Param4<float, float, float, bool>(position[0], position[1], position[2], breakSync);
148 player.RPCSingleParam(ERPCs.DEV_RPC_TELEPORT, params, true);
149 }
150 }
151
152 // Set Player Direction (MP support)
153 static void SetPlayerDirection(PlayerBase player, vector direction)
154 {
155 Object playerRoot = GetPlayerRootForTeleporting(player);
156
157 if (GetGame().IsServer())
158 {
159 playerRoot.SetDirection(direction);
160 }
161 else
162 {
163 Param3<float, float, float> params = new Param3<float, float, float>(direction[0], direction[1], direction[2]);
164 player.RPCSingleParam(ERPCs.DEV_RPC_SET_PLAYER_DIRECTION, params, true);
165 }
166 }
167
168 static void OnRPC(PlayerBase player, int rpc_type, ParamsReadContext ctx)
169 {
170 #ifdef DIAG_DEVELOPER
171 if ( rpc_type == ERPCs.DEV_RPC_TELEPORT )
172 {
173 OnRPCSetPlayerPosition(player, ctx);
174 }
175 else if ( rpc_type == ERPCs.DEV_RPC_SET_PLAYER_DIRECTION )
176 {
177 OnRPCSetPlayerDirection(player, ctx);
178 }
179 #endif
180 }
181
182 static protected void OnRPCSetPlayerPosition(PlayerBase player, ParamsReadContext ctx)
183 {
184 Param4<float, float, float, bool> p = new Param4<float, float, float, bool>(0, 0, 0, false);
185 if (ctx.Read(p))
186 {
187 vector v = "0 0 0";
188 v[0] = p.param1;
189 v[1] = p.param2;
190 v[2] = p.param3;
191 SetPlayerPosition(player, v, p.param4);
192 }
193 }
194
195 static protected void OnRPCSetPlayerDirection(PlayerBase player, ParamsReadContext ctx)
196 {
198 if (ctx.Read(p))
199 {
200 vector v = "0 0 0";
201 v[0] = p.param1;
202 v[1] = p.param2;
203 v[2] = p.param3;
204 SetPlayerDirection(player, v);
205 }
206 }
207}
proto native float SurfaceGetSeaLevel()
Super root of all classes in Enforce script.
Definition enscript.c:11
Definition debug.c:2
static const float TELEPORT_DISTANCE_MAX_EX
static void OnRPC(PlayerBase player, int rpc_type, ParamsReadContext ctx)
static const float TELEPORT_DISTANCE_MAX
static void TeleportAtCursor()
static void TeleportAtCursorEx()
void OnRPCSetPlayerPosition(PlayerBase player, ParamsReadContext ctx)
static Object GetPlayerRootForTeleporting(PlayerBase player)
static void SetPlayerDirection(PlayerBase player, vector direction)
void OnRPCSetPlayerDirection(PlayerBase player, ParamsReadContext ctx)
static void SetPlayerPosition(PlayerBase player, vector position, bool breakSync=false)
Definition enmath.c:7
Serialization general interface. Serializer API works with:
Definition serializer.c:56
PhxInteractionLayers
Definition dayzphysics.c:2
DiagMenuIDs
Definition ediagmenuids.c:2
ERPCs
Definition erpcs.c:2
proto native CGame GetGame()
proto native void SetVelocity(notnull IEntity ent, vector vel)
Sets linear velocity (for Rigid bodies)
proto void dBodySetAngularVelocity(notnull IEntity body, vector angvel)
Changed an angular velocity.
PlayerBase GetPlayer()