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

Solved [L4D2]Auto exec command to players on connect HELP


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Alex101192
Senior Member
Join Date: Aug 2018
Old 11-14-2019 , 17:40   [L4D2]Auto exec command to players on connect HELP
Reply With Quote #1

PHP Code:
public OnClientPutInServer(client
{
    
CreateTimer(5.0Timer_AutoShowGetClientUserId(client), TIMER_FLAG_NO_MAPCHANGE);
}

public 
Action:Timer_AutoShow(Handle:timerany:userid)
{
    new 
client GetClientOfUserId(userid);
    if(
client && IsClientInGame(client))
    {
        
FakeClientCommandEx(client"sm_join");
    }
    return 
Plugin_Handled;

This plugin forces a connecting client to use the command specified in FakeClientCommandEx within the time put inside CreateTimer. It works, however the problem I have is that the command is also forced on infected bots.

In this case the command is supposed to make you join the survivor team once you connect, and is intented to be used on players only and not bots. As of now if this plugin is used, the command will be executed not only on the players, but also on the new infected bots that spawn. As a result they will disappear as they tried to join the survivor team, and this also causes the survivor bots to disappear.

This simple plugin wasn't made for L4D2 and I just need someone to make it distinguish between human players and bots, and have the command be executed only on humans.

Last edited by Alex101192; 11-16-2019 at 16:14.
Alex101192 is offline
Silvers
SourceMod Plugin Approver
Join Date: Aug 2010
Location: SpaceX
Old 11-14-2019 , 18:57   Re: [L4D2]Auto exec command to players on connect HELP
Reply With Quote #2

IsFakeClient
__________________
Silvers is offline
PC Gamer
Veteran Member
Join Date: Mar 2014
Old 11-14-2019 , 22:38   Re: [L4D2]Auto exec command to players on connect HELP
Reply With Quote #3

Maybe something like this?

PHP Code:
public OnClientPutInServer(client
{
    if(
client && IsClientInGame(client) && !IsFakeClient(client))
    {
        
CreateTimer(5.0Timer_AutoShowGetClientUserId(client), TIMER_FLAG_NO_MAPCHANGE);
    }
    return 
Plugin_Handled;
}

public 
Action:Timer_AutoShow(Handle:timerany:userid)
{
    
FakeClientCommandEx(client"sm_join");
    return 
Plugin_Handled;

PC Gamer is offline
Alex101192
Senior Member
Join Date: Aug 2018
Old 11-15-2019 , 04:56   Re: [L4D2]Auto exec command to players on connect HELP
Reply With Quote #4

Quote:
Originally Posted by PC Gamer View Post
Maybe something like this?

PHP Code:
public OnClientPutInServer(client
{
    if(
client && IsClientInGame(client) && !IsFakeClient(client))
    {
        
CreateTimer(5.0Timer_AutoShowGetClientUserId(client), TIMER_FLAG_NO_MAPCHANGE);
    }
    return 
Plugin_Handled;
}

public 
Action:Timer_AutoShow(Handle:timerany:userid)
{
    
FakeClientCommandEx(client"sm_join");
    return 
Plugin_Handled;

plugin.sp(7) : error 088: cannot return a value from a void function
plugin.sp(7) : warning 213: tag mismatch
plugin.sp(1) : error 180: function return type differs from prototype. expected 'void', but got 'int'
plugin.sp(12) : error 017: undefined symbol "client"
Alex101192 is offline
Alex101192
Senior Member
Join Date: Aug 2018
Old 11-15-2019 , 07:07   Re: [L4D2]Auto exec command to players on connect HELP
Reply With Quote #5

PHP Code:
public OnClientPutInServer(client
{
    
CreateTimer(5.0Timer_AutoShowGetClientUserId(client), TIMER_FLAG_NO_MAPCHANGE);
}

public 
Action:Timer_AutoShow(Handle:timerany:userid)
{
    new 
client GetClientOfUserId(userid);
    if(
client && IsClientInGame(client) && !IsFakeClient(client))
    {
        
FakeClientCommandEx(client"sm_join");
    }
    return 
Plugin_Handled;

I modified the original code and added IsFakeClient. Now the command is only executed on players as it should be. I had a crash the first time we changed level on saferoom. But after that one, no more crashes occured. It seems to be working, though I will wait and test a bit more before calling it solved.

Last edited by Alex101192; 11-15-2019 at 07:08.
Alex101192 is offline
Alex101192
Senior Member
Join Date: Aug 2018
Old 11-16-2019 , 16:13   Re: [L4D2]Auto exec command to players on connect HELP
Reply With Quote #6

No crash occured, the code works good.

Last edited by Alex101192; 11-16-2019 at 16:13.
Alex101192 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 18:57.


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