I went ahead and edited the plugin to have the new style declarations (sorry for the leftover of the old code):
Code:
/**************************************************************************************************************************************************************
**************************************************************************************************************************************************************
******************************************************************!AND HERE BEGINS A DREAM!*******************************************************************
**************************************************************************************************************************************************************
**************************************************************************************************************************************************************
**************************************************************************************************************************************************************/
/******************************
INCLUDE ALL THE NECESSARY FILES
******************************/
#include <sourcemod>
#include <sdktools>
/******************************
COMPILE OPTIONS
******************************/
#pragma semicolon 1
#pragma newdecls required
/******************************
PLUGIN DEFINES
******************************/
/*Plugin Info*/
#define PLUGIN_NAME "Set My Name"
#define PLUGIN_AUTHOR "Eyal282 ( FuckTheSchool ) [Modified by Peter Brev with new style declarations]"
#define PLUGIN_VERSION "1.1.0.0"
#define PLUGIN_DESCRIPTION "Allows players to use a new name"
#define PLUGIN_URL "https://forums.alliedmods.net/showthread.php?t=308179"
/*Plugin defines for messages*/
#define TAG "[NAME]"
#define TAG_COLOR "\x07cc3300"
#define COLOR_AZURE "\x0700ace6"
#define COLOR_LIME "\x073ff206"
#define COLOR_PLAYER "\x07daaf0c"
#define COLOR_ERROR "\x07ff0000"
/******************************
PLUGIN INFO BASED ON PREVIOUS DEFINES
******************************/
public Plugin myinfo =
{
name = PLUGIN_NAME,
author = PLUGIN_AUTHOR,
description = PLUGIN_DESCRIPTION,
version = PLUGIN_VERSION,
url = PLUGIN_URL,
};
/******************************
INITIATE THE PLUGIN
******************************/
public void OnPluginStart()
{
//We want to hook player_changename in order to block the default message from showing
HookEvent("player_changename", namechange_callback, EventHookMode_Pre);
/***COMMANDS SETUP***/
//Create a convar for plugin version
CreateConVar("sm_name_version", PLUGIN_VERSION, "Plugin Version", FCVAR_NOTIFY|FCVAR_SPONLY);
//Create the public command
RegConsoleCmd("sm_name", Command_Name, "sm_name <new name>");
RegConsoleCmd("sm_oname", Command_Oname, "sm_oname <#userid|name> - Find the original Steam name of a player");
//Are we done here? Can we move to coding the real thing?
}
/******************************
PUBLIC CALLBACKS
******************************/
public Action namechange_callback(Event event, const char[] name, bool dontBroadcast)
{
SetEventBroadcast(event, true);
return Plugin_Continue;
}
public void OnClientAuthorized(int client)
{
char pname[50];
if (!GetClientInfo(client, "secretname", pname, sizeof(pname)))
return;
if (pname[0] == EOS)
return;
for (int i=0; i <= MaxClients; i++)
{
if (!IsClientInGame(i))
continue;
else if (IsFakeClient(i))
continue;
else if(!CheckCommandAccess(i, "sm_kick", ADMFLAG_KICK))
continue;
PrintToServer("Client %N has joined with the name %s.", client, pname);
}
SetClientInfo(client, "name", pname);
}
public Action Command_Name(int client, int args)
{
if (args < 1)
{
ReplyToCommand(client, "%s%s %sUsage: %ssm_name <new name>", TAG_COLOR, TAG, COLOR_AZURE, COLOR_LIME);
return Plugin_Handled;
}
char NewName[MAX_NAME_LENGTH];
GetCmdArgString(NewName, sizeof(NewName));
Handle DP = CreateDataPack();
RequestFrame(TwoTotalFrames, DP);
WritePackCell(DP, GetClientUserId(client));
WritePackString(DP, NewName);
return Plugin_Handled;
}
public void TwoTotalFrames(Handle DP)
{
RequestFrame(ChangeName, DP);
}
public void ChangeName(Handle DP)
{
ResetPack(DP);
int client = GetClientOfUserId(ReadPackCell(DP));
if (client <= 0 || client > MaxClients)
return;
else if(!IsClientInGame(client))
return;
char NewName[MAX_NAME_LENGTH];
ReadPackString(DP, NewName, sizeof(NewName));
CloseHandle(DP);
SetClientInfo(client, "name", NewName);
PrintToChatAll("%s%s %s%N %shas changed their name to %s%s.", TAG_COLOR, TAG, COLOR_PLAYER, client, COLOR_AZURE, COLOR_PLAYER, NewName);
}
public Action Command_Oname(int client, int args)
{
char targetarg[MAX_NAME_LENGTH];
GetCmdArgString(targetarg, sizeof(targetarg));
char target_name[MAX_TARGET_LENGTH];
int target_list[MAXPLAYERS], target_count;
bool tn_is_ml;
int targetclient;
if ((target_count = ProcessTargetString(
targetarg,
client,
target_list,
MAXPLAYERS,
COMMAND_FILTER_NO_MULTI,
target_name,
sizeof(target_name),
tn_is_ml)) > 0)
{
for (int i = 0; i < target_count; i++)
{
targetclient = target_list[i];
QueryClientConVar(targetclient, "name", OnSteamNameQueried, GetClientUserId(client));
}
}
else
{
ReplyToTargetError(client, target_count);
}
return Plugin_Handled;
}
public void OnSteamNameQueried(QueryCookie cookie, int targetclient, ConVarQueryResult result, const char[] cvarName, const char[] cvarValue, any UserId)
{
int client = GetClientOfUserId(UserId);
if (result != ConVarQuery_Okay)
{
PrintToChat(client, "%s%s %sError: Couldn't retrieve %s%N%s's Steam name.", TAG_COLOR, TAG, COLOR_ERROR, COLOR_PLAYER, targetclient, COLOR_ERROR);
return;
}
if (client <= 0 || client > MaxClients)
return;
else if (!IsClientInGame(client))
return;
PrintToChat(client, "%s%s %s%N%s's Steam name is %s%s.", TAG_COLOR, TAG, COLOR_PLAYER, targetclient, COLOR_AZURE, COLOR_PLAYER, cvarValue);
}
/**************************************************************************************************************************************************************
**************************************************************************************************************************************************************
**************************************************************************************************************************************************************
*****************************************************************!AND THE DREAM ENDS HERE!********************************************************************
**************************************************************************************************************************************************************
**************************************************************************************************************************************************************
**************************************************************************************************************************************************************/