SHARE
TWEET

noclip

a guest Dec 14th, 2019 90 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import * as alt from 'alt';
  2. import * as native from 'natives';
  3. import * as buttons from 'instructional-buttons';
  4.  
  5. let freecam = {
  6.     active: false,
  7.     camera: null,
  8.     interval: null,
  9.     moveF: false,
  10.     moveB: false,
  11.     moveL: false,
  12.     moveR: false,
  13.     multiplier: 1,
  14.     height: 0,
  15.     chat: false
  16. };
  17.  
  18. function toggleNoclip() {
  19.     if (!freecam.active) {
  20.         buttons.createInstructionalScaleform([
  21.             { text: 'Speed down', control: 62 },
  22.             { text: 'Speed up', control: 61 },
  23.             { text: 'Down', control: 44 },
  24.             { text: 'Up', control: 38 },
  25.             { text: 'Right', ontrol: 35 },
  26.             { text: 'Left', control: 34 },
  27.             { text: 'Back', control: 33 },
  28.             { text: 'Forward', control: 32 }
  29.         ]);
  30.         const crot = native.getGameplayCamRot(2);
  31.         freecam.camera = native.createCamWithParams(
  32.             'DEFAULT_SCRIPTED_CAMERA',
  33.             alt.Player.local.pos.x,
  34.             alt.Player.local.pos.y,
  35.             alt.Player.local.pos.z,
  36.             crot.x,
  37.             crot.y,
  38.             crot.z,
  39.             60,
  40.             true,
  41.             2
  42.         );
  43.         native.setCamActive(freecam.camera, true);
  44.         native.renderScriptCams(true, false, 0, true, false);
  45.         native.freezeEntityPosition(alt.Player.local.scriptID, true);
  46.         native.setEntityVisible(alt.Player.local.scriptID, false, 0);
  47.         native.setEntityInvincible(alt.Player.local.scriptID, true);
  48.         native.setEntityCollision(alt.Player.local.scriptID, false, false);
  49.  
  50.         freecam.active = true;
  51.         freecam.interval = alt.setInterval(() => {
  52.             if (freecam.chat) return;
  53.             let camRot = native.getCamRot(freecam.camera, 2);
  54.             let camPos = native.getCamCoord(freecam.camera);
  55.             let rightAxisX = native.getDisabledControlNormal(0, 220);
  56.             let rightAxisY = native.getDisabledControlNormal(0, 221);
  57.             let newCampos = { x: camPos.x, y: camPos.y, z: camPos.z };
  58.             if (freecam.moveF) {
  59.                 let camDir = calculateCamDirectionF(camRot);
  60.                 newCampos.x = camPos.x + camDir.x * (1.0 * freecam.multiplier);
  61.                 newCampos.y = camPos.y + camDir.y * (1.0 * freecam.multiplier);
  62.                 newCampos.z = camPos.z + camDir.z * (1.0 * freecam.multiplier);
  63.             }
  64.             if (freecam.moveB) {
  65.                 let camDir = calculateCamDirectionF(camRot);
  66.                 newCampos.x = camPos.x - camDir.x * (1.0 * freecam.multiplier);
  67.                 newCampos.y = camPos.y - camDir.y * (1.0 * freecam.multiplier);
  68.                 newCampos.z = camPos.z - camDir.z * (1.0 * freecam.multiplier);
  69.             }
  70.             if (freecam.moveR) {
  71.                 let camDir = calculateCamDirectionS(camRot);
  72.                 newCampos.x = camPos.x + camDir.x * (1.0 * freecam.multiplier);
  73.                 newCampos.y = camPos.y + camDir.y * (1.0 * freecam.multiplier);
  74.             }
  75.             if (freecam.moveL) {
  76.                 let camDir = calculateCamDirectionS(camRot);
  77.                 newCampos.x = camPos.x - camDir.x * (1.0 * freecam.multiplier);
  78.                 newCampos.y = camPos.y - camDir.y * (1.0 * freecam.multiplier);
  79.             }
  80.             native.setCamCoord(freecam.camera, newCampos.x, newCampos.y, newCampos.z + freecam.height * freecam.multiplier);
  81.             native.setCamRot(freecam.camera, camRot.x + rightAxisY * -5.0, 0.0, camRot.z + rightAxisX * -5.0, 2);
  82.             native.setEntityCoords(alt.Player.local.scriptID, camPos.x, camPos.y, camPos.z + freecam.height * freecam.multiplier, 1, 0, 0, 1);
  83.             native.setEntityRotation(alt.Player.local.scriptID, camRot.x + rightAxisY * -5.0, 0.0, camRot.z + rightAxisX * -5.0, 0, true);
  84.             native.resetPlayerStamina(alt.Player.local);
  85.             native.displayRadar(false);
  86.         }, 1);
  87.     } else {
  88.         alt.clearInterval(freecam.interval);
  89.         freecam.active = false;
  90.         native.renderScriptCams(false, false, 0, true, false);
  91.         native.freezeEntityPosition(alt.Player.local.scriptID, false);
  92.         native.setEntityVisible(alt.Player.local.scriptID, true, 0);
  93.         native.setEntityInvincible(alt.Player.local.scriptID, false);
  94.         native.setEntityCollision(alt.Player.local.scriptID, true, true);
  95.         native.destroyCam(freecam.camera);
  96.         native.displayRadar(true);
  97.     }
  98. }
  99.  
  100. alt.on('keydown', key => {
  101.     if (!freecam.active) return;
  102.     if (key === 87) freecam.moveF = true;
  103.     if (key === 65) freecam.moveL = true;
  104.     if (key === 68) freecam.moveR = true;
  105.     if (key === 83) freecam.moveB = true;
  106.     if (key === 16) freecam.multiplier = 2.5;
  107.     if (key === 17) freecam.multiplier = 0.2;
  108.     if (key === 69) freecam.height = 0.7;
  109.     if (key === 81) freecam.height = -0.7;
  110.     if (key === 84) freecam.chat = true;
  111.     if (key === 191) freecam.chat = true;
  112.     if (key === 13 && freecam.chat) freecam.chat = false;
  113. });
  114.  
  115. alt.on('keyup', key => {
  116.     if (key === 116) {
  117.         // F5
  118.         toggleNoclip();
  119.     }
  120.     if (!freecam.active) return;
  121.     if (key === 87) freecam.moveF = false;
  122.     if (key === 65) freecam.moveL = false;
  123.     if (key === 68) freecam.moveR = false;
  124.     if (key === 83) freecam.moveB = false;
  125.     if (key === 16) freecam.multiplier = 1;
  126.     if (key === 17) freecam.multiplier = 1;
  127.     if (key === 69) freecam.height = 0;
  128.     if (key === 81) freecam.height = 0;
  129. });
  130.  
  131. function calculateCamDirectionF(camRot) {
  132.     let rotInRad = {
  133.         x: camRot.x * (Math.PI / 180),
  134.         y: camRot.y * (Math.PI / 180),
  135.         z: camRot.z * (Math.PI / 180) + Math.PI / 2
  136.     };
  137.     let camDir = {
  138.         x: Math.cos(rotInRad.z),
  139.         y: Math.sin(rotInRad.z),
  140.         z: Math.sin(rotInRad.x)
  141.     };
  142.     return camDir;
  143. }
  144.  
  145. function calculateCamDirectionS(camRot) {
  146.     let rotInRad = {
  147.         x: camRot.x * (Math.PI / 180),
  148.         y: camRot.y * (Math.PI / 180),
  149.         z: camRot.z * (Math.PI / 180)
  150.     };
  151.     let camDir = {
  152.         x: Math.cos(rotInRad.z),
  153.         y: Math.sin(rotInRad.z),
  154.         z: Math.sin(rotInRad.x)
  155.     };
  156.     return camDir;
  157. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top