View Single Post
headline
SourceMod Moderator
Join Date: Mar 2015
Old 02-25-2018 , 03:21   Re: Snippet: Setting RGB/RGBA values via a command
Reply With Quote #2

Why are you so obsessed with regex?

PHP Code:
public Action Command_EnterRGBA(int clientint args)
{
    if (
args != 4)
    {
        
ReplyToCommand(client"[SM] Usage: sm_rgba <0-255> <0-255> <0-255> <0-255>");
        return 
Plugin_Handled;
    }
    if (
client == || !IsClientInGame(client))
    {
        
ReplyToCommand(client"[SM] You must be in-game to use this command!");
        return 
Plugin_Handled;
    }

    
char str1[4], str2[4], str3[4], str4[4];
    
GetCmdArg(1str1sizeof(str1));
    
GetCmdArg(2str2sizeof(str2));
    
GetCmdArg(3str3sizeof(str3));
    
GetCmdArg(4str4sizeof(str4));


    
int r StringToInt(str1);
    if (!(
<= <= 255))
    {
        
ReplyToCommand(client"[SM] Red value is outside the valid range of 0-255.");
        return 
Plugin_Handled;
    }
    
    
int g StringToInt(str2);
    if (!(
<= <= 255))
    {
        
ReplyToCommand(client"[SM] Green value is outside the valid range of 0-255.");
        return 
Plugin_Handled;
    }

    
int b StringToInt(str3);
    if (!(
<= <= 255))
    {
        
ReplyToCommand(client"[SM] Blue value is outside the valid range of 0-255.");
        return 
Plugin_Handled;
    }
    
    
int a StringToInt(str4);
    if (!(
<= <= 255))
    {
        
ReplyToCommand(client"[SM] Alpha value is outside the valid range of 0-255.");
        return 
Plugin_Handled;
    }
    
    
    
// use RGBA how you want
    
return Plugin_Handled;


Last edited by headline; 02-25-2018 at 03:22.
headline is offline