19.07.2010, 12:58
(
Last edited by mckennie; 26/07/2010 at 04:47 AM.
)
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
step two. assign text to each players speedo on connect. in the OnPlayerConnect callback, add this
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
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
step one. define an array that will hold all the speeds for each player
Code:
new Text:SPEEDOS[MAX_PLAYERS]
Code:
SPEEDOS[playerid] = TextDrawCreate(10.0,200.0," "); TextDrawShowForPlayer(playerid,SPEEDOS[playerid]);
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], " "); }
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