TheMaysTRo Posted June 16, 2014 Posted June 16, 2014 hello . i can't find a soultion or anything on the wiki or google . i want to ask how to get the vitesse of a specific vehicle ? i already tried getElementSpeed. thanks.
TheMaysTRo Posted June 16, 2014 Author Posted June 16, 2014 getElementVelocity If you meant that... not working also . i tried it
Et-win Posted June 16, 2014 Posted June 16, 2014 What do you mean then? I (And maybe others) don't understand it out of your first post.
TheMaysTRo Posted June 16, 2014 Author Posted June 16, 2014 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 ....)
Et-win Posted June 16, 2014 Posted June 16, 2014 Well, if you want to get it in mph or kmph then you just can use getElementSpeed... Otherwise, I don't know.
manawydan Posted June 16, 2014 Posted June 16, 2014 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)
#DRAGON!FIRE Posted June 16, 2014 Posted June 16, 2014 Simply .. use this function: https://wiki.multitheftauto.com/wiki/GetElementSpeed
TheMaysTRo Posted June 16, 2014 Author Posted June 16, 2014 Simply .. use this function: https://wiki.multitheftauto.com/wiki/GetElementSpeed i tried function getElementSpeed(source,mph) speed = getElementSpeed if speed > = 0 then guiProgressBarSetProgress(progressBar,tonumber(guiProgressBarGetProgress(progressBar))+1) end not working
_DrXenon Posted June 16, 2014 Posted June 16, 2014 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.
TheMaysTRo Posted June 16, 2014 Author Posted June 16, 2014 getElementSpeed is a useful function, so you can't just use it with out copying the source code to your file firstCopy 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
#DRAGON!FIRE Posted June 16, 2014 Posted June 16, 2014 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 )
TheMaysTRo Posted June 16, 2014 Author Posted June 16, 2014 I do not advise you to use progress Bar .. because the the upper limit 100 and Speed more than thatuse 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 .
_DrXenon Posted June 17, 2014 Posted June 17, 2014 what exactly do you want to do? tell us so we can understand each other D:
TheMaysTRo Posted June 17, 2014 Author Posted June 17, 2014 what exactly do you want to do?tell us so we can understand each other D: i want to get the vehicle speed so when its move i will make the progress bar of my job add 1% and i set on it timer
Snow-Man Posted June 17, 2014 Posted June 17, 2014 use setTimer and to cancel setTimer use isTimer killTimer
TheMaysTRo Posted June 18, 2014 Author Posted June 18, 2014 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 ???
Mr.unpredictable. Posted June 18, 2014 Posted June 18, 2014 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 )
Hazard| Posted June 18, 2014 Posted June 18, 2014 Atleast you have to getElementSpeed, then dxDrawText to draw the speed on the screen, not sure what you mean (rest of it)
TheMaysTRo Posted June 18, 2014 Author Posted June 18, 2014 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
Snow-Man Posted June 18, 2014 Posted June 18, 2014 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
TheMaysTRo Posted June 18, 2014 Author Posted June 18, 2014 i want to know the speed to say that if the speed is > 0 then add 1 to the progress bar any one can help me please ?
Mr.unpredictable. Posted June 19, 2014 Posted June 19, 2014 i want to know the speed to say that if the speed is > 0 then add 1 to the progress barany one can help me please ? can you explain clearly what you are trying to say?
cheez3d Posted June 19, 2014 Posted June 19, 2014 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);
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now