AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Snippets and Tutorials (https://forums.alliedmods.net/forumdisplay.php?f=112)
-   -   [INC] ColorVariables (https://forums.alliedmods.net/showthread.php?t=267743)

KissLick 07-31-2015 16:24

[INC] ColorVariables
 
In layman's terms:
Plugin developers are not supposed to use actual colors, but variables which can be easily set by server masters.

How does it work?

  1. Create a plugin with ColorVariables
  2. Use color variables in chat messages and not actual colors
  3. Optional: If you need some new variables, create them with CAddVariable
  4. Optional: If you want, you can create a forwarded variable for other plugins to use (like {@isRebel CLIENT_INDEX}, {@rank CLIENT_INDEX}, {@rainbow} etc.)
  5. Optional: If you want to use variables from other plugins, load them with CLoadPluginConfig or CLoadPluginVariables (If server master renamed plugin binary, this won't work!)

Quick example:

Normal: PrintToChatAll("\x02[prefix]\x01 %N gave you \x03AK-47\x01!", client)
ColorVariables: CPrintToChatAll("%N gave you {highlight}AK-47{default}!", client)

ColorVariables plugin example:
PHP Code:

#include <colorvariables>

public OnPluginStart()
{
    
CSetPrefix("KillInfo"); // Set plugin chat prefix to "KillInfo" (will be used in every print function)

    
HookEvent("player_death"Event_PlayerDeath);
}

public 
Action:Event_PlayerDeath(Handle:event, const String:name[], bool:dontBroadcast
{
    new 
victim GetClientOfUserId(GetEventInt(event"userid"));
    new 
attacker GetClientOfUserId(GetEventInt(event"attacker"));

    
CPrintToChatAll("{player %d}%N {default} killed {player %d}%N"attackerattackervictimvictim);
    
// {prefix}[KillInfo] {teamcolor}Will {default}killed {teamcolor}Mark

    
CPrintToChat(victim"{highlight}Player {player %d}%N {highlight}killed you!"attackerattacker);
    
// {prefix}[KillInfo] {highlight}Player {teamcolor}Will {highlight}killed you!

    
return Plugin_Continue


More info, full feature list and download in GitHub repository.

DJ Tsunami 03-10-2016 11:38

Re: [INC] ColorVariables
 
This thread needs more comments! Finally an include for colors across games, and very well written too. The only issue I had is that {teamcolor} is not in the list for Source 2009 games, I had to add it myself.

KissLick 03-10-2016 16:30

Re: [INC] ColorVariables
 
Quote:

Originally Posted by DJ Tsunami (Post 2401276)
This thread needs more comments! Finally an include for colors across games, and very well written too. The only issue I had is that {teamcolor} is not in the list for Source 2009 games, I had to add it myself.

Thx! I really appreciate that! As for the {teamcolor}, looks like I forgot that one O:-) - gonna add it.

EDIT:
Oh I think I remember why there is no {teamcolor}, you can use {player CLIENT_INDEX} to get a player's team color. But anyway, I will have a look at it.

Drixevel 03-11-2016 03:08

Re: [INC] ColorVariables
 
Wish I knew about this include sooner, It would've been useful a few months ago. :/

Thanks for the release! :)

DJ Tsunami 03-11-2016 03:43

Re: [INC] ColorVariables
 
Quote:

Originally Posted by KissLick (Post 2401334)
you can use {player CLIENT_INDEX} to get a player's team color.

True, but in my case (Advertisements) the server administrator gets to choose the messages and where to put the colors, and I don't want to have to figure out where they put {player %d} and then inject the client index :wink: I know {engine 3} also works, but {teamcolor} is easier for people to remember :)

KissLick 03-11-2016 06:57

Re: [INC] ColorVariables
 
Just added {teamcolor} to Source2009 colors :-)

But there still is that little problem with loading foreign color config whose binary was renamed... I would like to fix that somehow, but I am very unsure how.... Any ideas, please? O:-)

Franc1sco 03-11-2016 08:35

Re: [INC] ColorVariables
 
This include seems very useful. I will use it from now :)

KissLick 03-11-2016 10:24

Re: [INC] ColorVariables
 
Quote:

Originally Posted by Franc1sco (Post 2401507)
This include seems very useful. I will use it from now :)

Dear God... Now Valve can say I collaborated on some new weapon skins plugin... uaaaaaaaaaaaaaaaaaaaaaaaaaa it's driving me crazyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy :-D

Franc1sco 03-11-2016 10:51

Re: [INC] ColorVariables
 
Quote:

Originally Posted by KissLick (Post 2401537)
Dear God... Now Valve can say I collaborated on some new weapon skins plugin... uaaaaaaaaaaaaaaaaaaaaaaaaaa it's driving me crazyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy :-D

Sure ;)

condolent 06-19-2016 10:15

Re: [INC] ColorVariables
 
I get this error when compiling my plugin:
Code:

//// admin-see-all-chat.sp
//
// sourcemod\addons\sourcemod\scripting\include\colorvariables.inc(147) : error 017: undefined symbol "iTeam"
// sourcemod\addons\sourcemod\scripting\include\colorvariables.inc(153) : error 001: expected token: ")", but found "~"
// sourcemod\addons\sourcemod\scripting\include\colorvariables.inc(153) : warning 215: expression has no effect
// sourcemod\addons\sourcemod\scripting\include\colorvariables.inc(153) : error 001: expected token: ";", but found ")"
// sourcemod\addons\sourcemod\scripting\include\colorvariables.inc(153) : error 029: invalid expression, assumed zero
// sourcemod\addons\sourcemod\scripting\include\colorvariables.inc(153) : fatal error 189: too many error messages on one line
//
// Compilation aborted.
// 5 Errors.
//
// Compilation Time: 0,8 sec



All times are GMT -4. The time now is 19:56.

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