add cityhall menu, add self interaction menu (Arrow Down), fix freecam, add group creation, move (faction) invite from commands to menu
This commit is contained in:
@@ -1,135 +1,131 @@
|
||||
export default function freeCam() {
|
||||
const controlsIds = {
|
||||
F5: 327,
|
||||
W: 32, // 232
|
||||
S: 33, // 31, 219, 233, 268, 269
|
||||
A: 34, // 234
|
||||
D: 35, // 30, 218, 235, 266, 267
|
||||
Space: 321,
|
||||
LCtrl: 326
|
||||
export default function () {
|
||||
var getNormalizedVector = function (vector) {
|
||||
var mag = Math.sqrt(
|
||||
vector.x * vector.x + vector.y * vector.y + vector.z * vector.z
|
||||
);
|
||||
vector.x = vector.x / mag;
|
||||
vector.y = vector.y / mag;
|
||||
vector.z = vector.z / mag;
|
||||
return vector;
|
||||
};
|
||||
|
||||
var global = {
|
||||
gameplayCam: undefined,
|
||||
fly: undefined
|
||||
var getCrossProduct = function (v1, v2) {
|
||||
var vector = new mp.Vector3(0, 0, 0);
|
||||
vector.x = v1.y * v2.z - v1.z * v2.y;
|
||||
vector.y = v1.z * v2.x - v1.x * v2.z;
|
||||
vector.z = v1.x * v2.y - v1.y * v2.x;
|
||||
return vector;
|
||||
};
|
||||
|
||||
global.fly = {
|
||||
flying: false, f: 2.0, w: 2.0, h: 2.0, point_distance: 1000, l:0
|
||||
var bindVirtualKeys = {
|
||||
F2: 0x71
|
||||
};
|
||||
global.gameplayCam = mp.cameras.new('gameplay');
|
||||
|
||||
mp.game.graphics.notify('~r~Fly script loaded!');
|
||||
mp.game.graphics.notify('~r~F5~w~ - enable/disable\n~r~F5+Space~w~ - disable without warping to ground\n~r~W/A/S/D/Space/LCtrl~w~ - move');
|
||||
mp.game.graphics.notify('~r~/savecam~w~ - save Camera position.');
|
||||
|
||||
let direction = null;
|
||||
let coords = null;
|
||||
|
||||
function pointingAt(distance) {
|
||||
const farAway = new mp.Vector3((direction.x * distance) + (coords.x), (direction.y * distance) + (coords.y), (direction.z * distance) + (coords.z));
|
||||
|
||||
const result = mp.raycasting.testPointToPoint(coords, farAway, 16);
|
||||
if (result === undefined) {
|
||||
return 'undefined';
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
mp.events.add('render', () => {
|
||||
|
||||
const controls = mp.game.controls;
|
||||
const fly = global.fly;
|
||||
direction = global.gameplayCam.getDirection();
|
||||
coords = global.gameplayCam.getCoord();
|
||||
|
||||
coords.x = coords.x.toFixed(2);
|
||||
coords.y = coords.y.toFixed(2);
|
||||
coords.z = coords.z.toFixed(2);
|
||||
|
||||
direction.x = direction.x.toFixed(2);
|
||||
direction.y = direction.y.toFixed(2);
|
||||
direction.z = direction.z.toFixed(2);
|
||||
|
||||
//mp.game.graphics.drawText(`Coords: ${JSON.stringify(coords)}`, [0.5, 0.005], {
|
||||
// font: 0,
|
||||
// color: [255, 255, 255, 185],
|
||||
// scale: [0.3, 0.3],
|
||||
// outline: true,
|
||||
// centre: false
|
||||
//});
|
||||
|
||||
if (controls.isControlJustPressed(0, controlsIds.F5)) {
|
||||
fly.flying = !fly.flying;
|
||||
|
||||
const player = mp.players.local;
|
||||
|
||||
player.setInvincible(fly.flying);
|
||||
player.freezePosition(fly.flying);
|
||||
player.setAlpha(fly.flying ? 0 : 255);
|
||||
|
||||
if (!fly.flying && !controls.isControlPressed(0, controlsIds.Space)) {
|
||||
const position = mp.players.local.position;
|
||||
position.z = mp.game.gameplay.getGroundZFor3dCoord(position.x, position.y, position.z, 0.0, false);
|
||||
mp.players.local.setCoordsNoOffset(position.x, position.y, position.z, 0, 0, 0);
|
||||
}
|
||||
|
||||
mp.game.graphics.notify(fly.flying ? 'Fly: ~g~Enabled' : 'Fly: ~r~Disabled');
|
||||
} else if (fly.flying) {
|
||||
let updated = false;
|
||||
const position = mp.players.local.position;
|
||||
|
||||
if (controls.isControlPressed(0, controlsIds.W)) {
|
||||
if (fly.f < 8.0) { fly.f *= 1.025; }
|
||||
|
||||
position.x += direction.x * fly.f;
|
||||
position.y += direction.y * fly.f;
|
||||
position.z += direction.z * fly.f;
|
||||
updated = true;
|
||||
} else if (controls.isControlPressed(0, controlsIds.S)) {
|
||||
if (fly.f < 8.0) { fly.f *= 1.025; }
|
||||
|
||||
position.x -= direction.x * fly.f;
|
||||
position.y -= direction.y * fly.f;
|
||||
position.z -= direction.z * fly.f;
|
||||
updated = true;
|
||||
} else {
|
||||
fly.f = 2.0;
|
||||
}
|
||||
|
||||
if (controls.isControlPressed(0, controlsIds.A)) {
|
||||
if (fly.l < 8.0) { fly.l *= 1.025; }
|
||||
|
||||
position.x += (-direction.y) * fly.l;
|
||||
position.y += direction.x * fly.l;
|
||||
updated = true;
|
||||
} else if (controls.isControlPressed(0, controlsIds.D)) {
|
||||
if (fly.l < 8.0) { fly.l *= 1.05; }
|
||||
|
||||
position.x -= -direction.y * fly.l;
|
||||
position.y -= direction.x * fly.l;
|
||||
updated = true;
|
||||
} else {
|
||||
fly.l = 2.0;
|
||||
}
|
||||
|
||||
if (controls.isControlPressed(0, controlsIds.Space)) {
|
||||
if (fly.h < 8.0) { fly.h *= 1.025; }
|
||||
|
||||
position.z += fly.h;
|
||||
updated = true;
|
||||
} else if (controls.isControlPressed(0, controlsIds.LCtrl)) {
|
||||
if (fly.h < 8.0) { fly.h *= 1.05; }
|
||||
|
||||
position.z -= fly.h;
|
||||
updated = true;
|
||||
} else {
|
||||
fly.h = 2.0;
|
||||
}
|
||||
|
||||
if (updated) {
|
||||
mp.players.local.setCoordsNoOffset(position.x, position.y, position.z, 0, 0, 0);
|
||||
}
|
||||
var bindASCIIKeys = {
|
||||
Q: 69,
|
||||
E: 81,
|
||||
LCtrl: 17,
|
||||
Shift: 16
|
||||
};
|
||||
mp.game.graphics.notify('~r~NoClip ~w~by ~b~Morbo');
|
||||
var isNoClip = false;
|
||||
var noClipCamera;
|
||||
var shiftModifier = false;
|
||||
var controlModifier = false;
|
||||
var localPlayer = mp.players.local;
|
||||
mp.keys.bind(bindVirtualKeys.F2, true, function () {
|
||||
isNoClip = !isNoClip;
|
||||
mp.game.ui.displayRadar(!isNoClip);
|
||||
if (isNoClip) {
|
||||
startNoClip();
|
||||
} else {
|
||||
stopNoClip();
|
||||
}
|
||||
});
|
||||
function startNoClip() {
|
||||
mp.game.graphics.notify('NoClip ~g~activated');
|
||||
var camPos = new mp.Vector3(
|
||||
localPlayer.position.x,
|
||||
localPlayer.position.y,
|
||||
localPlayer.position.z
|
||||
);
|
||||
var camRot = mp.game.cam.getGameplayCamRot(2);
|
||||
noClipCamera = mp.cameras.new('default', camPos, camRot, 45);
|
||||
noClipCamera.setActive(true);
|
||||
mp.game.cam.renderScriptCams(true, false, 0, true, false);
|
||||
localPlayer.freezePosition(true);
|
||||
localPlayer.setInvincible(true);
|
||||
localPlayer.setVisible(false, false);
|
||||
localPlayer.setCollision(false, false);
|
||||
}
|
||||
function stopNoClip() {
|
||||
mp.game.graphics.notify('NoClip ~r~disabled');
|
||||
if (noClipCamera) {
|
||||
localPlayer.position = noClipCamera.getCoord();
|
||||
localPlayer.setHeading(noClipCamera.getRot(2).z);
|
||||
noClipCamera.destroy(true);
|
||||
noClipCamera = null;
|
||||
}
|
||||
mp.game.cam.renderScriptCams(false, false, 0, true, false);
|
||||
localPlayer.freezePosition(false);
|
||||
localPlayer.setInvincible(false);
|
||||
localPlayer.setVisible(true, false);
|
||||
localPlayer.setCollision(true, false);
|
||||
}
|
||||
mp.events.add('render', function () {
|
||||
if (!noClipCamera || mp.gui.cursor.visible) {
|
||||
return;
|
||||
}
|
||||
controlModifier = mp.keys.isDown(bindASCIIKeys.LCtrl);
|
||||
shiftModifier = mp.keys.isDown(bindASCIIKeys.Shift);
|
||||
var rot = noClipCamera.getRot(2);
|
||||
var fastMult = 1;
|
||||
var slowMult = 1;
|
||||
if (shiftModifier) {
|
||||
fastMult = 3;
|
||||
} else if (controlModifier) {
|
||||
slowMult = 0.5;
|
||||
}
|
||||
var rightAxisX = mp.game.controls.getDisabledControlNormal(0, 220);
|
||||
var rightAxisY = mp.game.controls.getDisabledControlNormal(0, 221);
|
||||
var leftAxisX = mp.game.controls.getDisabledControlNormal(0, 218);
|
||||
var leftAxisY = mp.game.controls.getDisabledControlNormal(0, 219);
|
||||
var pos = noClipCamera.getCoord();
|
||||
var rr = noClipCamera.getDirection();
|
||||
var vector = new mp.Vector3(0, 0, 0);
|
||||
vector.x = rr.x * leftAxisY * fastMult * slowMult;
|
||||
vector.y = rr.y * leftAxisY * fastMult * slowMult;
|
||||
vector.z = rr.z * leftAxisY * fastMult * slowMult;
|
||||
var upVector = new mp.Vector3(0, 0, 1);
|
||||
var rightVector = getCrossProduct(
|
||||
getNormalizedVector(rr),
|
||||
getNormalizedVector(upVector)
|
||||
);
|
||||
rightVector.x *= leftAxisX * 0.5;
|
||||
rightVector.y *= leftAxisX * 0.5;
|
||||
rightVector.z *= leftAxisX * 0.5;
|
||||
var upMovement = 0.0;
|
||||
if (mp.keys.isDown(bindASCIIKeys.Q)) {
|
||||
upMovement = 0.5;
|
||||
}
|
||||
var downMovement = 0.0;
|
||||
if (mp.keys.isDown(bindASCIIKeys.E)) {
|
||||
downMovement = 0.5;
|
||||
}
|
||||
mp.players.local.position = new mp.Vector3(
|
||||
pos.x + vector.x + 1,
|
||||
pos.y + vector.y + 1,
|
||||
pos.z + vector.z + 1
|
||||
);
|
||||
mp.players.local.heading = rr.z;
|
||||
noClipCamera.setCoord(
|
||||
pos.x - vector.x + rightVector.x,
|
||||
pos.y - vector.y + rightVector.y,
|
||||
pos.z - vector.z + rightVector.z + upMovement - downMovement
|
||||
);
|
||||
noClipCamera.setRot(
|
||||
rot.x + rightAxisY * -5.0,
|
||||
0.0,
|
||||
rot.z + rightAxisX * -5.0,
|
||||
2
|
||||
);
|
||||
});
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user