let cam: CameraMp;

let specPlayer: PlayerMp;

mp.events.add("SERVER:ADMIN_SPECTATE", (targetPlayer) => {
    //cam.attachTo(targetPlayer.handle, 0, 1.0, 1.0, 1.0, 0, 0, 0, true, false, false, false, 0, false);
    specPlayer = targetPlayer;
    cam = mp.cameras.new('spectateCam');
    cam.attachTo(targetPlayer.handle, 0, -4, 1.5, true);
    cam.pointAt(targetPlayer.handle, 0, 0, 0, true);
    cam.setActive(true);      
    mp.game.cam.renderScriptCams(true, false, 0, true, false);
    mp.players.local.attachTo(targetPlayer.handle, 0, 0, -4, 1, 0, 0, 0, true, false, false, false, 0, false);
});

mp.events.add("SERVER:ADMIN_STOP_SPECTATE", () => {
    if (mp.cameras.exists(cam)) {
        cam.destroy();
        mp.game.cam.renderScriptCams(false, false, 0, true, false);
        mp.players.local.detach(true, true);
    }
});

mp.events.add("render", () => {
    if (mp.cameras.exists(cam)) {
        cam.setRot(0, 0, specPlayer.getRotation(0).z, 0);
    }
});
   