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

Chars with Color Codes via Convars?


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
DJPlaya
Senior Member
Join Date: Nov 2014
Location: Germany
Old 08-12-2017 , 12:21   Chars with Color Codes via Convars?
Reply With Quote #1

Ime sure its possible, but how? It may Sound noobish but i couldent get it to work.
Also i think my ConVar to Char Methode could be optimized, i think its actually pretty bad.

Code:
Handle h_PREFIX;
char c_PREFIX[32];

public void OnPluginStart()
{
	h_PREFIX = CreateConVar("sm_plugin_prefix", "[Ma Plugin]", "The Prefix shown at the start of Messages from this Plugin", _, false, 0.0, true, 32.0);
}


public void OnConfigsExecuted()
{
	GetConVarString(h_PREFIX, c_PREFIX, 32);
}

Stuff(){PrintToChatAll("YO! my name is %s", c_PREFIX)}
TY for your help
__________________
My biggest Projects: Kigen AC Redux, Forlix Floodcheck Redux

Last edited by DJPlaya; 08-13-2017 at 18:45.
DJPlaya is offline
Send a message via Skype™ to DJPlaya
shavit
AlliedModders Donor
Join Date: Dec 2011
Location: Israel
Old 08-12-2017 , 14:23   Re: Chars with Color Codes via Convars?
Reply With Quote #2

Untested, but should work.

Code:
#include <sourcemod>

ConVar gCV_Colors[3];

public void OnPluginStart()
{
	gCV_Colors[0] = CreateConVar("swag_name_color", "{lime}");
	gCV_Colors[1] = CreateConVar("swag_variable_color", "{team}");
	gCV_Colors[2] = CreateConVar("swag_name_color", "{default}");
	
	PrintToChatAll("%c[SM] %cshavit has %c10 hp", GetColor(0), GetColor(1), GetColor(2));
}

char GetColor(int color)
{
	char[] cvar = new char[16];
	gCV_Colors[color].GetString(cvar, 16);
	
	ReplaceString(cvar, 16, "{default}", "\x01");
	ReplaceString(cvar, 16, "{team}", "\x03");
	ReplaceString(cvar, 16, "{lime}", "\x04");
	
	return cvar[0];
}
__________________
retired

Last edited by shavit; 08-12-2017 at 14:23.
shavit is offline
N0B0DY1x
Junior Member
Join Date: Jul 2014
Location: France
Old 08-19-2017 , 09:10   Re: Chars with Color Codes via Convars?
Reply With Quote #3

Hi,

You can use this library : https://github.com/Bara20/Multi-Colors

PHP Code:
#pragma semicolon 1

#include <sourcemod>
#include <multicolors>

public Plugin myinfo =
{
    
name "ConVar Prefix Color",
    
author "meh",
    
description "meh",
    
version "1.0",
    
url "http://www.sourcemod.net/"
}

ConVar g_hCVPrefix;

public 
void OnPluginStart()
{
    
// Create the ConVar and bind a hook function if someone change this CVar
    
g_hCVPrefix CreateConVar("sm_plugin_prefix""{default}[{lime}Ma Plugin{default}]""The Prefix shown at the start of Messages from this Plugin");
    
g_hCVPrefix.AddChangeHook(CVHook_OnPrefixChanged);
}

// When all plugins config are executed, get the new prefix from the config
public void OnConfigsExecuted()
{
    
char prefix[32];
    
g_hCVPrefix.GetString(prefixsizeof(prefix));

    
SetPrefix(prefix);
}

// If the CVar change, set the new prefix
public void CVHook_OnPrefixChanged(ConVar convar, const char[] oldValue, const char[] newValue)
{
    
SetPrefix(newValue);
}

// Code to set the prefix and send a message to see it
stock void SetPrefix(const char[] prefix)
{
    
CSetPrefix("%s"prefix);
    
CPrintToChatAll("New prefix !");

Result:


But I think it's better to put the plugin's prefix in translations files. (https://wiki.alliedmods.net/Translat...eMod_Scripting)

Last edited by N0B0DY1x; 08-19-2017 at 09:10.
N0B0DY1x is offline
OSWO
Senior Member
Join Date: Jul 2015
Location: United Kingdom, London
Old 08-19-2017 , 13:32   Re: Chars with Color Codes via Convars?
Reply With Quote #4

https://git.discordlogs.com/oscar/Ba...csgocolors.inc

Not sure if it's the same thing but I had to add Orange to the csgocolors.inc since it wasn't included.

You can see how I do everything with translation files in there, and make everything colourful
__________________
SourceTimer | WeaponSkins++ | BasePlugins++ https://github.com/OSCAR-WOS
OSWO is offline
Reply



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 08:00.


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