13.01.2019, 07:26
Hello guys I want to make a simple drift system, but I have no idea how to check if player drifts! Can somebody explain me? I mean with piece of code and explanation. I need to know just how to check it.
//code made by : codExpert // 13.01.19
#include <YSI_Coding\y_timers>
//variables - needed to stop drifting angle spam you have to build this yourself
new Float:pVehLastAngle[MAX_PLAYERS];
//params resets
public OnPlayerEnterVehicle(playerid,vehicleid,ispassenger){
pVehLastAngle[playerid]=0.0;
return 1;
}
//functions related with system
bool:vehTypeCar(modelID){
switch(modelID){
case 480,533,439,555,536,575,534,567,535,566,576,412,445,504,401,518,527,542,507,562,585,419,526,604,466,492,474,546,517,410,
551,516,467,426,436,547,405,580,560,550,549,540,491,529,421,602,429,496,402,541,415,589,587,565,494,502,503,411,559,603,
475,506,451,558,477,418,404,479,458,561: return true;
}
return false;
}
GetAngleToXY(Float:X, Float:Y, Float:CurrentX, Float:CurrentY, &Float:Angle){
Angle = atan2(Y-CurrentY, X-CurrentX);
Angle = floatsub(Angle, 90.0);
if(Angle < 0.0) Angle = floatadd(Angle, 360.0);
}
GetVehicleHeadingAngle(vehicleid, &Float:a){
new Float:x, Float:y, Float:z;
GetVehicleVelocity(vehicleid, x, y, z);
GetAngleToXY(x, y, 0.0, 0.0, a);
}
//makes timer more accurate and easier to create
ptask PlayerDriftChecker[500](playerid){
//checks if player is driver
if( GetPlayerState(playerid)==PLAYER_STATE_DRIVER){
new vehID=GetPlayerVehicleID(playerid);
vehModel=GetVehicleModel(vehID);
//checks if vehicle model type is car
if(vehTypeCar(vehModel)){
new Float:vehAngle=GetVehicleZAngle(vehID),
Float:vehHeadingAngle,
Float:angleDifference;
GetVehicleHeadingAngle(vehID, vehHeadingAngle);
//checking the angle difference
if((angleDifference=floatabs(vehAngle-vehHeadingAngle)) > 45.0){
new s[60];
format(s,60,"Drifting angle : %.2d",angleDifference);
SendClientMessage(playerid,-1,s);
}
}
}
}