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

[L4D] HELP: IsClientConnected and IsClientInGame return FALSE always


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
axelnieves2012
Senior Member
Join Date: Oct 2014
Location: Argentina
Old 01-19-2019 , 23:37   [L4D] HELP: IsClientConnected and IsClientInGame return FALSE always
Reply With Quote #1

Hello, I need help. I'm trying to find where is the bug since hours ago and cannot find it.
These two functions are ALWAYS returning FALSE.

WHAT IM TRYING TO DO....
I Need to check all players and collect some of them, according to some conditions (live and dead)
In this script, all players should be taken because I decided to collect live and dead ones on cvars.

I am playing alone with 3 bots.
PHP Code:
new possible_clients[MAXCLIENTS+1];
    new 
max_index 0;
    for (new 
i=1i<=MAXCLIENTSi++)
    {
        if (!
IsClientConnected(i))
        {
            
PrintToChatAll("Client(%i) 77"i);
            continue;
        }
        if (!
IsClientInGame(i)) 
        {
            
PrintToChatAll("Client(%i) 82"i);
            continue;
        }
        if (
GetClientTeam(i)!=2
        {
            
PrintToChatAll("Client(%i) Team(%i) 87"iGetClientTeam(i));
            continue;
        }
        if (!
IsPlayerAlive(i) && GetConVarInt(l4d_random_witcher_take_alive) ) 
        {
            
PrintToChatAll("Client(%i) 92"i);
            continue;
        }
        if (
IsPlayerAlive(i) && GetConVarInt(l4d_random_witcher_take_dead) ) 
        {
            
PrintToChatAll("Client(%i) 97"i);
            continue;
        }
        
possible_clients[max_index] = i;
        
PrintToChatAll("Client(%i) collected"i);
        
max_index++;
    } 
Is there any alternate way to check ALL players without for() statement?

Last edited by axelnieves2012; 01-19-2019 at 23:39.
axelnieves2012 is offline
Powerlord
AlliedModders Donor
Join Date: Jun 2008
Location: Seduce Me!
Old 01-19-2019 , 23:53   Re: [L4D] HELP: IsClientConnected and IsClientInGame return FALSE always
Reply With Quote #2

When is this code running? If it's OnMapStart, that's why it's failing; the game disconnects all players between map changes even between maps in the same campaign.
__________________
Not currently working on SourceMod plugin development.
Powerlord is offline
axelnieves2012
Senior Member
Join Date: Oct 2014
Location: Argentina
Old 01-20-2019 , 00:06   Re: [L4D] HELP: IsClientConnected and IsClientInGame return FALSE always
Reply With Quote #3

Quote:
Originally Posted by Powerlord View Post
When is this code running? If it's OnMapStart, that's why it's failing; the game disconnects all players between map changes even between maps in the same campaign.
No, It's on public event_witch_harasser_set(Handle:event, const String:name[], bool:dontBroadcast).

And after testing several times, Im getting different runtime errors. It seems sourcemod is bugged.
full code:

PHP Code:
#pragma semicolon 1
#include <sourcemod>

#define PLUGIN_VERSION    "1.0.0"
#define MAXCLIENTS    GetMaxClients()

#define IS_VALID_CLIENT(%1) (%1 > 0 && %1 <= MaxClients)
#define IS_CONNECTED_INGAME(%1) (IsClientConnected(%1) && IsClientInGame(%1))
#define IS_SURVIVOR(%1) (GetClientTeam(%1) == 2)
#define IS_INFECTED(%1) (GetClientTeam(%1) == 3)

#define IS_VALID_INGAME(%1) (IS_VALID_CLIENT(%1) && IS_CONNECTED_INGAME(%1))

#define IS_VALID_SURVIVOR(%1) (IS_VALID_INGAME(%1) && IS_SURVIVOR(%1))
#define IS_VALID_INFECTED(%1) (IS_VALID_INGAME(%1) && IS_INFECTED(%1))

#define IS_SURVIVOR_ALIVE(%1) (IS_VALID_SURVIVOR(%1) && IsPlayerAlive(%1))
#define IS_INFECTED_ALIVE(%1) (IS_VALID_INFECTED(%1) && IsPlayerAlive(%1))

#define IS_SURVIVOR_DEAD(%1) (IS_VALID_SURVIVOR(%1) && !IsPlayerAlive(%1))
#define IS_INFECTED_DEAD(%1) (IS_VALID_INFECTED(%1) && !IsPlayerAlive(%1))


new Handle:l4d_random_witcher_enable;
new 
Handle:l4d_random_witcher_take_alive;
new 
Handle:l4d_random_witcher_take_dead;

public 
Plugin:myinfo 
{
    
name "Random Witch target"
    
author "Axel Juan Nieves"
    
description "Makes startled witch think other person startled her"
    
version PLUGIN_VERSION
    
url ""
};

public 
OnPluginStart()
{
    
// Require Left 4 Dead 1/2
    
decl String:game_name[64];
    
GetGameFolderName(game_namesizeof(game_name));
    if (
StrContains(game_name"left4dead")<0)
    {
        
SetFailState("Use this in Left 4 Dead 1/2 only.");
    }
    
    
// Create convars
    
CreateConVar("l4d_random_witcher_version "PLUGIN_VERSION""0|FCVAR_DONTRECORD);
    
l4d_random_witcher_enable CreateConVar("l4d_random_witcher_enable""1""Enable/Disable this plugin."0);
    
l4d_random_witcher_take_alive CreateConVar("l4d_random_witcher_take_alive""1""Witch can take alive players"0);
    
l4d_random_witcher_take_dead CreateConVar("l4d_random_witcher_take_dead""1""Witch can take dead players"0);
    
    
AutoExecConfig(true"l4d_random_witcher");
    
    
HookEvent("witch_harasser_set"event_witch_harasser_setEventHookMode_Pre);
}

public 
event_witch_harasser_set(Handle:event, const String:name[], bool:dontBroadcast)
{
    if ( !
GetConVarInt(l4d_random_witcher_enable) ) 
        return;
    new 
witch_id GetEventInt(event"witchid");
    new 
witch_target GetClientOfUserId(GetEventInt(event"userid"));
    
    if (
witch_id == 0)
        return;
    
    if (!
IS_VALID_SURVIVOR(witch_target))
        return;
    
    new 
possible_clients[MAXCLIENTS+1];
    new 
max_index 0;
    for (new 
i=1i<=MAXCLIENTSi++)
    {
        if (!
IsClientConnected(i))
        {
            
PrintToChatAll("Client(%i) 77"i);
            continue;
        }
        if (!
IsClientInGame(i)) 
        {
            
PrintToChatAll("Client(%i) 82"i);
            continue;
        }
        
        if (
GetClientTeam(GetClientUserId(i))!=2
        {
            
//PrintToChatAll("Client(%i) Team(%i) 87", i, GetClientTeam(i));
            
continue;
        }
        if (!
IsPlayerAlive(i) && GetConVarInt(l4d_random_witcher_take_alive) ) 
        {
            
//PrintToChatAll("Client(%i) 92", i);
            
continue;
        }
        if (
IsPlayerAlive(i) && GetConVarInt(l4d_random_witcher_take_dead) ) 
        {
            
//PrintToChatAll("Client(%i) 97", i);
            
continue;
        }
        
possible_clients[max_index] = i;
        
PrintToChatAll("Client(%i) collected"i);
        
max_index++;
    }
    new 
client GetRandomInt(0max_index-1);
    new 
new_target;
    if (!
clientnew_target 0;
    else if ( 
IS_CONNECTED_INGAME(client) )
        
new_target GetClientUserId(witch_target);
    else
        
new_target 0;
    
    
PrintToChatAll("Old target(%i). New target(%i)"witch_targetnew_target);
    
PrintToChatAll("Ammount collected: %i"max_index);
    
//event = CreateEvent("witch_harasser_set");
    
SetEventInt(event"userid"new_target);
    
SetEventInt(event"witchid"witch_id);
    
//FireEvent(event2);

I am getting problems with IsClientInGame.
Id "10" returns TRUE and then GetClientTeam returns runtime error because id 10 is not connected.
But it was supposed IsClientInGame(10) would never return TRUE.
It's a very simple plugin that is making my head hurt.

Last edited by axelnieves2012; 01-20-2019 at 00:11.
axelnieves2012 is offline
Ilusion9
Veteran Member
Join Date: Jun 2018
Location: Romania
Old 01-20-2019 , 05:18   Re: [L4D] HELP: IsClientConnected and IsClientInGame return FALSE always
Reply With Quote #4

PHP Code:

stock void Test
()
{
    
int possible_clients[MAXPLAYERS 1];
    
int max_index 0;
    
    for (
int i 1<= MaxClientsi++)
    {
        if (!
IsClientConnected(i))
        {
            
PrintToChatAll("Client(%i) not connected"i);
            continue;
        }
        
        if (!
IsClientInGame(i)) 
        {
            
PrintToChatAll("Client(%i) not in game"i);
            continue;
        }
        
        if (
GetClientTeam(i) != 2
        {
            
PrintToChatAll("Client(%i) Team(%i) 87"iGetClientTeam(i));
            continue;
        }
        
        if (!
IsPlayerAlive(i) && GetConVarInt(l4d_random_witcher_take_alive)) 
        {
            
PrintToChatAll("Client(%i) 92"i);
            continue;
        }
        
        if (
IsPlayerAlive(i) && GetConVarInt(l4d_random_witcher_take_dead)) 
        {
            
PrintToChatAll("Client(%i) 97"i);
            continue;
        }
        
        
possible_clients[max_index] = i;
        
PrintToChatAll("Client(%i) collected"i);
        
        
max_index++;
    }  

Use MaxClients in a for statement.
Avoid these: #define IS_SURVIVOR(%1) (GetClientTeam(%1) == 2)
And use the new syntax.
__________________
Ilusion9 is offline
Reply


Thread Tools
Display Modes

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:10.


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