HustraDev Posted August 16, 2016 Share Posted August 16, 2016 Hi i'm looking for Making a new scripts that change cars window color could any body help me with functions or any way i can use to make it change ? Thanks Link to comment
HustraDev Posted August 16, 2016 Author Share Posted August 16, 2016 can you explain more and what i use from shaders ? Link to comment
HustraDev Posted August 17, 2016 Author Share Posted August 17, 2016 anybody can explain how to do it with shaders ?? Link to comment
Jayceon Posted August 17, 2016 Share Posted August 17, 2016 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
HustraDev Posted August 20, 2016 Author Share Posted August 20, 2016 i have tested but it doesn't work could any body help me ?! Link to comment
HustraDev Posted August 21, 2016 Author Share Posted August 21, 2016 This Script Drives me crazy Link to comment
Captain Cody Posted August 21, 2016 Share Posted August 21, 2016 Any thing in debug, and is everything defined right? Link to comment
HustraDev Posted August 21, 2016 Author Share Posted August 21, 2016 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? Link to comment
HustraDev Posted August 21, 2016 Author Share Posted August 21, 2016 i Have been all night trying to fix it but i failed i'm serously need Help Link to comment
HustraDev Posted August 21, 2016 Author Share Posted August 21, 2016 > could any body explain to what this code does engineApplyShaderToWorldTexture(tintShaders[this][1], texture, element) Link to comment
G-Stefan Posted August 22, 2016 Share Posted August 22, 2016 > 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
roaddog Posted August 22, 2016 Share Posted August 22, 2016 Are you sure you have set vehicle data? setElementData(vehicle, "tuning.tintedWindow", 1) Try outputing the value line 11 Link to comment
HustraDev Posted August 22, 2016 Author Share Posted August 22, 2016 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
roaddog Posted August 22, 2016 Share Posted August 22, 2016 No i mean output vehicleHaveTintedWindow variable line 11 in your script Link to comment
HustraDev Posted August 22, 2016 Author Share Posted August 22, 2016 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
G-Stefan Posted August 22, 2016 Share Posted August 22, 2016 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
HustraDev Posted August 22, 2016 Author Share Posted August 22, 2016 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
GTX Posted August 22, 2016 Share Posted August 22, 2016 (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 August 23, 2016 by Guest Link to comment
HustraDev Posted August 23, 2016 Author Share Posted August 23, 2016 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
GTX Posted August 23, 2016 Share Posted August 23, 2016 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. Link to comment
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now