proracer Posted January 10, 2011 Share Posted January 10, 2011 So I was trying to make script which does, when you reach example 100 km/h it outputs some message. But I don't know how to create that part, when some player reaches some speed. I tried and this code, but ofcourse its not good. function getVehicleSpeed() speedx, speedy, speedz = getElementVelocity (getPedOccupiedVehicle(getLocalPlayer()) actualspeed = (speedx^2 + speedy^2 + speedz^2)^(0.5) if (actualspeed) = 100 then -- i know this isn't good, if you know please tell me. outputChatBox ("Nice speed man.") addEventHandler("onResourceStart", getResourceRootElement(getThisResource)) Link to comment
SDK Posted January 10, 2011 Share Posted January 10, 2011 One possibility would be to check the speed every second: function checkSpeed() speedx, speedy, speedz = getElementVelocity (getPedOccupiedVehicle(getLocalPlayer()) actualspeed = (speedx^2 + speedy^2 + speedz^2)^(0.5) if (actualspeed) >= 100 then outputChatBox ("Nice speed man.") killTimer ( timer1 ) end end timer1 = setTimer(checkSpeed, 1000, 0) Link to comment
proracer Posted January 10, 2011 Author Share Posted January 10, 2011 I tested but it doesn't work. Link to comment
SDK Posted January 10, 2011 Share Posted January 10, 2011 How does it not work? Say what you did, how you tested it, how you put it in your scripts, what errors appeared in debugscript, etc. Link to comment
AcidbRain Posted January 10, 2011 Share Posted January 10, 2011 The actualspeed variable must still be multiplied by a factor greater than 1 in order to yield a useful value. However there's no conclusive argument on what exactly is the unit of the getElementVelocity value. On scripts available at the community site, I've seen people multiply it by 100, 160 or even by 200. Link to comment
BinSlayer1 Posted January 10, 2011 Share Posted January 10, 2011 One possibility would be to check the speed every second: function checkSpeed() speedx, speedy, speedz = getElementVelocity (getPedOccupiedVehicle(getLocalPlayer()) actualspeed = (speedx^2 + speedy^2 + speedz^2)^(0.5) * 100 * 1.61 if (actualspeed) >= 100 then outputChatBox ("Nice speed man.") killTimer ( timer1 ) end end timer1 = setTimer(checkSpeed, 1000, 0) Use this one ^ Link to comment
DiSaMe Posted January 11, 2011 Share Posted January 11, 2011 However there's no conclusive argument on what exactly is the unit of the getElementVelocity value. On scripts available at the community site, I've seen people multiply it by 100, 160 or even by 200. There is. It's number of GTA units per 1/50 seconds. I'm not sure about GTA units, maybe they're metres, so element velocity x50 is m/s, x180 is km/h. Link to comment
AcidbRain Posted January 12, 2011 Share Posted January 12, 2011 There is. It's number of GTA units per 1/50 seconds. I'm not sure about GTA units, maybe they're metres, so element velocity x50 is m/s, x180 is km/h. Thank you. GTA's distance unit is indeed equal to one meter (http://gta.wikia.com/Unit#GTA3.2C_GTAVC_.26_GTASA), I was just not aware of the 1/50 quirk. 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