Guest User

Velocity, Health filterscript

a guest
Oct 7th, 2014
491
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 2.52 KB | None | 0 0
  1. #include <a_samp>
  2. new PlayerText:Velocity[MAX_PLAYERS];
  3.  
  4. forward VehicleUpdate(); // forwarding VehicleUpdate();
  5.  
  6.  
  7.  
  8. public OnFilterScriptInit()
  9. {
  10.     printf("lcp9's velocity and health filterscript");
  11.     SetTimer("VehicleUpdate",1*750,1);
  12.     return 1;
  13. }
  14.  
  15. public OnPlayerConnect(playerid)
  16. {
  17.     Velocity[playerid] = CreatePlayerTextDraw(playerid,520,320,"_~N~Velocity: 0~N~Health: 0~N~_");
  18.     PlayerTextDrawTextSize(playerid,Velocity[playerid],630,0);
  19.     PlayerTextDrawUseBox(playerid,Velocity[playerid],1);
  20.     PlayerTextDrawBoxColor(playerid,Velocity[playerid],0x00000066);
  21.     PlayerTextDrawHide(playerid,Velocity[playerid]);
  22.     return 1;
  23. }
  24. stock GetKph(vehicleid)
  25. {
  26.     new Float:x,Float:y,Float:z; // Creating Float variables
  27.     GetVehicleVelocity(vehicleid,x,y,z); // Writing in the x,y,z coordinates the speed values.
  28.     return floatround(floatsqroot((x*x)+(y*y)+(z*z))*156.666667); // It returns the kph of the vehicle
  29. }
  30. public VehicleUpdate()
  31. {
  32.     for(new i = 0;i < MAX_PLAYERS; i++) // i is the playerid
  33.     {
  34.         if(IsPlayerConnected(i)) // the same as if(IsPlayerConnected(i) == 1)
  35.         {
  36.             if(IsPlayerInAnyVehicle(i) == 1) // You could also write if(IsPlayerInAnyVehicle(i))
  37.             {
  38.                 new vehicleid = GetPlayerVehicleID(i); // Getting the vehicleid, and write it into the vehicleid variable
  39.                 new kph = GetKph(vehicleid); // Using our function to get the kph velocity of our vehicle
  40.                 new Float:health;
  41.                 GetVehicleHealth(vehicleid,health); //writing in health the health of the vehicle
  42.                 new string[256];
  43.                 format(string,sizeof(string),"_~N~Velocity: %i~N~Health: %i%%~N~_",kph,floatround(health / 10)); // %i if you want to write an integer variable into the string, %% if you want to write a %, we want to show health with per cents so we have to to 'health / 10'
  44.                 PlayerTextDrawSetString(i,Velocity[i],string); // setting the PlayerTextDraw string
  45.                 PlayerTextDrawShow(i,Velocity[i]); // Showing the TextDraw to the player i
  46.             }
  47.             else if(!IsPlayerInAnyVehicle(i)) // You could also write else if(IsPlayerInAnyVehicle(i) == 0))
  48.             {
  49.                 PlayerTextDrawHide(i,Velocity[i]); // The TextDraw has to be hidden
  50.             }
  51.         }
  52.         else if(!IsPlayerConnected(i)) //same as if(IsPlayerConnected(i) == 0)
  53.         {
  54.             PlayerTextDrawHide(i,Velocity[i]); // The TextDraw has to be hidden
  55.         }
  56.     }
  57.     return 1;
  58. }
Advertisement
Add Comment
Please, Sign In to add comment