Advertisement
Guest User

Untitled

a guest
Aug 22nd, 2019
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.00 KB | None | 0 0
  1. const pointing =
  2. {
  3. active: false,
  4. interval: null,
  5. lastSent: 0,
  6.  
  7. start: function () {
  8. if (!this.active) {
  9. this.active = true;
  10.  
  11. mp.game.streaming.requestAnimDict("anim@mp_point");
  12. while (!mp.game.streaming.hasAnimDictLoaded("anim@mp_point")) {
  13. mp.game.wait(0);
  14. }
  15.  
  16. mp.game.invoke("0x0725a4ccfded9a70", mp.players.local.handle, 0, 1, 1, 1);
  17. mp.players.local.setConfigFlag(36, true)
  18. mp.players.local.taskMoveNetwork("task_mp_pointing", 0.5, false, "anim@mp_point", 24);
  19. mp.game.streaming.removeAnimDict("anim@mp_point");
  20.  
  21. this.interval = setInterval(this.process.bind(this), 0);
  22. }
  23. },
  24.  
  25. stop: function () {
  26. if (this.active) {
  27. clearInterval(this.interval);
  28. this.interval = null
  29. this.active = false;
  30.  
  31. mp.game.invoke("0xd01015c7316ae176", mp.players.local.handle, "Stop");
  32. if (!mp.players.local.isInjured()) {
  33. mp.players.local.clearTasks();
  34. }
  35.  
  36. if (!mp.players.local.isInAnyVehicle(true)) {
  37. mp.game.invoke("0x0725a4ccfded9a70", mp.players.local.handle, 1, 1, 1, 1);
  38. }
  39.  
  40. mp.players.local.setConfigFlag(36, false);
  41. mp.players.local.clearTasks()
  42. }
  43. },
  44.  
  45. gameplayCam: mp.cameras.new("gameplay"),
  46. lastSync: 0,
  47.  
  48. getRelativePitch: function () {
  49. const camRot = this.gameplayCam.getRot(2);
  50.  
  51. return camRot.x - mp.players.local.getPitch();
  52. },
  53.  
  54. process: function () {
  55. if (this.active) {
  56. mp.game.invoke("0x921ce12c489c4c41", mp.players.local.handle);
  57.  
  58. let camPitch = this.getRelativePitch();
  59. if (camPitch < -70.0) {
  60. camPitch = -70.0;
  61. } else if (camPitch > 42.0) {
  62. camPitch = 42.0;
  63. }
  64.  
  65. camPitch = (camPitch + 70.0) / 112.0;
  66.  
  67. let camHeading = mp.game.cam.getGameplayCamRelativeHeading();
  68. let cosCamHeading = mp.game.system.cos(camHeading);
  69. let sinCamHeading = mp.game.system.sin(camHeading);
  70.  
  71. if (camHeading < -180.0) {
  72. camHeading = -180.0;
  73. } else if (camHeading > 180.0) {
  74. camHeading = 180.0;
  75. }
  76.  
  77. camHeading = (camHeading + 180.0) / 360.0;
  78.  
  79. let coords = mp.players.local.getOffsetFromGivenWorldCoords((cosCamHeading * -0.2) - (sinCamHeading * (0.4 * camHeading + 0.3)), (sinCamHeading * -0.2) + (cosCamHeading * (0.4 * camHeading + 0.3)), 0.6);
  80. let blocked = (typeof mp.raycasting.testPointToPoint(new mp.Vector3(coords.x, coords.y, coords.z - 0.2), new mp.Vector3(coords.x, coords.y, coords.z + 0.2), mp.players.local.handle, 7) !== 'undefined');
  81.  
  82. mp.game.invoke('0xd5bb4025ae449a4e', mp.players.local.handle, "Pitch", camPitch)
  83. mp.game.invoke('0xd5bb4025ae449a4e', mp.players.local.handle, "Heading", camHeading * -1.0 + 1.0)
  84. mp.game.invoke('0xb0a6cfd2c69c1088', mp.players.local.handle, "isBlocked", blocked)
  85. mp.game.invoke('0xb0a6cfd2c69c1088', mp.players.local.handle, "isFirstPerson", mp.game.invoke('0xee778f8c7e1142e2', mp.game.invoke('0x19cafa3c87f7c2ff')) == 4)
  86.  
  87. if ((Date.now() - this.lastSent) > 100) {
  88. this.lastSent = Date.now();
  89. mp.events.callRemote("fpsync.update", camPitch, camHeading);
  90. }
  91. }
  92. }
  93. }
  94.  
  95. mp.events.add("fpsync.update", (playerH, camPitch, camHeading) => {
  96. const netPlayer = getPlayerByHandle(parseInt(playerH.handle));
  97. if (netPlayer != null) {
  98. if (netPlayer != mp.players.local) {
  99. netPlayer.lastReceivedPointing = Date.now();
  100.  
  101. if (!netPlayer.pointingInterval) {
  102. netPlayer.pointingInterval = setInterval((function () {
  103. if ((Date.now() - netPlayer.lastReceivedPointing) > 1000) {
  104. clearInterval(netPlayer.pointingInterval);
  105.  
  106. netPlayer.lastReceivedPointing = undefined;
  107. netPlayer.pointingInterval = undefined;
  108.  
  109. mp.game.invoke("0xd01015c7316ae176", netPlayer.handle, "Stop");
  110.  
  111.  
  112. if (!netPlayer.isInAnyVehicle(true)) {
  113. mp.game.invoke("0x0725a4ccfded9a70", netPlayer.handle, 1, 1, 1, 1);
  114. }
  115. netPlayer.setConfigFlag(36, false);
  116.  
  117. }
  118. }).bind(netPlayer), 500);
  119.  
  120. mp.game.streaming.requestAnimDict("anim@mp_point");
  121.  
  122. while (!mp.game.streaming.hasAnimDictLoaded("anim@mp_point")) {
  123. mp.game.wait(0);
  124. }
  125.  
  126. mp.game.invoke("0x0725a4ccfded9a70", netPlayer.handle, 0, 1, 1, 1);
  127. netPlayer.setConfigFlag(36, true)
  128. netPlayer.taskMoveNetwork("task_mp_pointing", 0.5, false, "anim@mp_point", 24);
  129. mp.game.streaming.removeAnimDict("anim@mp_point");
  130. }
  131. mp.game.invoke('0xd5bb4025ae449a4e', netPlayer.handle, "Pitch", camPitch)
  132. mp.game.invoke('0xd5bb4025ae449a4e', netPlayer.handle, "Heading", camHeading * -1.0 + 1.0)
  133. mp.game.invoke('0xb0a6cfd2c69c1088', netPlayer.handle, "isBlocked", 0);
  134. mp.game.invoke('0xb0a6cfd2c69c1088', netPlayer.handle, "isFirstPerson", 0);
  135. }
  136. }
  137. });
  138.  
  139. mp.keys.bind(0x42, true, () => {
  140. pointing.start();
  141. });
  142.  
  143. mp.keys.bind(0x42, false, () => {
  144. pointing.stop();
  145. });
  146.  
  147. function getPlayerByHandle(handle) {
  148. let pla = mp.players.atHandle(handle);
  149. if (pla == undefined || pla == null) {
  150. return null;
  151. }
  152. return pla;
  153. }
  154.  
  155.  
  156. /*
  157. //Serverside
  158. public class Sync : Script
  159. {
  160. [RemoteEvent("fpsync.update")]
  161. public static void FingerPoint(Client sender, float camPitch, float camHeading)
  162. {
  163. NAPI.ClientEvent.TriggerClientEventInRange(sender.Position, 100, "fpsync.update", sender.Handle, camPitch, camHeading);
  164. }
  165. }
  166. */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement