Raised This Month: $ Target: $400
 0% 

messagemode - getting more than 1 argument


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
shadow.hk
Senior Member
Join Date: Dec 2008
Location: WA, Australia
Old 10-11-2009 , 02:03   messagemode - getting more than 1 argument
Reply With Quote #1

I've been using messagemode for a few of my plugins and was wondering if you could use more than 1 argument on the same messagemode?

i.e. custom_colour:255 255 255

For a command that requires 3 arguments won't work. Is there any way around this?
shadow.hk is offline
Send a message via MSN to shadow.hk
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 10-11-2009 , 02:41   Re: messagemode - getting more than 1 argument
Reply With Quote #2

You could parse the text. But that defeats the point of using message mode, imo. You will need to use some kind of delimiter when separating your arguments. So, it will be nearly just bad as having to go into your console and typing it.
__________________
fysiks is offline
shadow.hk
Senior Member
Join Date: Dec 2008
Location: WA, Australia
Old 10-11-2009 , 02:57   Re: messagemode - getting more than 1 argument
Reply With Quote #3

So really, if I were to use messagemode then I'd need to use it for each argument... that sucks.
shadow.hk is offline
Send a message via MSN to shadow.hk
Jon
Veteran Member
Join Date: Dec 2007
Old 10-11-2009 , 05:41   Re: messagemode - getting more than 1 argument
Reply With Quote #4

Quote:
Originally Posted by fysiks View Post
You could parse the text
PHP Code:
public CmdGetDataiClient )
{
    new 
szArg32 ];
    
read_argsszArg32 );

    if( !
strlenszArg ) )
    {
        return 
PLUGIN_HANDLED;
    }
    
    
remove_quotesszArg );
    
    new 
szR], szG], szB];
    
parseszArgszR3szG3szB);
    
    new 
iRiGiB;
    
iR str_to_numszR ), iG str_to_numszG ), iB str_to_numszB );
    
    
console_printiClient"%i %i %i"iRiGiB );
    
    return 
PLUGIN_HANDLED;

You should also clamp the values.
Jon is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 10-11-2009 , 16:42   Re: messagemode - getting more than 1 argument
Reply With Quote #5

You could use hex (e.g. White = "FFFFFF"). It's only one argument but you would still need to parse it into decimal of course.
__________________
fysiks is offline
Jon
Veteran Member
Join Date: Dec 2007
Old 10-11-2009 , 17:35   Re: messagemode - getting more than 1 argument
Reply With Quote #6

Quote:
Originally Posted by fysiks View Post
You could use hex (e.g. White = "FFFFFF"). It's only one argument but you would still need to parse it into decimal of course.
Don't tell me you walk around knowing hex codes for all colours?

What is hex for cyan?
Jon is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 10-11-2009 , 17:47   Re: messagemode - getting more than 1 argument
Reply With Quote #7

I'm not sure exactly what you're trying to do or if this will apply to messagemode but here's a more efficient way of storing RGB values.
PHP Code:
//Sample color values
new 125;
new 
220;
new 
53;
    
//Variable to store our RGB values
new RGB = ( << 16 ) | ( << ) | B;
    
//Retrieve individual R, G, & B values from RGB variable
RGB >> 16;
= ( RGB >> ) & ~0xFF00;
RGB & ~0xFFFF00
__________________

Last edited by Bugsy; 10-11-2009 at 17:51.
Bugsy is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 10-11-2009 , 18:42   Re: messagemode - getting more than 1 argument
Reply With Quote #8

Quote:
Originally Posted by Jon View Post
Don't tell me you walk around knowing hex codes for all colours?

What is hex for cyan?
Cyan? No. But, I know the easy ones. It's just as hard to know what color cyan is in any RGB method. The more you use them the more you will remember.

EDIT: Google. I don't think I will forget now (for a while).

Why not use HSV? Sounds fun.
__________________

Last edited by fysiks; 10-11-2009 at 18:44.
fysiks is offline
vitorrd
Senior Member
Join Date: Jul 2009
Old 10-11-2009 , 20:18   Re: messagemode - getting more than 1 argument
Reply With Quote #9

Quote:
Originally Posted by Jon View Post
Don't tell me you walk around knowing hex codes for all colours?

What is hex for cyan?
rofl @ that, haha. White is always the maximum value in any of the representations, 0xFFFFFF is just another way to write 255 255 255 (0xFF = 255).

Quote:
Originally Posted by Bugsy View Post
I'm not sure exactly what you're trying to do or if this will apply to messagemode but here's a more efficient way of storing RGB values.
PHP Code:
//Sample color values
new 125;
new 
220;
new 
53;
 
//Variable to store our RGB values
new RGB = ( << 16 ) | ( << ) | B;
 
//Retrieve individual R, G, & B values from RGB variable
RGB >> 16;
= ( RGB >> ) & ~0xFF00;
RGB & ~0xFFFF00
There is a small mistake in your RGB retrieving.

R = (RGB & 0xFF0000) >> 16;
G= (RGB & 0xFF00) >> 8;
B = RGB & 0xFF;

The mistake lies in the use of the bitwise not, as ~0xFF00 is not 0x00FF but 0xFFFF00FF, therefore any error in the encoding would screw things over.

Last edited by vitorrd; 10-11-2009 at 20:21.
vitorrd is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 10-11-2009 , 21:54   Re: messagemode - getting more than 1 argument
Reply With Quote #10

Quote:
Originally Posted by vitorrd View Post
The mistake lies in the use of the bitwise not, as ~0xFF00 is not 0x00FF but 0xFFFF00FF, therefore any error in the encoding would screw things over.
I tested my code with various values (0-255) and each time it returned correctly. If you are referring to someone using value(s) outside of 0-255 for any of the RGB values then yes I am aware this would then return erroneous values. I wrote the code with the understanding that the proper values would always be used; a clamp() call would be a good idea as a safeguard if anyone implements this into a plugin.

For anyone that is unsure of what is taking place:

The RGB holder
1111 1111 1111 1111 1111 1111

R = RGB >> 16

For red we want bits 17 through 24 so a shift of 16 to the right will leave us with only those bits:
0000 0000 0000 0000 1111 1111

G = ( RGB >> 8 ) & ~0xFF00

For green we need bits 9 through 16 so we need to shift right 8 and then the and-not operation to mask bits 9-16. (bits 1-8 now hold green)

RGB >> 8

0000 0000 1111 1111 1111 1111

Then do our bitmask, leaving just the green value
( RGB >> 8 ) & ~0xFF00

0000 0000 0000 0000 1111 1111

B = RGB & ~0xFFFF00

For blue we need bits 1-8 only so a bit-mask for bits 9-24 can be used.

RGB & ~0xFFFF00

0000 0000 0000 0000 1111 1111
__________________

Last edited by Bugsy; 10-12-2009 at 00:12.
Bugsy is offline
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

Forum Jump


All times are GMT -4. The time now is 22:38.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode