Jump to content

smooth variable changing?


Derpy

Recommended Posts

Posted

hi there!

i wanted to ask, how could i smoothly change a value of variable(e.g from 0-255 and then when it's at 255 it goes back to 0,and keeps doing that in an infinite loop)?

  • Moderators
Posted

By using your frames per second? FPS

https://wiki.multitheftauto.com/wiki/OnClientRender

It can't be smoother then that, you won't see the differences if you do it faster.

Do you want to improve your Lua programming skills and make less mistakes?   Start with Lua Language Server!   🙀

 

  Useful functions  3x 

  Tutorials  4x 

 

Posted
  
variable = 0 
function changeVariables() 
local vAlpha = getElementAlpha(getPedOccupiedVehicle(localPlayer))) 
if variable >= 0 and < 255 then 
variable = variable + 0.1 
 setElementAlpha(getPedOccupiedVehicle(localPlayer), variable)  
elseif variable == 255 then 
variable = variable - 0.1 
setElementAlpha(getPedOccupiedVehicle(localPlayer), variable)  
end 
end 

yea i tried 1020139332 ways of making this crap and i never figured it out

can you help?

  • Moderators
Posted

try this: (not tested)

local variable = 0 
local stateOfAlphaChanging = false 
function changeVariables() 
    local vehicle = getPedOccupiedVehicle(localPlayer) 
    if vehicle then 
        dxDrawText(200,300,tostring(getElementAlpha(vehicle))) -- debug 
  
        if stateOfAlphaChanging then  
            variable = variable + 0.1 
        else 
            variable = variable - 0.1 
        end 
  
        if variable < 0 then 
            stateOfAlphaChanging = true 
            variable = 0--reset 
        elseif variable > 255 then 
            stateOfAlphaChanging = false 
            variable = 255--reset 
        end 
        setElementAlpha(vehicle, variable) 
    end 
end 
  
addEventHandler("onClientRender",root,changeVariables) 

1 extra variable is managing the state of the alpha change.

Do you want to improve your Lua programming skills and make less mistakes?   Start with Lua Language Server!   🙀

 

  Useful functions  3x 

  Tutorials  4x 

 

  • Moderators
Posted

If you base it on time, you won't have smooth animated alpha.

Do you want to improve your Lua programming skills and make less mistakes?   Start with Lua Language Server!   🙀

 

  Useful functions  3x 

  Tutorials  4x 

 

  • Moderators
Posted

It is an effect, not something critical.

Do you want to improve your Lua programming skills and make less mistakes?   Start with Lua Language Server!   🙀

 

  Useful functions  3x 

  Tutorials  4x 

 

Posted

try this

function changeVariables() 
    local vehicle = getPedOccupiedVehicle(localPlayer) 
    if vehicle then 
        local alpha = getElementAlpha(vehicle) 
        alpha = alpha*math.abs(getTickCount()%1000-500)/500 
        setElementAlpha(vehicle, alpha) 
    end 
end 
addEventHandler("onClientRender",root,changeVariables) 

Omerta Roleplay

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