SoManyTears Posted January 21, 2020 Share Posted January 21, 2020 How can I turn a texture ON and OFF with just one command?Texture needs to be active when they enter the server.This is what confuses me. addEventHandler('onClientResourceStart', resourceRoot, function() shader = dxCreateShader('shader.fx') terrain = dxCreateTexture('img/road.jpg') dxSetShaderValue(shader, 'gTexture', terrain) engineApplyShaderToWorldTexture(shader, 'cj_rubbish1') engineApplyShaderToWorldTexture(shader, 'sf_junction2') engineApplyShaderToWorldTexture(shader, ':Oroad01_law') engineApplyShaderToWorldTexture(shader, 'des_1line256') engineApplyShaderToWorldTexture(shader, 'concretebig4256128') end ) Link to comment
Addlibs Posted January 21, 2020 Share Posted January 21, 2020 (edited) -- make these accessible throughout this file local shader = nil local terrain = nil local active = false function toggleShader(state) if state == active then return false -- don't do anything if it's already in the desired state end if state then engineApplyShaderToWorldTexture(shader, 'cj_rubbish1') engineApplyShaderToWorldTexture(shader, 'sf_junction2') engineApplyShaderToWorldTexture(shader, ':Oroad01_law') engineApplyShaderToWorldTexture(shader, 'des_1line256') engineApplyShaderToWorldTexture(shader, 'concretebig4256128') active = true else engineRemoveShaderFromWorldTexture(shader, 'cj_rubbish1') engineRemoveShaderFromWorldTexture(shader, 'sf_junction2') engineRemoveShaderFromWorldTexture(shader, ':Oroad01_law') engineRemoveShaderFromWorldTexture(shader, 'des_1line256') engineRemoveShaderFromWorldTexture(shader, 'concretebig4256128') active = false end return true end addEventHandler('onClientResourceStart', resourceRoot, function() shader = dxCreateShader('shader.fx') terrain = dxCreateTexture('img/road.jpg') dxSetShaderValue(shader, 'gTexture', terrain) toggleShader(true) -- toggle on at start end ) addCommandHandler("shadertogglecmd", function() toggleShader(not active) -- invert toggle on command end ) Edited January 21, 2020 by MrTasty Link to comment
SoManyTears Posted January 21, 2020 Author Share Posted January 21, 2020 thank you mr.Tasty 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