MasterTobi Posted February 2, 2010 Share Posted February 2, 2010 hey i have a question about this tread https://forum.multitheftauto.com/viewtopic.php?f=91&t=24819&p=292845&hilit=cruise+control#p292845 cokacola write if(theCar) then local x, y, z = getElementVelocity(theCar) .sqrt(x^2 + y^2 + z^2) * 161 local speed = math local.sqrt(x^2 + y^2 + z^ speed =2) * 161 math.sqrt(x^2 + y^2 + z^2) * 161 but my console say that .sqrt(x^2 + y^2 + z^2) * 161 <<< it´s wrong exceptet near "." and local.sqrt(x^2 + y^2 + z^ speed =2) * 161 math.sqrt(x^2 + y^2 + z^2) * 161 << i think it´s wrong can everybody help me thx Link to comment
50p Posted February 2, 2010 Share Posted February 2, 2010 sqrt function is part of math library. This means you need to use math.sqrt. Link to comment
MasterTobi Posted February 2, 2010 Author Share Posted February 2, 2010 yes i know but i understand the code .sqrt(x^2 + y^2 + z^2) * 161 << cokacola says that the code goes local speed = math local.sqrt(x^2 + y^2 + z^ speed =2) * 161 <<< speed=2 is not going math.sqrt(x^2 + y^2 + z^2) * 161 and this musst be math.sqrt((x^2 + y^2 + z^2) * 161) or not ? Link to comment
MasterTobi Posted February 2, 2010 Author Share Posted February 2, 2010 so i have edit the code and it goes --some form of cruise control theCruiseTimer = "noone-nothing" function cruiseOff(thePlayer) --its on, so turn it off killTimer(theCruiseTimer) theCruiseTimer = "noone-nothing" setControlState ( thePlayer, "accelerate", false ) setControlState ( thePlayer, "brake_reverse", false ) end function cruiseOn(thePlayer, speed, theCar) theCar1 = getPedOccupiedVehicle(thePlayer) if(theCar1) then local x1, y1, z1 = getElementVelocity(theCar) local speed1 =((x1^2 + y1^2 + z1^2)^0.5) * 161 if(speed1 < speed) then setControlState ( thePlayer, "brake_reverse", false ) setControlState ( thePlayer, "accelerate", true ) elseif(speed1 > speed) then setControlState ( thePlayer, "accelerate", false ) -- setControlState ( thePlayer, "brake_reverse", true ) end else cruiseOff(thePlayer) end end function cruiseControl(thePlayer) local theCar = getPedOccupiedVehicle(thePlayer) if(theCruiseTimer == "noone-nothing") then if(theCar) then local x, y, z = getElementVelocity(theCar) local speed =((x^2 + y^2 + z^ 2)^0.5) * 161 --its off, so turn it on theCruiseTimer = setTimer(cruiseOn, 50, 0, thePlayer, speed, theCar) else outputChatBox("Error: players don't have cruise control switches. Must be in car.", thePlayer) end else cruiseOff(thePlayer) end end addCommandHandler("ct", cruiseControl) Link to comment
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