Plugin works fine, but it's giving me these errors:
Code:
L 08/27/2016 - 08:40:49: [SM] Call stack trace:
L 08/27/2016 - 08:40:49: [SM] [0] Format
L 08/27/2016 - 08:40:49: [SM] [1] Line 164, /groups/sourcemod/upload_tmp/textF103Ip.sp::Timer_UpdateHudHint()
L 08/27/2016 - 08:40:49: [SM] Exception reported: Client index 140 is invalid
L 08/27/2016 - 08:40:49: [SM] Blaming: speclist.smx()
new Handle:HudHintTimers[MAXPLAYERS+1]; new Handle:sm_speclist_enabled; new Handle:sm_speclist_allowed; new Handle:sm_speclist_adminonly; new bool:g_Enabled; new bool:g_AdminOnly;
public Plugin:myinfo = { name = "Spectator List", author = "GoD-Tony", description = "View who is spectating you in CS:S", version = PLUGIN_VERSION, url = "http://www.sourcemod.net/" };
public OnPluginStart() { CreateConVar("sm_speclist_version", PLUGIN_VERSION, "Spectator List Version", FCVAR_PLUGIN|FCVAR_SPONLY|FCVAR_REPLICATED|FCVAR_NOTIFY|FCVAR_DONTRECORD); sm_speclist_enabled = CreateConVar("sm_speclist_enabled","1","Enables the spectator list for all players by default."); sm_speclist_allowed = CreateConVar("sm_speclist_allowed","1","Allows players to enable spectator list manually when disabled by default."); sm_speclist_adminonly = CreateConVar("sm_speclist_adminonly","0","Only admins can use the features of this plugin.");
public OnConVarChange(Handle:hCvar, const String:oldValue[], const String:newValue[]) { if (hCvar == sm_speclist_enabled) { g_Enabled = GetConVarBool(sm_speclist_enabled);
if (g_Enabled) { // Enable timers on all players in game. for(new i = 1; i <= MaxClients; i++) { if (!IsClientInGame(i)) continue;
CreateHudHintTimer(i); } } else { // Kill all of the active timers. for(new i = 1; i <= MaxClients; i++) KillHudHintTimer(i); } } else if (hCvar == sm_speclist_adminonly) { g_AdminOnly = GetConVarBool(sm_speclist_adminonly);
if (g_AdminOnly) { // Kill all of the active timers. for(new i = 1; i <= MaxClients; i++) KillHudHintTimer(i);
// Enable timers on all admins in game. for(new i = 1; i <= MaxClients; i++) { if (!IsClientInGame(i)) continue;
CreateHudHintTimer(i); } } } }
public OnClientPostAdminCheck(client) { if (g_Enabled) CreateHudHintTimer(client); }
public OnClientDisconnect(client) { KillHudHintTimer(client); }
// Using 'sm_speclist' to toggle the spectator list per player. public Action:Command_SpecList(client, args) { if (HudHintTimers[client] != INVALID_HANDLE) { KillHudHintTimer(client); ReplyToCommand(client, "[SM] Spectator list disabled."); } else if (g_Enabled || GetConVarBool(sm_speclist_allowed)) { CreateHudHintTimer(client); ReplyToCommand(client, "[SM] Spectator list enabled."); }
return Plugin_Handled; }
public Action:Timer_UpdateHudHint(Handle:timer, any:client) { new iSpecModeUser = GetEntProp(client, Prop_Send, "m_iObserverMode"); new iSpecMode, iTarget, iTargetUser; new bool:bDisplayHint = false; new bool:bOther = false;
decl String:szText[511]; szText[0] = '\0';
// Dealing with a client who is in the game and playing. if (IsPlayerAlive(client)) { for(new i = 1; i <= MaxClients; i++) { if (!IsClientInGame(i) || !IsClientObserver(i)) continue;
// The client isn't spectating any one person, so ignore them. if (iSpecMode != SPECMODE_FIRSTPERSON && iSpecMode != SPECMODE_3RDPERSON) continue;
// Find out who the client is spectating. iTarget = GetEntPropEnt(i, Prop_Send, "m_hObserverTarget");
// Are they spectating the same player as User? if (iTarget == iTargetUser) Format(szText, sizeof(szText), "%s%N, ", szText, i); } }
/* We do this to prevent displaying a message to a player if no one is spectating them anyway. */ if (bDisplayHint) { if (!bOther) { Format(szText, sizeof(szText), "<font size='15' color='#FF0000'>Spectating %N:\n</font><font size='14' color='#FFFFFF'>%s", client, szText); } Format(szText, sizeof(szText), "%s</font>", szText); PrintHintText(client, szText); bDisplayHint = false; }
Its not checking if the index is valid, meaning if it's associated with an actual in-game player.
Try use this:
PHP Code:
/** * Check if a client index is a player. * * @param num1 Client index. * @return True if index is player, false if not. */ stock bool IsValidClient(int client) { return (client >= 1 && client <= MaxClients && IsClientConnected(client) && IsClientInGame(client) && !IsClientSourceTV(client)); }
Last edited by Michael Shoe Maker; 08-27-2016 at 12:03.