Raised This Month: $2 Target: $400
 0% 

Solved Creating Timer with OnClientPostAdminCheck


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
PC Gamer
Senior Member
Join Date: Mar 2014
Old 06-08-2020 , 05:27   Creating Timer with OnClientPostAdminCheck
Reply With Quote #1

Can you solve this Riddle?

Game is TF2. Sourcemod version 1.10.0.6478

Issue: Timer doesn't appear to run when used with OnClientPostAdminCheck

Desired effect: When a human player joins the server, game will check to see if any other human players are present. If so, nothing happens. If not, a server command is executed.

When I run the code and join the server all I get on the server console is: Debug: Starting Timer. Nothing else happens. Server command doesn't execute. No error in log.

PHP Code:
#pragma semicolon 1
#pragma newdecls required

public Plugin myinfo =
{
    
name "Execute Commands when First Human Player Joins Server",
    
author "PC Gamer, using code from Franc1sco Franug",
    
description "",
    
version "1.0",
    
url "http://alliedmods.net"
};

public 
void OnClientPostAdminCheck(int client)
{
    if (!
IsFakeClient(client)) 
    {
        
PrintToServer("Debug: Starting Timer");
        
CreateTimer(1.0Timer_CheckPlayers);
    }
}

public 
Action Timer_CheckPlayers(Handle timer)
{
    
PrintToServer("Debug: Checking for Real Players");
    if (!
RealPlayerExist
    {
        
PrintToServer("Debug: No Real Players Exist");
        
ServerCommand("exec round1.cfg");
        
PrintToServer("Debug: First Human Player Joined. Resetting Bots");
    }
}

bool RealPlayerExist(int iExclude 0)
{
    
PrintToServer("Debug: Running function for RealPlayerExist");
    for (
int client 1client MaxClientsclient++)
    {
        if (
client != iExclude && IsClientConnected(client))
        {
            if (!
IsFakeClient(client)) {
                return (
true);
            }
        }
    }
    return (
false);


Last edited by PC Gamer; 06-08-2020 at 15:15.
PC Gamer is offline
Silvers
AlliedModders Donor
Join Date: Aug 2010
Location: SpaceX
Old 06-08-2020 , 06:49   Re: Creating Timer with OnClientPostAdminCheck
Reply With Quote #2

This is checking the function exists (or something) and not actually calling it (always returns true):
if (!RealPlayerExist)
Should be:
if (!RealPlayerExist())


for (int client = 1; client < MaxClients; client++)
Should be:
for (int client = 1; client <= MaxClients; client++)


Put:
#include <sourcemod>
At the top, although I can't see why else this would fail.
__________________

Last edited by Silvers; 06-08-2020 at 06:52.
Silvers is offline
PC Gamer
Senior Member
Join Date: Mar 2014
Old 06-08-2020 , 13:15   Re: Creating Timer with OnClientPostAdminCheck
Reply With Quote #3

Thanks for the help Silvers. I made your recommended changes along with a few others.

Issue: Plugin only gets to Debug Stage 3. It should at least get to Stage 4 for all players, and get to Stage 6 for the very first player.

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

public Plugin myinfo =
{
    
name "Execute Commands when First Human Player Joins Server",
    
author "PC Gamer, using code from Franc1sco Franug",
    
description "",
    
version "1.0",
    
url "http://alliedmods.net"
};

public 
void OnClientPostAdminCheck(int client)
{
    if (!
IsFakeClient(client)) 
    {
        
PrintToServer("Debug: Stage 1");
        
CreateTimer(1.0Timer_CheckPlayers);
    }
}

public 
Action Timer_CheckPlayers(Handle timer)
{
    
PrintToServer("Debug: Stage 2");
    if (!
RealPlayerExist()) 
    {
        
PrintToServer("Debug: Stage 5");
        
ServerCommand("exec round1.cfg");
        
PrintToServer("Debug: Stage 6");
    }
}

bool RealPlayerExist()
{
    
PrintToServer("Debug: Stage 3");
    
int pcount 0;
    for(
int i 1<= MaxClientsi++)
    {
        if(
IsClientInGame(i) && !IsFakeClient(i))
        {
            
pcount++;
            
PrintToServer("Debug Stage 4: Number of Human Players: %d"pcount);            
            if (
pcount 1)
            {
                return (
true);
            }
        }
    }
    return (
false);

PC Gamer is offline
Silvers
AlliedModders Donor
Join Date: Aug 2010
Location: SpaceX
Old 06-08-2020 , 14:02   Re: Creating Timer with OnClientPostAdminCheck
Reply With Quote #4

Very strange, are you compiling using the same SM version your servers running? Just tried the plugin:

Quote:
Debug: Stage 1
Debug: Stage 2
Debug: Stage 3
Debug Stage 4: Number of Human Players: 1
Debug: Stage 5
Debug: Stage 6
exec: couldn't exec round1.cfg
__________________
Silvers is offline
PC Gamer
Senior Member
Join Date: Mar 2014
Old 06-08-2020 , 14:35   Re: Creating Timer with OnClientPostAdminCheck
Reply With Quote #5

Interesting observation...

First player to join: Server console shows stage 1,2,3,5,6 (missing stage 4)
Second and subsequent players join: Server console shows stage 1,2,3 (missing stages 4,5,6)

Compiler version: 1.10.0.6478
sm version on console: Build ID: 6478:a8b9da9a

Since it worked for you I will install a newer version of Sourcemod and test it. Thanks for your feedback. It helps with the troubleshooting.
PC Gamer is offline
Silvers
AlliedModders Donor
Join Date: Aug 2010
Location: SpaceX
Old 06-08-2020 , 14:48   Re: Creating Timer with OnClientPostAdminCheck
Reply With Quote #6

I'm using 1.10.0.6460 (tested in L4D2). I can't test other clients joining, using local dedi. Really strange that it's not working as expected.
__________________
Silvers is offline
PC Gamer
Senior Member
Join Date: Mar 2014
Old 06-08-2020 , 15:15   Re: Creating Timer with OnClientPostAdminCheck
Reply With Quote #7

Just upgraded to latest stable version of Sourcemod 1.10.0.6488 .

Same results. However, I learned this....

This line does not execute in TF2. No error is given: PrintToServer("Debug Stage 4: Number of Human Players: %d", pcount);

But it works when I change it to this: PrintToServer("Debug Stage 4: %d players", pcount);

Very odd. Thanks for your help Silvers. I'll chalk this up as some sort of weird TF2 anomaly.

Marked solved since technically it does execute the command when first player joins.
PC Gamer is offline
Silvers
AlliedModders Donor
Join Date: Aug 2010
Location: SpaceX
Old 06-08-2020 , 15:22   Re: Creating Timer with OnClientPostAdminCheck
Reply With Quote #8

Very interesting thanks for letting us know!
__________________
Silvers 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:03.


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