Raised This Month: $51 Target: $400
 12% 

[SM] Exception reported: Client index 0 is invalid


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
beastedout
Member
Join Date: Aug 2018
Old 08-25-2018 , 05:43   [SM] Exception reported: Client index 0 is invalid
Reply With Quote #1

What am I doing wrong ;_;? No Compilation error! Server Console error (in title) whenever round starting..
PHP Code:
#include <sourcemod>


public void OnPluginStart()
{
    
HookEvent("round_start"OnRoundStart);
}
public 
void OnRoundStart(Handle eventchar[] namebool dbc)
{
    new 
client GetClientOfUserId(GetEventInt(event,"userid"));
    if (
GetClientTeam(client) == 2
    {
        
PrintToChat(client,"Hello Terrorists!");
    }

beastedout is offline
Ilusion9
Veteran Member
Join Date: Jun 2018
Location: Romania
Old 08-25-2018 , 06:17   Re: [SM] Exception reported: Client index 0 is invalid
Reply With Quote #2

round_start doesn't have a variable called userid.

PHP Code:
#include <sourcemod>


public void OnPluginStart()
{
    
HookEvent("round_start"OnRoundStart);
}
public 
void OnRoundStart(Handle eventchar[] namebool dbc)
{
    for(
int i 1<= MaxClientsi++)
    {
        if(
IsClientInGame(i))
        {
            if (
GetClientTeam(i) == 2
            {
                
PrintToChat(i,"Hello Terrorists!");
            }
        }
    }


Last edited by Ilusion9; 08-25-2018 at 06:18.
Ilusion9 is offline
beastedout
Member
Join Date: Aug 2018
Old 08-25-2018 , 11:56   Re: [SM] Exception reported: Client index 0 is invalid
Reply With Quote #3

Quote:
Originally Posted by Ilusion9 View Post
round_start doesn't have a variable called userid.

PHP Code:
#include <sourcemod>


public void OnPluginStart()
{
    
HookEvent("round_start"OnRoundStart);
}
public 
void OnRoundStart(Handle eventchar[] namebool dbc)
{
    for(
int i 1<= MaxClientsi++)
    {
        if(
IsClientInGame(i))
        {
            if (
GetClientTeam(i) == 2
            {
                
PrintToChat(i,"Hello Terrorists!");
            }
        }
    }

OO, thanks man!
beastedout is offline
Neuro Toxin
Veteran Member
Join Date: Oct 2013
Location: { closing the void; }
Old 08-25-2018 , 21:31   Re: [SM] Exception reported: Client index 0 is invalid
Reply With Quote #4

CS_TEAM_T should be used instead of 2 for readability
__________________
Neuro Toxin is offline
mug1wara
AlliedModders Donor
Join Date: Jun 2018
Old 08-26-2018 , 06:19   Re: [SM] Exception reported: Client index 0 is invalid
Reply With Quote #5

Quote:
Originally Posted by Neuro Toxin View Post
CS_TEAM_T should be used instead of 2 for readability
What?!
mug1wara is offline
Neuro Toxin
Veteran Member
Join Date: Oct 2013
Location: { closing the void; }
Old 08-26-2018 , 07:38   Re: [SM] Exception reported: Client index 0 is invalid
Reply With Quote #6

Code:
GetClientTeam(i) == CS_TEAM_T
__________________
Neuro Toxin is offline
mug1wara
AlliedModders Donor
Join Date: Jun 2018
Old 08-26-2018 , 09:09   Re: [SM] Exception reported: Client index 0 is invalid
Reply With Quote #7

Quote:
Originally Posted by Neuro Toxin View Post
Code:
GetClientTeam(i) == CS_TEAM_T
I totally understood that.

But to be totally honest, making a comment that says "Use CS_TEAM_T instead of 2" is just ridiculously dumb.
mug1wara is offline
DarkDeviL
SourceMod Moderator
Join Date: Apr 2012
Old 08-26-2018 , 09:26   Re: [SM] Exception reported: Client index 0 is invalid
Reply With Quote #8

Quote:
Originally Posted by mug1wara View Post
But to be totally honest, making a comment that says "Use CS_TEAM_T instead of 2" is just ridiculously dumb.
Constructive criticism is not "ridiculously dumb".

Frowning upon constructive criticism is "ridiculously dumb" though.

@Neuro Toxin is right, use == CT_TEAM_CT, etc. for readability. The team numbers are not the same in-game, and as such, things could confuse people with == 1, == 2, .. etc. in the code. CT_TEAM_CT would be easy to understand by reading the code.
__________________
Mostly known as "DarkDeviL".

Dropbox FastDL: Public folder will no longer work after March 15, 2017!
For more info, see the [SRCDS Thread], or the [HLDS Thread].
DarkDeviL is offline
Powerlord
AlliedModders Donor
Join Date: Jun 2008
Location: Seduce Me!
Old 08-26-2018 , 09:57   Re: [SM] Exception reported: Client index 0 is invalid
Reply With Quote #9

Quote:
Originally Posted by Neuro Toxin View Post
CS_TEAM_T should be used instead of 2 for readability
That adds a dependency on the cstrike module, though.

Right now it works on any game, although it'd be weird to refer to the Survivors (L4D/L4D2), RED team (TF2), Combine (HL2:DM), or Allies (DoD:S) as "Terrorists".
__________________
Not currently working on SourceMod plugin development.

Last edited by Powerlord; 08-26-2018 at 09:59.
Powerlord is offline
mug1wara
AlliedModders Donor
Join Date: Jun 2018
Old 08-26-2018 , 14:08   Re: [SM] Exception reported: Client index 0 is invalid
Reply With Quote #10

Quote:
Originally Posted by Powerlord View Post
That adds a dependency on the cstrike module, though.

Right now it works on any game, although it'd be weird to refer to the Survivors (L4D/L4D2), RED team (TF2), Combine (HL2M), or Allies (DoD:S) as "Terrorists".
That's what I thought!
mug1wara 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:09.


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