[Tutorial] Simple Speedboost Command.
#1

Credits To :-
Zamaroht - The Functions
JernejL - The Functions
Sa-mp Team

Speed-Boost
First Off Getting The Functions By (See Credits)
pawn Код:
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;
    }
2. Lets Make The Command! To Speedboost!
pawn Код:
CMD:speedboost(playerid, params[])// Header Of The Command Using Zcmd
{
2-a.For Dcmd You Would Use
pawn Код:
dcmd_speedboost(playerid, params[])// Header Of The Command Using dcmd
{
2-b.strcmp ( OnPlayerCommandText )
pawn Код:
if(strcmp(cmd, "/speedboost", true) == 0)
{
3. Lets Make A Check To Check If The Player Is In A Vehicle Or Not!
pawn Код:
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.
4.Now I Need You To Create Some Variables! "With Float Tags! Or You Will Get A Tag Mismatch".
pawn Код:
new Float:currspeed[3], Float:direction[3], Float:total;
4-a. Example, New Float:currspeed[3] - The "[3]" Part Means Your Creating 3 "currspeeds" broken down into different variables. currspeed[0] - 1 currspeed[1] - 2 and currspeed[2] - 3.
4-b. remember you created [3] which means 3 variables and not [1] [2] [3], 0 is always included!

5.Now We Get The Vehicle's Velocity/Speed - Remember We Checked If The Player Was In A Vehicle?
pawn Код:
GetVehicleVelocity(GetPlayerVehicleID(playerid), currspeed[0], currspeed[1], currspeed[2]);
6.Here We Calculate the square root of The variable we created "total"
pawn Код:
total =
(Total Equals!, This Is Where You Set The Variable Total To Something!)
6-a. We're Going To Calculate All The Speeds (x,y,z) Of The Vehicle Now.
pawn Код:
(currspeed[0] * currspeed[0]) + (currspeed[1] * currspeed[1]) + (currspeed[2] * currspeed[2])
That Basically Means. Speedx Times Speedx + Speedy Times Speedy + Speedz Times Speedz!

6-b. Now We Find The Square Root Of The Total
6-c.
pawn Код:
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
6-d. You Should Have This When Your Finished.
pawn Код:
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
7.Here You Can Set How Much Speed You Want Your Vehicle To Increase To.
pawn Код:
total +=
7-a. The Variable total += which means total plus equal aka, adds something to the variable "total"
pawn Код:
total += 0.7
7-b. Don't Forget your delimiter!
pawn Код:
;
7-c. Were going to use 0.7 for now! this means, your total vehicle speed *(times,multiply) by 0.7.
pawn Код:
total +=0.7;
8.Some More New Variables For The Next Function!
pawn Код:
new Float:invector[3] = {0.0, -1.0, 0.0};
9.Now Using The New Function Added In 0.3b, GetVehicleRotationQuat! To Rotate The Vehicle
pawn Код:
RotatePointVehicleRotation(GetPlayerVehicleID(playerid), invector, direction[0], direction[1], direction[2]);
10.Finally We Made It! Now For The Real Part! The Real Speedboost! Here We Set The Players/Vehicle's Speed 0.7*His Current Speed! Like Whoa!
pawn Код:
SetVehicleVelocity(GetPlayerVehicleID(playerid), direction[0] * total, direction[1] * total, direction[2] * total);
11. Now To Kill The Function.
pawn Код:
return 1;
}
12. Entire Code For Those People Who DIdn't Completely Understand.
pawn Код:
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;
}
- From Zamaroht .
Quote:

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.

Credits To :-
Zamaroht - The Functions
JernejL - The Functions
Sa-mp Team
Reply
#2

Sorry but I don't really like it. It's a bit copy-paste. You do it something like:
"Do this"
{code}

"Now this"
{code}

And, it should be AWESOME if you explain a bit more about the float function you used. floatsqroot for example. Now, people will start thinking that you self don't even understand this and you just copied it from a script to givve it to other people (with credits). I personally think that.

"A bit math"
{the code I didn't understand}

Yeah you saw it. I didn't got it. I'm not really good with the float function etc. I would like it to find an tutorial with more information of that.

- Kevin
Reply
#3

OR you just use
pawn Код:
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);
Works perfectly fine.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)