Raised This Month: $ Target: $400
 0% 

Where is the error? Exception reported: Client index 0 is invalid


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Kempus
Member
Join Date: Jan 2016
Old 07-28-2016 , 22:36   Where is the error? Exception reported: Client index 0 is invalid
Reply With Quote #1

Hi,
I get some errors in my server console from one plugin. What is wrong?

Error code:
Code:
L 07/29/2016 - 04:36:40: [SM] Exception reported: Client index 0 is invalid
L 07/29/2016 - 04:36:40: [SM] Blaming: reklama.smx()
L 07/29/2016 - 04:36:40: [SM] Call stack trace:
L 07/29/2016 - 04:36:40: [SM]   [0] IsClientConnected
L 07/29/2016 - 04:36:40: [SM]   [1] Line 23, E:\codek\addons\sourcemod\scripting\reklama.sp::Timer_Advertise()
Here is plugin code:
Code:
#include <sourcemod>
#include <sdktools>
#include <cstrike>

public Plugin:myinfo =
{
    name = "Reklama",
    author = "Kempus",
    description = "Plugin wyświetlający reklamę przy wejściu",
    version = "1.0",
    url = "http://google.pl/"
};

public void OnClientPutInServer(int client)
{
    CreateTimer(10.0, Timer_Advertise, GetClientSerial(client), true);
}

public Action Timer_Advertise(Handle timer, any data)
{
    int client = GetClientFromSerial(data);

    if (!IsClientConnected(client) || CheckCommandAccess(client, "sm_reklama", ADMFLAG_RESERVATION))
        return Plugin_Stop; // Our client is gone or have access to the admin command sm_reklama... ABORT!
    else if (IsClientInGame(client))
    {
        FakeClientCommandEx(client, "say !reklama"); // say !reklama
        return Plugin_Stop; // We done what we needed, end timer.
    }

    return Plugin_Continue; // Timer will trigger again.
}

Last edited by Kempus; 07-28-2016 at 22:36.
Kempus is offline
ddhoward
Veteran Member
Join Date: May 2012
Location: California
Old 07-28-2016 , 23:06   Re: Where is the error? Exception reported: Client index 0 is invalid
Reply With Quote #2

GetClientFromSerial returns 0 if the client is no longer connected.

Passing 0 through IsClientConnected will result in an error, as 0 is not between 1 and MaxClients.

You should do a client != 0 check instead of an IsClientConnected check.
__________________
ddhoward is offline
Miu
Veteran Member
Join Date: Nov 2013
Old 07-29-2016 , 11:58   Re: Where is the error? Exception reported: Client index 0 is invalid
Reply With Quote #3

problem is that it's zero
Miu is offline
Grey83
Veteran Member
Join Date: Dec 2014
Location: Ukraine
Old 07-29-2016 , 12:58   Re: Where is the error? Exception reported: Client index 0 is invalid
Reply With Quote #4

May be better to do it this way?
PHP Code:
#include <sourcemod>
#include <sdktools>
#include <cstrike>

Handle AdvTimer[MAXPLAYERS+1];

public 
Plugin:myinfo =
{
    
name "Reklama",
    
author "Kempus",
    
description "Plugin wyświetlający reklamę przy wejściu",
    
version "1.0",
    
url "https://forums.alliedmods.net/showthread.php?t=285715"
}

public 
void OnClientPostAdminCheck(int client)
{
    if(
client <= MaxClients && !CheckCommandAccess(client"sm_reklama"ADMFLAG_RESERVATION))
        
AdvTimer[client] = CreateTimer(10.0Timer_AdvertiseclientTIMER_REPEAT);
}

public 
void OnClientDisconnect(int client)
{
    if(
AdvTimer[client] != null)
    {
        
KillTimer(AdvTimer[client]);
        
AdvTimer[client] = null;
    }
}

public 
Action Timer_Advertise(Handle timerany client)
{
    if(
IsClientInGame(client))
    {
        
FakeClientCommandEx(client"say !reklama"); // say !reklama
        
OnClientDisconnect(client);
    }

Timers
__________________

Last edited by Grey83; 07-29-2016 at 13:00.
Grey83 is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 05:44.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode