PDA

View Full Version : Coding Guestion


Taalasmaa1337
01-13-2012, 14:04
Hey.

Today I tried to code an sourcemod addon plugin whatever its called to my server. I have some understanding of C++ so I managed to do something. But I was trying to create an plugin which changes all of the admins name to red.
I was trying to search for some chat functions etc.. and failed.
If this even possible to do? If it is help is more than appreciated :D

Thank You.

Starbish
01-13-2012, 14:25
#include <sourcemod>
#include <sdktools>
#include <colors> // it requires colors.inc on your include folder.

public OnPluginStart()
{
RegConsoleCmd("say", SayHook);
}

public Action:SayHook(client, args)
{
// Is Client Admin?
if(GetUserAdmin(client) != INVALID_ADMIN_ID)
{
// Get Client's Name
new String:Name[128];
GetClientName(client, Name, 256);

// Get Client's Chat
new String:Chat[256];
GetCmdArgString(Chat, sizeof(Chat));
CPrintToChatAll("{red}%s{default}: %s", Name, Chat);
return Plugin_Handled;
}
}


hmm..... Maybe it'd work.

Taalasmaa1337
01-13-2012, 14:34
Thanks, Ill try it later since I'm on my laptop atm :D

Powerlord
01-13-2012, 15:24
Just a suggestion: Use a color other than Red, Blue, or Grey for admin names.

Source already uses these colors for its various teams: Red = Rebels (HL2:DM Team Deathmatch), Terrorists (CS:S), Axis (DoD:S), Reliable Excavation Demolition (TF2), and Infected (L4D/L4D2); Blue = Combine (HL2:DM Team Deathmatch), Counter-Terrorists (CS:S), Allies (DoD:S), Builders League United (TF2), and Survivors (L4D/L4D2); Grey = Spectators (All).

Unless you really want half the people on your server to be mistaken for admins...

Taalasmaa1337
01-14-2012, 03:21
I planned to make it green color but what should I make inside the colors file :D I'm new to this so I got no idea.:oops:

Taalasmaa1337
01-14-2012, 03:50
It works but only thing it shows " always when an admin talks.

I figured it's because of the
CPrintToChatAll("{green}%s{default}: %s", Name, Chat);

those two ", I tried to remove them but it always failed to compile, is there a way to hide them?

Impact123
01-14-2012, 04:11
@Starbish
Your posted code is kinda rubbish, i hope you know that.
You should not reg a existing command, if you define a fixed size then use it anywhere for that variable, use the existing defines if possible, add a few checks, et cetera.

@Taalasmaa1337
You cannot remove the ", this is the syntax of the function, so if you remove it -> Error.
Here, i did'nt tested this, just edited the code from Starbish

#include <sourcemod>
#include <sdktools>
#include <colors> // it requires colors.inc on your include folder.




public OnPluginStart()
{
AddCommandListener(SayHook, "say");
}



public Action:SayHook(client, const String:command[], argc)
{
if(!IsChatTrigger())
{
if(client > 0 && GetUserAdmin(client) != INVALID_ADMIN_ID)
{
// Get Client's Name
new String:Name[MAX_NAME_LENGTH];
GetClientName(client, Name, sizeof(Name));

// Get Client's Chat
new String:Chat[256];
GetCmdArgString(Chat, sizeof(Chat));
StripQuotes(Chat);

CPrintToChatAll("{red}%s{default}: %s", Name, Chat);

return Plugin_Handled;
}
}

return Plugin_Continue;
}
Yours sincerely
impact

Taalasmaa1337
01-14-2012, 04:24
Thanks Impact :)

Theres only 1 problem left. Whenever I try type any sm commands like !admin it ofcourse shows it in the chat since its ! but when I type with / it should hide it but it still shows it.

Impact123
01-14-2012, 04:39
I edited the above posted code to fit your needs and fix your problem.
Have fun!

Yours sincerely
Impact

Taalasmaa1337
01-14-2012, 07:30
Now there's one problem left.

Whenever I type an 'registered' sm command like !admin or !noclip or !slap etc

it now removes the coloring, So it becomes the team color. This doesn't really matter I can live with this but If you can make some quick fix to fix it please, do it :D