Derpy Posted October 25, 2014 Share 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)? Link to comment
Moderators IIYAMA Posted October 25, 2014 Moderators Share 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. Link to comment
Derpy Posted October 25, 2014 Author Share 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? Link to comment
Moderators IIYAMA Posted October 25, 2014 Moderators Share 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. Link to comment
MTA Team botder Posted October 25, 2014 MTA Team Share Posted October 25, 2014 Don't base your calculations on the FPS rate! Link to comment
Moderators IIYAMA Posted October 25, 2014 Moderators Share Posted October 25, 2014 If you base it on time, you won't have smooth animated alpha. Link to comment
Et-win Posted October 25, 2014 Share 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 Link to comment
MTA Team botder Posted October 25, 2014 MTA Team Share Posted October 25, 2014 He is using absolute values: The effect will differ for each amount of fps Link to comment
Moderators IIYAMA Posted October 25, 2014 Moderators Share Posted October 25, 2014 It is an effect, not something critical. Link to comment
Et-win Posted October 25, 2014 Share 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 Link to comment
WASSIm. Posted October 26, 2014 Share 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) Link to comment
ixjf Posted October 26, 2014 Share Posted October 26, 2014 Use interpolateBetween with onClientRender or use the dt parameter from the onClientPreRender to calculate the step. 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