Raised This Month: $32 Target: $400
 8% 

When starting a server, client index 1 is apparently invalid.


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
dilalmon
AlliedModders Donor
Join Date: Apr 2013
Old 04-17-2015 , 23:52   When starting a server, client index 1 is apparently invalid.
Reply With Quote #1

There's this code OnPluginStart on a plugin just in case the plugin is reloaded mid-game:

Code:
    for (new idx = 1; idx < MAXPLAYERS; idx++)
    {
        if (IsClientInGame (idx))
        {
            ClientConnected (idx);
        }
    }
And this always outputs this error in the log when the server is started without any players for the first time:

Code:
L 04/17/2015 - 04:08:49: [SM] Native "IsClientInGame" reported: Client index 1 is invalid
Why is this a case and how would I be able to prevent it?
dilalmon is offline
necavi
Veteran Member
Join Date: Sep 2010
Old 04-18-2015 , 00:18   Re: When starting a server, client index 1 is apparently invalid.
Reply With Quote #2

Wait until OnMapStart to run that code (at which point you can use for(int idx = 1; idx <= MaxClients; idx++) which is preferable anyway).
necavi is offline
Dr. Greg House
Professional Troll,
Part-Time Asshole
Join Date: Jun 2010
Old 04-18-2015 , 08:19   Re: When starting a server, client index 1 is apparently invalid.
Reply With Quote #3

No. Since this is lateload logic check if you're lateloading the plugin, then do whatever stuff you like in OnPluginStart.
__________________
Santa or Satan?

Watch out when you're paying people for private requests! Most stuff already exists and you can hardly assess the quality of what you'll get, and if it's worth the money.
Dr. Greg House is offline
Miu
Veteran Member
Join Date: Nov 2013
Old 04-18-2015 , 08:31   Re: When starting a server, client index 1 is apparently invalid.
Reply With Quote #4

um, are you actually checking for late loads or just doing this all the time in onpluginstart?
Miu is offline
Chdata
Veteran Member
Join Date: Aug 2012
Location: Computer Chair, Illinois
Old 04-18-2015 , 14:24   Re: When starting a server, client index 1 is apparently invalid.
Reply With Quote #5

I hear checking for late loads via AskPluginLoad2 can be unreliable, and I did have problems with it before, until FlaminSarge told me it's unreliable and I changed my method of 'detecting' that. I was trying to make something happen during only the first 1-2 rounds and if the plugin is sm plugins reload-ed, then it doesn't do that. So instead I used GetTeamScore() on both teams instead. I have a logging plugin that only prints "Changing map to x" if GetGameTime() is less than 5.0 - 10.0 or so, to prevent spamming map change messages each time I reload the plugin.

I also hear that MaxClients may not be initialized during OnPluginStart sometimes and that those types of loops should be in OnMapStart instead, where it will be initialized and OnMapStart is always called on loads too anyway.
__________________

Last edited by Chdata; 04-18-2015 at 14:26.
Chdata is offline
Darkness_
Veteran Member
Join Date: Nov 2014
Old 04-18-2015 , 14:51   Re: When starting a server, client index 1 is apparently invalid.
Reply With Quote #6

I've done this in all of my plugins that utilize SDKHooks and have never encountered an error like this.
Except I used for (int i = 1; i <= MaxClients; i++).

Last edited by Darkness_; 04-18-2015 at 14:51.
Darkness_ is offline
WildCard65
Veteran Member
Join Date: Aug 2013
Location: Canada
Old 04-18-2015 , 17:17   Re: When starting a server, client index 1 is apparently invalid.
Reply With Quote #7

Quote:
Originally Posted by Darkness_ View Post
I've done this in all of my plugins that utilize SDKHooks and have never encountered an error like this.
Except I used for (int i = 1; i <= MaxClients; i++).
MaxClients is always 0 in OnPluginStart()(unless plugin was late loaded), always do things with MaxClients in OnMapStart() as MaxClients gets set b4 then.
__________________

Last edited by WildCard65; 04-18-2015 at 17:17.
WildCard65 is offline
Dr. Api
BANNED
Join Date: Mar 2015
Location: France
Old 04-21-2015 , 19:04   Re: When starting a server, client index 1 is apparently invalid.
Reply With Quote #8

MaxClients = 0 OnPluginStart ?? Sure ? Cause I use some function and it always works and no error.

Last edited by Dr. Api; 04-21-2015 at 19:04.
Dr. Api is offline
WildCard65
Veteran Member
Join Date: Aug 2013
Location: Canada
Old 04-21-2015 , 20:07   Re: When starting a server, client index 1 is apparently invalid.
Reply With Quote #9

Ok, correction about MaxClients, It's not always going to be correct b4 map is loaded which you just experienced with the native error because of this:
PHP Code:
if ((index 1) || (index playerhelpers->GetMaxClients())) 
which means that 1 was greater then the max clients server can have at time native was called.
__________________
WildCard65 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 22:48.


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