Jump to content

[Help] SetElementVelocity (onClientRender)


2kristof2

Recommended Posts

Posted (edited)

Hi,

Here is my script:

NumToCount = 0.05 
CountSpeed = 100 
local b = 0.001 
  
marker = createMarker(5497.0727539063, -2612.5356445313, 7.6, "corona",6, 0, 0, 0, 0) 
function flying (player) 
   if source == marker then 
      if isPedInVehicle(player) then 
       vehicle=getPedOccupiedVehicle(player) 
       x,y,z = getElementVelocity(vehicle) 
       addEventHandler ( "onClientRender", getRootElement(), MyB) 
       setTimer (function() removeEventHandler ( "onClientRender", getRootElement(), MyB) end, 1100 , 1 ) 
      end 
   end 
end 
addEventHandler("onClientMarkerHit", getRootElement(), flying) 
  
function MyB ( ) 
setTimer (function() b = b + 0.0015 end, CountSpeed , NumToCount ) 
setElementVelocity(vehicle, x,y,b)  
end 
  

My question is how to change local b to the primary value (0.001), because when I hit the marker and hit it again after X seconds I'll get different velocity..

Thanks for help :)

regards,

2kristof2

Edited by Guest
Posted
  
CountSpeed = 100 
local b = 0.001 
local tick 
  
marker = createMarker(5497.0727539063, -2612.5356445313, 7.6, "corona",6, 0, 0, 0, 0) 
function flying (player) 
   if source == marker then 
      if isPedInVehicle(player) then 
       vehicle=getPedOccupiedVehicle(player) 
       b = 0.001 
       tick = getTickCount() 
       x,y,z = getElementVelocity(vehicle) 
       addEventHandler ( "onClientRender", getRootElement(), MyB) 
       setTimer (function() removeEventHandler ( "onClientRender", getRootElement(), MyB) end, 1100 , 1 ) 
      end 
   end 
end 
addEventHandler("onClientMarkerHit", getRootElement(), flying) 
  
function MyB ( ) 
if (getTickCount() - tick) >= CountSpeed then 
       b = b + 0.0015 
       tick = getTickCount() 
end 
setElementVelocity(vehicle, x,y,b)  
end 
  

Posted

Not entirely sure what the problem is, but could it be due to the fact that the timer repeats infinitely? NumToCount is set to 0.05 and I'm pretty sure the timer only accepts an integer, so it'll interpret it as 0 which means infinite looping.

Posted

Be careful because it creates a timer every render, that's a crazy idea if we think about the eficient.

Posted

Yeah i know but the function lasts only 1,4 sec so there is no lags and everything works correctly. Anyway if you have better idea you can write it here :P. (because your script doesn't work for me :/)

Posted

I'm back, try this:

  
local CountSpeed = 100 
local b = 0.001 
local tick 
  
local marker = createMarker(5497.0727539063, -2612.5356445313, 7.6, "corona",6, 0, 0, 0, 0) 
  
function flying (player) 
   if source == marker then 
      if isPedInVehicle(player) then 
           vehicle=getPedOccupiedVehicle(player) 
           b = 0.001 
           tick = getTickCount() 
           x,y,z = getElementVelocity(vehicle) 
           addEventHandler ( "onClientRender", getRootElement(), MyB) 
           setTimer (function() removeEventHandler ( "onClientRender", getRootElement(), MyB) end, 1100 , 1 ) 
      end 
   end 
end 
addEventHandler("onClientMarkerHit", getRootElement(), flying) 
  
function MyB ( ) 
    if (getTickCount() - tick) >= CountSpeed then 
       b = b + 0.024 
       tick = getTickCount() 
    end 
    setElementVelocity(vehicle, x,y,b) 
end 

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...