DakiLLa Posted November 23, 2008 Share Posted November 23, 2008 hi. I want to make not too much difficult code for drift. I tryed to make it with marker, for begin. And i have two questions: how to calculate numbers of "getVehicleTurnVelocity" like 400 not 0.00456789...e" ? example from wiki gives only decimal value.. And how to sum all picked up values from turnVelocity when player is in marker? This code gives me result when player only hits marker. function onMarkerHit ( thePlayer, matchingDimension ) if source == marker then local vehicle = getPlayerOccupiedVehicle ( thePlayer ) if ( not vehicle ) then outputChatBox ( "You need to be in a vehicle to activate this marker!", thePlayer, 255, 0, 0 ) else local x, y, z = getVehicleTurnVelocity ( vehicle ) actualturn = ( x^2 + y^2 + z^2)^(0.5) outputChatBox ( "Your current turn velocity: " .. actualturn .. " points.", thePlayer, 0, 255, 0 ) end end end addEventHandler ( "onMarkerHit", marker, onMarkerHit ) Link to comment
DefiniteIntegral Posted November 24, 2008 Share Posted November 24, 2008 I am not certain, but I think turn velocity is measured in radians per second. Can someone confirm this? Drift is about a bit more than turn velocity. You should take rotation, velocity and speed into account also. Trigonometry, vectors and dot products are your friend. Getting a really accurate measurement of drift in MTA might be difficult though, since I don't think there is a way to get the coordinates of the center of the front and back axles. So yeah a good drift measurement is difficult if you don't know some math. If you want an simple one you should be able to do that pretty easily. Just set some parameters for min and max speed and turn velocity, and come up with an arbitrary score. eg minspeed = 0.1 maxspeed = 1.5 minturnspeed = math.rad(1) maxturnspeed = math.rad(45) maxscore = 10.0 -- Score when drifting at maximum speed and turn velocity function someFunction(vehicle) local vx, vy, vz = getElementVelocity(vehicle) local rx, ry, rz = getVehicleRotation(vehicle) local rvx, rvy, rvz = getVehicleTurnVelocity(vehicle) local speed = math.sqrt(vx*vx + vy*vy + vz*vz) local score = 0 local onGround = isVehicleOnGround(vehicle) -- this wont work for monster truck local upright =((rx >= 0 and rx <= 90) or (rx >= 270 and rx <= 360)) and ((ry >= 0 and ry <= 90) or (ry >= 270 and ry <= 360)) -- Don't score upside down vehicle -- only score if on ground and upright if onGround == true and upright == true then -- only score if above minimum speed and turn speed limits -- Only take vehicles Z rotation into account since it is vehicle relative if speed >= minspeed and rvz >= minturnspeed then -- cap speeds at maximum. This allows scoring above max speed, capped at max rate. if speed > maxspeed then speed = maxspeed end if turnspeed > maxturnspeed then turnspeed = maxturnspeed end -- add score local speedRatio = (speed - minspeed) / (maxspeed - minspeed) -- Get speed and turn speed ratio local turnSpeedRatio = (rvz - minturnspeed) / (maxturnspeed - minturnspeed) local scoreScalar = speedRatio * turnSpeedRatio -- Multiply ratios to find combined ratio. score = maxscore * scoreScalar -- Scale max score by combined speed ratio end end return score end .. or something like that. I just came up with that off the top of my head, there are probably mistakes. As for your marker issue... you could use the server events onMarkerHit and onMarkerLeave to start/stop a timer to accumulate score. Or, you could just have an infinitely repeating timer so drifting can be scored constantly. Link to comment
DakiLLa Posted December 17, 2008 Author Share Posted December 17, 2008 hm, if i will use onClientRender for this, but i think it will not get a result there is some server functions. I dont know what i need to use, onMarkerHit and Leave - wrong ways to activate this script i think..somebody help i really need this script working nice! 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