Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <a_samp>
- #include <sscanf2> //Credits to Y_Less (http://forum.sa-mp.com/showthread.php?t=120356)
- #include <zcmd> //Credits to Zeex (http://forum.sa-mp.com/showthread.php?t=91354)
- #define COLOR_RED 0xAA3333AA
- #define COLOR_YELLOW 0xFFFF00AA
- #undef MAX_PLAYERS
- #define MAX_PLAYERS 100 //number of server slots
- #define UPDATE_RATE 50 //define update rate of vehicle speed (milliseconds); lower values might cause lag; higher values causes not constant vehicle speed
- #define CCKey KEY_ACTION //define key for CC mode
- #define JumpKey KEY_CROUCH //define key for vehicle jump
- #define JumpSize 0.2 //define vehicle jump size when press JumpKey
- #define AutoRepair 1 //autorepair vehicle while using CC mode: on - 1; off - 0
- //Speedboost functions were found at http://forum.sa-mp.com/showthread.php?t=199628 tutorial by The_Gangstas
- new bool: cc[MAX_PLAYERS char];
- new Float: ccspeed[MAX_PLAYERS];
- public OnFilterScriptInit()
- {
- for(new i=0; i<MAX_PLAYERS; i++) if(IsPlayerConnected(i)) OnPlayerConnect(i);
- return print("Cruise Control/Flying Car Mode by Riccor loaded!");
- }
- public OnPlayerConnect(playerid)
- {
- cc{playerid} = false;
- ccspeed[playerid] = 0.1;
- return 1;
- }
- CMD:cc(playerid,params[])
- {
- new Float: value;
- if(!sscanf(params,"f", value))
- {
- if(value < 0.05 || value > 3.0) return SendClientMessage(playerid, COLOR_RED, "[ERROR:] Invalid Speed Value! [0.05-3.0]");
- ccspeed[playerid] = value;
- new string[128];
- format(string,sizeof(string),":: You setted CC Speed Value to %.2f!", ccspeed[playerid]);
- return SendClientMessage(playerid, COLOR_YELLOW, string);
- }
- if(cc{playerid})
- {
- cc{playerid} = false;
- return SendClientMessage(playerid, COLOR_RED, ":: You disabled CC mode!");
- }
- else
- {
- cc{playerid} = true;
- return SendClientMessage(playerid, COLOR_YELLOW, ":: You enabled CC mode! Press and hold CTRL key while driving to use it. Use /cc [value] to change CC speed.");
- }
- }
- public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
- {
- if(cc{playerid})
- {
- if(newkeys & CCKey) ccf(playerid);
- else if(newkeys & JumpKey)
- {
- new Float: x, Float:y, Float:z;
- GetVehicleVelocity(GetPlayerVehicleID(playerid), x, y, z);
- SetVehicleVelocity(GetPlayerVehicleID(playerid),x, y, z + JumpSize);
- }
- }
- return 1;
- }
- forward ccf(playerid);
- public ccf(playerid)
- {
- new keys, ud, lr;
- GetPlayerKeys(playerid, keys, ud, lr);
- if((keys & CCKey))
- {
- new Float: adirection[3];
- new vehid = GetPlayerVehicleID(playerid);
- new Float:Quaternion[4];
- new Float:transformationmatrix[4][4];
- GetVehicleRotationQuat(vehid, Quaternion[0], Quaternion[1], Quaternion[2], Quaternion[3]);
- new Float:xx = Quaternion[0] * Quaternion[0];
- new Float:xy = Quaternion[0] * Quaternion[1];
- new Float:xz = Quaternion[0] * Quaternion[2];
- new Float:xw = Quaternion[0] * Quaternion[3];
- new Float:yy = Quaternion[1] * Quaternion[1];
- new Float:yz = Quaternion[1] * Quaternion[2];
- new Float:yw = Quaternion[1] * Quaternion[3];
- new Float:zz = Quaternion[2] * Quaternion[2];
- new Float:zw = Quaternion[2] * Quaternion[3];
- transformationmatrix[0][0] = 1 - 2 * ( yy + zz );
- transformationmatrix[0][1] = 2 * ( xy - zw );
- transformationmatrix[0][2] = 2 * ( xz + yw );
- transformationmatrix[0][3] = 0.0;
- transformationmatrix[1][0] = 2 * ( xy + zw );
- transformationmatrix[1][1] = 1 - 2 * ( xx + zz );
- transformationmatrix[1][2] = 2 * ( yz - xw );
- transformationmatrix[1][3] = 0.0;
- transformationmatrix[2][0] = 2 * ( xz - yw );
- transformationmatrix[2][1] = 2 * ( yz + xw );
- transformationmatrix[2][2] = 1 - 2 * ( xx + yy );
- transformationmatrix[2][3] = 0;
- transformationmatrix[3][0] = 0;
- transformationmatrix[3][1] = 0;
- transformationmatrix[3][2] = 0;
- transformationmatrix[3][3] = 1;
- adirection[2] = -1 * transformationmatrix[0][1] + transformationmatrix[0][3];
- adirection[1] = -1 * transformationmatrix[1][1] + transformationmatrix[1][3];
- adirection[0] = -(-1 * transformationmatrix[2][1] + transformationmatrix[2][3]);
- #if AutoRepair == 1
- RepairVehicle(vehid);
- #endif
- SetVehicleVelocity(vehid, adirection[0]*ccspeed[playerid], adirection[1]*ccspeed[playerid], adirection[2]*ccspeed[playerid]);
- SetTimerEx("ccf", UPDATE_RATE, false, "i", playerid);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment