However, when compiling I got the following errors:
Here is all the code:
cannounce.sp
Spoiler
Code:
/**
*
* This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License, version 3.0, as published by the
* Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
* details.
*
* You should have received a copy of the GNU General Public License along with
* this program. If not, see <http://www.gnu.org/licenses/>.
*
* As a special exception, AlliedModders LLC gives you permission to link the
* code of this program (as well as its derivative works) to "Half-Life 2," the
* "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software
* by the Valve Corporation. You must obey the GNU General Public License in
* all respects for all other code used. Additionally, AlliedModders LLC grants
* this exception to all derivative works. AlliedModders LLC defines further
* exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007),
* or <http://www.sourcemod.net/license.php>.
*
*/
#pragma semicolon 1
#include <sourcemod>
#include <sdktools>
#include <geoip>
#undef REQUIRE_EXTENSIONS
#include <geoipcity>
#undef REQUIRE_PLUGIN
#include <adminmenu>
#include <morecolors.inc>
#define VERSION "1.6"
/*****************************************************************
G L O B A L V A R S
*****************************************************************/
static g_iSColors[5] = {1, 3, 4, 6, 5};
static String:g_sSColors[5][13] = {"{DEFAULT}", "{LIGHTGREEN}", "{GREEN}", "{YELLOW}", "{OLIVE}"};
new Handle:hTopMenu = INVALID_HANDLE;
new String:g_fileset[128];
new String:g_filesettings[128];
new bool:g_UseGeoIPCity = false;
new Handle:g_CvarConnectDisplayType = INVALID_HANDLE;
/*****************************************************************
L I B R A R Y I N C L U D E S
*****************************************************************/
#include "cannounce/countryshow.sp"
#include "cannounce/joinmsg.sp"
#include "cannounce/geolist.sp"
#include "cannounce/suppress.sp"
/*****************************************************************
P L U G I N I N F O
*****************************************************************/
public Plugin:myinfo =
{
name = "Connect Announce",
author = "",
description = "",
version = VERSION,
url = "http://forums.alliedmods.net/showthread.php?t=77306"
};
/*****************************************************************
F O R W A R D P U B L I C S
*****************************************************************/
public OnPluginStart()
{
LoadTranslations("common.phrases");
LoadTranslations("cannounce.phrases");
CreateConVar("sm_cannounce_version", VERSION, "Connect announce replacement", FCVAR_REPLICATED|FCVAR_NOTIFY|FCVAR_DONTRECORD);
g_CvarConnectDisplayType = CreateConVar("sm_ca_connectdisplaytype", "1", "[1|0] if 1 then displays connect message after admin check and allows the {PLAYERTYPE} placeholder. If 0 displays connect message on client auth (earlier) and disables the {PLAYERTYPE} placeholder");
BuildPath(Path_SM, g_fileset, 128, "data/cannounce_messages.txt");
BuildPath(Path_SM, g_filesettings, 128, "data/cannounce_settings.txt");
//event hooks
HookEvent("player_disconnect", event_PlayerDisconnect, EventHookMode_Pre);
//country show
SetupCountryShow();
//custom join msg
SetupJoinMsg();
//geographical player list
SetupGeoList();
//suppress standard connection message
SetupSuppress();
//Account for late loading
new Handle:topmenu;
if (LibraryExists("adminmenu") && ((topmenu = GetAdminTopMenu()) != INVALID_HANDLE))
{
OnAdminMenuReady(topmenu);
}
// Check if we have GeoIPCity.ext loaded
g_UseGeoIPCity = LibraryExists("GeoIPCity");
//create config file if not exists
AutoExecConfig(true, "cannounce");
}
public OnMapStart()
{
//get, precache and set downloads for player custom sound files
LoadSoundFilesCustomPlayer();
//precahce and set downloads for sounds files for all players
LoadSoundFilesAll();
OnMapStart_JoinMsg();
}
public OnClientAuthorized(client, const String:auth[])
{
if( GetConVarInt(g_CvarConnectDisplayType) == 0 )
{
if( !IsFakeClient(client) && GetClientCount(true) < MaxClients )
{
OnPostAdminCheck_CountryShow(client);
OnPostAdminCheck_JoinMsg(auth);
}
}
}
public OnClientPostAdminCheck(client)
{
decl String:auth[32];
if( GetConVarInt(g_CvarConnectDisplayType) == 1 )
{
GetClientAuthId( client, auth, sizeof(auth) );
if( !IsFakeClient(client) && GetClientCount(true) < MaxClients )
{
OnPostAdminCheck_CountryShow(client);
OnPostAdminCheck_JoinMsg(auth);
}
}
}
public OnPluginEnd()
{
OnPluginEnd_JoinMsg();
OnPluginEnd_CountryShow();
}
public OnAdminMenuReady(Handle:topmenu)
{
//Block us from being called twice
if (topmenu == hTopMenu)
{
return;
}
//Save the Handle
hTopMenu = topmenu;
OnAdminMenuReady_JoinMsg();
}
public OnLibraryRemoved(const String:name[])
{
//remove this menu handle if adminmenu plugin unloaded
if (strcmp(name, "adminmenu") == 0)
{
hTopMenu = INVALID_HANDLE;
}
// Was the GeoIPCity extension removed?
if(StrEqual(name, "GeoIPCity"))
g_UseGeoIPCity = false;
}
public OnLibraryAdded(const String:name[])
{
// Is the GeoIPCity extension running?
if(StrEqual(name, "GeoIPCity"))
g_UseGeoIPCity = true;
}
/****************************************************************
C A L L B A C K F U N C T I O N S
****************************************************************/
public Action:event_PlayerDisconnect(Handle:event, const String:name[], bool:dontBroadcast)
{
new client = GetClientOfUserId(GetEventInt(event, "userid"));
if( client && !IsFakeClient(client) && !dontBroadcast )
{
event_PlayerDisc_CountryShow(event, name, dontBroadcast);
OnClientDisconnect_JoinMsg();
}
return event_PlayerDisconnect_Suppress( event, name, dontBroadcast );
}
/*****************************************************************
P L U G I N F U N C T I O N S
*****************************************************************/
//Thanks to Darkthrone (https://forums.alliedmods.net/member.php?u=54636)
bool:IsLanIP( String:src[16] )
{
decl String:ip4[4][4];
new ipnum;
if(ExplodeString(src, ".", ip4, 4, 4) == 4)
{
ipnum = StringToInt(ip4[0])*65536 + StringToInt(ip4[1])*256 + StringToInt(ip4[2]);
if((ipnum >= 655360 && ipnum < 655360+65535) || (ipnum >= 11276288 && ipnum < 11276288+4095) || (ipnum >= 12625920 && ipnum < 12625920+255))
{
return true;
}
}
return false;
}
PrintFormattedMessageToAll( String:rawmsg[301], client )
{
decl String:message[301];
GetFormattedMessage( rawmsg, client, message, sizeof(message) );
PrintToChatAll( "%s", message );
}
PrintFormattedMessageToAdmins( String:rawmsg[301], client )
{
decl String:message[301];
GetFormattedMessage( rawmsg, client, message, sizeof(message) );
for (new i = 1; i <= GetMaxClients(); i++)
{
if( IsClientInGame(i) && CheckCommandAccess( i, "", ADMFLAG_GENERIC, true ) )
{
PrintToChat(i, "%s", message);
}
}
}
PrintFormattedMsgToNonAdmins( String:rawmsg[301], client )
{
decl String:message[301];
GetFormattedMessage( rawmsg, client, message, sizeof(message) );
for (new i = 1; i <= GetMaxClients(); i++)
{
if( IsClientInGame(i) && !CheckCommandAccess( i, "", ADMFLAG_GENERIC, true ) )
{
PrintToChat(i, "%s", message);
}
}
}
//GetFormattedMessage - based on code from the DJ Tsunami plugin Advertisements - http://forums.alliedmods.net/showthread.php?p=592536
GetFormattedMessage( String:rawmsg[301], client, String:outbuffer[], outbuffersize )
{
decl String:buffer[256];
decl String:ip[16];
decl String:city[46];
decl String:region[46];
decl String:country[46];
decl String:ccode[3];
decl String:ccode3[4];
decl String:sColor[4];
decl String:sPlayerAdmin[32];
decl String:sPlayerPublic[32];
new bool:bIsLanIp;
decl AdminId:aid;
if( client > -1 )
{
GetClientIP(client, ip, sizeof(ip));
//detect LAN ip
bIsLanIp = IsLanIP( ip );
// Using GeoIPCity extension...
if ( g_UseGeoIPCity )
{
if( !GeoipGetRecord( ip, city, region, country, ccode, ccode3 ) )
{
if( bIsLanIp )
{
Format( city, sizeof(city), "%T", "LAN City Desc", LANG_SERVER );
Format( region, sizeof(region), "%T", "LAN Region Desc", LANG_SERVER );
Format( country, sizeof(country), "%T", "LAN Country Desc", LANG_SERVER );
Format( ccode, sizeof(ccode), "%T", "LAN Country Short", LANG_SERVER );
Format( ccode3, sizeof(ccode3), "%T", "LAN Country Short 3", LANG_SERVER );
}
else
{
Format( city, sizeof(city), "%T", "Unknown City Desc", LANG_SERVER );
Format( region, sizeof(region), "%T", "Unknown Region Desc", LANG_SERVER );
Format( country, sizeof(country), "%T", "Unknown Country Desc", LANG_SERVER );
Format( ccode, sizeof(ccode), "%T", "Unknown Country Short", LANG_SERVER );
Format( ccode3, sizeof(ccode3), "%T", "Unknown Country Short 3", LANG_SERVER );
}
}
}
else // Using GeoIP default extension...
{
if( !GeoipCode2(ip, ccode) )
{
if( bIsLanIp )
{
Format( ccode, sizeof(ccode), "%T", "LAN Country Short", LANG_SERVER );
}
else
{
Format( ccode, sizeof(ccode), "%T", "Unknown Country Short", LANG_SERVER );
}
}
if( !GeoipCountry(ip, country, sizeof(country)) )
{
if( bIsLanIp )
{
Format( country, sizeof(country), "%T", "LAN Country Desc", LANG_SERVER );
}
else
{
Format( country, sizeof(country), "%T", "Unknown Country Desc", LANG_SERVER );
}
}
// Since the GeoIPCity extension isn't loaded, we don't know the city or region.
if( bIsLanIp )
{
Format( city, sizeof(city), "%T", "LAN City Desc", LANG_SERVER );
Format( region, sizeof(region), "%T", "LAN Region Desc", LANG_SERVER );
Format( ccode3, sizeof(ccode3), "%T", "LAN Country Short 3", LANG_SERVER );
}
else
{
Format( city, sizeof(city), "%T", "Unknown City Desc", LANG_SERVER );
Format( region, sizeof(region), "%T", "Unknown Region Desc", LANG_SERVER );
Format( ccode3, sizeof(ccode3), "%T", "Unknown Country Short 3", LANG_SERVER );
}
}
// Fallback for unknown/empty location strings
if( StrEqual( city, "" ) )
{
Format( city, sizeof(city), "%T", "Unknown City Desc", LANG_SERVER );
}
if( StrEqual( region, "" ) )
{
Format( region, sizeof(region), "%T", "Unknown Region Desc", LANG_SERVER );
}
if( StrEqual( country, "" ) )
{
Format( country, sizeof(country), "%T", "Unknown Country Desc", LANG_SERVER );
}
if( StrEqual( ccode, "" ) )
{
Format( ccode, sizeof(ccode), "%T", "Unknown Country Short", LANG_SERVER );
}
if( StrEqual( ccode3, "" ) )
{
Format( ccode3, sizeof(ccode3), "%T", "Unknown Country Short 3", LANG_SERVER );
}
// Add "The" in front of certain countries
if( StrContains( country, "United", false ) != -1 ||
StrContains( country, "Republic", false ) != -1 ||
StrContains( country, "Federation", false ) != -1 ||
StrContains( country, "Island", false ) != -1 ||
StrContains( country, "Netherlands", false ) != -1 ||
StrContains( country, "Isle", false ) != -1 ||
StrContains( country, "Bahamas", false ) != -1 ||
StrContains( country, "Maldives", false ) != -1 ||
StrContains( country, "Philippines", false ) != -1 ||
StrContains( country, "Vatican", false ) != -1 )
{
Format( country, sizeof(country), "The %s", country );
}
if (StrContains(rawmsg, "{PLAYERNAME}") != -1)
{
GetClientName(client, buffer, sizeof(buffer));
ReplaceString(rawmsg, sizeof(rawmsg), "{PLAYERNAME}", buffer);
}
if (StrContains(rawmsg, "{STEAMID}") != -1)
{
GetClientAuthId(client, buffer, sizeof(buffer));
ReplaceString(rawmsg, sizeof(rawmsg), "{STEAMID}", buffer);
}
if (StrContains(rawmsg, "{PLAYERCOUNTRY}") != -1 )
{
ReplaceString(rawmsg, sizeof(rawmsg), "{PLAYERCOUNTRY}", country);
}
if (StrContains(rawmsg, "{PLAYERCOUNTRYSHORT}") != -1 )
{
ReplaceString(rawmsg, sizeof(rawmsg), "{PLAYERCOUNTRYSHORT}", ccode);
}
if (StrContains(rawmsg, "{PLAYERCOUNTRYSHORT3}") != -1 )
{
ReplaceString(rawmsg, sizeof(rawmsg), "{PLAYERCOUNTRYSHORT3}", ccode3);
}
if (StrContains(rawmsg, "{PLAYERCITY}") != -1 )
{
ReplaceString(rawmsg, sizeof(rawmsg), "{PLAYERCITY}", city);
}
if (StrContains(rawmsg, "{PLAYERREGION}") != -1 )
{
ReplaceString(rawmsg, sizeof(rawmsg), "{PLAYERREGION}", region);
}
if (StrContains(rawmsg, "{PLAYERIP}") != -1 )
{
ReplaceString(rawmsg, sizeof(rawmsg), "{PLAYERIP}", ip);
}
if( StrContains(rawmsg, "{PLAYERTYPE}") != -1 && GetConVarInt(g_CvarConnectDisplayType) == 1 )
{
aid = GetUserAdmin( client );
if( GetAdminFlag( aid, Admin_Generic ) )
{
Format( sPlayerAdmin, sizeof(sPlayerAdmin), "%T", "CA Admin", LANG_SERVER );
ReplaceString(rawmsg, sizeof(rawmsg), "{PLAYERTYPE}", sPlayerAdmin);
}
else
{
Format( sPlayerPublic, sizeof(sPlayerPublic), "%T", "CA Public", LANG_SERVER );
ReplaceString(rawmsg, sizeof(rawmsg), "{PLAYERTYPE}", sPlayerPublic);
}
}
}
for (new c = 0; c < sizeof(g_iSColors); c++)
{
if ( StrContains(rawmsg, g_sSColors[c]) != -1 )
{
Format(sColor, sizeof(sColor), "%c", g_iSColors[c]);
ReplaceString(rawmsg, sizeof(rawmsg), g_sSColors[c], sColor);
}
}
Format( outbuffer, outbuffersize, "%s", rawmsg );
}
allow.sp
Spoiler
Code:
/*****************************************************************
F O R W A R D P U B L I C S
*****************************************************************/
SetupJoinMsg_Allow()
{
RegAdminCmd("sm_joinmsgon", Command_AllowJoinMsg, CHECKFLAG, "sm_joinmsgon <name or #userid> - allows a client to set a custom join message");
RegAdminCmd("sm_joinmsgonid", Command_AllowJoinMsgID, CHECKFLAG, "sm_joinmsgonid \"<steamId>\" \"<player name>\" - allows specified steamid to set a custom join message");
}
OnAdminMenuReady_JoinMsg_Allow(TopMenuObject:player_commands)
{
AddToTopMenu(hTopMenu,
"sm_joinmsgon",
TopMenuObject_Item,
AdminMenu_AllowJoinMsg,
player_commands,
"sm_joinmsgon",
CHECKFLAG);
}
/****************************************************************
C A L L B A C K F U N C T I O N S
****************************************************************/
public Action:Command_AllowJoinMsg(client, args)
{
decl String:target[65];
decl String:target_name[MAX_TARGET_LENGTH];
decl target_list[MAXPLAYERS];
decl target_count;
decl bool:tn_is_ml;
new String:steamId[24];
//not enough arguments, display usage
if (args < 1)
{
ReplyToCommand(client, "[SM] Usage: sm_joinmsgon <name or #userid>");
return Plugin_Handled;
}
//get command arguments
GetCmdArg(1, target, sizeof(target));
//get the target of this command, return error if invalid
if ((target_count = ProcessTargetString(
target,
client,
target_list,
MAXPLAYERS,
COMMAND_FILTER_NO_MULTI,
target_name,
sizeof(target_name),
tn_is_ml)) <= 0)
{
ReplyToTargetError(client, target_count);
return Plugin_Handled;
}
//set allowed custom join in kv file
if( target_count > 0 && GetClientAuthId(target_list[0], steamId, sizeof(steamId)) )
{
DoAllowJoinMsg(steamId,target_name,client);
//inform player of their enabled custom join msg
PrintToChat(target_list[0], "[SM] type sm_joinmsg in console to set your custom join message!");
}
else
{
ReplyToCommand(client, "[SM] Unable to find player's steam id");
}
return Plugin_Handled;
}
public Action:Command_AllowJoinMsgID(client, args)
{
decl String:player_name[MAX_TARGET_LENGTH];
new String:steamId[24];
//not enough arguments, display usage
if (args != 2)
{
ReplyToCommand(client, "[SM] Usage: sm_joinmsgonid \"<steamId>\" \"<player name>\"");
return Plugin_Handled;
}
//get command arguments
GetCmdArg(1, steamId, sizeof(steamId));
GetCmdArg(2, player_name, sizeof(player_name));
//allow steam id
DoAllowJoinMsg(steamId,player_name,client);
return Plugin_Handled;
}
/*****************************************************************
P L U G I N F U N C T I O N S
*****************************************************************/
DoAllowJoinMsg( String:steamId[], String:target_name[], client )
{
if( AllowJoinMsg(steamId,target_name) )
{
LogMessage( "\"%L\" allowed custom join message for player \"%s\" (Steam ID: %s)", client, target_name, steamId );
ReplyToCommand(client, "[SM] Allowed custom join message for player %s (Steam ID: %s)", target_name, steamId);
}
else
{
ReplyToCommand(client, "[SM] Player %s (Steam ID: %s) is already allowed custom join message", target_name, steamId);
}
}
bool:AllowJoinMsg( String:steamId[], String:player_name[] )
{
if(!KvJumpToKey(hKVCustomJoinMessages, steamId))
{
KvJumpToKey(hKVCustomJoinMessages, steamId, true);
KvSetString(hKVCustomJoinMessages, "playerwasnamed", player_name );
KvRewind(hKVCustomJoinMessages);
KeyValuesToFile(hKVCustomJoinMessages, g_fileset);
return true;
}
else
{
KvRewind(hKVCustomJoinMessages);
return false;
}
}
/*****************************************************************
A D M I N M E N U F U N C T I O N S
*****************************************************************/
public AdminMenu_AllowJoinMsg(Handle:topmenu,
TopMenuAction:action,
TopMenuObject:object_id,
param,
String:buffer[],
maxlength)
{
if (action == TopMenuAction_DisplayOption)
{
Format(buffer, maxlength, "%s", "Allow custom join message");
}
else if (action == TopMenuAction_SelectOption)
{
DisplayAllowJoinMsgMenu(param);
}
}
DisplayAllowJoinMsgMenu(client)
{
new Handle:menu = CreateMenu(MenuHandler_AllowJoinMsg);
decl String:title[100];
Format(title, sizeof(title), "%s:", "Allow custom join message");
SetMenuTitle(menu, title);
SetMenuExitBackButton(menu, true);
AddTargetsToMenu(menu, client, true, false);
DisplayMenu(menu, client, MENU_TIME_FOREVER);
}
public MenuHandler_AllowJoinMsg(Handle:menu, MenuAction:action, param1, param2)
{
if (action == MenuAction_End)
{
CloseHandle(menu);
}
else if (action == MenuAction_Cancel)
{
if (param2 == MenuCancel_ExitBack && hTopMenu != INVALID_HANDLE)
{
DisplayTopMenu(hTopMenu, param1, TopMenuPosition_LastCategory);
}
}
else if (action == MenuAction_Select)
{
decl String:info[32];
new userid, target;
new String:steamId[24];
new String:target_name[MAX_TARGET_LENGTH];
GetMenuItem(menu, param2, info, sizeof(info));
userid = StringToInt(info);
if ((target = GetClientOfUserId(userid)) == 0)
{
PrintToChat(param1, "[SM] %t", "Player no longer available");
}
else if (!CanUserTarget(param1, target))
{
PrintToChat(param1, "[SM] %t", "Unable to target");
}
else
{
GetClientName(target, target_name, sizeof(target_name));
//set allowed custom join in kv file
if( GetClientAuthId(target, steamId, sizeof(steamId)) )
{
DoAllowJoinMsg(steamId,target_name,param1);
//inform player of their enabled custom join msg
PrintToChat(target, "[SM] type sm_joinmsg in console to set your custom join message!");
}
else
{
PrintToChat(param1, "[SM] Unable to find player's steam id");
}
}
/* Re-draw the menu if they're still valid */
if (IsClientInGame(param1) && !IsClientInKickQueue(param1))
{
DisplayAllowJoinMsgMenu(param1);
}
}
}
disallow.sp
Spoiler
Code:
/*****************************************************************
F O R W A R D P U B L I C S
*****************************************************************/
SetupJoinMsg_DisAllow()
{
RegAdminCmd("sm_joinmsgoff", Command_DisAllowJoinMsg, CHECKFLAG, "sm_joinmsgoff <name or #userid> - disallows a client from setting a custom join message");
RegAdminCmd("sm_joinmsgoffid", Command_DisAllowJoinMsgID, CHECKFLAG, "sm_joinmsgoffid \"<steamId>\" - allows specified steamid from setting a custom join message");
}
OnAdminMenuReady_JoinMsg_DAllow(TopMenuObject:player_commands)
{
AddToTopMenu(hTopMenu,
"sm_joinmsgoff",
TopMenuObject_Item,
AdminMenu_DisAllowJoinMsg,
player_commands,
"sm_joinmsgoff",
CHECKFLAG);
}
/****************************************************************
C A L L B A C K F U N C T I O N S
****************************************************************/
public Action:Command_DisAllowJoinMsg(client, args)
{
decl String:target[65];
decl String:target_name[MAX_TARGET_LENGTH];
decl target_list[MAXPLAYERS];
decl target_count;
decl bool:tn_is_ml;
new String:steamId[24];
//not enough arguments, display usage
if (args < 1)
{
ReplyToCommand(client, "[SM] Usage: sm_joinmsgoff <name or #userid>");
return Plugin_Handled;
}
//get command arguments
GetCmdArg(1, target, sizeof(target));
//get the target of this command, return error if invalid
if ((target_count = ProcessTargetString(
target,
client,
target_list,
MAXPLAYERS,
COMMAND_FILTER_NO_MULTI,
target_name,
sizeof(target_name),
tn_is_ml)) <= 0)
{
ReplyToTargetError(client, target_count);
return Plugin_Handled;
}
//remove allowed custom join in kv file
if( target_count > 0 && GetClientAuthId(target_list[0], steamId, sizeof(steamId)) )
{
DoDisAllowJoinMsg( steamId, target_name, client );
}
else
{
ReplyToCommand(client, "[SM] Unable to find player's steam id");
}
return Plugin_Handled;
}
public Action:Command_DisAllowJoinMsgID(client, args)
{
new String:steamId[24];
//not enough arguments, display usage
if (args < 1)
{
ReplyToCommand(client, "[SM] Usage: sm_joinmsgoffid \"<steamId>\"");
return Plugin_Handled;
}
//get command arguments
GetCmdArg(1, steamId, sizeof(steamId));
//disallow steam id
DoDisAllowJoinMsg(steamId, "<unknown>", client);
return Plugin_Handled;
}
/*****************************************************************
P L U G I N F U N C T I O N S
*****************************************************************/
DoDisAllowJoinMsg( String:steamId[], String:target_name[], client )
{
if( DisAllowJoinMsg( steamId ) )
{
LogMessage( "\"%L\" disallowed custom join message for player \"%s\" (Steam ID: %s)", client, target_name, steamId );
ReplyToCommand(client, "[SM] Disallowed custom join message for player %s (Steam ID: %s)", target_name, steamId);
}
else
{
ReplyToCommand(client, "[SM] Player %s (Steam ID: %s) is not currently allowed a custom join message", target_name, steamId);
}
}
bool:DisAllowJoinMsg( String:steamId[] )
{
if(KvJumpToKey(hKVCustomJoinMessages, steamId))
{
KvDeleteThis(hKVCustomJoinMessages);
KvRewind(hKVCustomJoinMessages);
KeyValuesToFile(hKVCustomJoinMessages, g_fileset);
return true;
}
else
{
KvRewind(hKVCustomJoinMessages);
return false;
}
}
/*****************************************************************
A D M I N M E N U F U N C T I O N S
*****************************************************************/
public AdminMenu_DisAllowJoinMsg(Handle:topmenu,
TopMenuAction:action,
TopMenuObject:object_id,
param,
String:buffer[],
maxlength)
{
if (action == TopMenuAction_DisplayOption)
{
Format(buffer, maxlength, "%s", "Disallow custom join message");
}
else if (action == TopMenuAction_SelectOption)
{
DisplayDisAllowJoinMsgMenu(param);
}
}
DisplayDisAllowJoinMsgMenu(client)
{
new Handle:menu = CreateMenu(MenuHandler_DisAllowJoinMsg);
decl String:title[100];
Format(title, sizeof(title), "%s:", "Disallow custom join message");
SetMenuTitle(menu, title);
SetMenuExitBackButton(menu, true);
AddTargetsToMenu(menu, client, true, false);
DisplayMenu(menu, client, MENU_TIME_FOREVER);
}
public MenuHandler_DisAllowJoinMsg(Handle:menu, MenuAction:action, param1, param2)
{
if (action == MenuAction_End)
{
CloseHandle(menu);
}
else if (action == MenuAction_Cancel)
{
if (param2 == MenuCancel_ExitBack && hTopMenu != INVALID_HANDLE)
{
DisplayTopMenu(hTopMenu, param1, TopMenuPosition_LastCategory);
}
}
else if (action == MenuAction_Select)
{
decl String:info[32];
new userid, target;
new String:steamId[24];
new String:target_name[MAX_TARGET_LENGTH];
GetMenuItem(menu, param2, info, sizeof(info));
userid = StringToInt(info);
if ((target = GetClientOfUserId(userid)) == 0)
{
PrintToChat(param1, "[SM] %t", "Player no longer available");
}
else if (!CanUserTarget(param1, target))
{
PrintToChat(param1, "[SM] %t", "Unable to target");
}
else
{
GetClientName(target, target_name, sizeof(target_name));
//remove allowed custom join in kv file
if( GetClientAuthId(target, steamId, sizeof(steamId)) )
{
DoDisAllowJoinMsg( steamId, target_name, param1 );
}
else
{
PrintToChat(param1, "[SM] Unable to find player's steam id");
}
}
/* Re-draw the menu if they're still valid */
if (IsClientInGame(param1) && !IsClientInKickQueue(param1))
{
DisplayDisAllowJoinMsgMenu(param1);
}
}
}
set.sp
Spoiler
Code:
new Handle:g_CvarAutoAllowMsg = INVALID_HANDLE;
new Handle:g_CvarDisableClientJoinMsg = INVALID_HANDLE;
/*****************************************************************
F O R W A R D P U B L I C S
*****************************************************************/
SetupJoinMsg_Set()
{
RegAdminCmd("sm_setjoinmsg", Command_SetJoinMsg, CHECKFLAG, "sm_setjoinmsg <name or #userid> \"<message>\" - sets a custom join message for specified player");
RegAdminCmd("sm_setjoinmsgid", Command_SetJoinMsgID, CHECKFLAG, "sm_setjoinmsgid \"<steamId>\" \"<message>\" - sets a custom join message for specified steam ID");
RegConsoleCmd("sm_joinmsg", Command_JoinMsg, "sm_joinmsg [message] - Sets a message to be displayed when you join the game, or returns current message");
g_CvarAutoAllowMsg = CreateConVar("sm_ca_autoallowmsg", "1", "Always allow custom join messages for admins with the ADMIN_KICK flag");
g_CvarDisableClientJoinMsg = CreateConVar("sm_ca_disableclientmsgchange", "0", "Prevent clients from being able to change their own custom join message");
}
/****************************************************************
C A L L B A C K F U N C T I O N S
****************************************************************/
public Action:Command_SetJoinMsg(client, args)
{
decl String:target[65];
decl String:target_name[MAX_TARGET_LENGTH];
decl target_list[MAXPLAYERS];
decl target_count;
decl bool:tn_is_ml;
new String:steamId[24];
new String:message[MSGLENGTH + 2];
decl charsSet;
//not enough arguments, display usage
if (args != 2)
{
ReplyToCommand(client, "[SM] Usage: sm_setjoinmsg <name or #userid> \"<message>\"");
return Plugin_Handled;
}
//get command arguments
GetCmdArg(1, target, sizeof(target));
//check message length
charsSet = GetCmdArg( 2, message, sizeof(message) );
TrimString(message);
if( charsSet > MSGLENGTH)
{
ReplyToCommand(client, "[SM] Maximum message length is %d characters", MSGLENGTH );
return Plugin_Handled;
}
//get the target of this command, return error if invalid
if ((target_count = ProcessTargetString(
target,
client,
target_list,
MAXPLAYERS,
COMMAND_FILTER_NO_MULTI,
target_name,
sizeof(target_name),
tn_is_ml)) <= 0)
{
ReplyToTargetError(client, target_count);
return Plugin_Handled;
}
//set custom join msg in kv file
if( target_count > 0 && GetClientAuthId (target_list[0], steamId, sizeof(steamId)) )
{
CheckAutoAdd( target_list[0], target_name, steamId);
if( SetJoinMsg( steamId, message ) )
{
LogMessage( "\"%L\" set custom join message for player \"%s\" (Steam ID: %s)", client, target_name, steamId );
ReplyToCommand(client, "[SM] Auto join message set for player %s", target_name);
}
else
{
ReplyToCommand(client, "[SM] Player %s is not allowed to have a custom join message", target_name);
}
}
else
{
ReplyToCommand(client, "[SM] Unable to find player's steam id");
}
return Plugin_Handled;
}
public Action:Command_SetJoinMsgID(client, args)
{
decl String:steamId[24];
new String:message[MSGLENGTH + 2];
decl charsSet;
//not enough arguments, display usage
if (args != 2)
{
ReplyToCommand(client, "[SM] Usage: sm_setjoinmsgid \"<steamId>\" \"<message>\"");
return Plugin_Handled;
}
//get command arguments
GetCmdArg(1, steamId, sizeof(steamId));
//check message length
charsSet = GetCmdArg( 2, message, sizeof(message) );
TrimString(message);
if( charsSet > MSGLENGTH)
{
ReplyToCommand(client, "[SM] Maximum message length is %d characters", MSGLENGTH );
return Plugin_Handled;
}
//set custom join msg in kv file
if( SetJoinMsg( steamId, message ) )
{
LogMessage( "\"%L\" set custom join message for steam id: \"%s\"", client, steamId );
ReplyToCommand(client, "[SM] Auto join message set for steam ID \"%s\"", steamId);
}
else
{
ReplyToCommand(client, "[SM] Steam ID \"%s\" is not allowed to have a custom join message", steamId);
}
return Plugin_Handled;
}
public Action:Command_JoinMsg(client, args)
{
new String:steamId[24];
new String:message[MSGLENGTH + 2];
decl charsSet;
decl String:target_name[MAX_TARGET_LENGTH];
//not enough arguments, display current join msg
if (args < 1)
{
if( client && GetClientAuthId(client, steamId, sizeof(steamId)) )
{
//get from kv file
KvRewind(hKVCustomJoinMessages);
if(KvJumpToKey(hKVCustomJoinMessages, steamId) && !GetConVarInt(g_CvarDisableClientJoinMsg))
{
KvGetString(hKVCustomJoinMessages, "message", message, sizeof(message), "");
ReplyToCommand(client, "[SM] Your join message is: \"%s\"", message);
}
else
{
ReplyToCommand(client, "[SM] You are not allowed to have a custom join message");
}
KvRewind(hKVCustomJoinMessages);
}
else
{
LogMessage( "\"%L\" set their custom join message", client );
ReplyToCommand(client, "[SM] Unable to find your steam id");
}
return Plugin_Handled;
}
//check message length
charsSet = GetCmdArg(1, message, sizeof(message) );
TrimString(message);
if( charsSet > MSGLENGTH)
{
ReplyToCommand(client, "[SM] Maximum message length is %d characters", MSGLENGTH );
return Plugin_Handled;
}
//set custom join msg in kv file
if( client && GetClientAuthId(client, steamId, sizeof(steamId)) )
{
GetClientName( client, target_name, sizeof(target_name));
CheckAutoAdd( client, target_name, steamId);
if( SetJoinMsg( steamId, message ) )
{
ReplyToCommand(client, "[SM] Your auto join message is set!");
}
else
{
ReplyToCommand(client, "[SM] You are not allowed to have a custom join message");
}
}
else
{
ReplyToCommand(client, "[SM] Unable to find your steam id");
}
return Plugin_Handled;
}
/*****************************************************************
P L U G I N F U N C T I O N S
*****************************************************************/
bool:SetJoinMsg( String:steamId[], String:message[] )
{
if(KvJumpToKey(hKVCustomJoinMessages, steamId))
{
KvSetString(hKVCustomJoinMessages, "message", message );
KvRewind(hKVCustomJoinMessages);
KeyValuesToFile(hKVCustomJoinMessages, g_fileset);
return true;
}
else
{
KvRewind(hKVCustomJoinMessages);
return false;
}
}
bool:CheckAutoAdd( target, String:playerName[], String:steamId[] )
{
new AdminId:id = GetUserAdmin(target);
new bool:has_kick;
has_kick = (id == INVALID_ADMIN_ID) ? false : GetAdminFlag(id, Admin_Kick);
if(GetConVarInt(g_CvarAutoAllowMsg) && has_kick)
{
if( AllowJoinMsg( steamId, playerName ) )
{
LogMessage( "Automatically allowed custom join message for player \"%s\" (Steam ID: %s) due to sm_ca_autoallowmsg and admin kick flag present", playerName, steamId );
}
return true;
}
else
{
return false;
}
}
sound.sp
Spoiler
Code:
/*****************************************************************
F O R W A R D P U B L I C S
*****************************************************************/
SetupJoinSound_Set()
{
RegAdminCmd("sm_setjoinsnd", Command_SetJoinSnd, CHECKFLAG, "sm_setjoinsnd <name or #userid> \"<path to sound file>\" - sets a custom join sound for specified player");
RegAdminCmd("sm_setjoinsndid", Command_SetJoinSndID, CHECKFLAG, "sm_setjoinsndid \"<steamId>\" \"<path to sound file>\" - sets a custom join sound for specified steam ID");
RegAdminCmd("sm_playsnd", Command_PlaySnd, CHECKFLAG, "sm_playsnd \"<path to sound file>\" [entity] - Plays sound file on all clients, entity is optional - default 'from player'");
}
/****************************************************************
C A L L B A C K F U N C T I O N S
****************************************************************/
public Action:Command_SetJoinSnd(client, args)
{
decl String:target[65];
decl String:target_name[MAX_TARGET_LENGTH];
decl target_list[MAXPLAYERS];
decl target_count;
decl bool:tn_is_ml;
new String:steamId[24];
new String:sndFile[SOUNDFILE_PATH_LEN];
decl charsSet;
//not enough arguments, display usage
if (args != 2)
{
ReplyToCommand(client, "[SM] Usage: sm_setjoinsnd <name or #userid> \"<path to sound file>\"");
return Plugin_Handled;
}
//get command arguments
GetCmdArg(1, target, sizeof(target));
//check message length
charsSet = GetCmdArg( 2, sndFile, sizeof(sndFile) );
if( charsSet > SOUNDFILE_PATH_LEN)
{
ReplyToCommand(client, "[SM] Maximum sound file path length is %d characters", MSGLENGTH );
return Plugin_Handled;
}
//get the target of this command, return error if invalid
if ((target_count = ProcessTargetString(
target,
client,
target_list,
MAXPLAYERS,
COMMAND_FILTER_NO_MULTI,
target_name,
sizeof(target_name),
tn_is_ml)) <= 0)
{
ReplyToTargetError(client, target_count);
return Plugin_Handled;
}
//set custom join msg in kv file
if( target_count > 0 && GetClientAuthId(target_list[0], steamId, sizeof(steamId)) )
{
if( SetJoinSnd( steamId, sndFile ) )
{
LogMessage( "\"%L\" set custom join sound for player \"%s\" (Steam ID: %s)", client, target_name, steamId );
ReplyToCommand(client, "[SM] Auto join sound set for player %s", target_name);
}
else
{
ReplyToCommand(client, "[SM] Player %s is not allowed to have a custom join sound", target_name);
}
}
else
{
ReplyToCommand(client, "[SM] Unable to find player's steam id");
}
return Plugin_Handled;
}
public Action:Command_SetJoinSndID(client, args)
{
decl String:steamId[24];
new String:sndFile[SOUNDFILE_PATH_LEN];
decl charsSet;
//not enough arguments, display usage
if (args != 2)
{
ReplyToCommand(client, "[SM] Usage: sm_setjoinsndid \"<steamId>\" \"<path to sound file>\"");
return Plugin_Handled;
}
//get command arguments
GetCmdArg(1, steamId, sizeof(steamId));
//check message length
charsSet = GetCmdArg( 2, sndFile, sizeof(sndFile) );
if( charsSet > SOUNDFILE_PATH_LEN)
{
ReplyToCommand(client, "[SM] Maximum sound file path length is %d characters", MSGLENGTH );
return Plugin_Handled;
}
//set custom join msg in kv file
if( SetJoinSnd( steamId, sndFile ) )
{
LogMessage( "\"%L\" set custom join sound for steam id: \"%s\"", client, steamId );
ReplyToCommand(client, "[SM] Auto join sound set for steam ID \"%s\"", steamId);
}
else
{
ReplyToCommand(client, "[SM] Steam ID \"%s\" is not allowed to have a custom join sound", steamId);
}
return Plugin_Handled;
}
public Action:Command_PlaySnd(client, args)
{
decl String:sFile[256];
new entity = SOUND_FROM_PLAYER;
decl String:arg2[20];
//not enough arguments, display usage
if (args < 1)
{
ReplyToCommand(client, "[SM] Usage: sm_playsnd \"<path to sound file>\" [entity]");
return Plugin_Handled;
}
//get entity param, if supplied
if (args > 1)
{
GetCmdArg(2, arg2, sizeof(arg2));
if (StringToIntEx(arg2, entity) == 0)
{
ReplyToCommand(client, "[SM] Invalid entity");
return Plugin_Handled;
}
}
//get command arguments
GetCmdArg(1, sFile, sizeof(sFile));
PrecacheSound(sFile);
//play sound
EmitSoundToAll( sFile, entity);
ReplyToCommand(client, "[SM] Played Sound \"%s\"", sFile);
return Plugin_Handled;
}
/*****************************************************************
P L U G I N F U N C T I O N S
*****************************************************************/
bool:SetJoinSnd( String:steamId[], String:sndFile[] )
{
if(KvJumpToKey(hKVCustomJoinMessages, steamId))
{
KvSetString(hKVCustomJoinMessages, "soundfile", sndFile );
KvRewind(hKVCustomJoinMessages);
KeyValuesToFile(hKVCustomJoinMessages, g_fileset);
return true;
}
else
{
KvRewind(hKVCustomJoinMessages);
return false;
}
}
LoadSoundFilesCustomPlayer()
{
new String:sndFile[SOUNDFILE_PATH_LEN];
new String:sndFileFullPath[SOUNDFILE_PATH_LEN + 6];
KvGotoFirstSubKey(hKVCustomJoinMessages);
//cycle thru soundfile values, if they exist, add to download table and precache
do
{
KvGetString(hKVCustomJoinMessages,"soundfile", sndFile, sizeof(sndFile) );
if( strlen( sndFile ) > 0 )
{
Format(sndFileFullPath, sizeof(sndFileFullPath), "sound/%s", sndFile);
if( FileExists( sndFileFullPath ) )
{
AddFileToDownloadsTable(sndFileFullPath);
PrecacheSound(sndFile);
}
else
{
LogError( "[CANNOUNCE] Sound file '%s' does not exist on server", sndFileFullPath );
}
}
}
while (KvGotoNextKey(hKVCustomJoinMessages));
KvRewind(hKVCustomJoinMessages);
}
So in your case it should look like GetClientAuthId(target_list[0], PUT THE AUTH ID TYPE HERE, steamId, sizeof(steamId)). I'm not sure which one you would want though. At a glance it looks like that should solve most of your problems.
(Also, I'm pretty sure this can go in Scripting and not General).
So in your case it should look like GetClientAuthId(target_list[0], PUT THE AUTH ID TYPE HERE, steamId, sizeof(steamId)). I'm not sure which one you would want though. At a glance it looks like that should solve most of your problems.
(Also, I'm pretty sure this can go in Scripting and not General).
So i need to replace ((steamId) with something like ((AuthId_Steam3) ?
Or do i need to put if( target_count > 0 && GetClientAuthId(target_list[0], AuthId_SteamID64, steamId, sizeof(steamId)) )