• how do i add Velocity meter
    7 replies, posted
I was looking around the place and came across this: [url]http://facepunch.com/showthread.php?t=925617[/url] (scroll down to the video) How do I make a velocity meter like this? I can make the text that shows the speed but not the meter. Please help.
Can you draw two boxes and change their width?
Scale a rectangle by [code]velocity / maxvelocity * maxwidth[/code] You should also clamp it between 0 and the maxwidth.
Can I have an example?
He posted the code right above the video... Edit for his function, but it's pretty much the same: [lua]local velocity = 0; if (LocalPlayer( ):InVehicle( )) then velocity = LocalPlayer( ):GetVehicle( ):GetVelocity( ):Length( ) else velocity = LocalPlayer( ):GetVelocity( ):Length( ) end draw.RoundedBox(0, ScrW( ) - 250, ScrH( ) - 35, velocity/CONVERSION_UNITS_TO_FEET, 15, Color(0,255,0,255))[/lua]
[QUOTE=Acecool;40428944]He posted the code right above the video... Edit for his function, but it's pretty much the same: [lua]local velocity = 0; if (LocalPlayer( ):InVehicle( )) then velocity = LocalPlayer( ):GetVehicle( ):GetVelocity( ):Length( ) else velocity = LocalPlayer( ):GetVelocity( ):Length( ) end draw.RoundedBox(0, ScrW( ) - 250, ScrH( ) - 35, velocity/CONVERSION_UNITS_TO_FEET, 15, Color(0,255,0,255))[/lua][/QUOTE] Thankyou Acecool! Though this piece of code didnt work, it gave me this error: [ERROR] gamemodes/bunnyhop/gamemode/cl_init.lua:86: attempt to perform arithmetic on global 'CONVERSION_UNITS_TO_FEET' (a nil value) 1. unknown - gamemodes/bunnyhop/gamemode/cl_init.lua:86 So I removed this: velocity/CONVERSION_UNITS_TO_FEET and it works "decent...."
[code]draw.RoundedBox(0, ScrW( ) - 250, ScrH( ) - 35, math.Clamp(velocity/250,0,200 ), 15, Color(0,255,0,255))[/code]
Sorry, that was part of my debug hud, and that ENUM is supposed to be: [lua]CONVERSION_UNITS_TO_INCHES = 4/3; // 4/3 units per 1 inch, 16 units per foot CONVERSION_UNITS_TO_FEET = CONVERSION_UNITS_TO_INCHES * 12 // == 16 in game units [/lua]
Sorry, you need to Log In to post a reply to this thread.