Jump to content

[Help] Disable and Enable txd


Recommended Posts

So I created some vgncarshade1 (road) textures and landjump (ramp)

The thing is, I want to put a option ''When the player press a button, lets say ''F3'' and then, the Texture should be disabled

I tried with

bindKey( 'F3', 'down', 
    function( ) 
        state = not state 
        if state then 
            destroyElement( txd ) 
            outputChatBox( '#ffcc00[MSG]: #c0c0c0Road texture disabled!', 255,255,255,true ) 
        else 
            txd = engineLoadTXD( 'vgncarshade1.txd', 3458 ) 
            engineImportTXD( txd, 3458 ) 
            outputChatBox( '#ffcc00[MSG]: #c0c0c0Road texture enabled!', 255,255,255,true ) 
        end 
    end 
)   

It's not disabling the txd, only restarting it. ;c

Link to comment

Try this:

local state = false 
bindKey( 'F3', 'down', 
    function( ) 
        state = not state 
        local value = _G[ "engine" .. (state and "RestoreModel" or "LoadTXD") ]( (state and 3458 or 'vgncarshade1.txd'), not state and 3458 ) 
        if isElement(value) then engineImportTXD( value, 3458 ) end 
        outputChatBox( '#ffcc00[MSG]: #c0c0c0Road texture '.. (state and "disabled" or "enabled")..'!', 255,255,255,true ) 
    end 
) 

Link to comment
Try this:
local state = false 
bindKey( 'F3', 'down', 
    function( ) 
        state = not state 
        local value = _G[ "engine" .. (state and "RestoreModel" or "LoadTXD") ]( (state and 3458 or 'vgncarshade1.txd'), not state and 3458 ) 
        if isElement(value) then engineImportTXD( value, 3458 ) end 
        outputChatBox( '#ffcc00[MSG]: #c0c0c0Road texture '.. (state and "disabled" or "enabled")..'!', 255,255,255,true ) 
    end 
) 

Well It's not working As it should, It disables and enables the roads when I turn 2 roads on and disable one, But after I reconnect it's only restarting the roads. It types '''road texture disabled and ''road ''texture enabled'' but It's not working :cc*

Link to comment

Replace destroyElement() with engineRestoreModel()

local state = false 
  
bindKey( 'F3', 'down', 
    function( ) 
        if state then 
            engineRestoreModel (3458) 
            outputChatBox( '#ffcc00[MSG]: #c0c0c0Road texture disabled!', 255,255,255,true ) 
            state = false 
        else 
            txd = engineLoadTXD( 'vgncarshade1.txd', 3458 ) 
            engineImportTXD( txd, 3458 ) 
            state = true 
            outputChatBox( '#ffcc00[MSG]: #c0c0c0Road texture enabled!', 255,255,255,true ) 
        end 
    end 
)   
  
  

Link to comment

It's still not removing. Sry, I'm noob scripter but Is that lua file correct?

function replace () 
txd = engineLoadTXD ("vgncarshade1.txd") 
engineImportTXD( txd , 3458) 
  
dff = engineLoadDFF ("vgncarshade1.dff", 0 ) 
engineReplaceModel( dff ,3458) 
  
end 
addEventHandler("onClientResourceStart",getRootElement(), replace) 
  
local state = false 
  
bindKey( 'F3', 'down', 
    function( ) 
        if state then 
            engineRestoreModel (3458) 
            outputChatBox( '#ffcc00[MSG]: #c0c0c0Road texture disabled!', 255,255,255,true ) 
            state = false 
        else 
            txd = engineLoadTXD( 'vgncarshade1.txd', 3458 ) 
            engineImportTXD( txd, 3458 ) 
            state = true 
            outputChatBox( '#ffcc00[MSG]: #c0c0c0Road texture enabled!', 255,255,255,true ) 
        end 
    end 
)   
  

I got only this, and the meta.xml

Link to comment

try this:

local state = true     
bindKey( 'F3', 'down', 
    function( ) 
        if state then 
            engineRestoreModel (3458); 
            outputChatBox( '#ffcc00[MSG]: #c0c0c0Road texture disabled!', 255,255,255,true ); 
            state = false; 
        else 
            dff = engineLoadDFF("vgncarshade1.dff", 3458); -- dff file. 
            engineReplaceModel(dff, 3458); 
            txd = engineLoadTXD( 'vgncarshade1.txd', 3458 ); 
            engineImportTXD( txd, 3458 ); 
            state = true; 
            outputChatBox( '#ffcc00[MSG]: #c0c0c0Road texture enabled!', 255,255,255,true ); 
        end 
    end 
)   

Link to comment
try this:
local state = true     
bindKey( 'F3', 'down', 
    function( ) 
        if state then 
            engineRestoreModel (3458); 
            outputChatBox( '#ffcc00[MSG]: #c0c0c0Road texture disabled!', 255,255,255,true ); 
            state = false; 
        else 
            dff = engineLoadDFF("vgncarshade1.dff", 3458); -- dff file. 
            engineReplaceModel(dff, 3458); 
            txd = engineLoadTXD( 'vgncarshade1.txd', 3458 ); 
            engineImportTXD( txd, 3458 ); 
            state = true; 
            outputChatBox( '#ffcc00[MSG]: #c0c0c0Road texture enabled!', 255,255,255,true ); 
        end 
    end 
)   

Still the same

Link to comment

engineLoadTXD and engineImportTXD must be called before.

Also, engineLoadTXD and engineLoadDFF has only the first argument.

  
local state 
addEventHandler( "onClientResourceStart", resourceRoot, 
    function() 
        replaceTexture() 
        state = true 
    end 
) 
  
function replaceTexture() 
    engineImportTXD( engineLoadTXD("vgncarshade1.txd"), 3458 ) 
    engineReplaceModel( engineLoadDFF("vgncarshade1.dff"), 3458 ) 
end 
  
bindKey( 'F3', 'down', 
    function( ) 
        if state then 
            engineRestoreModel(3458) 
        else 
            replaceTexture() 
        end 
        outputChatBox( '#ffcc00[MSG]: #c0c0c0Road texture '..(state and 'disabled' or 'enabled')..'!', 255,255,255,true ) 
        state = not state 
    end 
) 
  

Try it.

Link to comment
engineLoadTXD and engineImportTXD must be called before.

Also, engineLoadTXD and engineLoadDFF has only the first argument.

  
local state 
addEventHandler( "onClientResourceStart", resourceRoot, 
    function() 
        replaceTexture() 
        state = true 
    end 
) 
  
function replaceTexture() 
    engineImportTXD( engineLoadTXD("vgncarshade1.txd"), 3458 ) 
    engineReplaceModel( engineLoadDFF("vgncarshade1.dff"), 3458 ) 
end 
  
bindKey( 'F3', 'down', 
    function( ) 
        if state then 
            engineRestoreModel(3458) 
        else 
            replaceTexture() 
        end 
        outputChatBox( '#ffcc00[MSG]: #c0c0c0Road texture '..(state and 'disabled' or 'enabled')..'!', 255,255,255,true ) 
        state = not state 
    end 
) 
  

Try it.

It didn't workd. But I found a function that worked

function() 
if ( guiCheckBoxGetSelected (txdModCheckBox) ) then 
txd = engineLoadTXD ( "RoadTexture/vgncarshade1.txd" ) 
engineImportTXD ( txd, 3458 ) 
else 
destroyElement(txd, 3458)    

Thanks for the spending time. :)

Link to comment

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