Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import * as alt from 'alt';
- import * as native from 'natives';
- import * as buttons from 'instructional-buttons';
- let freecam = {
- active: false,
- camera: null,
- interval: null,
- moveF: false,
- moveB: false,
- moveL: false,
- moveR: false,
- multiplier: 1,
- height: 0,
- chat: false
- };
- function toggleNoclip() {
- if (!freecam.active) {
- buttons.createInstructionalScaleform([
- { text: 'Speed down', control: 62 },
- { text: 'Speed up', control: 61 },
- { text: 'Down', control: 44 },
- { text: 'Up', control: 38 },
- { text: 'Right', ontrol: 35 },
- { text: 'Left', control: 34 },
- { text: 'Back', control: 33 },
- { text: 'Forward', control: 32 }
- ]);
- const crot = native.getGameplayCamRot(2);
- freecam.camera = native.createCamWithParams(
- 'DEFAULT_SCRIPTED_CAMERA',
- alt.Player.local.pos.x,
- alt.Player.local.pos.y,
- alt.Player.local.pos.z,
- crot.x,
- crot.y,
- crot.z,
- 60,
- true,
- 2
- );
- native.setCamActive(freecam.camera, true);
- native.renderScriptCams(true, false, 0, true, false);
- native.freezeEntityPosition(alt.Player.local.scriptID, true);
- native.setEntityVisible(alt.Player.local.scriptID, false, 0);
- native.setEntityInvincible(alt.Player.local.scriptID, true);
- native.setEntityCollision(alt.Player.local.scriptID, false, false);
- freecam.active = true;
- freecam.interval = alt.setInterval(() => {
- if (freecam.chat) return;
- let camRot = native.getCamRot(freecam.camera, 2);
- let camPos = native.getCamCoord(freecam.camera);
- let rightAxisX = native.getDisabledControlNormal(0, 220);
- let rightAxisY = native.getDisabledControlNormal(0, 221);
- let newCampos = { x: camPos.x, y: camPos.y, z: camPos.z };
- if (freecam.moveF) {
- let camDir = calculateCamDirectionF(camRot);
- newCampos.x = camPos.x + camDir.x * (1.0 * freecam.multiplier);
- newCampos.y = camPos.y + camDir.y * (1.0 * freecam.multiplier);
- newCampos.z = camPos.z + camDir.z * (1.0 * freecam.multiplier);
- }
- if (freecam.moveB) {
- let camDir = calculateCamDirectionF(camRot);
- newCampos.x = camPos.x - camDir.x * (1.0 * freecam.multiplier);
- newCampos.y = camPos.y - camDir.y * (1.0 * freecam.multiplier);
- newCampos.z = camPos.z - camDir.z * (1.0 * freecam.multiplier);
- }
- if (freecam.moveR) {
- let camDir = calculateCamDirectionS(camRot);
- newCampos.x = camPos.x + camDir.x * (1.0 * freecam.multiplier);
- newCampos.y = camPos.y + camDir.y * (1.0 * freecam.multiplier);
- }
- if (freecam.moveL) {
- let camDir = calculateCamDirectionS(camRot);
- newCampos.x = camPos.x - camDir.x * (1.0 * freecam.multiplier);
- newCampos.y = camPos.y - camDir.y * (1.0 * freecam.multiplier);
- }
- native.setCamCoord(freecam.camera, newCampos.x, newCampos.y, newCampos.z + freecam.height * freecam.multiplier);
- native.setCamRot(freecam.camera, camRot.x + rightAxisY * -5.0, 0.0, camRot.z + rightAxisX * -5.0, 2);
- native.setEntityCoords(alt.Player.local.scriptID, camPos.x, camPos.y, camPos.z + freecam.height * freecam.multiplier, 1, 0, 0, 1);
- native.setEntityRotation(alt.Player.local.scriptID, camRot.x + rightAxisY * -5.0, 0.0, camRot.z + rightAxisX * -5.0, 0, true);
- native.resetPlayerStamina(alt.Player.local);
- native.displayRadar(false);
- }, 1);
- } else {
- alt.clearInterval(freecam.interval);
- freecam.active = false;
- native.renderScriptCams(false, false, 0, true, false);
- native.freezeEntityPosition(alt.Player.local.scriptID, false);
- native.setEntityVisible(alt.Player.local.scriptID, true, 0);
- native.setEntityInvincible(alt.Player.local.scriptID, false);
- native.setEntityCollision(alt.Player.local.scriptID, true, true);
- native.destroyCam(freecam.camera);
- native.displayRadar(true);
- }
- }
- alt.on('keydown', key => {
- if (!freecam.active) return;
- if (key === 87) freecam.moveF = true;
- if (key === 65) freecam.moveL = true;
- if (key === 68) freecam.moveR = true;
- if (key === 83) freecam.moveB = true;
- if (key === 16) freecam.multiplier = 2.5;
- if (key === 17) freecam.multiplier = 0.2;
- if (key === 69) freecam.height = 0.7;
- if (key === 81) freecam.height = -0.7;
- if (key === 84) freecam.chat = true;
- if (key === 191) freecam.chat = true;
- if (key === 13 && freecam.chat) freecam.chat = false;
- });
- alt.on('keyup', key => {
- if (key === 116) {
- // F5
- toggleNoclip();
- }
- if (!freecam.active) return;
- if (key === 87) freecam.moveF = false;
- if (key === 65) freecam.moveL = false;
- if (key === 68) freecam.moveR = false;
- if (key === 83) freecam.moveB = false;
- if (key === 16) freecam.multiplier = 1;
- if (key === 17) freecam.multiplier = 1;
- if (key === 69) freecam.height = 0;
- if (key === 81) freecam.height = 0;
- });
- function calculateCamDirectionF(camRot) {
- let rotInRad = {
- x: camRot.x * (Math.PI / 180),
- y: camRot.y * (Math.PI / 180),
- z: camRot.z * (Math.PI / 180) + Math.PI / 2
- };
- let camDir = {
- x: Math.cos(rotInRad.z),
- y: Math.sin(rotInRad.z),
- z: Math.sin(rotInRad.x)
- };
- return camDir;
- }
- function calculateCamDirectionS(camRot) {
- let rotInRad = {
- x: camRot.x * (Math.PI / 180),
- y: camRot.y * (Math.PI / 180),
- z: camRot.z * (Math.PI / 180)
- };
- let camDir = {
- x: Math.cos(rotInRad.z),
- y: Math.sin(rotInRad.z),
- z: Math.sin(rotInRad.x)
- };
- return camDir;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement