Jump to content

Making this script shorter


Deagle

Recommended Posts

Hey, I want to use this script in a map.

-- 
-- c_uv_scroll.lua 
-- 
  
  
addEventHandler( "onClientResourceStart", resourceRoot, 
    function() 
  
        -- Version check 
        if getVersion ().sortable < "1.1.0" then 
            outputChatBox( "Resource is not compatible with this client." ) 
            return 
        end 
  
        -- Create shader 
        local shader, tec = dxCreateShader ( "uv_scroll.fx" ) 
  
        if not shader then 
            outputChatBox( "Could not create shader. Please use debugscript 3" ) 
        else 
            outputChatBox( "Using technique " .. tec ) 
  
            -- Apply to world texture 
            engineApplyShaderToWorldTexture ( shader, "bobo_2" ) 
  
            -- Create object with model 4729 (billboard) 
            local x,y,z = getElementPosition( getLocalPlayer() ) 
            createObject ( 4729, x-15, y, z+3 ) 
        end 
    end 
) 

I mean, I used it already and it's working, but I want to make it shorter, by deleting this part, because I dont need outputChatBox :

        if not shader then 
            outputChatBox( "Could not create shader. Please use debugscript 3" ) 
        else 
            outputChatBox( "Using technique " .. tec ) 

But when I delete it, the script is not working. I tried to delete the "tec" from here :

local shader, tec = dxCreateShader ( "uv_scroll.fx" ) 

local shader, dxCreateShader ( "uv_scroll.fx" ) 

This is my shorter script which is working :

function() 
local shader, tec = dxCreateShader ( "uv_scroll.fx" ) 
  
 if not shader then 
  outputChatBox( "Could not create shader. Please use debugscript 3" ) 
 else 
  outputChatBox( "Using technique " .. tec ) 
  
engineApplyShaderToWorldTexture ( shader, "bobo_2" ) 
  
        end 
    end 
) 

Link to comment

I want to delete this too, because I dont need the text in the chat. But when I delete it, the script it's not working :

        if not shader then 
            outputChatBox( "Could not create shader. Please use debugscript 3" ) 
        else 
            outputChatBox( "Using technique " .. tec ) 

Link to comment
addEventHandler( "onClientResourceStart", resourceRoot, 
    function() 
        -- Version check 
        if getVersion().sortable < "1.1.0" then 
            outputChatBox( "Resource is not compatible with this client." ) 
            return 
        end 
  
        -- Create shader 
        local shader, tec = dxCreateShader ( "uv_scroll.fx" ) 
  
        if shader then 
            -- Apply to world texture 
            engineApplyShaderToWorldTexture ( shader, "bobo_2" ) 
            -- Create object with model 4729 (billboard) 
            local x,y,z = getElementPosition( getLocalPlayer() ) 
            createObject ( 4729, x-15, y, z+3 ) 
        end 
    end 
) 

Link to comment

Thanks Aibo, you could say only that I have to leave this part :

if shader then 

Oh, I forgot to say that I am using this in the race mode. Maybe that's why you wrote me the entire script.

Now the script is working and it's way more shorter :

addEventHandler( "onClientResourceStart", resourceRoot, 
function() 
 local shader, tec = dxCreateShader ( "uv_scroll.fx" ) 
  if shader then 
engineApplyShaderToWorldTexture ( shader, "bobo_2" ) 
        end 
    end 
) 

Link to comment

well you're discarding the version check, not sure if it's a good idea.

addEventHandler( "onClientResourceStart", resourceRoot, 
    function() 
        if getVersion().sortable >= "1.1.0" then 
            local shader, tec = dxCreateShader ( "uv_scroll.fx" ) 
            if shader then 
                engineApplyShaderToWorldTexture ( shader, "bobo_2" ) 
            end 
        end 
    end 
) 

Link to comment
You could delete that addEventHandler ( "onClientResourceStart" ), I don't use that event handler as the whole script is already executed when the resource starts.

No, it's executed when the file has been downloaded (the .lua file)

This means that while the lua file has been downloaded, the shader files may have not been and executing them will not work

However, this should not be a problem if the resource was already downloaded somehow

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