STEAM GROUP
SourceMod SM
STEAM GROUP
SourceMod SM
5,582
IN-GAME
10,784
ONLINE
Founded
August 6, 2007
Switch Mar 24, 2018 @ 6:08am
Color variables
How to create color variable and then use it? In sourcemod
I will make xsay plugin with "ShowSyncHudText" for CS:GO, but i dont know how to create color variales and then use it with prefix "@". Example: sm_xsay @blue [text]

my sm_xsay.sp: https://pastebin.com/6EtpXnQg

Help pls
Last edited by Switch; Mar 24, 2018 @ 6:08am
< >
Showing 1-7 of 7 comments
Vertex Mar 24, 2018 @ 7:56am 
You should use this format and get the arguments inputted into the command.
public Action Command_XSay(int client, int args) { if (args < 1) { ReplyToCommand(client, "[SM] Usage: sm_xsay <@colour> <message>"); return Plugin_Handled; } char color_name[32]; // Get the colour name in the first argument GetCmdArg(1, color_name, sizeof(color_name)); char display_text[128]; // Get the text in the second argument GetCmdArg(2, display_text, sizeof(display_text)); }
Then use a string function[sm.alliedmods.net] like StrEqual() or StrContains() to check the value of the colour string and setup the colour in SetHudTextParams[sm.alliedmods.net]
Last edited by Vertex; Mar 24, 2018 @ 8:02am
Switch Mar 25, 2018 @ 4:52am 
like this? i dont know where is right string and left string
My sourcepawn skills are shit. pls help me:D

#include <sourcemod> #pragma semicolon 1 #pragma newdecls required Handle g_hSynchronizer = null; public Plugin myinfo = { name = "sm_xsay", author = "Switchback", description = "Admin messages using game_text entity", version = "1.0.0", url = "http://steamcommunity.com/id/switchwwe/" }; #define CHAT_SYMBOL '@' char g_ColorNames[13][10] = {"White", "Red", "Green", "Blue", "Yellow", "Purple", "Cyan", "Orange", "Pink", "Olive", "Lime", "Violet", "Lightblue"}; int g_Colors[13][3] = {{255,255,255},{255,0,0},{0,255,0},{0,0,255},{255,255,0},{255,0,255},{0,255,255},{255,128,0},{255,0,128},{128,255,0},{0,255,128},{128,0,255},{0,128,255}}; ConVar g_Cvar_Chatmode; public void OnPluginStart() { LoadTranslations("common.phrases"); g_hSynchronizer = CreateHudSynchronizer(); RegAdminCmd("sm_xsay", Command_XSay, ADMFLAG_CHAT, "sm_xsay [color] <message> - sends game text message at the top of mid to all players"); } public Action Command_XSay(int client, int args) { if (args < 1) { ReplyToCommand(client, "[SM] Usage: sm_xsay <@colour> <message>"); return Plugin_Handled; } char color_name[32]; // Get the colour name in the first argument GetCmdArg(1, color_name, sizeof(color_name)); char display_text[128]; // Get the text in the second argument GetCmdArg(2, display_text, sizeof(display_text)); bool StrEqual(const char[] str1, const char[] str2, bool caseSensitive=false) char text[100], colorStr[16]; GetCmdArgString(text, sizeof(text)); int len = BreakString(text, colorStr, 16); if (color == -1) { color = 0; } char sBuffer[256]; Format(sBuffer, sizeof(sBuffer), "%N: %s", client, text); SetHudTextParams(-1.0, 0.2, 5.0, 255, 0, 0, 255, 2, 0.5, 0.02, 0.3); for (int i = 1; i < MaxClients; i++) { if (!IsClientInGame(i)) { continue; } ShowSyncHudText(i, g_hSynchronizer, sBuffer); } LogAction(client, -1, "\"%L\" triggered sm_xsay (text %s)", client, text); return Plugin_Handled; } int FindColor(colorStr) { for (int i = 0; i < sizeof(g_ColorNames); i++) { if (strcmp(color, g_ColorNames, false) == 0)
return i;
}
}
Last edited by Switch; Mar 25, 2018 @ 4:53am
Vertex Mar 25, 2018 @ 7:25am 
Don't try to overcomplicate this plugin. Keep it simple if you're new to sourcepawn.
#define COLOR_COUNT 13 char g_ColorNames[13][10] = {"White", "Red", "Green", "Blue", "Yellow", "Purple", "Cyan", "Orange", "Pink", "Olive", "Lime", "Violet", "Lightblue"}; int g_Colors[13][3] = {{255,255,255},{255,0,0},{0,255,0},{0,0,255},{255,255,0},{255,0,255},{0,255,255},{255,128,0},{255,0,128},{128,255,0},{0,255,128},{128,0,255},{0,128,255}}; public Action Command_XSay(int client, int args) { char color_name[32]; // Get the colour name in the first argument GetCmdArg(1, color_name, sizeof(color_name)); // Default to color white, if no color is found int displayColor[3] = { 255, 255, 255 }; // Loop through all the colors and see if the color_name argument matches for (int color = 0; color < COLOR_COUNT; color++) { if (StrEqual(color_name, g_ColorNames[color], false)) { displayColor = g_Colors[color]; break; // exit loop if color is found } } // Set up the hud text and use the default or user inputed color SetHudTextParams(-1.0, 0.2, 5.0, displayColor[0], displayColor[1], displayColor[2], 255, 2, 0.5, 0.02, 0.3); }
Last edited by Vertex; Mar 25, 2018 @ 7:28am
Switch Mar 25, 2018 @ 12:57pm 
but your code not using "ShowSyncHudText" , and plugin are not work
Switch Mar 25, 2018 @ 12:58pm 
i will make, but so many errors. idk how to fix

#include <sourcemod> #pragma semicolon 1 #pragma newdecls required Handle g_hSynchronizer = null; public Plugin myinfo = { name = "sm_xsay", author = "Switchback", description = "Admin messages using game_text entity", version = "1.0.0", url = "http://steamcommunity.com/id/switchwwe/" }; #define CHAT_SYMBOL '@' #define COLOR_COUNT 13 char g_ColorNames[13][10] = {"White", "Red", "Green", "Blue", "Yellow", "Purple", "Cyan", "Orange", "Pink", "Olive", "Lime", "Violet", "Lightblue"}; int g_Colors[13][3] = {{255,255,255},{255,0,0},{0,255,0},{0,0,255},{255,255,0},{255,0,255},{0,255,255},{255,128,0},{255,0,128},{128,255,0},{0,255,128},{128,0,255},{0,128,255}}; ConVar g_Cvar_Chatmode; public void OnPluginStart() { LoadTranslations("common.phrases"); g_hSynchronizer = CreateHudSynchronizer(); RegAdminCmd("sm_xsay", Command_XSay, ADMFLAG_CHAT, "sm_xsay [color] <message> - sends game text message at the top of mid to all players"); } public Action Command_XSay(int client, int args) { if (args < 1) { ReplyToCommand(client, "[SM] Usage: sm_xsay <@colour> <message>"); return Plugin_Handled; } char color_name[32]; // Get the colour name in the first argument GetCmdArg(1, color_name, sizeof(color_name)); // Default to color white, if no color is found int displayColor[3] = { 255, 255, 255 }; // Loop through all the colors and see if the color_name argument matches for (int color = 0; color < COLOR_COUNT; color++) { if (StrEqual(color_name, g_ColorNames[color], false)) { displayColor = g_Colors[color]; break; // exit loop if color is found } } // Set up the hud text and use the default or user inputed color SetHudTextParams(-1.0, 0.2, 5.0, displayColor[0], displayColor[1], displayColor[2], 255, 2, 0.5, 0.02, 0.3); for (int i = 1; i < MaxClients; i++) { if (!IsClientInGame(i)) { continue; } ShowSyncHudText(i, g_hSynchronizer, sBuffer); } char text[100], colorStr[16]; GetCmdArgString(text, sizeof(text)); char sBuffer[256]; Format(sBuffer, sizeof(sBuffer), "%N: %s", client, text); LogAction(client, -1, "\"%L\" triggered sm_xsay (text %s)", client, text); return Plugin_Handled; }
Last edited by Switch; Mar 25, 2018 @ 12:59pm
Vertex Mar 25, 2018 @ 1:16pm 
This line here is incorrect.
ShowSyncHudText(i, g_hSynchronizer, sBuffer);

You need to get the text from the cmd arg 2 and put it where sBuffer is. The following function works like this (but with different names). ShowSyncHudText(client, synchronizer, text).
https://sm.alliedmods.net/new-api/halflife/ShowHudText

I gave you this example in my first post.
char display_text[128]; // Get the text in the second argument GetCmdArg(2, display_text, sizeof(display_text));
Last edited by Vertex; Mar 25, 2018 @ 1:19pm
Switch Mar 25, 2018 @ 2:21pm 
ohh.. my brain is broken o_o
< >
Showing 1-7 of 7 comments
Per page: 1530 50