Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Updated 2020-12-17 | Rewiews: 144
- //Created by Vok3
- #define Velocity 0.5
- #define SpeedCap 1.0
- public OnPlayerUpdate(playerid)
- {
- GetPlayerVehicleVelocity(playerid);
- return 1;
- }
- stock GetPlayerVehicleVelocity(playerid)
- {
- if(IsPlayerInAnyVehicle(playerid))
- {
- if(GetPlayerState(playerid) == PLAYER_STATE_DRIVER)
- {
- new Float: Veloc[3];
- GetVehicleVelocity(GetPlayerVehicleID(playerid), Veloc[0], Veloc[1], Veloc[2]);
- if(Veloc[0] > Velocity || Veloc[0] < -Velocity || Veloc[1] > Velocity || Veloc[1] < -Velocity || Veloc[2] > Velocity)
- {
- static Float:s_fX, Float:s_fY, Float:s_fZ, Float:s_fVX, Float:s_fVY, Float:s_fVZ;
- GetVehiclePos(GetPlayerVehicleID(playerid), s_fX, s_fY, s_fZ);
- GetVehicleVelocity(GetPlayerVehicleID(playerid), s_fVX, s_fVY, s_fVZ);
- if(!IsPlayerInRangeOfPoint(playerid, SpeedCap + 0.05, s_fX + s_fVX, s_fY + s_fVY, s_fZ + s_fVZ))
- {
- static Float:s_fLength;
- s_fLength = floatsqroot((s_fVX * s_fVX ) + ( s_fVY * s_fVY ) + ( s_fVZ * s_fVZ ) );
- s_fVX=(s_fVX / s_fLength) * SpeedCap;
- s_fVY=(s_fVY / s_fLength) * SpeedCap;
- s_fVZ=(s_fVZ / s_fLength) * SpeedCap;
- SetVehicleVelocity(GetPlayerVehicleID(playerid), s_fVX, s_fVY, s_fVZ );
- }
- }
- }
- }
- else
- {
- new Float: Veloc[3];
- GetPlayerVelocity(playerid, Veloc[0], Veloc[1], Veloc[2]);
- if(Veloc[0] > Velocity || Veloc[0] < -Velocity || Veloc[1] > Velocity || Veloc[1] < -Velocity || Veloc[2] > Velocity)
- {
- FixPlayerPosition(playerid);
- }
- }
- return 1;
- }
- stock FixPlayerPosition(playerid)
- {
- new Float:Position[3];
- GetPlayerPos(playerid, Position[0], Position[1], Position[2]);
- SetPlayerPos(playerid, Position[0], Position[1], Position[2]);
- return 1;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement