Raised This Month: $12 Target: $400
 3% 

GetConVarColor + Clamp


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Seta00
The Seta00 user has crashed.
Join Date: Jan 2010
Location: Berlin
Old 08-15-2010 , 12:18   GetConVarColor + Clamp
Reply With Quote #1

Code:
stock GetConVarColor(Handle:p_cvarHandle, p_color[4]) {     new String:color[16]; // "RRR GGG BBB AAA"     GetConVarString(p_cvarHandle, color, sizeof color);         new String:exploded[4][4];     ExplodeString(color, " ", exploded, sizeof exploded, sizeof exploded[]);         for (new i = 0; i < 4; ++i) {         p_color[i] = Clamp(StringToInt(exploded[i]), 0, 255);     }         if (strlen(exploded[3]) < 1)         p_color[3] = 255;     return; } stock Clamp(value, min, max) {     return value < min ? min : (value > max ? max : value); }

GetConVarColor converted from ConnorMcLeod's get_pcvar_color

How to use GetConVarColor:
Code:
new myShinyConVar = CreateConVar("sm_shiny", "150 125 0 255"); // RRR BBB GGG AAA -> Red Blue Green Alpha (Transparency) new color[4]; GetConVarColor(myShinyConVar, color);

Note: If there isn't a fourth color component (alpha) it defaults to 255 (fully visible)

How to use Clamp:
Code:
SetEntityHealth(client, Clamp(health, minHealth, maxHealth));

Last edited by Seta00; 08-15-2010 at 12:20.
Seta00 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 04:53.


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