> For the complete documentation index, see [llms.txt](https://eaglepb2.gitbook.io/pb2-editor-manual/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://eaglepb2.gitbook.io/pb2-editor-manual/secret-weaponry/createcolormatrix-script.md).

# createColorMatrix Script

This script uses the original color of the weapon, and the final result of color, to convert into flash supported matrix.

The way to execute the script is by pasting this function just below the function:

```javascript
colorMatrix([76, 76, 76], [32, 32, 32], [96, 95, 77], [128, 32, 0]);

//([first input RGB], [first output RGB], [second input RGB], [second output RGB]);
```

Anyways, here's the code you had to paste in console, at the advanced level editor:

```javascript
function getLine(x1, x2, y1, y2) {
	let x = x1 - x2;
	let y = y1 - y2;
	let m = y / x;
	let b = (y1 - m * x1) / 255;

    return { m, b }
}

function copy(str) {
    let textarea = document.createElement("textarea");

    textarea.value = str;
    
    document.body.append(textarea);
    textarea.select();
    document.execCommand("copy");
    textarea.remove();
}

function colorMatrix(input1, output1, input2, output2) {
    let diffR = Math.abs(input1[0] - input2[0]);
    let diffG = Math.abs(input1[1] - input2[1]);
    let diffB = Math.abs(input1[2] - input2[2]);
	let mainColor = Math.max(diffR, diffG, diffB);
	
	if (mainColor == diffR) {
		mainColor = 0;
	} else if (mainColor == diffG) {
		mainColor = 1;
	} else if (mainColor == diffB) {
		mainColor = 2;
	}
	
	let equationR = getLine(input1[mainColor], input2[mainColor], output1[0], output2[0]);
	let equationG = getLine(input1[mainColor], input2[mainColor], output1[1], output2[1]);
	let equationB = getLine(input1[mainColor], input2[mainColor], output1[2], output2[2]);
	let matrix = [];
	
	if (mainColor == 0) {
		matrix.push(equationR.m, 0, 0, 0, equationR.b);
        matrix.push(equationG.m, 0, 0, 0, equationG.b);
        matrix.push(equationB.m, 0, 0, 0, equationB.b);
	}
	
	if (mainColor == 1) {
		matrix.push(0, equationR.m, 0, 0, equationR.b);
        matrix.push(0, equationG.m, 0, 0, equationG.b);
        matrix.push(0, equationB.m, 0, 0, equationB.b);
	}
	
	if (mainColor == 2) {
		matrix.push(0, 0, equationR.m, 0, equationR.b);
        matrix.push(0, 0, equationG.m, 0, equationG.b);
        matrix.push(0, 0, equationB.m, 0, equationB.b);
	}

    matrix.push(0, 0, 0, 1, 0);

	copy('VarSetValue( "_colorMatrix", "' + matrix.join(",") + '" );\nop349( "_colorMatrix", "," );\nop403( "0", "_colorMatrix" );');
}
```

After executing this code, it will prompt you to set a variable name of your choice, after that, the code will automatically be pasted onto your clipboard.

Prepare an empty trigger, set it into text mode, paste it, change the guns if you want, then save. Your guns should be color filtered to your likings.

## Tutorial Videos

The following videos are tutorials from nknwn :D&#x20;

{% embed url="<https://youtu.be/L9Gy93uKJ5E>" %}
