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

Solved [L4D2] Send Players to Spec on Connect


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
diorfo
Member
Join Date: Dec 2013
Old 11-26-2018 , 21:48   [L4D2] Send Players to Spec on Connect
Reply With Quote #1

Hi all,

I need a little help with a simple code for a plugin that i'm trying to put in my server.

I need a plugin that sends players to spec on connect after certain numbers of players in game even with bots in game also.

I found the plugin https://forums.alliedmods.net/showthread.php?p=892093 but doesn't work properly anymore.

I tried to develop the plugin with code below but every map changes the plugin sends players already connected and playing to spec because OnClientPutInServer is triggered after every map load.

PHP Code:
public OnClientPutInServer(client) {

    new 
NotBots 0;
    for(new 
1<= MaxClientsi++)
    {
        if (
&& IsClientInGame(i) && !IsFakeClient(i))
        {
NotBots++;}
    }

    new 
AdminId:admin FindAdminByIdentity(AUTHMETHOD_STEAMsteamID);

    if (
NotBots && !IsFakeClient(admin) && !GetAdminFlag(adminAdmin_Kick))
 
    {
        
ChangeClientTeam(admin1);        
    }     

Is there a Forward similar to OnClientPutInServer but triggered only on player enter in server for first time to me put on my plugin?

Last edited by diorfo; 11-29-2018 at 06:33.
diorfo is offline
LenHard
Senior Member
Join Date: Jan 2016
Old 11-27-2018 , 07:07   Re: [L4D2] Send Players to Spec on Connect
Reply With Quote #2

player_activate event with a little timer would probably work.
__________________
LenHard is offline
MasterMind420
BANNED
Join Date: Nov 2010
Old 11-27-2018 , 09:17   Re: [L4D2] Send Players to Spec on Connect
Reply With Quote #3

Quote:
Originally Posted by LenHard View Post
player_activate event with a little timer would probably work.
player_activate event fires at the beginning of every map load...you want to use player_first_spawn event, also timing is crucial when doing it, i believe it needs a small delay...I do this in a private plugin I made...
MasterMind420 is offline
midnight9
Senior Member
Join Date: Nov 2012
Old 11-27-2018 , 09:23   Re: [L4D2] Send Players to Spec on Connect
Reply With Quote #4

You could use boolean for each player, set to true OnClientPutInServer then hook player_disconnect event and set it to false if player leaves.
midnight9 is offline
diorfo
Member
Join Date: Dec 2013
Old 11-27-2018 , 10:29   Re: [L4D2] Send Players to Spec on Connect
Reply With Quote #5

Quote:
Originally Posted by MasterMind420 View Post
player_activate event fires at the beginning of every map load...you want to use player_first_spawn event, also timing is crucial when doing it, i believe it needs a small delay...I do this in a private plugin I made...
But player_first_spawn event doesn't fire also every map on spawn of survivor?

Quote:
Originally Posted by midnight9 View Post
You could use boolean for each player, set to true OnClientPutInServer then hook player_disconnect event and set it to false if player leaves.
I was thinking about that solution too.

Looks like will be the way to solve.
diorfo is offline
MasterMind420
BANNED
Join Date: Nov 2010
Old 11-27-2018 , 13:43   Re: [L4D2] Send Players to Spec on Connect
Reply With Quote #6

Quote:
Originally Posted by diorfo View Post
But player_first_spawn event doesn't fire also every map on spawn of survivor?



I was thinking about that solution too.

Looks like will be the way to solve.
no it only fires when the player first connects to the server or the start of a new campaign...
MasterMind420 is offline
diorfo
Member
Join Date: Dec 2013
Old 11-27-2018 , 21:57   Re: [L4D2] Send Players to Spec on Connect
Reply With Quote #7

I tried with solution of boolean but every new map load still sends player already playing to spec with below code.

Should do it only first time player enter in server.

Can someone please explain to me why it's not working properly?

PHP Code:
#include <sourcemod>
#include <sdktools>

#define PLUGIN_VERSION "1.0"

new bool:Round false;

public 
Plugin:myinfo =
{
    
name "Spec On Connect",
    
author "diorfo",
    
description "Send players to spec on connect after certain quantities of players in game",
    
version PLUGIN_VERSION,
    
url ""
}

public 
OnPluginStart()
{
    
CreateConVar("sm_l4d2_speconconnect_version"PLUGIN_VERSION"l4d2 Spec On Connect Version"FCVAR_PLUGIN|FCVAR_SPONLY|FCVAR_REPLICATED|FCVAR_NOTIFY);
    
    
HookEvent("map_transition"Event_MapTransitionEventHookMode_PostNoCopy);
    
HookEvent("player_disconnect"Event_PlayerDisconnectEventHookMode_PostNoCopy);
}

public 
Event_MapTransition(Handle:event, const String:name[], bool:dontBroadcast)
{
       
Round true;
}

public 
OnClientPutInServer(client
{
    new 
NotBots 0;
    for(new 
1<= MaxClientsi++)
    {
        if (
&& IsClientInGame(i) && !IsFakeClient(i))
        {
NotBots++;}
    }

    if (!
Round && NotBots >= && !IsFakeClient(client))
    {
        
CreateTimer(5.0Timer_SendToSpecclient);
    }    
}

public 
Action:Timer_SendToSpec(Handle:timerany:client)
{
    
ChangeClientTeam(client1);
}

public 
Event_PlayerDisconnect(Handle:event, const String:name[], bool:dontBroadcast)
{
       
Round false;


Last edited by diorfo; 11-27-2018 at 22:00.
diorfo is offline
midnight9
Senior Member
Join Date: Nov 2012
Old 11-28-2018 , 01:31   Re: [L4D2] Send Players to Spec on Connect
Reply With Quote #8

Try this

Code:
#include <sourcemod>
#include <sdktools>

#define PLUGIN_VERSION "1.0"

new bool:g_bAlreadyConnected[MAXPLAYERS+1];

public Plugin:myinfo =
{
	name = "Spec On Connect",
	author = "diorfo",
	description = "Send players to spec on connect after certain quantities of players in game",
	version = PLUGIN_VERSION,
	url = ""
}

public OnPluginStart()
{
	CreateConVar("sm_l4d2_speconconnect_version", PLUGIN_VERSION, "l4d2 Spec On Connect Version", FCVAR_PLUGIN|FCVAR_SPONLY|FCVAR_REPLICATED|FCVAR_NOTIFY);
	
	HookEvent("player_disconnect", Event_PlayerDisconnect, EventHookMode_PostNoCopy);
}


public OnClientPutInServer(client) 
{
	
	if (g_bAlreadyConnected[client])
		return;
	
	g_bAlreadyConnected[client] = true;
	
	new NotBots = 0;
	for(new i = 1; i <= MaxClients; i++)
	{
		if (i > 0 && IsClientInGame(i) && !IsFakeClient(i))
		{NotBots++;}
	}
	
	if (NotBots >= 0 && !IsFakeClient(client))
	{
		CreateTimer(5.0, Timer_SendToSpec, client);
	}    
}

public Action:Timer_SendToSpec(Handle:timer, any:client)
{
	ChangeClientTeam(client, 1);
}

public Event_PlayerDisconnect(Handle:event, const String:name[], bool:dontBroadcast)
{
	new client = GetClientOfUserId(GetEventInt(event, "userid"));
	g_bAlreadyConnected[client] = false;
}
midnight9 is offline
diorfo
Member
Join Date: Dec 2013
Old 11-28-2018 , 16:37   Re: [L4D2] Send Players to Spec on Connect
Reply With Quote #9

Quote:
Originally Posted by midnight9 View Post
Try this

Code:
#include <sourcemod>
#include <sdktools>

#define PLUGIN_VERSION "1.0"

new bool:g_bAlreadyConnected[MAXPLAYERS+1];

public Plugin:myinfo =
{
	name = "Spec On Connect",
	author = "diorfo",
	description = "Send players to spec on connect after certain quantities of players in game",
	version = PLUGIN_VERSION,
	url = ""
}

public OnPluginStart()
{
	CreateConVar("sm_l4d2_speconconnect_version", PLUGIN_VERSION, "l4d2 Spec On Connect Version", FCVAR_PLUGIN|FCVAR_SPONLY|FCVAR_REPLICATED|FCVAR_NOTIFY);
	
	HookEvent("player_disconnect", Event_PlayerDisconnect, EventHookMode_PostNoCopy);
}


public OnClientPutInServer(client) 
{
	
	if (g_bAlreadyConnected[client])
		return;
	
	g_bAlreadyConnected[client] = true;
	
	new NotBots = 0;
	for(new i = 1; i <= MaxClients; i++)
	{
		if (i > 0 && IsClientInGame(i) && !IsFakeClient(i))
		{NotBots++;}
	}
	
	if (NotBots >= 0 && !IsFakeClient(client))
	{
		CreateTimer(5.0, Timer_SendToSpec, client);
	}    
}

public Action:Timer_SendToSpec(Handle:timer, any:client)
{
	ChangeClientTeam(client, 1);
}

public Event_PlayerDisconnect(Handle:event, const String:name[], bool:dontBroadcast)
{
	new client = GetClientOfUserId(GetEventInt(event, "userid"));
	g_bAlreadyConnected[client] = false;
}
It worked properly with your modifications.

Thank you.
diorfo 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 06:16.


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