SoManyTears

enable /disable texture with same command

Recommended Posts

 

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
)

 

Share this post


Link to post
-- 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 by MrTasty

Share this post


Link to post

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.