All Projects → c0rp3n → colorlib-sm

c0rp3n / colorlib-sm

Licence: GPL-3.0 License
A sourcepawn library for chat colors.

Programming Languages

SourcePawn
201 projects

ColorLib

A sourcepawn library for chat colors.

ColorLib is built as a replacement for Colors, it uses a a less naive approach to formatting messages to drastically improve the performance of C* functions.

Status

This project is still under active development and has not yet reached a stable version until v1.0.0 So when using this code currently expect random error and dragons.

Performance

CPrintToChat

  • ColorLib - Time needed for 10000 messages: 0.0600535
  • Multi-Colors - Time needed for 10000 messages: 0.114196

CPrintToServer

  • ColorLib - Time needed for 10000 messages: 0.037418‬
  • Multi-Colors - Time needed for 10000 messages: 0.0842195‬

Usage

Color Lib

First clone the repo.

git clone --recursive https://github.com/c0rp3n/colorlib-sm.git

Then include colorlib in your project make sure to either pass the include dir to spcomp or copy the includes to your include dir. For an example vscode config see here.

If previously using another color library make sure to no longer include it, and update the config and regenerate the colorlib_map.inc as show below with your old colors.

Example Usage

#pragma semicolon 1
#pragma newdecls required

#include <sourcemod>
#include <colorlib>

public void OnPluginStart()
{
    RegConsoleCmd("sm_colorlib", Command_ColorLib);
}

public Action Command_ColorLib(int client, int args)
{
    CPrintToChat(client, "CPrintToChat - {darkblue}%s - {darkred}%s", "Test", "Test");
}

Color Gen

To change the output colors you first need to install colorlib_gen.

cd tools/colorlib-gen/
pip install requirements.txt
pip install .

There is an example config file provided that it is recommended you copy it and make any required changes can be seen here.

Then you can rerun colorlib_gen to generate a new colorlib_map.inc to replace the default one provided.

Example Usage

# for more info use ./color_gen.py -h
colorlib_gen -re --target "sourcepawn" --config "./example_conf.yaml" colorlib_map.inc

Example GitHub workflow for SourcePawn

Note: This must executed before the plugins will be compiled.

- name: Set up Python
  uses: actions/setup-python@v2
  with:
    python-version: '3.x'

- name: Install dependencies
  run: python3 -m pip install --upgrade pip setuptools wheel

- name: Download colorlib-gen
  run: |
    cd tools
    git clone https://github.com/c0rp3n/colorlib-gen.git

- name: Install colorlib-gen
  run: |
    cd tools/colorlib-gen
    pip install -r ./requirements.txt
    python3 ./setup.py install
- name: Generate colorlib_map.inc
  run: colorlib_gen -re --target "sourcepawn" --config "./example_conf.yaml" colorlib_map.inc

Functions

void CPrintToChat(int client, const char[] message, any ...)
void CPrintToChatAll(const char[] message, any ...)
void CPrintToChatEx(int client, int author, const char[] message, any ...)
void CPrintToChatAllEx(int author, const char[] message, any ...)
void CPrintToChatTeam(int team, const char[] message, any ...)
void CPrintToChatTeamEx(int team, int author, const char[] message, any ...)
void CPrintToChatAdmins(int flags, const char[] message, any ...)
void CReplyToCommand(int author, const char[] message, any ...)
void CReplyToCommandEx(int client, int author, const char[] message, any ...)
void CShowActivity(int author, const char[] message, any ...)
void CShowActivityEx(int author, const char[] tag, const char[] message, any ...)
void CShowActivity2(int author, const char[] tag, cconst char[] message, any ...)
void CPrintToServer(const char[] message, any ...)
void CGetClientName(int client, char[] name, int mexlength)
int  CPreFormat(char[] message, int maxlength)
void CFormat(char[] message, int maxlength, int author = -1)
void CRemoveTags(char[] message, int maxlength)
void CRemoveColors(char[] message, int maxlength)
void CEscapeColors(char[] message, int maxlength)

Related Projects

Download

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].