26.11.2013, 12:12
(
Последний раз редактировалось Dragonsaurus; 28.11.2013 в 12:26.
)
Say goodbye to drift counting plugins and includes:
This lil' code will return the difference between facing angle and heading angle.
This difference will always be <= 90 degrees (That's the maximum angle of drift possible).
Tested for a whole hour with one hundred 100ms timers consecutively at a home test server, in a low spec PC (504 MB of RAM) for 1 player, with absolutely no lag.
Important: If you get any "function with tag result used before definition, forcing reparse" warning, place the code after the includes.
pawn Код:
stock Float:ReturnDriftAngle(playerid)
{
new vehicleid = GetPlayerVehicleID(playerid);
if(vehicleid == INVALID_VEHICLE_ID || !vehicleid) return 0.0;
new Float:v[3], Float:a[3];
GetVehicleVelocity(vehicleid, v[0], v[1], v[2]); GetVehicleZAngle(vehicleid, a[0]);
if(floatmul(floatsqroot(floatadd(floatadd(floatpower(v[0], 2), floatpower(v[1], 2)), floatpower(v[2], 2))), 181.5) < 20.0) return 0;
a[0] = (a[0] >= 360.0) ? (floatsub(a[0], 360.0)) : (a[0] < 0.0) ? (floatadd(a[0], 360.0)) : (a[0]);
a[0] = (a[0] > 180.0) ? (floatsub(0.0, floatsub(360.0, a[0]))) : (a[0]);
a[1] = floatsub(atan2(v[1], v[0]), 90.0);
a[1] = (a[1] >= 360.0) ? (floatsub(a[1], 360.0)) : (a[1] < 0.0) ? (floatadd(a[1], 360.0)) : (a[1]);
a[1] = (a[1] > 180.0) ? (floatsub(0.0, floatsub(360.0, a[1]))) : (a[1]);
a[2] = floatabs(floatsub(a[0], a[1]));
a[2] = (a[2] > 180.0) ? (floatsub(a[2], 180.0)) : (a[2]);
return (a[2] >= 90.0) ? (floatsub(180.0, a[2])) : (a[2]);
}
This difference will always be <= 90 degrees (That's the maximum angle of drift possible).
Tested for a whole hour with one hundred 100ms timers consecutively at a home test server, in a low spec PC (504 MB of RAM) for 1 player, with absolutely no lag.
Important: If you get any "function with tag result used before definition, forcing reparse" warning, place the code after the includes.