SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Scripting Help > Tutorials

Thread Tools Display Modes
Old 08/05/2018, 10:51 AM   #1
Little Clucker
Vennox's Avatar
Join Date: Apr 2018
Location: Romania
Posts: 31
Reputation: 7
Post Creating a rainbow textdraw

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:

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:

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 redgreenblue;
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.

PHP Code:
forward UpdateColor();
//will complete this later
red 255;
green 0;
blue 0;
//creating the textdraw:
public OnPlayerConnect(playerid){
MyTextdraw[playerid] = CreatePlayerTextDraw(playerid637.980529424.166625"This is a textdraw!");
PlayerTextDrawLetterSize(playeridMyTextdraw[playerid], 0.3087051.541666);
PlayerTextDrawAlignment(playeridMyTextdraw[playerid], 3);
PlayerTextDrawColor(playeridMyTextdraw[playerid], -1);
PlayerTextDrawSetShadow(playeridMyTextdraw[playerid], 0);
PlayerTextDrawSetOutline(playeridMyTextdraw[playerid], 1);
PlayerTextDrawBackgroundColor(playeridMyTextdraw[playerid], 255);
PlayerTextDrawFont(playeridMyTextdraw[playerid], 1);
PlayerTextDrawSetProportional(playeridMyTextdraw[playerid], 1);
PlayerTextDrawSetShadow(playeridMyTextdraw[playerid], 0);

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():

PHP Code:
public UpdateColor(){
red == 255 && blue == && green != 255green += 15//as i said before, the green increases until is 255 - rgb(255, 255, 0) that is yellow
if(red != && blue == && green == 255red -= 15//we continue decreasing the red, so at the end we will have rgb(0, 255, 0) - pure green
   //and so on.. :
if(red == && blue != 255 && green == 255blue += 15//making it cyan
if(red == && blue == 255 && green != 0green -= 15;  //making it pure blue
if(red != 255 && blue == 255 && green == 0red += 15//making it purple
if(red == 255 && green == && blue != 0blue -= 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<<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 iMAX_PLAYERSi++){
PlayerTextDrawColor(iMyTextdraw[i], finalcolorhex); //updating the color
PlayerTextDrawShow(iMyTextdraw[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
Sorry for gramatical issues \_(ツ)_/
Vennox is offline   Reply With Quote
Old 08/05/2018, 03:23 PM   #2
Join Date: Apr 2018
Posts: 51
Reputation: 2
Default Re: Creating a rainbow textdraw

good job
CrystalGamer is offline   Reply With Quote
Old 29/09/2018, 01:46 PM   #3
Little Clucker
Join Date: Mar 2018
Location: Romania
Posts: 9
Reputation: 0
Default Re: Creating a rainbow textdraw

Thanks <3
ExodusxD is offline   Reply With Quote
Old 29/09/2018, 04:14 PM   #4
Little Clucker
Join Date: Sep 2017
Posts: 12
Reputation: 6
Default Re: Creating a rainbow textdraw

thanks alot
Pwn3D is offline   Reply With Quote

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Creating textdraw Acres Scripting Help 2 22/01/2014 11:44 AM
[Tutorial] --: Creating Textdraw's In The Easiest Way :-- [Helpful for textdraw creators] Nirzor Tutorials 15 04/10/2012 12:32 PM
[Help] - Creating Textdraw xRyder Help Archive 5 18/02/2011 04:31 AM

All times are GMT. The time now is 04:56 PM.

Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.