Raised This Month: $81 Target: $400
 20% 

[L4D2] About "IsClientInGame()"


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Iciaria
Member
Join Date: Aug 2022
Old 03-25-2023 , 09:27   [L4D2] About "IsClientInGame()"
Reply With Quote #1

I'm having some problems writing a plugin.
The code snippet looks like this

PHP Code:
public void OnPluginStart()
{
#if DEBUG
        
HookEvent("weapon_fire"Event_Weapon_FireEventHookMode_PostNoCopy);            
#endif
}

void CheckStatus()
{
        for(
int i =1i<=MaxClientsi++)
        {
//              if(!IS_VALID_SURVIVOR(i))
//              if(!IsValidEntity(i) )
//                      return;
//              PrintToChatAll("1");
//              if(!IsClientConnected(i) )
//                      return;
//              PrintToChatAll("2");
//              if(!IsValiClient(i) )
//                      return;
                
if(!IsClientInGame(i) )
                        return;
                if(
GetClientTeam(i) == 2)
                {       
                        
char name[64];
                        
GetClientName(inamesizeof(name) );
                        
int health GetEntProp(iProp_Send"m_iHealth");
                        
float buffer GetTempHealth(i);
//GetEntPropFloat(i, Prop_Send, "m_healthBuffer");
                        
int count GetEntProp(iProp_Send"m_currentReviveCount");
                        
PrintToChatAll("%s#HP:%d, TEMP:%f, REV:%d,"namehealthbuffercount);
                        
PrintToServer("%s#HP:%d, TEMP:%f, REV:%d,"namehealthbuffercount);
                }
        }


I run many tests on my multiple servers.
"IsClientInGame()" sometimes thinks the client is not in the game.

The following situations have occurred in the test:
Code:
1.Only the first player to join is considered "in game".
2.Following the first point, when a second player joins the server, the fake client will be considered "Not in game", and . The second player is also sometimes considered "Not in game".
3.All players, fake clients or not, are correctly considered "in game"
4.Only real players are considered "in game"
I also tested in pure server and the result is still the same
Initially, it throws
Code:
 03/24/2023 - 19:59:23: [SM] Call stack trace:
L 03/24/2023 - 19:59:23: [SM]   [0] Event.GetInt
L 03/24/2023 - 19:59:23: [SM]   [1] Line 90, test.sp::Event_Weapon_Fire
After I removed "EventHookMode_PostNoCopy", the error in the log above disappeared. However, the problem is still happening..

I also tried changing the cvars "sv_lan" and "sv_cheats", but, the miracle didn't happen.

Can anyone tell me what exactly is going on?
I'm very confused.......
__________________
Sorry,my english not good
Iciaria is offline
Marttt
Veteran Member
Join Date: Jan 2019
Location: Brazil
Old 03-25-2023 , 10:32   Re: [L4D2] About "IsClientInGame()"
Reply With Quote #2

Wrong section, and the snippet provided doesn't give any clue about your exception (the error is the line above "Call stack trace" that you didn't copy+paste)

anyway, your "for" loop is wrong, if you use "return" inside, it will exit the "CheckStatus" function,
use "continue" instead to go to the next index, otherwise it will stop looping in the first "not in game" client
__________________

Last edited by Marttt; 03-25-2023 at 10:36.
Marttt is offline
Iciaria
Member
Join Date: Aug 2022
Old 03-25-2023 , 10:44   Re: [L4D2] About "IsClientInGame()"
Reply With Quote #3

Quote:
Originally Posted by Marttt View Post
Wrong section, and the snippet provided doesn't give any clue about your exception (the error is the line above "Call stack trace" that you didn't copy+paste)

anyway, your "for" loop is wrong, if you use "return" inside, it will exit the "CheckStatus" function,
use "continue" instead to go to the next index, otherwise it will stop looping in the first "not in game" client
Thanks a lot, everything is clear now.my stupid mistakexD

PS.I only see this error in the log, so I didn't paste the other lines because they are the same.
__________________
Sorry,my english not good
Iciaria is offline
Marttt
Veteran Member
Join Date: Jan 2019
Location: Brazil
Old 03-25-2023 , 19:17   Re: [L4D2] About "IsClientInGame()"
Reply With Quote #4

They may be the same, but the specific error message is above

E.g:

PHP Code:
L 03/12/2023 21:07:22: [SMException reportedEntity 1 (1is invalid
L 03
/12/2023 21:07:22: [SMBlamingsomeplugin.smx
L 03
/12/2023 21:07:22: [SMCall stack trace:
L 03/12/2023 21:07:22: [SM]   [0SetEntPropEnt
L 03
/12/2023 21:07:22: [SM]   [1Line 210someplugin.sp::OnGameFrame 
"Exception reported: Entity 1 (1) is invalid" part also matters to someone help you.

In your case if you are using "EventHookMode_PostNoCopy" you can't use Event.GetInt functions,
cause EventHookMode_PostNoCopy is just a notification,
without any values from event, just triggers after it was sent.

So you will keep having errors in log, just change to EventHookMode_Post (or leave it blank cause is the default value)

PHP Code:
enum EventHookMode
{
    
EventHookMode_Pre,                  //< Hook callback fired before event is fired */
    
EventHookMode_Post,                 //< Hook callback fired after event is fired */
    
EventHookMode_PostNoCopy            //< Hook callback fired after event is fired, but event data won't be copied */
}; 
__________________

Last edited by Marttt; 03-25-2023 at 21:07.
Marttt is offline
Grey83
Veteran Member
Join Date: Dec 2014
Location: Ukraine
Old 03-26-2023 , 00:15   Re: [L4D2] About "IsClientInGame()"
Reply With Quote #5

PHP Code:
                if(!IsClientInGame(i) )
                        return; 
==>
PHP Code:
                if(!IsClientInGame(i) )
                        continue; 
https://wiki.alliedmods.net/Introduc...7#Loop_Control
__________________
Grey83 is offline
Iciaria
Member
Join Date: Aug 2022
Old 03-26-2023 , 12:11   Re: [L4D2] About "IsClientInGame()"
Reply With Quote #6

that should be right
PHP Code:
public void OnPluginStart()
{
#if DEBUG
        
HookEvent("weapon_fire"Event_Weapon_Fire);            
#endif
}
void Event_Weapon_Fire(Event event, const char[] namebool dontBroadcast)
{
        
int client GetClientOfUserId(event.GetInt("userid"));
        if(!
IsFakeClient(client))
        {
                
CheckStatus();
        }
}
void CheckStatus()
{
        for(
int i =1i<=MaxClientsi++)
        {
                if(!
IsClientInGame(i) )
                        continue;
                if(
GetClientTeam(i) == 2)
                {       
                        
char name[64];
                        
GetClientName(inamesizeof(name) );
                        
int health GetEntProp(iProp_Send"m_iHealth");
                        
float buffer GetTempHealth(i);
                        
int count GetEntProp(iProp_Send"m_currentReviveCount");
                        
PrintToChatAll("%s#HP:%d, TEMP:%f, REV:%d,"namehealthbuffercount);
                        
PrintToServer("%s#HP:%d, TEMP:%f, REV:%d,"namehealthbuffercount);
                }
        }


Code:
L 03/24/2023 - 19:59:23: [SM] Blaming: test.smx
L 03/24/2023 - 19:59:23: [SM] Call stack trace:
L 03/24/2023 - 19:59:23: [SM]   [0] Event.GetInt
L 03/24/2023 - 19:59:23: [SM]   [1] Line 90, test.sp::Event_Weapon_Fire
Sorry I seem to have forgotten to paste a lot of important stuff
, the problem is only because of "return;"
Anyway thanks.
__________________
Sorry,my english not good
Iciaria is offline
Grey83
Veteran Member
Join Date: Dec 2014
Location: Ukraine
Old 03-26-2023 , 13:49   Re: [L4D2] About "IsClientInGame()"
Reply With Quote #7

PHP Code:
#pragma semicolon 1
#pragma newdecls required

public void OnPluginStart()
{
#if DEBUG
    
HookEvent("weapon_fire"Event_Weapon_Fire);
#endif
}

public 
void Event_Weapon_Fire(Event event, const char[] namebool dontBroadcast)
{
    
int client GetClientOfUserId(event.GetInt("userid"));
    if(
client && !IsFakeClient(client)) CheckStatus();
}

stock void CheckStatus()
{
    
float buffer;
    for(
int i 1healthcount<= MaxClientsi++) if(IsClientInGame(i) && GetClientTeam(i) == 2)
    {
        
health GetEntProp(iProp_Send"m_iHealth");
        
buffer GetTempHealth(i);
        
count GetEntProp(iProp_Send"m_currentReviveCount");

        
PrintToChatAll("%N#HP:%d, TEMP:%f, REV:%d,"ihealthbuffercount);
        
PrintToServer("%N#HP:%d, TEMP:%f, REV:%d,"ihealthbuffercount);
    }

__________________

Last edited by Grey83; 03-26-2023 at 13:53.
Grey83 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 13:44.


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