DayZ 1.27
DayZ Explorer by KGB
 
Загрузка...
Поиск...
Не найдено
DeveloperTeleport.c
См. документацию.
2{
3 protected static const float TELEPORT_DISTANCE_MAX = 1000;
4
5 static void TeleportAtCursor()
6 {
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
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() );
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 (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}
PhxInteractionLayers
Определения DayZPhysics.c:2
DiagMenuIDs
Определения EDiagMenuIDs.c:2
ERPCs
Определения ERPCs.c:2
PlayerBase GetPlayer()
Определения ModifierBase.c:51
proto native float SurfaceGetSeaLevel()
proto native vector GetCurrentCameraPosition()
proto native vector GetCurrentCameraDirection()
Super root of all classes in Enforce script.
Определения 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)
Определения DayZPhysics.c:124
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.
Определения Debug.c:230
Определения Debug.c:2
static bool IsFreeCameraEnabled()
Определения DeveloperFreeCamera.c:23
static const float TELEPORT_DISTANCE_MAX_EX
Определения DeveloperTeleport.c:44
static void OnRPC(PlayerBase player, int rpc_type, ParamsReadContext ctx)
Определения DeveloperTeleport.c:168
static const float TELEPORT_DISTANCE_MAX
Определения DeveloperTeleport.c:3
static void TeleportAtCursor()
Определения DeveloperTeleport.c:5
static void TeleportAtCursorEx()
Определения DeveloperTeleport.c:45
void OnRPCSetPlayerPosition(PlayerBase player, ParamsReadContext ctx)
Определения DeveloperTeleport.c:182
static Object GetPlayerRootForTeleporting(PlayerBase player)
Определения DeveloperTeleport.c:85
static void SetPlayerDirection(PlayerBase player, vector direction)
Определения DeveloperTeleport.c:153
void OnRPCSetPlayerDirection(PlayerBase player, ParamsReadContext ctx)
Определения DeveloperTeleport.c:195
static void SetPlayerPosition(PlayerBase player, vector position, bool breakSync=false)
Определения DeveloperTeleport.c:115
Определения EnDebug.c:233
Определения human.c:620
proto native Transport GetTransport()
Определения human.c:690
Определения EnMath.c:7
Определения ObjectTyped.c:2
Определения EntityAI.c:95
Определения PlayerBaseClient.c:2
proto bool Read(void value_in)
static const vector Zero
Определения EnConvert.c:110
static proto native float Distance(vector v1, vector v2)
Returns the distance between tips of two 3D vectors.
Определения EnConvert.c:106
Serializer ParamsReadContext
Определения gameplay.c:15
proto native CGame GetGame()
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 RAD2DEG
Определения EnMath.c:16
static const float PI
Определения EnMath.c:12
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.