Jump to content

Quick Lua Question


OffRoader23

Recommended Posts

I'm trying to run a check if speed is higher then 30 MPH and under 250 MPH, how would I do that?

I know it would be like

  
function blah ( ) 
      local shpeed = getPlayerSpeed ( player, 1) 
      if shpeed >= 30 and shpeed <= 250 then 
          do crap 
      else 
          dont do crap 
      end 
end 
  

What would I replaced and with? &? ||? or?

Link to comment

as there's no getPlayerSpeed function i think you should do it like this =) (at least the wiki says this is the way to calculate the speed)

  
function blah () 
     local speedx, speedy, speedz = getElementVelocity ( player ) 
     local speed = (speedx^2 + speedy^2 + speedz^2)^(0.5) 
     if speed >= 30 and speed <= 250 then 
          do crap 
     else 
          don't do crap 
     end 
end  
  

Link to comment

But I tried and it it's like OMFG SYNTAX....

Maybe I did something wrong, I'll try it again and post results, thanks.

And yea, I know, my script has getPlayerSpeed function released by that guy a while back, I have code that works already but am trying to get a range from 30-250 for a speed boost script when you hold accelerate.

Link to comment

Nevermind, I'm dumb, I don't know what I did wrong before but it works fine now. I think I did if speed => 30 and <= 250.

What is the key called for reverse/brakes when your in the car?

if ( getControlState ( v, "accelerate") ) then

works for accelerate

if ( getControlState ( v, "brakes") ) then

doesn't.

Thanks for the help btw.

Link to comment

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...