[Tutorial] Simple speedometer script
#1

hi, this is a short tutorial for making a simple text speedometer. it can measure in MPH or KM/H, but it only shows when the player is it a vehicle so, lets get started

step one. define an array that will hold all the speeds for each player

Code:
new Text:SPEEDOS[MAX_PLAYERS]
step two. assign text to each players speedo on connect. in the OnPlayerConnect callback, add this

Code:
SPEEDOS[playerid] = TextDrawCreate(10.0,200.0," ");
TextDrawShowForPlayer(playerid,SPEEDOS[playerid]);
explanation: textdrawcreate creates a textdraw, and the numbers next to it are its position on a 640x480 'canvas' that covers the screen. in the quotes is the default text for the textdraw, and since we dont want anything to show until the player gets into a car, its just a space

step 3. we need some code to read the cars speed and draw it to the screen, so thats up next. add the following code to the OnPlayerUpdate callback

Code:
new vehicleid,Float:speed_x,Float:speed_y,Float:speed_z,Float:final_speed,speed_string[256],final_speed_int;
	vehicleid = GetPlayerVehicleID(playerid);
	if(vehicleid != 0)
	{
		GetVehicleVelocity(vehicleid,speed_x,speed_y,speed_z);
		final_speed = floatsqroot(((speed_x*speed_x)+(speed_y*speed_y))+(speed_z*speed_z))*136.666667;
		final_speed_int = floatround(final_speed,floatround_round);
		format(speed_string,256,"Speed: %i",final_speed_int);
		TextDrawSetString(SPEEDOS[playerid], speed_string);
	}
	else
	{
		TextDrawSetString(SPEEDOS[playerid], " ");
	}
basicly, we're creating some variables, getting the id of the car the players driving, checking if the players in a car or walking, getting the speed of the car, and then drawing the speed to the screen. here ive multiplyed the speed by 136.666667 to get KM/H, but if you change it to 85.4166672 you would get MPH


i hope you liked my tutorial, and post with some ideas of stuff i could write if you cant be bothered, im out of ideas
Reply


Messages In This Thread
Simple speedometer script - by mckennie - 19.07.2010, 12:58
Re: Simple speedometer script - by [DK]JaloNik - 19.07.2010, 12:59
Re: Simple speedometer script - by Kar - 19.07.2010, 13:03
Re: Simple speedometer script - by Joe_ - 19.07.2010, 14:38
Re: Simple speedometer script - by mckennie - 19.07.2010, 20:40
Re: Simple speedometer script - by hab2ever - 19.07.2010, 20:58
Re: Simple speedometer script - by mckennie - 19.07.2010, 21:10
Re: Simple speedometer script - by AiVAMAN - 19.07.2010, 21:56
Re: Simple speedometer script - by Garc1a - 21.07.2010, 16:32
Re: Simple speedometer script - by Sergei - 21.07.2010, 17:16

Forum Jump:


Users browsing this thread: 1 Guest(s)