Derpy Posted October 25, 2014 Posted October 25, 2014 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 IIYAMA Posted October 25, 2014 Moderators Posted October 25, 2014 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 Spoiler checkPassiveTimer getScreenStartPositionFromBox getPedGender Tutorials 4x Spoiler Scaling DX Events Attach an addEventHandler on a group of elements Debugging
Derpy Posted October 25, 2014 Author Posted October 25, 2014 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 IIYAMA Posted October 25, 2014 Moderators Posted October 25, 2014 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 Spoiler checkPassiveTimer getScreenStartPositionFromBox getPedGender Tutorials 4x Spoiler Scaling DX Events Attach an addEventHandler on a group of elements Debugging
MTA Team botder Posted October 25, 2014 MTA Team Posted October 25, 2014 Don't base your calculations on the FPS rate! GitHub: Debug Console • MTA-Discord Relay Scripting: How to draw a line chart with DirectX functions? • Doppler Effect in MTA • Get the client's FPS • Customizable Blur Shader
Moderators IIYAMA Posted October 25, 2014 Moderators Posted October 25, 2014 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 Spoiler checkPassiveTimer getScreenStartPositionFromBox getPedGender Tutorials 4x Spoiler Scaling DX Events Attach an addEventHandler on a group of elements Debugging
Et-win Posted October 25, 2014 Posted October 25, 2014 @Necktrox: This depends on how you calculate it. You should use getTickCount() too to make it the same speed in every FPS ~Scripts~ Clan War System V1.2.0 ~Maps~ [DM]Et-win - The Run [FUN]Et-win - Drift Rocket [FUN]Et-win - Drift Rocket // [DD]Et-win - Cross 3xC
MTA Team botder Posted October 25, 2014 MTA Team Posted October 25, 2014 He is using absolute values: The effect will differ for each amount of fps GitHub: Debug Console • MTA-Discord Relay Scripting: How to draw a line chart with DirectX functions? • Doppler Effect in MTA • Get the client's FPS • Customizable Blur Shader
Moderators IIYAMA Posted October 25, 2014 Moderators Posted October 25, 2014 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 Spoiler checkPassiveTimer getScreenStartPositionFromBox getPedGender Tutorials 4x Spoiler Scaling DX Events Attach an addEventHandler on a group of elements Debugging
Et-win Posted October 25, 2014 Posted October 25, 2014 He is using absolute values: The effect will differ for each amount of fps I know: You should use getTickCount() too to make it the same speed in every FPS ~Scripts~ Clan War System V1.2.0 ~Maps~ [DM]Et-win - The Run [FUN]Et-win - Drift Rocket [FUN]Et-win - Drift Rocket // [DD]Et-win - Cross 3xC
WASSIm. Posted October 26, 2014 Posted October 26, 2014 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)
ixjf Posted October 26, 2014 Posted October 26, 2014 Use interpolateBetween with onClientRender or use the dt parameter from the onClientPreRender to calculate the step. I used to know how to code, but then I took an arrow in the knee. Project Redivivus - Remaking Old School MTA With New Code MTA 0.6 Nightly 1 released
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