Dayz Build 1.29.163047, Scripts Rev. 123548
Dayz Code Explorer by Zeroy
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 {
8 {
9 PlayerBase player = PlayerBase.Cast( g_Game.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 = g_Game.GetCurrentCameraPosition();
19 vector rayEnd = rayStart + g_Game.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( g_Game.GetPlayer() );
48 vector rayStart = g_Game.GetCurrentCameraPosition();
49 vector rayEnd = rayStart + g_Game.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
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 (g_Game.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] < g_Game.SurfaceGetSeaLevel())
137 {
138 position[1] = g_Game.SurfaceGetSeaLevel();
139 }
140
141 if (g_Game.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 (g_Game.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}
Super root of all classes in Enforce script.
Definition enscript.c:11
static proto bool RaycastRV(vector begPos, vector endPos, out vector contactPos, out vector contactDir, out int contactComponent, set< Object > results=NULL, Object with=NULL, Object ignore=NULL, bool sorted=false, bool ground_only=false, int iType=ObjIntersectView, float radius=0.0, CollisionFlags flags=CollisionFlags.NEARESTCONTACT)
Raycasts world by given parameters.
static proto bool SphereCastBullet(vector begPos, vector endPos, float radius, PhxInteractionLayers layerMask, Object ignoreObj, out Object hitObject, out vector hitPosition, out vector hitNormal, out float hitFraction)
Definition debug.c:2
static void LogWarning(string message=LOG_DEFAULT, string plugin=LOG_DEFAULT, string author=LOG_DEFAULT, string label=LOG_DEFAULT, string entity=LOG_DEFAULT)
Prints debug message as warning message.
Definition debug.c:290
static bool IsFreeCameraEnabled()
static void TeleportAtCursor()
void OnRPCSetPlayerDirection(PlayerBase player, ParamsReadContext ctx)
static void OnRPC(PlayerBase player, int rpc_type, ParamsReadContext ctx)
static Object GetPlayerRootForTeleporting(PlayerBase player)
static void TeleportAtCursorEx()
void OnRPCSetPlayerPosition(PlayerBase player, ParamsReadContext ctx)
static const float TELEPORT_DISTANCE_MAX_EX
static const float TELEPORT_DISTANCE_MAX
static void SetPlayerPosition(PlayerBase player, vector position, bool breakSync=false)
static void SetPlayerDirection(PlayerBase player, vector direction)
proto native Transport GetTransport()
Definition enmath.c:7
proto bool Read(void value_in)
static proto native float Distance(vector v1, vector v2)
Returns the distance between tips of two 3D vectors.
static const vector Zero
Definition enconvert.c:123
DayZGame g_Game
Definition dayzgame.c:3942
PhxInteractionLayers
Definition dayzphysics.c:2
DiagMenuIDs
Definition ediagmenuids.c:2
ERPCs
Definition erpcs.c:2
Serializer ParamsReadContext
Definition gameplay.c:15
static proto bool GetBool(int id, bool reverse=false)
Get value as bool from the given script id.
static proto bool CastTo(out Class to, Class from)
Try to safely down-cast base class to child class.
static proto float RandomFloat(float min, float max)
Returns a random float number between and min[inclusive] and max[exclusive].
static const float PI
Definition enmath.c:12
static const float RAD2DEG
Definition enmath.c:16
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.