Virus xD Posted August 14, 2010 Posted August 14, 2010 Soz for my bad english i have problem whit my script (distancemeter) wher is problem? function startdistance (thePlayer, seat, jacked) distancemeter ( thePlayer ) end addEventHandler ("onVehicleEnter", getRootElement(), startdistance ) function distancemeter ( thePlayer ) meterX = getElementData ( thePlayer, "X" ) meterY = getElementData ( thePlayer, "Y" ) local meterX2, meterY2, meterZ2 = getElementPosition (thePlayer) Distancedrived = getDistanceBetweenPoints2D ( meterX, meterY, meterX2, meterY2 ) if ( Distancedrived ) then checkdistanced = getElementData ( thePlayer, "distance" ) if ( distance ) then setElementData ( thePlayer, "distance", Distancedrived ) local X, Y, Z = getElementPosition (thePlayer) setElementData ( thePlayer, "X", X ) setElementData ( thePlayer, Y", Y ) setTimer ( distancemeter, 1000, 1, thePlayer ) else local X, Y, Z = getElementPosition (thePlayer) setElementData ( thePlayer, "X", X ) setElementData ( thePlayer, "Y", Y ) local newdistance = checkdistanced+Distancedrived newdistance2 = newdistance setElementData ( thePlayer, "distance", newdistance2 ) setTimer ( distancemeter, 1000, 1, thePlayer ) end end end function vehExit ( thePlayer, seat, jacked ) exitdistance = getElementData ( thePlayer, "distance" ) outputChatBox("You drive: " .. exitdistance .. " meters.", thePlayer) setElementData ( thePlayer, "distance", false ) end addEventHandler ( "onVehicleExit", getRootElement(), vehExit ) ~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~ how to cut out all the figures after the decimal point Sorry for my bad English
dzek (varez) Posted August 14, 2010 Posted August 14, 2010 lua highlighter on forums are showing your error (notice that half of script is red) for rounding values: function round2(num, idp) return tonumber(string.format("%." .. (idp or 0) .. "f", num)) end -- usage: outputChatBox("PI: "..round2(22/7, 2)) -- will output PI: 3.14 Multi theft auto tools - replace cars and peds, move your map or compile your Lua files online! programista php rzeszów Need free webhosting for your small site? PM me. Need help with portforwarding? PM me. Do not PM me asking for help with scripting. Having problems with port forwarding? Send me pm, I can do whole thing for you using TeamViewer (already helped about 20 people, no worries)!
Virus xD Posted August 15, 2010 Author Posted August 15, 2010 ty varez +respekt lock free Sorry for my bad English
Recommended Posts