08.05.2018, 10:51
Hello, some time ago i made this simple script and i want to share with you.
This script allows you to create a textdraw that changes its color smoothly after some time.
Something similar with this image: https://www.youtube.com/watch?v=w6SA7bEkLsQ
So how we are gonna do that?
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:
![](http://i.imgur.com/nVmZkaq.png)
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.
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.
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():
And that's it, you have a rainbow textdraw
Sorry for gramatical issues Ї\_(ツ)_/Ї
This script allows you to create a textdraw that changes its color smoothly after some time.
Something similar with this image: https://www.youtube.com/watch?v=w6SA7bEkLsQ
So how we are gonna do that?
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:
![](http://i.imgur.com/nVmZkaq.png)
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.
PHP Code:
#include <a_samp>
new red, green, blue;
new PlayerText:MyTextdraw[MAX_PLAYERS];
PHP Code:
forward UpdateColor();
public UpdateColor(){
//will complete this later
}
public OnGameModeInit()
{
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;
}
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():
PHP Code:
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
}
}
Sorry for gramatical issues Ї\_(ツ)_/Ї