This system allows displaying a text on screen that automatically and cyclically changes its color (Rainbow Effect).
The script converts RGB values into hexadecimal format and updates the color for all players, keeping the animation active while they are connected to the server. In this way, the system provides a personalized textdraw with a “rainbow” effect that adds life and extra visual appeal to the server’s interface.
Colors can be written in different formats (rgb, Hex, RGBA) The most simple is rgb (stands for red, green, blue), witch stores 3 numbers, reprezenting the amount of pigment a color has from 0 to 255. For example, rgb(255, 0, 0) is pure red. rgb(0, 0, 255) is pure blue. We also can combine colors, so rgb(255, 0, 255) is purple.
If we search "color picker", we will get directly a color picker that looks like this:
The left side shows the value of the color in rgb - in this case, rgb(255, 0, 0) and hex - in this case, #ff0000. If we slide with the down thin bar, we can get colors, also, the rgb values are changing.
If we start from the pure red (left) rgb(255,0,0) and slide to yellow, we can see that the green amount of color is increasing from 0 to 255, so the purest yellow is rgb(255, 255, 0). This stands for all the colors, the amount of pigments are increasing and decreasing.
Since we know that, let's put it in a pawn script:
First, we create variables for red, green and blue (the main colors in this case) and the textdraw.
#include <a_samp>
new red, green, blue;
new PlayerText:MyTextdraw[MAX_PLAYERS]; As we have seen, the colors starts from rgb(255, 0, 0), so we insert into OnGameModeInit the certain values. We also need a timer that repeats every second.
forward UpdateColor();
public UpdateColor()
{
//will complete this later
}
public OnGameModeInit() //or OnFilterScriptInit
{
red = 255;
green = 0;
blue = 0;
SetTimer("UpdateColor", 1000, true);
return 1;
}
//creating the textdraw:
public OnPlayerConnect(playerid)
{
MyTextdraw[playerid] = CreatePlayerTextDraw(playerid, 637.980529, 424.166625, "This is a textdraw!");
PlayerTextDrawLetterSize(playerid, MyTextdraw[playerid], 0.308705, 1.541666);
PlayerTextDrawAlignment(playerid, MyTextdraw[playerid], 3);
PlayerTextDrawColor(playerid, MyTextdraw[playerid], -1);
PlayerTextDrawSetShadow(playerid, MyTextdraw[playerid], 0);
PlayerTextDrawSetOutline(playerid, MyTextdraw[playerid], 1);
PlayerTextDrawBackgroundColor(playerid, MyTextdraw[playerid], 255);
PlayerTextDrawFont(playerid, MyTextdraw[playerid], 1);
PlayerTextDrawSetProportional(playerid, MyTextdraw[playerid], 1);
PlayerTextDrawSetShadow(playerid, MyTextdraw[playerid], 0);
return 1;
} So at the start of the gamemode, the color is pure red - rgb(255, 0, 0);
Every second, our color will change. I recomend you changing it by 15 every time, i tested it and is smooth enough.
Returing to UpdateColor():
public UpdateColor()
{
if(red == 255 && blue == 0 && green != 255) green += 15; //as i said before, the green increases until is 255 - rgb(255, 255, 0) that is yellow
if(red != 0 && blue == 0 && green == 255) red -= 15; //we continue decreasing the red, so at the end we will have rgb(0, 255, 0) - pure green
//and so on.. :
if(red == 0 && blue != 255 && green == 255) blue += 15; //making it cyan
if(red == 0 && blue == 255 && green != 0) green -= 15; //making it pure blue
if(red != 255 && blue == 255 && green == 0) red += 15; //making it purple
if(red == 255 && green == 0 && blue != 0) blue -= 15; //making it pure red and reinitializing the cycle
//we have all the colors needed in rbg format (r, g, b), but textdraws use HEX format (0xRRGGBBAA) where AA is the alpha. So we use the folowing script:
new finalcolorhex; //the color that will be applied on the textdraw
finalcolorhex = red<<24 | green<<16 | blue<<8 | 255; // where 255 is the alpha, you can modify this value to change its transparency.
//we now have to change it for all players:
for(new i; i < MAX_PLAYERS; i++)
{
PlayerTextDrawColor(i, MyTextdraw[i], finalcolorhex); //updating the color
PlayerTextDrawShow(i, MyTextdraw[i]); //acording to samp wiki, we have to reshow the textdraw to the player in order to update
}
}And that's it, you have a rainbow textdraw!
You can modify or adjust any part of the system if needed, add more colors, expand features, or add more textdraws. You can also correct text, improve functions, or add details you find useful. This allows you to better adapt it to your project or the way you prefer the system to work.
- Idea and Tutorial - (Vennox)

