Created
October 29, 2021 14:49
-
-
Save Seregamil/10e6a3312d181096bec2cd1d3c0bf33a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const controlsIds = | |
{ | |
F5: 327, | |
W: 32, //232 | |
S: 33, //31, 219, 233, 268, 269 | |
A: 34, //234 | |
D: 35, //30, 218, 235, 266, 267 | |
Shift: 21, | |
E: 38, | |
Q: 44, | |
Space: 321, | |
LCtrl: 326, | |
MOUSE_RIGHT: 220, | |
MOUSE_DOWN: 221 | |
}; | |
class FlyMode { | |
static cameraMp: CameraMp = mp.cameras.new("gameplay"); | |
private static speed: number = 0.2; | |
private static multiple: number = 1; | |
static multipleAdd() { | |
this.multiple ++; | |
if(this.multiple > 3) | |
this.multiple = 1; | |
} | |
static multipleGet() { | |
return this.multiple; | |
} | |
static speedSet(val: number) { | |
this.speed = val; | |
} | |
static speedGet() { | |
return this.speed; | |
} | |
static toggle(state: boolean) { | |
if(!doesPlayerAdmin) | |
return; | |
playerInfo.tools.fly = state; | |
mp.players.local.setInvincible(playerInfo.tools.fly); | |
// mp.players.local.setVisible(adminTools.fly.state, adminTools.fly.state); | |
mp.players.local.freezePosition(playerInfo.tools.fly); | |
mp.players.local.setConfigFlag(ConfigFlags.PED_FLAG_FREEZE, playerInfo.tools.fly); | |
mp.players.local.setAlpha(playerInfo.tools.fly ? 0 : 255); | |
if(!playerInfo.tools.fly) | |
{ | |
let position: Vector3Mp = 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, false, false, false); | |
} | |
} | |
} | |
mp.keys.bind(KeyCodes.E, true, () => { | |
if(!doesPlayerAdmin() || isChatOpen()) | |
return; | |
if(!playerInfo.tools.fly) | |
return; | |
FlyMode.multipleAdd(); | |
}); | |
mp.events.add("render", () => { | |
if(!doesPlayerAdmin() || isChatOpen()) | |
return; | |
let direction: Vector3Mp = FlyMode.cameraMp.getDirection(); | |
if(playerInfo.tools.fly) { | |
if(mp.keys.isDown(KeyCodes.SHIFT)) { // shift | |
FlyMode.speedSet(1.6 * FlyMode.multipleGet()); | |
} else if(mp.keys.isUp(KeyCodes.SHIFT)) { | |
FlyMode.speedSet(0.2 * FlyMode.multipleGet()); | |
} | |
} | |
if(mp.game.controls.isControlJustPressed(0, controlsIds.F5)) | |
FlyMode.toggle(!playerInfo.tools.fly); | |
if(playerInfo.tools.fly) | |
{ | |
let updated: boolean = false; | |
let position: Vector3Mp = mp.players.local.position; | |
if(mp.game.controls.isControlPressed(0, controlsIds.W)) | |
{ | |
position.x += direction.x * FlyMode.speedGet() * FlyMode.multipleGet(); | |
position.y += direction.y * FlyMode.speedGet() * FlyMode.multipleGet(); | |
position.z += direction.z * FlyMode.speedGet() * FlyMode.multipleGet(); | |
updated = true; | |
} | |
else if(mp.game.controls.isControlPressed(0, controlsIds.S)) | |
{ | |
position.x -= direction.x * FlyMode.speedGet() * FlyMode.multipleGet(); | |
position.y -= direction.y * FlyMode.speedGet() * FlyMode.multipleGet(); | |
position.z -= direction.z * FlyMode.speedGet() * FlyMode.multipleGet(); | |
updated = true; | |
} | |
if(mp.game.controls.isControlPressed(0, controlsIds.A)) | |
{ | |
position.x += (-direction.y) * FlyMode.speedGet() * FlyMode.multipleGet(); | |
position.y += direction.x * FlyMode.speedGet() * FlyMode.multipleGet(); | |
updated = true; | |
} | |
else if(mp.game.controls.isControlPressed(0, controlsIds.D)) | |
{ | |
position.x -= (-direction.y) * FlyMode.speedGet() * FlyMode.multipleGet(); | |
position.y -= direction.x * FlyMode.speedGet() * FlyMode.multipleGet(); | |
updated = true; | |
} | |
if(mp.game.controls.isControlPressed(0, controlsIds.Space)) | |
{ | |
position.z += FlyMode.speedGet() * FlyMode.multipleGet(); | |
updated = true; | |
} | |
else if(mp.game.controls.isControlPressed(0, controlsIds.LCtrl)) | |
{ | |
position.z -= FlyMode.speedGet() * FlyMode.multipleGet(); | |
updated = true; | |
} | |
if(updated) | |
{ | |
mp.players.local.setCoordsNoOffset(position.x, position.y, position.z, false, false, false); | |
mp.game.player.restoreStamina(100); | |
} | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment