I'm new to Garry's Mod lua and have created a simple Bunny Hop HUD, as you may know "Speed" is a main part of this HUD. I need help displaying the players speed in Unit/s not as a vector
I'm using
[CODE]local velocity = ply:GetVelocity()[/CODE]
Put this before that.
[CODE]local ply = LocalPlayer()[/CODE]
[lua]local velocity = ply:GetVelocity():Length()[/lua]
Anyway, this's units/sec
If you want it on MPH you should div this with 22.65
Please guys...USE GOOGLE! below this, there's the same guy asking the same and we gave him this function
[QUOTE=gonzalolog;45806562][lua]local velocity = ply:GetVelocity():Length()[/lua]
Anyway, this's units/sec
If you want it on MPH you should div this with 22.65
Please guys...USE GOOGLE! below this, there's the same guy asking the same and we gave him this function[/QUOTE]
Cheers, for this mate. Another nub question, how do I format it so there is no decimal, in other words rounds to 1 d.p.
math.floor
[QUOTE=HumbleTH;45807078]math.floor[/QUOTE]
How do I make it round?
math.Round
Come on, can you even google?
I'm working on a massive unit conversion table for gmod. Essentially all types of conversions ( 42kb at the moment ) to convert between lengths, speeds, etc..
Here's the light-weight version:
[code]//
// Conversions - Josh 'Acecool' Moser
//
// 1 unit = 0.75 inches.
// 4/3 units = 1 inch - from this we base our calculations.
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
CONVERSION_UNITS_TO_METERS = 0.0254 / CONVERSION_UNITS_TO_INCHES;
UNITS_PER_METER = 39.3701 * CONVERSION_UNITS_TO_INCHES;
// Crap choices...
CONVERSION_UNITS_TO_METERS = CONVERSION_UNITS_TO_FEET * 0.3048; -- 1 foot = 0.3048 meters. 16 units = 1 foot...
CONVERSION_UNITS_TO_MILES = CONVERSION_UNITS_TO_FEET * 5280;
CONVERSION_UNITS_TO_KILOMETERS = CONVERSION_UNITS_TO_FEET * 3280.84;
CONVERSION_UNITS_TO_MPH = CONVERSION_UNITS_TO_INCHES * 17.6;
CONVERSION_UNITS_TO_KPH = CONVERSION_UNITS_TO_INCHES * 10.936133;
CONVERSION_UNITS_KM_TO_MILE = 0.62137119223733387264;
CONVERSION_UNITS_MILE_TO_KM = 1.609344;[/code]
For MPH:
local _speed = math.Round( _v:GetVelocity( ):Length( ) / CONVERSION_UNITS_TO_MPH );
[QUOTE=Acecool;45811313]I'm working on a massive unit conversion table for gmod. Essentially all types of conversions ( 42kb at the moment ) to convert between lengths, speeds, etc..
Here's the light-weight version:
[code]//
// Conversions - Josh 'Acecool' Moser
//
// 1 unit = 0.75 inches.
// 4/3 units = 1 inch - from this we base our calculations.
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
CONVERSION_UNITS_TO_METERS = 0.0254 / CONVERSION_UNITS_TO_INCHES;
UNITS_PER_METER = 39.3701 * CONVERSION_UNITS_TO_INCHES;
// Crap choices...
CONVERSION_UNITS_TO_METERS = CONVERSION_UNITS_TO_FEET * 0.3048; -- 1 foot = 0.3048 meters. 16 units = 1 foot...
CONVERSION_UNITS_TO_MILES = CONVERSION_UNITS_TO_FEET * 5280;
CONVERSION_UNITS_TO_KILOMETERS = CONVERSION_UNITS_TO_FEET * 3280.84;
CONVERSION_UNITS_TO_MPH = CONVERSION_UNITS_TO_INCHES * 17.6;
CONVERSION_UNITS_TO_KPH = CONVERSION_UNITS_TO_INCHES * 10.936133;
CONVERSION_UNITS_KM_TO_MILE = 0.62137119223733387264;
CONVERSION_UNITS_MILE_TO_KM = 1.609344;[/code]
For MPH:
local _speed = math.Round( _v:GetVelocity( ):Length( ) / CONVERSION_UNITS_TO_MPH );[/QUOTE]
Thank you for this but all I need is Unit/s which I now have thanks to the help on this post. I now only need to figure out a way to position the number in one place as for now it moves to the right as the speed increases e.g 1 = 5 px 10 = 10px 250 = 20px
I don't quite understand...
Set the X and Y coordinates to not move, or to be centered along a bar like this:
[code]// Example text
local _text = "50 MPH";
// Set the font to we can get the text size properly...
surface.SetFont( "Default" );
// Width and height of the text
local _w, _h = surface.GetTextSize( _text );
// This is the position we want the text to be centered on
local _x, _y = 100, 250;
// 2 options, you can position the text at the x and y and set the function to V-ALIGN and H-ALIGN, OR you can calculate it yourself which just means take HALF of the width and half of the height and add or subtract it...
surface.SetTextPos( _x - ( _w / 2 ), _y - ( _h / 2 ) );
// Finally set the color and draw it..
surface.SetTextColor( color_white );
surface.DrawText( _text );[/code]
Aside from that, I don't understand what you're asking... If you want the number to move based on speed, that can be done.. If you want it to stay still, make sure you're not changing the position of it...
[code] draw.SimpleText(velocity, "SpeedFont", 435, ScrH() - 67, Color(255,255,255))
velocity = math.Round(ply:GetVelocity():Length()) [/code]
This code is in a function hooked to HUDPaint.
[video=youtube;kMda-2s8ccg]https://www.youtube.com/watch?v=kMda-2s8ccg[/video]
The only way I can think of making the increasing number stay centered on the box is to use If statements. Anything else?
Sorry, you need to Log In to post a reply to this thread.