16.12.2010, 03:56
(
Последний раз редактировалось The_Gangstas; 16.12.2010 в 15:48.
)
Credits To :-
Zamaroht - The Functions
JernejL - The Functions
Sa-mp Team
Speed-Boost
First Off Getting The Functions By (See Credits)
2. Lets Make The Command! To Speedboost!
2-a.For Dcmd You Would Use
2-b.strcmp ( OnPlayerCommandText )
3. Lets Make A Check To Check If The Player Is In A Vehicle Or Not!
4.Now I Need You To Create Some Variables! "With Float Tags! Or You Will Get A Tag Mismatch".
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?
6.Here We Calculate the square root of The variable we created "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.
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.
6-d. You Should Have This When Your Finished.
7.Here You Can Set How Much Speed You Want Your Vehicle To Increase To.
7-a. The Variable total += which means total plus equal aka, adds something to the variable "total"
7-b. Don't Forget your delimiter!
7-c. Were going to use 0.7 for now! this means, your total vehicle speed *(times,multiply) by 0.7.
8.Some More New Variables For The Next Function!
9.Now Using The New Function Added In 0.3b, GetVehicleRotationQuat! To Rotate The Vehicle
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!
11. Now To Kill The Function.
12. Entire Code For Those People Who DIdn't Completely Understand.
- From Zamaroht .
Credits To :-
Zamaroht - The Functions
JernejL - The Functions
Sa-mp Team
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;
}
pawn Код:
CMD:speedboost(playerid, params[])// Header Of The Command Using Zcmd
{
pawn Код:
dcmd_speedboost(playerid, params[])// Header Of The Command Using dcmd
{
pawn Код:
if(strcmp(cmd, "/speedboost", true) == 0)
{
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.
pawn Код:
new Float:currspeed[3], Float:direction[3], Float:total;
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]);
pawn Код:
total =
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])
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
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
pawn Код:
total +=
pawn Код:
total += 0.7
pawn Код:
;
pawn Код:
total +=0.7;
pawn Код:
new Float:invector[3] = {0.0, -1.0, 0.0};
pawn Код:
RotatePointVehicleRotation(GetPlayerVehicleID(playerid), invector, direction[0], direction[1], direction[2]);
pawn Код:
SetVehicleVelocity(GetPlayerVehicleID(playerid), direction[0] * total, direction[1] * total, direction[2] * total);
pawn Код:
return 1;
}
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;
}
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. |
Zamaroht - The Functions
JernejL - The Functions
Sa-mp Team