Guest User

Automatic Velocity

a guest
Jan 6th, 2013
528
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 2.38 KB | None | 0 0
  1. //BY ADRI1
  2. #include <a_samp>
  3. new speed123[MAX_PLAYERS];
  4. new timer[MAX_PLAYERS];
  5. #define FILTERSCRIPT
  6. #if defined FILTERSCRIPT
  7.  
  8.  
  9. public OnPlayerStateChange(playerid, newstate, oldstate)
  10. {
  11.     if(oldstate == PLAYER_STATE_DRIVER && newstate == PLAYER_STATE_ONFOOT)
  12.     {
  13.         if(GetPVarInt(playerid, "automaticspeed"))
  14.         {
  15.             KillTimer(timer[playerid]);
  16.             speed123[playerid] = 0;
  17.             DeletePVar(playerid, "automaticspeed");
  18.             GameTextForPlayer(playerid, "~g~AV:~r~  OFF", 500, 1);
  19.         }
  20.     }
  21.     return 1;
  22. }
  23.  
  24.  
  25. public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
  26. {
  27.     if(newkeys & KEY_FIRE)
  28.     {
  29.         if(!IsPlayerInAnyVehicle(playerid)) return 1;
  30.         if(GetPlayerState(playerid) != PLAYER_STATE_DRIVER) return 1;
  31.         if(!GetPVarInt(playerid, "automaticspeed"))
  32.         {
  33.             speed123[playerid] = GetPlayerSpeed(playerid,false);
  34.             if(speed123[playerid] == 0) return 1;
  35.             timer[playerid] = SetTimerEx("asd",100,1,"i",playerid);
  36.             SetPVarInt(playerid,"automaticspeed" , true);
  37.             GameTextForPlayer(playerid, "~r~AV:~g~  ON", 500, 1);
  38.         }
  39.         else
  40.         {
  41.             KillTimer(timer[playerid]);
  42.             speed123[playerid] = 0;
  43.             DeletePVar(playerid, "automaticspeed");
  44.             GameTextForPlayer(playerid, "~g~AV:~r~  OFF", 500, 1);
  45.         }
  46.     }
  47.     return 1;
  48. }
  49. forward asd(playerid);public asd(playerid)
  50. {
  51.     if(GetPVarInt(playerid, "automaticspeed"))
  52.     {
  53.         new Keys,ud,lr;
  54.         GetPlayerKeys(playerid,Keys,ud,lr);
  55.  
  56.         if(Keys & KEY_HANDBRAKE || Keys & KEY_DOWN) KillTimer(timer[playerid]), DeletePVar(playerid, "automaticspeed") ,GameTextForPlayer(playerid, "~g~AV:~r~  OFF", 500, 1);
  57.         SetVehicleSpeed(GetPlayerVehicleID(playerid),speed123[playerid]);
  58.     }
  59.     return 1;
  60. }
  61. stock SetVehicleSpeed(vehicleid,mph)
  62. {
  63.     new Float:Vx,Float:Vy,Float:Vz,Float:DV,Float:multiple;
  64.     GetVehicleVelocity(vehicleid,Vx,Vy,Vz);
  65.     DV = floatsqroot(Vx*Vx + Vy*Vy + Vz*Vz);
  66.     if(DV > 0)
  67.     {
  68.         multiple = (mph / (DV * 100));
  69.         return SetVehicleVelocity(vehicleid,Vx*multiple,Vy*multiple,Vz*multiple);
  70.     }
  71.     return 0;
  72. }
  73. stock GetPlayerSpeed(playerid,bool:kmh)
  74. {
  75.     new Float:Vx,Float:Vy,Float:Vz,Float:rtn;
  76.     if(IsPlayerInAnyVehicle(playerid)) GetVehicleVelocity(GetPlayerVehicleID(playerid),Vx,Vy,Vz); else GetPlayerVelocity(playerid,Vx,Vy,Vz);
  77.     rtn = floatsqroot(floatabs(floatpower(Vx + Vy + Vz,2)));
  78.     return kmh?floatround(rtn * 100 * 1.61):floatround(rtn * 100);
  79. }
  80. #endif
Advertisement
Add Comment
Please, Sign In to add comment