|
Originally Posted by Rav
I think it's a matter of comparing the angle of the car with the direction someone is going in.. for example if the angle is 90 (facing east), but the car's 'y-position' changes positively (car is moving north) that person is drifting
|
// make some variable for each player
Float: LastVehiclePos[MAX_PLAYERS][3];
// foward timer function
forward CheckDrift(playerid);
// OnPlayerConnect
SetTimerEx("CheckDrift"477, 0, "i", playerid);
LastVehiclePos[playerid][0] = 0.0;
LastVehiclePos[playerid][1] = 0.0;
LastVehiclePos[playerid][2] = 0.0;
// custom function
public CheckDrift(playerid)
{
// sometimes the entire idea of running the timer is useless
if (!IsPlayerConnected(playerid))
return 1;
if (!IsPlayerInAnyVehicle(playerid))
return 1;
// the timer isn't automatically repeated, so lets set a new timer now
SetTimerEx("CheckDrift"477, 0, "i", playerid);
new vid = GetPlayerVehicleID(playerid);
new Float: angle;
GetVehicleZAngle (vid, angle); // stores the angle of the car in a variable
// now comes the tricky bit.. which I suck at.. and that is maths..
// you need to take the position of the car, how it's moved and convert it radially (make it an angle)
// this way you can compare the vehicle angle and the driving angle
// compare the absolute (always positive) value of the angles, if they're more than 30 degrees apart, someone is drifting
if (floatabs(DrivingAngle-Angle) > 30)
{
// you need to do something here, 1 check isn't enough to see a full drift, could just be someone turning their car etc..
}
// save new position of the car
GetVehiclePos(vid, LastVehiclePos[playerid][0], LastVehiclePos[playerid][1], LastVehiclePos[playerid][2]);
}
|
Originally Posted by Rav
Well, it would be quite a big script, so I'm just going to give you a small scheme you can work off
Код:
// make some variable for each player
Float: LastVehiclePos[MAX_PLAYERS][3];
// foward timer function
forward CheckDrift(playerid);
// OnPlayerConnect
SetTimerEx("CheckDrift"477, 0, "i", playerid);
LastVehiclePos[playerid][0] = 0.0;
LastVehiclePos[playerid][1] = 0.0;
LastVehiclePos[playerid][2] = 0.0;
// custom function
public CheckDrift(playerid)
{
// sometimes the entire idea of running the timer is useless
if (!IsPlayerConnected(playerid))
return 1;
if (!IsPlayerInAnyVehicle(playerid))
return 1;
// the timer isn't automatically repeated, so lets set a new timer now
SetTimerEx("CheckDrift"477, 0, "i", playerid);
new vid = GetPlayerVehicleID(playerid);
new Float: angle;
GetVehicleZAngle (vid, angle); // stores the angle of the car in a variable
// now comes the tricky bit.. which I suck at.. and that is maths..
// you need to take the position of the car, how it's moved and convert it radially (make it an angle)
// this way you can compare the vehicle angle and the driving angle
// compare the absolute (always positive) value of the angles, if they're more than 30 degrees apart, someone is drifting
if (floatabs(DrivingAngle-Angle) > 30)
{
// you need to do something here, 1 check isn't enough to see a full drift, could just be someone turning their car etc..
}
// save new position of the car
GetVehiclePos(vid, LastVehiclePos[playerid][0], LastVehiclePos[playerid][1], LastVehiclePos[playerid][2]);
}
|
|
Originally Posted by plɹoʍ ʎʇɹǝqıl
and how about this
i saw in a server when you get nos it stays only for like 1-2 seconds after it stops but its infinity. how to make that? |