Quote:
Originally Posted by RogueDrifter
You deleted it lmao, you seriously gonna deny that?
What did you even update? I see no changes from the older thread that was about a year ago.
|
This is an entire different include, the old one was released in 2016 which was poorly written and I don't want to support it anymore, thus a new thread.
Changes:
drift-detection.inc:
PHP код:
public OnPlayerUpdate(playerid)
{
if(g_DriftFlags & DRIFT_CHECK_ENABLED && g_DriftPlayers[playerid][playerFlags] & DRIFT_CHECK_ENABLED)
{
if(GetTickCount() > g_DriftPlayers[playerid][lastTimestamp])
{
new vehicleID = GetPlayerVehicleID(playerid);
if(vehicleID && GetPlayerState(playerid) == PLAYER_STATE_DRIVER && IsModelACar(GetVehicleModel(vehicleID)))
{
new Float: vX, Float: vY, Float: vZ;
GetVehicleVelocity(vehicleID, vX, vY, vZ);
new Float: angle;
GetVehicleZAngle(vehicleID, angle);
new Float: speed;
speed = floatsqroot(vX*vX + vY*vY + vZ*vZ) * 180.0;
new Float: direction;
direction = atan2(vY, vX);
direction -= 90.0;
if(direction < 0) direction += 360.0;
new Float: driftAngle;
driftAngle = angle - floatabs(direction);
if(driftAngle > 270.0) driftAngle -= 270.0;
if(driftAngle < -270.0) driftAngle += 270.0;
driftAngle = floatabs(driftAngle);
switch(g_DriftPlayers[playerid][driftState])
{
case DRIFT_STATE_NONE:
{
if(MIN_DRIFT_ANGLE <= driftAngle <= MAX_DRIFT_ANGLE && speed >= MIN_DRIFT_SPEED)
{
g_DriftPlayers[playerid][driftState] = DRIFT_STATE_DRIFTING;
g_DriftPlayers[playerid][startTimestamp] = GetTickCount();
GetVehicleHealth(vehicleID, g_DriftPlayers[playerid][vHealth]);
GetPlayerPos(playerid, g_DriftPlayers[playerid][startPosX], g_DriftPlayers[playerid][startPosY], g_DriftPlayers[playerid][startPosZ]);
#if defined OnPlayerDriftStart
OnPlayerDriftStart(playerid);
#endif
}
}
case DRIFT_STATE_DRIFTING:
{
if(g_DriftFlags & DAMAGE_CHECK_ENABLED && g_DriftPlayers[playerid][playerFlags] & DAMAGE_CHECK_ENABLED)
{
new Float: vehicleHealth;
GetVehicleHealth(vehicleID, vehicleHealth);
if(vehicleHealth < g_DriftPlayers[playerid][vHealth])
{
GetPlayerPos(playerid, vX, vY, vZ);
g_DriftPlayers[playerid][driftState] = DRIFT_STATE_NONE;
g_DriftPlayers[playerid][timeoutTicks] = 0;
#if defined OnPlayerDriftEnd
new Float: distance;
distance = GetPlayerDistanceFromPoint(playerid, g_DriftPlayers[playerid][startPosX], g_DriftPlayers[playerid][startPosY], g_DriftPlayers[playerid][startPosZ]);
OnPlayerDriftEnd(playerid, DRIFT_END_REASON_DAMAGED, distance, GetTickCount() - g_DriftPlayers[playerid][startTimestamp]);
#endif
}
}
else if(MIN_DRIFT_ANGLE <= driftAngle <= MAX_DRIFT_ANGLE && speed >= MIN_DRIFT_SPEED)
{
g_DriftPlayers[playerid][timeoutTicks] = 0;
#if defined OnPlayerDriftUpdate
OnPlayerDriftUpdate(playerid, driftAngle, speed);
#endif
}
else
{
g_DriftPlayers[playerid][timeoutTicks]++;
if(g_DriftPlayers[playerid][timeoutTicks] >= DRIFT_TIMEOUT_INTERVAL)
{
GetPlayerPos(playerid, vX, vY, vZ);
g_DriftPlayers[playerid][driftState] = DRIFT_STATE_NONE;
g_DriftPlayers[playerid][timeoutTicks] = 0;
#if defined OnPlayerDriftEnd
new Float: distance;
distance = GetPlayerDistanceFromPoint(playerid, g_DriftPlayers[playerid][startPosX], g_DriftPlayers[playerid][startPosY], g_DriftPlayers[playerid][startPosZ]);
OnPlayerDriftEnd(playerid, DRIFT_END_REASON_TIMEOUT, distance, GetTickCount() - g_DriftPlayers[playerid][startTimestamp]);
#endif
}
}
}
}
}
g_DriftPlayers[playerid][lastTimestamp] = GetTickCount() + DRIFT_PROCESS_INTERVAL;
}
}
#if defined Drift_OnPlayerUpdate
return Drift_OnPlayerUpdate(playerid);
#else
return true;
#endif
}
drift.inc: (2016)
PHP код:
public OnPlayerUpdate(playerid) {
if(GetTickCount() > P_DATA[playerid][T_TICK])
{
new vehicleid;
if( (vehicleid = GetPlayerVehicleID(playerid)) && GetPlayerState(playerid) == PLAYER_STATE_DRIVER )
{
if(__IsModelACar(GetVehicleModel(vehicleid)))
{
new Float:x, Float:y, Float:z, Float:a, Float:d, Float:s, Float:drift_angle;
GetVehicleVelocity(vehicleid, x, y, z);
GetVehicleZAngle(vehicleid, a);
s = floatround(floatsqroot( x*x + y*y + z*z) * 180);
d = atan2(y, x);
d = floatsub(d, 90.0);
if(d < 0.0) d = floatadd(d, 360.0);
drift_angle = a - d;
if(drift_angle > 270.0) drift_angle -= 270.0;
if(drift_angle < -270.0) drift_angle += 270.0;
drift_angle = floatabs(drift_angle);
switch (P_DATA[playerid][P_DRIFTING])
{
case 0:
{
if(MIN_DRIFT_ANGLE <= drift_angle <= MAX_DRIFT_ANGLE && s >= MIN_DRIFT_SPEED && !__IsVehicleDrivingBackwards(x, y, a))
{
P_DATA[playerid][P_DRIFTING] = true;
P_DATA[playerid][D_STARTTICK] = GetTickCount();
GetVehicleHealth(vehicleid, P_DATA[playerid][V_HEALTH]);
GetPlayerPos(playerid, P_DATA[playerid][P_STARTX], P_DATA[playerid][P_STARTY], x);
CallLocalFunction("OnDriftStart", "i", playerid);
}
}
case 1:
{
new Float:vhealth, Float:_x, Float:_y, Float:_z;
GetVehicleHealth(vehicleid, vhealth);
GetPlayerPos(playerid, _x, _y, _z);
if(vhealth < P_DATA[playerid][V_HEALTH])
{
CallLocalFunction("OnDriftEnd", "iifi", playerid, DRIFT_END_REASON_CRASH, __GetPointDistanceToPoint(P_DATA[playerid][P_STARTX], P_DATA[playerid][P_STARTY], _x, _y), GetTickCount() - P_DATA[playerid][D_STARTTICK]);
P_DATA[playerid] = R_DATA;
}
else if(__IsVehicleDrivingBackwards(x, y, a) || s < MIN_DRIFT_SPEED)
{
CallLocalFunction("OnDriftEnd", "iifi", playerid, DRIFT_END_REASON_OTHER, __GetPointDistanceToPoint(P_DATA[playerid][P_STARTX], P_DATA[playerid][P_STARTY], _x, _y), GetTickCount() - P_DATA[playerid][D_STARTTICK]);
P_DATA[playerid] = R_DATA;
}
else if(MIN_DRIFT_ANGLE <= drift_angle <= MAX_DRIFT_ANGLE && s >= MIN_DRIFT_SPEED)
{
P_DATA[playerid][T_TIMEOUT] = 0;
CallLocalFunction("OnDriftUpdate", "iff", playerid, drift_angle, s);
}
else
{
P_DATA[playerid][T_TIMEOUT]++;
if(P_DATA[playerid][T_TIMEOUT] >= DRIFT_TIMEOUT_INTERVAL)
{
CallLocalFunction("OnDriftEnd", "iifi", playerid, DRIFT_END_REASON_TIMEOUT, __GetPointDistanceToPoint(P_DATA[playerid][P_STARTX], P_DATA[playerid][P_STARTY], _x, _y), GetTickCount() - P_DATA[playerid][D_STARTTICK]);
P_DATA[playerid] = R_DATA;
}
}
}
}
}
}
P_DATA[playerid][T_TICK] = GetTickCount() + PROCESS_INTERVAL;
}
#if defined D_OnPlayerUpdate
return D_OnPlayerUpdate(playerid);
#else
return true;
#endif
}