Jump to content

[Question] about vehicle speed


Recommended Posts

What do you mean then? I (And maybe others) don't understand it out of your first post.

all i want to know is a way to know for example a car like turismo speed .

like now im not moving so the speed is 0 .

(i want to know my car speed

i tied speed = getelementspeed

if speed =0 then ....)

Link to comment

try this, no tested

local screenWidth, screenHeight = guiGetScreenSize ( ) 
  
function outputSpeed() 
if isPedInVehicle(localPlayer) then 
local vehicle = getPedOccupiedVehicle(localPlayer) 
local x,y,z = getElementVelocity(vehicle) 
local km = (x^2 + y^2 + z^2) ^ 0.5 * 180 
dxDrawText(km,44,screenHeight - 43, screenWidth, screenHeight, tocolor ( 255, 255, 255, 255 ), 1, "pricedown" )  
  
end 
end 
addEventHandler("onClientRender", root, outputSpeed)  

Link to comment

getElementSpeed is a useful function, so you can't just use it with out copying the source code to your file first

Copy and paste the source code, then use it

( if you didn't already)

and ofc, use onClientRender even to get player speed on every frame.

Link to comment
getElementSpeed is a useful function, so you can't just use it with out copying the source code to your file first

Copy and paste the source code, then use it

( if you didn't already)

and ofc, use onClientRender even to get player speed on every frame.

function getElementSpeed(element,unit) 
    if (unit == nil) then unit = 0 end 
    if (isElement(element)) then 
        local x,y,z = getElementVelocity(element) 
        if (unit=="mph" or unit==1 or unit =='1') then 
            return (x^2 + y^2 + z^2) ^ 0.5 * 100 
        else 
            return (x^2 + y^2 + z^2) ^ 0.5 * 1.8 * 100 
        end 
    else 
        outputDebugString("Not an element. Can't get speed") 
        return false 
    end 
end 
  
  
  
 function test(source,mph) 
 speed = getElementSpeed 
 if speed > = 0 then  
 guiProgressBarSetProgress(progressBar,tonumber(guiProgressBarGetProgress(progressBar))+1) 
 end 
     
addEventHandler ( "onClientRender", root, test ) 
settimer (test,1000,100)     

this is what i used

Link to comment

I do not advise you to use progress Bar .. because the the upper limit 100 and Speed more than that

use Dx .. just try this > :

function getElementSpeed(element,unit) 
    if (unit == nil) then unit = 0 end 
    if (isElement(element)) then 
        local x,y,z = getElementVelocity(element) 
        if (unit=="mph" or unit==1 or unit =='1') then 
            return (x^2 + y^2 + z^2) ^ 0.5 * 100 
        else 
            return (x^2 + y^2 + z^2) ^ 0.5 * 1.8 * 100 
        end 
    else 
        outputDebugString("Not an element. Can't get speed") 
        return false 
    end 
end 
  
addEventHandler( "onClientRender", root, function(   ) 
  if ( guiGetVisible ( progressBar ) ~= true ) then return end 
      local vehicle = getPedOccupiedVehicle ( localPlayer ) 
         if ( vehicle ) then 
           if ( getElementSpeed( vehicle, "kph" ) =< 100 ) then 
                  guiProgressBarSetProgress( progressBar, getElementSpeed( vehicle, "kph" ) ) 
              end 
          end 
     end 
end ) 
Link to comment
I do not advise you to use progress Bar .. because the the upper limit 100 and Speed more than that

use Dx .. just try this > :

function getElementSpeed(element,unit) 
    if (unit == nil) then unit = 0 end 
    if (isElement(element)) then 
        local x,y,z = getElementVelocity(element) 
        if (unit=="mph" or unit==1 or unit =='1') then 
            return (x^2 + y^2 + z^2) ^ 0.5 * 100 
        else 
            return (x^2 + y^2 + z^2) ^ 0.5 * 1.8 * 100 
        end 
    else 
        outputDebugString("Not an element. Can't get speed") 
        return false 
    end 
end 
  
addEventHandler( "onClientRender", root, function(   ) 
  if ( guiGetVisible ( progressBar ) ~= true ) then return end 
      local vehicle = getPedOccupiedVehicle ( localPlayer ) 
         if ( vehicle ) then 
           if ( getElementSpeed( vehicle, "kph" ) =< 100 ) then 
                  guiProgressBarSetProgress( progressBar, getElementSpeed( vehicle, "kph" ) ) 
              end 
          end 
     end 
end ) 

i don't want to apply the speed on the screen the progress bar is for something else .

Link to comment

 function getElementSpeed(element,unit) 
        if (unit == nil) then unit = 0 end 
        if (isElement(element)) then 
            local x,y,z = getElementVelocity(element) 
            if (unit=="mph" or unit==1 or unit =='1') then 
                return (x^2 + y^2 + z^2) ^ 0.5 * 100 
            else 
                return (x^2 + y^2 + z^2) ^ 0.5 * 1.8 * 100 
            end 
        else 
            outputDebugString("Not an element. Can't get speed") 
            return false 
        end 
    end 
    addEventHandler( "onClientVehicleEnter", getRootElement(), getElementSpeed ) 
     
  
 function speed (client , seat , jacked) 
  if ( getElementModel ( veh ) == 531 ) then 
 speed = getElementSpeed (veh,"mph") 
 if speed > 0 then 
 guiProgressBarSetProgress(progressBar,tonumber(guiProgressBarGetProgress(progressBar))+1) 
 end 
 end 
 end 
  
  
  
     
    addEventHandler( "onClientVehicleEnter", getRootElement(), speed ) 

whats the problem ???

Link to comment

i really don't understand what you are trying to say but if you are trying say that you want a command that outputs current speed of a player in both mph and kph to that chat.

then try this

addCommandHandler("getmyspeed", 
function (player, cmd) 
  outputChatBox ("Your speed in mph: "..getElementSpeed(player, "mph"),player) 
  outputChatBox ("Your speed in kph: "..getElementSpeed(player, "kph"),player) 
end 
) 

Link to comment
i really don't understand what you are trying to say but if you are trying say that you want a command that outputs current speed of a player in both mph and kph to that chat.

then try this

addCommandHandler("getmyspeed", 
function (player, cmd) 
  outputChatBox ("Your speed in mph: "..getElementSpeed(player, "mph"),player) 
  outputChatBox ("Your speed in kph: "..getElementSpeed(player, "kph"),player) 
end 
) 

i want to know the speed to say that if the speed is > 0 then add 1 to the progress bar

Link to comment

this is not progress, it's dx text

  
function getElementSpeed(element, unit) 
    if (unit == nil) then unit = 0 end 
    if (isElement(element)) then 
        local x,y,z = getElementVelocity(element) 
        if (unit=="mph" or unit==1 or unit =='1') then 
            return (x^2 + y^2 + z^2) ^ 0.5 * 100 
        else 
            return (x^2 + y^2 + z^2) ^ 0.5 * 1.61 * 100 
        end 
    else 
        return false 
    end 
end 
 function Stats ( )  
  local car = getPedOccupiedVehicle ( localPlayer ) 
if ( car ) then 
  
  
    local newS = getElementSpeed(car, "mph") 
        local speed= getElementSpeed(car, "kph") 
    local newS = math.ceil(newS) 
        local speed = math.ceil(speed) 
dxDrawText("KPH : "..speed.." / MPH : "..newS, (sizeX-229), (sizeY-70), 1041, 808, tocolor(0, 0, 0, 255), 0.40, "bankgothic", "left", "top", true, true, true, true, false) 
        dxDrawText("KPH : "..speed.." / MPH : "..newS, (sizeX-229), (sizeY-70), 1041, 806, tocolor(0, 0, 0, 255), 0.40, "bankgothic", "left", "top", true, true, true, true, false) 
        dxDrawText("KPH : "..speed.." / MPH : "..newS, (sizeX-229), (sizeY-70), 1039, 808, tocolor(0, 0, 0, 255), 0.40, "bankgothic", "left", "top", true, true, true, true, false) 
        dxDrawText("KPH : "..speed.." / MPH : "..newS, (sizeX-229), (sizeY-70), 1039, 806, tocolor(0, 0, 0, 255), 0.40, "bankgothic", "left", "top", true, true, true, true, false) 
        dxDrawText("KPH : "..speed.." / MPH : "..newS, (sizeX-229), (sizeY-70), 1040, 807, tocolor(255, 255, 255, 255), 0.40, "bankgothic", "left", "top", true, true, true, true, false) 
        end 
        end 

Link to comment
  
local SquareRoot = math.sqrt; 
local GetSpeed = function(element) 
    local Velocity = {getElementVelocity(element)}; 
    return SquareRoot(Velocity[1]^2+Velocity[2]^2+Velocity[3]^2)*100; 
end; 
  
local ScreenSizeX,ScreenSizeY = guiGetScreenSize(); 
local Vehicles = {}; 
local ProgressBar = guiCreateProgressBar((ScreenSizeX-300)/2,(ScreenSizeY-20)/2,300,20,false); 
addEventHandler("onClientPlayerVehicleEnter",root,function(vehicle) 
    if getElementModel(vehicle) == 531 then 
        Vehicles[vehicle] = function() 
            if GetSpeed(vehicle)>0 then 
                local Progress = guiProgressBarGetProgress(ProgressBar); 
                guiProgressBarSetProgress(ProgressBar,Progress+1); 
                if Progress>=100 then 
                    removeEventHandler("onClientRender",root,Vehicles[vehicle]); 
                end; 
            end; 
        end; 
        addEventHandler("onClientRender",root,Vehicles[vehicle]); 
    end; 
end); 
addEventHandler("onClientPlayerVehicleExit",root,function(vehicle) 
    if Vehicles[vehicle] then 
        removeEventHandler("onClientRender",root,Vehicles[vehicle]); 
    end; 
end); 
  

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...