Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <a_samp>
- new PlayerText:Velocity[MAX_PLAYERS];
- forward VehicleUpdate(); // forwarding VehicleUpdate();
- public OnFilterScriptInit()
- {
- printf("lcp9's velocity and health filterscript");
- SetTimer("VehicleUpdate",1*750,1);
- return 1;
- }
- public OnPlayerConnect(playerid)
- {
- Velocity[playerid] = CreatePlayerTextDraw(playerid,520,320,"_~N~Velocity: 0~N~Health: 0~N~_");
- PlayerTextDrawTextSize(playerid,Velocity[playerid],630,0);
- PlayerTextDrawUseBox(playerid,Velocity[playerid],1);
- PlayerTextDrawBoxColor(playerid,Velocity[playerid],0x00000066);
- PlayerTextDrawHide(playerid,Velocity[playerid]);
- return 1;
- }
- stock GetKph(vehicleid)
- {
- new Float:x,Float:y,Float:z; // Creating Float variables
- GetVehicleVelocity(vehicleid,x,y,z); // Writing in the x,y,z coordinates the speed values.
- return floatround(floatsqroot((x*x)+(y*y)+(z*z))*156.666667); // It returns the kph of the vehicle
- }
- public VehicleUpdate()
- {
- for(new i = 0;i < MAX_PLAYERS; i++) // i is the playerid
- {
- if(IsPlayerConnected(i)) // the same as if(IsPlayerConnected(i) == 1)
- {
- if(IsPlayerInAnyVehicle(i) == 1) // You could also write if(IsPlayerInAnyVehicle(i))
- {
- new vehicleid = GetPlayerVehicleID(i); // Getting the vehicleid, and write it into the vehicleid variable
- new kph = GetKph(vehicleid); // Using our function to get the kph velocity of our vehicle
- new Float:health;
- GetVehicleHealth(vehicleid,health); //writing in health the health of the vehicle
- new string[256];
- 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'
- PlayerTextDrawSetString(i,Velocity[i],string); // setting the PlayerTextDraw string
- PlayerTextDrawShow(i,Velocity[i]); // Showing the TextDraw to the player i
- }
- else if(!IsPlayerInAnyVehicle(i)) // You could also write else if(IsPlayerInAnyVehicle(i) == 0))
- {
- PlayerTextDrawHide(i,Velocity[i]); // The TextDraw has to be hidden
- }
- }
- else if(!IsPlayerConnected(i)) //same as if(IsPlayerConnected(i) == 0)
- {
- PlayerTextDrawHide(i,Velocity[i]); // The TextDraw has to be hidden
- }
- }
- return 1;
- }
Advertisement
Add Comment
Please, Sign In to add comment