SA-MP Forums

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

Reply
 
Thread Tools Display Modes
Old 28/08/2013, 12:36 AM   #1
Mean
High-roller
 
Join Date: Jul 2010
Location: 14th annual lemon party
Posts: 2,727
Reputation: 229
Default Converting colors from 'normal' to embed

Is there a function, that for example, converts 0xFFFFFFFF to FFFFFF?
__________________
I'm pretty much the creator of the PUB: macro used in many scripts today, therefore I'm a legitimate genius.

Ground breaking stuff
Quote:
Originally Posted by ******
I've met Mean on a few occasions in real life, a true genius and a 400 pound all-muscle gorilla alpha male. He has had a great influence on my life.
Quote:
Originally Posted by Kalcor
I don't know where I'd be today without Mean. He has helped me through some tough times in my life. He always brings a smile to my face. Such a positive lad!
Mean is offline   Reply With Quote
Old 28/08/2013, 12:40 AM   #2
Matnix
Big Clucker
 
Join Date: Jul 2013
Location: mars
Posts: 198
Reputation: 22
Default Re : Converting colors from 'normal' to embed

pawn Code:
0xFFFFFFFF =


0x
FFFFFF // the embded code
FF // color power

I always use this methods, but I hope you will found a converter It's will help me too. ahah.
Matnix is offline   Reply With Quote
Old 28/08/2013, 12:41 AM   #3
Vule.
Huge Clucker
 
Join Date: Mar 2012
Location: ل͜
Posts: 230
Reputation: 63
Wink Re: Converting colors from 'normal' to embed

You can use this
http://forum.sa-mp.com/showthread.php?t=387690
Vule. is offline   Reply With Quote
Old 28/08/2013, 12:51 AM   #4
Luis-
High-roller
 
Luis-'s Avatar
 
Join Date: Jan 2010
Location: England
Posts: 3,917
Reputation: 391
Default Re: Converting colors from 'normal' to embed

You know what, i'm going to attempt to make a converter tomorrow. I could do with one as well.
__________________
Luis- is offline   Reply With Quote
Old 28/08/2013, 12:54 AM   #5
Mean
High-roller
 
Join Date: Jul 2010
Location: 14th annual lemon party
Posts: 2,727
Reputation: 229
Default Re: Converting colors from 'normal' to embed

Quote:
Originally Posted by Luis- View Post
You know what, i'm going to attempt to make a converter tomorrow. I could do with one as well.
I'd need a function, converting the color manually is easy, you just remove the 0x and the last 2 characters (opacity), but I'd need a PAWN function that would automatically do that.
__________________
I'm pretty much the creator of the PUB: macro used in many scripts today, therefore I'm a legitimate genius.

Ground breaking stuff
Quote:
Originally Posted by ******
I've met Mean on a few occasions in real life, a true genius and a 400 pound all-muscle gorilla alpha male. He has had a great influence on my life.
Quote:
Originally Posted by Kalcor
I don't know where I'd be today without Mean. He has helped me through some tough times in my life. He always brings a smile to my face. Such a positive lad!
Mean is offline   Reply With Quote
Old 28/08/2013, 01:01 AM   #6
Luis-
High-roller
 
Luis-'s Avatar
 
Join Date: Jan 2010
Location: England
Posts: 3,917
Reputation: 391
Default Re: Converting colors from 'normal' to embed

Okay! Something like 'HEX2RGB(colour)' & 'RGB2HEX(colour)'.
__________________
Luis- is offline   Reply With Quote
Old 28/08/2013, 01:45 AM   #7
Mean
High-roller
 
Join Date: Jul 2010
Location: 14th annual lemon party
Posts: 2,727
Reputation: 229
Default Re: Converting colors from 'normal' to embed

Wrote my own function.

pawn Code:
stock ColorToEmbed(const color[]) {
    new finalclr[7];
    format(finalclr, sizeof finalclr, "%s", color[2]);
    return finalclr;
}

CMD:embed(playerid, params) {
    new str[128], col[7];
    col = ColorToEmbed("0xFFFFFFFF");
    format(str, sizeof str, "Hi {%s}there.", col);
    SendClientMessage(playerid, 0xFF0000FF, str);
    return 1;
}

You need to input your color as a string into ColorToEmbed and it will return a color string without 0x and the last 2 characters. Works like charm.
__________________
I'm pretty much the creator of the PUB: macro used in many scripts today, therefore I'm a legitimate genius.

Ground breaking stuff
Quote:
Originally Posted by ******
I've met Mean on a few occasions in real life, a true genius and a 400 pound all-muscle gorilla alpha male. He has had a great influence on my life.
Quote:
Originally Posted by Kalcor
I don't know where I'd be today without Mean. He has helped me through some tough times in my life. He always brings a smile to my face. Such a positive lad!
Mean is offline   Reply With Quote
Old 28/08/2013, 03:25 AM   #8
Luis-
High-roller
 
Luis-'s Avatar
 
Join Date: Jan 2010
Location: England
Posts: 3,917
Reputation: 391
Default Re: Converting colors from 'normal' to embed

Ah, fair enough! How does it remove the 0x and FF though?
__________________
Luis- is offline   Reply With Quote
Old 28/08/2013, 04:48 AM   #9
Squash
Little Clucker
 
Squash's Avatar
 
Join Date: Aug 2013
Location: England, UK
Posts: 13
Reputation: 21
Default Re: Converting colors from 'normal' to embed

Quote:
Originally Posted by Luis- View Post
Ah, fair enough! How does it remove the 0x and FF though?
The trick is in the size of the strings. A string is basically an array with a value for each character and a final value of NUL to signify the end of string. Keep in mind that array keys start at zero. Mean sets the size of finalchr to seven, meaning that only a string six characters in length can fit inside of it. He then formats the string using color[2], which returns the value of color starting from the third character. The first two characters are therefore omitted, leaving us with the "FFFFFFFF". This is eight characters long and so when it tries to fit in to finalchr, the last two characters are omitted to make room, leaving us with "FFFFFF".

Last edited by Squash; 28/08/2013 at 07:02 AM.
Squash is offline   Reply With Quote
Old 28/08/2013, 08:46 AM   #10
Vince
Spam Machine
 
Vince's Avatar
 
Join Date: Sep 2007
Location: Belgium
Posts: 10,083
Reputation: 2655
Default Re: Converting colors from 'normal' to embed

Shifting to the right is the only thing you need to do. You can then format using %06x.

pawn Code:
new embedColor = originalColor >>> 8;
__________________
Vince is offline   Reply With Quote
Reply

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
Hex to embed colour Richie© Scripting Help 3 29/06/2013 01:00 AM
converting normal loop to foreach. [D]ry[D]esert Scripting Help 4 06/01/2013 10:17 AM
Converting car colors into hex? OFirst Scripting Help 9 01/12/2011 12:46 AM


All times are GMT. The time now is 01:54 AM.


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