Skip to content

Instantly share code, notes, and snippets.

@spacemud
Forked from Southclaws/samp plane stuff lol
Created November 8, 2020 18:48
Show Gist options
  • Save spacemud/9ae38d305b76d20bb5595141eb9e5ec3 to your computer and use it in GitHub Desktop.
Save spacemud/9ae38d305b76d20bb5595141eb9e5ec3 to your computer and use it in GitHub Desktop.
#include <a_samp>
#include <rotations.inc>
main() {}
// for debug
static PlayerText:MessageTextdraw[MAX_PLAYERS];
static bool:AP = false;
static TargetAlt = 1000; // 1000ft - low altitude cruise
static Float:TargetVS = 250.0; // 500f/s - a gradual climb
public OnGameModeInit() {
AddPlayerClass(61, -1657.4613, -164.8150, 13.9812, -45.0, 0, 0, 0, 0, 0, 0);
AddStaticVehicle(593, -1650.6632, -159.1763, 13.9812, -45.0, 0, 0);
}
public OnPlayerConnect(playerid) {
MessageTextdraw[playerid] = CreatePlayerTextDraw(playerid, 328.000091, 350.947723, "");
PlayerTextDrawLetterSize(playerid, MessageTextdraw[playerid], 0.2, 1.0);
PlayerTextDrawAlignment(playerid, MessageTextdraw[playerid], 2);
PlayerTextDrawColor(playerid, MessageTextdraw[playerid], -1);
PlayerTextDrawSetShadow(playerid, MessageTextdraw[playerid], 0);
PlayerTextDrawSetOutline(playerid, MessageTextdraw[playerid], 1);
PlayerTextDrawBackgroundColor(playerid, MessageTextdraw[playerid], 255);
PlayerTextDrawFont(playerid, MessageTextdraw[playerid], 1);
PlayerTextDrawSetProportional(playerid, MessageTextdraw[playerid], 1);
PlayerTextDrawSetShadow(playerid, MessageTextdraw[playerid], 0);
PlayerTextDrawShow(playerid, MessageTextdraw[playerid]);
}
stock Float:frandom(Float:max, Float:min = 0.0, decimalPlaces = 4) {
new
Float:multiplier = floatpower(10.0, decimalPlaces),
minRounded = floatround(min * multiplier),
maxRounded = floatround(max * multiplier);
return float(random(maxRounded - minRounded) + minRounded) / multiplier;
}
public OnPlayerUpdate(playerid) {
new vehicleid = GetPlayerVehicleID(playerid);
if(!IsValidVehicle(vehicleid)) {
return 1;
}
new
Float:qw,
Float:qx,
Float:qy,
Float:qz,
Float:rX,
Float:rY,
Float:rZ;
GetVehicleRotationQuat(vehicleid, qw, qx, qy, qz);
GetEulerFromQuat(qw, qx, qy, qz, rX, rY, rZ);
new Float:x, Float:y, Float:z;
GetVehiclePos(vehicleid, x, y, z);
new Float:altitude = z * 3.28084; // altitude is measured in feet-above-sea-level.
// new Float:turbulence = 0.002; // ??? wobble the plane a bit idk
// if(altitude > 100) {
// SetVehicleAngularVelocity(vehicleid,
// frandom(turbulence, -turbulence),
// frandom(turbulence, -turbulence),
// frandom(turbulence, -turbulence));
// }
new Float:vx, Float:vy, Float:vz;
GetVehicleVelocity(vehicleid, vx, vy, vz);
new Float:vertical_speed = vz * 1968.5; // velocity is km/s (?) so fpm conversion is one decimal place up from m/s
// Auto pilot
if(AP) {
if(altitude < TargetAlt) {
if(vertical_speed < TargetVS) {
SetVehicleAngularVelocity(vehicleid,
0.0,
-0.01,
0.0);
} else if(vertical_speed > TargetVS) {
SetVehicleAngularVelocity(vehicleid,
0.0,
0.01,
0.0);
}
} else {
SetVehicleAngularVelocity(vehicleid,
0.0,
0.01,
0.0);
}
}
new str[128];
format(str, sizeof str,
"Pitch %f~n~\
Roll %f~n~\
Yaw %f~n~\
Alt %f Target: %d~n~\
VS %f Target: %f~n~\
", rX, rY, rZ, altitude, TargetAlt, vertical_speed, TargetVS);
PlayerTextDrawSetString(playerid, MessageTextdraw[playerid], str);
return 1;
}
public OnPlayerKeyStateChange(playerid, newkeys, oldkeys) {
if(newkeys & KEY_FIRE) {
AP = !AP;
new str[128];
format(str, sizeof str, "Auto pilot: %d", AP);
SendClientMessage(playerid, 0xFFFFFFFF, str);
}
if(newkeys & KEY_LOOK_BEHIND) {
new
Float: w,
Float: x,
Float: y,
Float: z,
Float: matrix[4][4],
Float: vx = 0.1,
Float: vy = 0.0,
Float: vz = 0.0,
Float: wvx,
Float: wvy,
Float: wvz;
GetVehicleRotationQuat(GetPlayerVehicleID(playerid), w, x, y, z);
GetRotationMatrixFromQuat(matrix, w, x, y, z);
MatrixRotate(matrix, vx, vy, vz, 0.0, wvx, wvy, wvz);
SetVehicleAngularVelocity(GetPlayerVehicleID(playerid), wvx, wvy, wvz);
}
}
public OnPlayerCommandText(playerid, cmdtext[]) {
if(!strcmp(cmdtext, "/althold")) {
new target = strval(cmdtext[10]);
new str[128];
format(str, sizeof str, "Target altitude: %dft", target);
SendClientMessage(playerid, 0xFFFFFFFF, str);
TargetAlt = target;
}
if(!strcmp(cmdtext, "/vs")) {
new Float:target = floatstr(cmdtext[4]);
new str[128];
format(str, sizeof str, "Target vertical speed: %fft/s", target);
SendClientMessage(playerid, 0xFFFFFFFF, str);
TargetVS = target;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment