View Single Post
ddhoward
Veteran Member
Join Date: May 2012
Location: California
Old 02-25-2018 , 04:13   Re: Snippet: Setting RGB/RGBA values via a command
Reply With Quote #3

Quote:
Originally Posted by Headline View Post
Why are you so obsessed with regex?

Spoiler
Even this is a little excessive; it's not necessary to hold the user's hand for the range validation, just as it's not necessary to use regex to check for non-numeric characters. Even if they omit an argument, I'd just go with it.

PHP Code:
public Action Command_EnterRGBA(int clientint args) {

    if (
client == || !IsClientInGame(client)) {
        
ReplyToCommand(client"[SM] You must be in-game to use this command!");
        return 
Plugin_Handled;
    }

    
char chRGBA[4][4];
    
int iRGBA[4];
    for (
int isizeof(chRGBA) && argsi++) {
        
GetCmdArg(i+1chRGBA[i], sizeof(chRGBA[i]));
        
iRGBA[i] = StringToInt(chRGBA[i]);
        if (!(
<= iRGBA[i] <= 255)) {
            
iRGBA[i] = 0;
            
ReplyToCommand(client"RGBA values must be between 0 and 255.");
        }
    }
        
    
// use RGBA how you want
    
return Plugin_Handled;

__________________

Last edited by ddhoward; 02-25-2018 at 04:20.
ddhoward is offline