Jump to content

Changing Object Color


ShayF

Recommended Posts

I'm trying to change the color of a vehicle upgrade object. ID: 1001, name: spl_b_bab_m.dff. TXD not present. This is a spoiler. It changes the alpha and shade. However it only seems to toggle between white/grey and black. I need help with this.


client.lua

addEventHandler('onClientResourceStart',resourceRoot,function()
	shader = dxCreateShader('shader.fx',0,0,false,'object')
	setTimer(function()
		for i,v in pairs(getElementsByType('vehicle')) do
			if isElementStreamedIn(v) then
				local r,g,b = getVehicleColor(v)
				local a = getElementAlpha(v)
				dxSetShaderValue(shader,"red",(tonumber(r)/255))
				dxSetShaderValue(shader,"green",(tonumber(g)/255))
				dxSetShaderValue(shader,"blue",(tonumber(b)/255))
				dxSetShaderValue(shader,"alpha",(tonumber(a)/255))
				for _,attached in ipairs(getAttachedElements(v)) do
					local model = getElementModel(attached)
					if (model == 1001) then
						engineApplyShaderToWorldTexture(shader,'*',attached)
					end
				end
			end
		end
	end,50,0)
end)

shader.fx

float red;
float green;
float blue;
float alpha;

technique simple
{
    pass P0
    {
        MaterialAmbient = float4(red,green,blue,alpha);
    }
}

meta.xml

<meta>
	<script src="client.lua" type="client"/>
	<file src="shader.fx"/>
	<file src="mta-helper.fx"/>
</meta>

Alpha Change

Shades Change (Normal is black)

Edited by shay01
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...