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

Invalid Player index


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Halt
Senior Member
Join Date: Jan 2015
Location: Black Mesa
Old 09-19-2017 , 22:21   Invalid Player index
Reply With Quote #1

Any idea why this would return a -1 client index?

PHP Code:
GetRandomPlayer()
{
    new 
players[MaxClients 1];
    new 
ClientCount;
    for    (new 
1<= MaxClientsi++)
        if(
IsClientInGame(i))
            if    (
PlayerTeam[i] == TFTeam_Blue && PlayerClass[i] >= 1)
                
players[ClientCount++] = i;
    return (
ClientCount == 0) ? -players[GetRandomInt(0ClientCount 1)];

Halt is offline
headline
SourceMod Moderator
Join Date: Mar 2015
Old 09-19-2017 , 23:50   Re: Invalid Player index
Reply With Quote #2

When no players match the following check
PHP Code:
if (PlayerTeam[i] == TFTeam_Blue && PlayerClass[i] >= 1
headline is offline
Halt
Senior Member
Join Date: Jan 2015
Location: Black Mesa
Old 09-20-2017 , 00:33   Re: Invalid Player index
Reply With Quote #3

Wow.... I'm a moron, I never had a check if players are even in the server... my mod was just calling this on an empty server. Thanks man.
Halt is offline
Bacardi
Veteran Member
Join Date: Jan 2010
Location: mom's basement
Old 09-20-2017 , 09:31   Re: Invalid Player index
Reply With Quote #4

...why you not use GetClientTeam(client) to get client team index ?
__________________
Do not Private Message @me
Bacardi is offline
Halt
Senior Member
Join Date: Jan 2015
Location: Black Mesa
Old 09-20-2017 , 10:27   Re: Invalid Player index
Reply With Quote #5

I do, but I get it when I client spawns and store it in a global variable (PlayerTeam)
Halt is offline
Bacardi
Veteran Member
Join Date: Jan 2010
Location: mom's basement
Old 09-20-2017 , 11:40   Re: Invalid Player index
Reply With Quote #6

Quote:
Originally Posted by Halt View Post
I do, but I get it when I client spawns and store it in a global variable (PlayerTeam)
...roger that. I don't want to start preach
__________________
Do not Private Message @me
Bacardi is offline
Halt
Senior Member
Join Date: Jan 2015
Location: Black Mesa
Old 09-20-2017 , 14:16   Re: Invalid Player index
Reply With Quote #7

Quote:
Originally Posted by Bacardi View Post
...roger that. I don't want to start preach
No please, I'm in the business of learning. If I'm doing something improperly please tell me why.
Halt 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 11:56.


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