stock MatrixTransformVector(Float:vector[3], Float:m[4][4], &Float:resx, &Float:resy, &Float:resz) {
resz = vector[2] * m[0][0] + vector[1] * m[0][1] + vector[0] * m[0][2] + m[0][3];
resy = vector[2] * m[1][0] + vector[1] * m[1][1] + vector[0] * m[1][2] + m[1][3];
resx = -(vector[2] * m[2][0] + vector[1] * m[2][1] + vector[0] * m[2][2] + m[2][3]); // don't ask why -x was needed, i don't know either.
}
stock RotatePointVehicleRotation(vehid, Float:Invector[3], &Float:resx, &Float:resy, &Float:resz, worldspace=0)
{
new Float:Quaternion[4];
new Float:transformationmatrix[4][4];
GetVehicleRotationQuat(vehid, Quaternion[0], Quaternion[1], Quaternion[2], Quaternion[3]);
// build a transformation matrix out of the quaternion
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;
// transform the point thru car's rotation
MatrixTransformVector(Invector, transformationmatrix, resx, resy, resz);
// if worldspace is set it'll return the coords in global space - useful to check tire coords against tire spike proximity directly, etc..
if (worldspace == 1) {
new Float:fX, Float:fY, Float:fZ;
GetVehiclePos(vehid, fX, fY, fZ);
resx += fX;
resy += fY;
resz += fZ;
}
CMD:speedboost(playerid, params[])// Header Of The Command Using Zcmd
{
dcmd_speedboost(playerid, params[])// Header Of The Command Using dcmd
{
if(strcmp(cmd, "/speedboost", true) == 0)
{
if(!IsPlayerInAnyVehicle(playerid)) return SendClientMessage(playerid,RED,"Error: You Are Not In A Vehicle");
//If The Player Isn't In A Vehicle it Will Return The Error.
new Float:currspeed[3], Float:direction[3], Float:total;
GetVehicleVelocity(GetPlayerVehicleID(playerid), currspeed[0], currspeed[1], currspeed[2]);
total =
(currspeed[0] * currspeed[0]) + (currspeed[1] * currspeed[1]) + (currspeed[2] * currspeed[2])
floatsqroot((currspeed[0] * currspeed[0]) + (currspeed[1] * currspeed[1]) + (currspeed[2] * currspeed[2]));//This Adds Up All The X,Y,Z Positions Of The Vehicle
total = floatsqroot((currspeed[0] * currspeed[0]) + (currspeed[1] * currspeed[1]) + (currspeed[2] * currspeed[2]));//This Adds Up All The X,Y,Z Positions Of The Vehicle
total +=
total += 0.7
;
total +=0.7;
new Float:invector[3] = {0.0, -1.0, 0.0};
RotatePointVehicleRotation(GetPlayerVehicleID(playerid), invector, direction[0], direction[1], direction[2]);
SetVehicleVelocity(GetPlayerVehicleID(playerid), direction[0] * total, direction[1] * total, direction[2] * total);
return 1;
}
CMD:speedboost(playerid, params[])
{
if(!IsPlayerInAnyVehicle(playerid)) return SendClientMessage(playerid,RED,"Error: You Are Not In A Vehicle");
new Float:currspeed[3], Float:direction[3], Float:total;
GetVehicleVelocity(GetPlayerVehicleID(playerid), currspeed[0], currspeed[1], currspeed[2]);
total = floatsqroot((currspeed[0] * currspeed[0]) + (currspeed[1] * currspeed[1]) + (currspeed[2] * currspeed[2]));
total += 0.7;
new Float:invector[3] = {0.0, -1.0, 0.0};
RotatePointVehicleRotation(GetPlayerVehicleID(playerid), invector, direction[0], direction[1], direction[2]);
SetVehicleVelocity(GetPlayerVehicleID(playerid), direction[0] * total, direction[1] * total, direction[2] * total);
return 1;
}
That code will, for example, add 0.7 speed to whatever position the vehicle that playerid is driving is facing. This function is very powerful, you will be able to add side speeds (regardless if the car is going up a cliff or not), or even detect if the player's vehicle is flipped, among others. |
new Float:vx,Float:vy,Float:vz;
GetVehicleVelocity(GetPlayerVehicleID(playerid),vx,vy,vz);
SetVehicleVelocity(GetPlayerVehicleID(playerid), vx * 1.3, vy *1.3, vz * 1.3);