Jump to content

[Help]How to Change Car Window color?


HustraDev

Recommended Posts

Posted

shader fx:

  
technique tintedWindow 
{ 
    pass P0 
    { 
        DepthBias = -0.0000; 
        AlphaBlendEnable = TRUE; 
        SrcBlend = SRCALPHA; 
        DestBlend = INVSRCALPHA; 
    } 
} 
  
technique fallback 
{ 
    pass P0 
    { 
     
    } 
} 
  

LUA:

  
local tintShaders = {} 
local elementShaders = {} 
  
local availableTintedWindows = { 
   [405] = "@hite", 
} 
  
addEventHandler("onClientResourceStart", resourceRoot, function() 
    for _, vehicle in ipairs(getElementsByType("vehicle", root, true)) do 
        local vehicleHaveTintedWindow = getElementData(vehicle, "tuning.tintedWindow") or 0 
         
        if vehicleHaveTintedWindow ~= 0 then 
            setVehicleWindowType(vehicle) 
        end 
    end 
end) 
  
addEventHandler("onClientElementStreamIn", root, function() 
    if getElementType(source) == "vehicle" then 
        local vehicleHaveTintedWindow = getElementData(source, "tuning.tintedWindow") or 0 
         
        if vehicleHaveTintedWindow ~= 0 then 
            setVehicleWindowType(source) 
        end 
    end 
end) 
  
addEventHandler("onClientElementDestroy", root, function() 
    if getElementType(source) == "vehicle" then 
        destroyTintedWindowShader(source) 
    end 
end) 
  
addEventHandler("onClientElementStreamOut", root, function() 
    if getElementType(source) == "vehicle" then 
        destroyTintedWindowShader(source) 
    end 
end) 
  
addEvent("tuning->TintedWindow", true) 
function setVehicleWindowType(vehicle, adding) 
    local vehicleModel = getElementModel(vehicle) 
    local windowTexture = availableTintedWindows[vehicleModel] 
     
    if adding == 0 then 
        destroyTintedWindowShader(vehicle) 
    else 
        if windowTexture then 
            applyTintedWindowShader(windowTexture, 100, vehicle) 
        else 
            destroyTintedWindowShader(vehicle) 
        end 
    end 
end 
addEventHandler("tuning->TintedWindow", root, setVehicleWindowType) 
  
function destroyTintedWindowShader(element) 
    if elementShaders[element] then 
        destroyElement(elementShaders[element][1][1]) 
        elementShaders[element] = nil 
    end 
end 
  
function applyTintedWindowShader(texture, distance, element) 
    if element then 
        destroyTintedWindowShader(element) 
    end 
     
    local this = #tintShaders + 1 
     
    tintShaders[this] = {} 
    tintShaders[this][1] = dxCreateShader("files/textures/tintedWindow.fx", 0, distance, true) 
     
    if not tintShaders[this][1] then 
        tintShaders[this] = nil 
        return 
    end 
     
    if element then 
        if not elementShaders[element] then 
            elementShaders[element] = {tintShaders[this], texture} 
        end 
    end 
     
    if tintShaders[this][1] and tintShaders[this][2] then 
        engineApplyShaderToWorldTexture(tintShaders[this][1], texture, element) 
    end 
end 
  

Posted
Any thing in debug, and is everything defined right?

Thanks for reply man but there is nothing in debug and i have a question

this scripts need a Texture ? like a image file with the window color or not?

Posted
> could any body explain to what this code does
  
engineApplyShaderToWorldTexture(tintShaders[this][1], texture, element) 
  

This function aplies a shader to a given texrure.For example if you create a shader which contains an image you can use that shader to change a model texture

This is how multiple paintjobs for any vehicles are created

Posted
Are you sure you have set vehicle data?

setElementData(vehicle, "tuning.tintedWindow", 1)

Try outputing the value line 11

i do outputing and there's nothing wrong with it

  
if setElementData(vehicle,"tuning.tintedWindow",1) then 
    outputChatBox("Perfect") 
end 
  

Chat : Perfect

Posted
No i mean output vehicleHaveTintedWindow variable line 11 in your script

    local vehicleHaveTintedWindow = getElementData(vehicle, "tuning.tintedWindow") or 0 then 
       if vehicleHaveTintedWindow then 
           outputChatBox("perfect") 
end 

i do this and there is nothing in chatbox

Posted
No i mean output vehicleHaveTintedWindow variable line 11 in your script

    local vehicleHaveTintedWindow = getElementData(vehicle, "tuning.tintedWindow") or 0 then 
       if vehicleHaveTintedWindow then 
           outputChatBox("perfect") 
end 

i do this and there is nothing in chatbox

Try this:

local windowData = getElementData(vehicle, "tuning.tintedWindow") 
if windowData then 
outputChatBox("The data exists") 
else 
outputChatBox("Unable to get the data") 
end 

Posted
No i mean output vehicleHaveTintedWindow variable line 11 in your script

    local vehicleHaveTintedWindow = getElementData(vehicle, "tuning.tintedWindow") or 0 then 
       if vehicleHaveTintedWindow then 
           outputChatBox("perfect") 
end 

i do this and there is nothing in chatbox

Try this:

local windowData = getElementData(vehicle, "tuning.tintedWindow") 
if windowData then 
outputChatBox("The data exists") 
else 
outputChatBox("Unable to get the data") 
end 

ChatBox : The Data Exists

Posted (edited)

First, work from the start. Make one vehicle and apply tinted windows for it.

  
local shader = dxCreateShader("tint.fx", 1, 0, true) -- Create a shader 
local vehicle = createVehicle(411, 0, 0, 4) -- This will create a vehicle on that GTA farm - in center of GTA map 
-- Apply that shader we created to vehicle(s) 
engineApplyShaderToWorldTexture(shader, "vehiclegeneric256", vehicle) -- Apply shader to windows of vehicle 
  

  
technique tint { 
    pass P0 { 
        DepthBias = 0.0000; 
        AlphaBlendEnable = FALSE; // Disable alpha blending 
        SrcBlend = SRCALPHA; // Source blend factor 
        DestBlend = INVSRCALPHA; // Destination blend factor 
    } 
} 
  
// Fallback method 
technique fallback { 
    pass P0 { 
        // Normal drawing 
    } 
} 
  

Note: You don't need to load shaders for each vehicle. Only 1 is required, then you can apply that to many elements.

Edited by Guest
Posted
First, work from the start. Make one vehicle and apply tinted windows for it.
  
    local shader = dxCreateShader("tint.fx", 1, 0, true) -- Create a shader 
    local vehicle = createVehicle(411, 0, 0, 4) -- This will create a vehicle on that GTA farm - in center of GTA map 
    -- Apply that shader we created to vehicle(s) 
    engineApplyShaderToWorldTexture(shader, "okoshko", vehicle) -- I don't know if this is correct 
  

  
    technique tint { 
        pass P0 { 
            DepthBias = 0.0000; 
            AlphaBlendEnable = FALSE; // Disable alpha blending 
            SrcBlend = SRCALPHA; // Source blend factor 
            DestBlend = INVSRCALPHA; // Destination blend factor 
        } 
} 
  
// Fallback method 
technique fallback { 
    pass P0 { 
        [color=#FF0000]// Normal drawing[/color] 
    } 
} 
  

Note: You don't need to load shaders for each vehicle. Only 1 is required, then you can apply that to many elements.

what is normal drawing !?`

Posted

If tint technique won't work, it will trigger fallback and will normally draw shader.

EDIT:

I edited the code and tested it, it works.

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