AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   messagemode - getting more than 1 argument (https://forums.alliedmods.net/showthread.php?t=106045)

shadow.hk 10-11-2009 02:03

messagemode - getting more than 1 argument
 
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?

fysiks 10-11-2009 02:41

Re: messagemode - getting more than 1 argument
 
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.

shadow.hk 10-11-2009 02:57

Re: messagemode - getting more than 1 argument
 
So really, if I were to use messagemode then I'd need to use it for each argument... that sucks.

Jon 10-11-2009 05:41

Re: messagemode - getting more than 1 argument
 
Quote:

Originally Posted by fysiks (Post 958295)
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.

fysiks 10-11-2009 16:42

Re: messagemode - getting more than 1 argument
 
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.

Jon 10-11-2009 17:35

Re: messagemode - getting more than 1 argument
 
Quote:

Originally Posted by fysiks (Post 958993)
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? :D

What is hex for cyan?

Bugsy 10-11-2009 17:47

Re: messagemode - getting more than 1 argument
 
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


fysiks 10-11-2009 18:42

Re: messagemode - getting more than 1 argument
 
Quote:

Originally Posted by Jon (Post 959037)
Don't tell me you walk around knowing hex codes for all colours? :D

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.

vitorrd 10-11-2009 20:18

Re: messagemode - getting more than 1 argument
 
Quote:

Originally Posted by Jon (Post 959037)
Don't tell me you walk around knowing hex codes for all colours? :D

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 (Post 959056)
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.

Bugsy 10-11-2009 21:54

Re: messagemode - getting more than 1 argument
 
Quote:

Originally Posted by vitorrd (Post 959177)
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


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

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