Jump to content

[Help]How to Change Car Window color?


HustraDev

Recommended Posts

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 
  

Link to comment
> 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

Link to comment
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

Link to comment
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

Link to comment
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 

Link to comment
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

Link to comment

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
Link to comment
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 !?`

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