Raised This Month: $ Target: $400
 0% 

[L4D2] Play on Team 4


Post New Thread Reply   
 
Thread Tools Display Modes
Spirit_12
Veteran Member
Join Date: Dec 2012
Location: Toronto, CA
Old 10-07-2018 , 19:59   Re: [L4D2] Play on Team 4
Reply With Quote #11

I was looking at the source code and found a couple of redundant things.
  • Cache convars into handle instead of using FindConVar at each instance.
  • IsValidClient checks are reduntant as client has to be in game and not be a bot as bots would never type the command.
  • Repitions of the same code. Don't do that, instead put your code in a stock and call that instead.

I'm still not sure what kind of error you got when you say client returns 0. Can you elaborate on that and maybe I can chime in?

With the above mentioned optimizations. This is how the code will look like.

PHP Code:
#include <sourcemod>

#pragma semicolon 1
#pragma newdecls required

#define PLUGIN_VERSION "1.0"

ConVar Cvar_TeamSwitches;

public 
Plugin myinfo =
{
    
name "[L4D2] Play as Team 4",
    
author "Xanaguy/MasterMe",
    
description "Play on the hidden Team 4!",
    
version PLUGIN_VERSION,
    
url "https://forums.alliedmods.net/showthread.php?t=311185"
};

public 
void OnPluginStart()
{
    
CreateConVar("team4version"PLUGIN_VERSION"\"Play as Team 4\" plugin version"FCVAR_NOTIFY|FCVAR_DONTRECORD);
    
Cvar_TeamSwitches    =    FindConVar("vs_max_team_switches");
    
    
RegAdminCmd("sm_team4"ClientToTeam4ADMFLAG_ROOT"Switch to Team 4.");
    
RegAdminCmd("sm_team3"ClientToTeam3ADMFLAG_ROOT"Switch to Team 3.");
    
RegAdminCmd("sm_team2"ClientToTeam2ADMFLAG_ROOT"Switch to Team 2.");
}

public 
Action ClientToTeam4(int clientint args)
{
    
ChangeClientTeam(client4);
    return 
Plugin_Handled;
}

public 
Action ClientToTeam2(int clientint args)
{
    
SwitchTeam(client1);
    return 
Plugin_Handled;
}

public 
Action ClientToTeam3(int clientint args)
{
    
SwitchTeam(client2);
    return 
Plugin_Handled;
}

stock void SwitchTeam(int clientint team)
{    
    
Cvar_TeamSwitches.SetInt(9999);
    switch(
team)
    {
        case 
1ClientCommand(client"jointeam 2");
        case 
2ClientCommand(client"jointeam 3");
    }
    
Cvar_TeamSwitches.SetInt(1);

__________________
Spirit_12 is offline
Xanaguy
Senior Member
Join Date: Jan 2017
Old 10-07-2018 , 22:37   Re: [L4D2] Play on Team 4
Reply With Quote #12

Quote:
Originally Posted by Spirit_12 View Post
I was looking at the source code and found a couple of redundant things.

I'm still not sure what kind of error you got when you say client returns 0. Can you elaborate on that and maybe I can chime in?
When the team swapping commands are used in a singleplayer game, (Such as !team2 or !team3), I would get a Client Index 0 Is invalid error at "ClientCommand(client, "jointeam 3");" or "ClientCommand(client, "jointeam 2");"

So let's say I start a versus game offline, using your optimizations, swapping teams the first time works perfectly (From team 2 to team 3). But when trying to swap back, I get this:


] sm_team2
L 10/07/2018 - 21:47:52: [SM] Exception reported: Client index 0 is invalid
L 10/07/2018 - 21:47:52: [SM] Blaming: l4d2_team4.smx
L 10/07/2018 - 21:47:52: [SM] Call stack trace:
L 10/07/2018 - 21:47:52: [SM] [0] ClientCommand
L 10/07/2018 - 21:47:52: [SM] [1] Line 52, C:\Users\Xanag\Downloads\l4d2_team4.sp::Switc hTeam
L 10/07/2018 - 21:47:52: [SM] [2] Line 37, C:\Users\Xanag\Downloads\l4d2_team4.sp::Clien tToTeam2

Last edited by Xanaguy; 10-07-2018 at 22:50.
Xanaguy is offline
Spirit_12
Veteran Member
Join Date: Dec 2012
Location: Toronto, CA
Old 10-07-2018 , 23:59   Re: [L4D2] Play on Team 4
Reply With Quote #13

Joining team 3 means infected and 2 means survivor. My guess would be that you need to use SDK method for this. I’m assuming error only happens when you are changing to survivor team ?
__________________
Spirit_12 is offline
Xanaguy
Senior Member
Join Date: Jan 2017
Old 10-08-2018 , 00:15   Re: [L4D2] Play on Team 4
Reply With Quote #14

Yes on the first statement. But it happens regardless of the team (except team 4). Even swapping from team 4, I would then get this error when I try either of the other two commands (the team 4 command works fine no matter what).

Last edited by Xanaguy; 10-08-2018 at 00:24.
Xanaguy is offline
Spirit_12
Veteran Member
Join Date: Dec 2012
Location: Toronto, CA
Old 10-08-2018 , 03:11   Re: [L4D2] Play on Team 4
Reply With Quote #15

In short it doesn’t matter what team you switch from. Error happens when you try to change team to survivor ( jointeam 2 ) ? If that is true then you need to use SDK method.
__________________
Spirit_12 is offline
Xanaguy
Senior Member
Join Date: Jan 2017
Old 10-08-2018 , 04:08   Re: [L4D2] Play on Team 4
Reply With Quote #16

Error happens with jointeam 2 and jointeam 3. I'll have to employ SDK. Which will require signatures if I'm not mistaken. That's beyond me for the moment. So I'll just hook in an emergency spectating command for those in team 4.

Last edited by Xanaguy; 10-08-2018 at 04:16.
Xanaguy is offline
Spirit_12
Veteran Member
Join Date: Dec 2012
Location: Toronto, CA
Old 10-08-2018 , 18:46   Re: [L4D2] Play on Team 4
Reply With Quote #17

Quote:
Originally Posted by Xanaguy View Post
Error happens with jointeam 2 and jointeam 3. I'll have to employ SDK. Which will require signatures if I'm not mistaken. That's beyond me for the moment. So I'll just hook in an emergency spectating command for those in team 4.
You shouldn't be having issues when switching to infected. Switching to infected does not require SDK method, only to take over a bot.

I might have a solution to your problem. Based on your replies I think you are using this on listen server and not dedicated. Try FakeClientCommand instead of ClientCommand.

PHP Code:
#include <sourcemod>

#pragma semicolon 1
#pragma newdecls required

#define PLUGIN_VERSION "1.0"

ConVar Cvar_TeamSwitches;

public 
Plugin myinfo =
{
    
name "[L4D2] Play as Team 4",
    
author "Xanaguy/MasterMe",
    
description "Play on the hidden Team 4!",
    
version PLUGIN_VERSION,
    
url "https://forums.alliedmods.net/showthread.php?t=311185"
};

public 
void OnPluginStart()
{
    
CreateConVar("team4version"PLUGIN_VERSION"\"Play as Team 4\" plugin version"FCVAR_NOTIFY|FCVAR_DONTRECORD);
    
Cvar_TeamSwitches    =    FindConVar("vs_max_team_switches");
    
    
RegAdminCmd("sm_team4"ClientToTeam4ADMFLAG_ROOT"Switch to Team 4.");
    
RegAdminCmd("sm_team3"ClientToTeam3ADMFLAG_ROOT"Switch to Team 3.");
    
RegAdminCmd("sm_team2"ClientToTeam2ADMFLAG_ROOT"Switch to Team 2.");
}

public 
Action ClientToTeam4(int clientint args)
{
    
ChangeClientTeam(client4);
    return 
Plugin_Handled;
}

public 
Action ClientToTeam2(int clientint args)
{
    
SwitchTeam(client1);
    return 
Plugin_Handled;
}

public 
Action ClientToTeam3(int clientint args)
{
    
SwitchTeam(client2);
    return 
Plugin_Handled;
}

stock void SwitchTeam(int clientint team)
{    
    
Cvar_TeamSwitches.SetInt(9999);
    switch(
team)
    {
        case 
1FakeClientCommand(client"jointeam 2");
        case 
2FakeClientCommand(client"jointeam 3");
    }
    
Cvar_TeamSwitches.SetInt(1);

__________________
Spirit_12 is offline
Xanaguy
Senior Member
Join Date: Jan 2017
Old 10-08-2018 , 18:59   Re: [L4D2] Play on Team 4
Reply With Quote #18

Odd... When I tried using FakeClientCommand last time, it resulted in the same error. Or maybe I was using the wrong variant. It works fine now. Thanks!

No update: Since players can now join Team 4, I am willing to convert any reasonable plugin to support Team 4, meaning any plugin that supports Team 2, but don't support Team 4 should suffice. Just contact me. (Exceptions apply)

Description: Added two additional notes of interest.

Last edited by Xanaguy; 10-10-2018 at 02:48.
Xanaguy is offline
Shadowysn
Senior Member
Join Date: Sep 2015
Location: Location:
Old 07-08-2022 , 04:49   Re: [L4D2] Play on Team 4
Reply With Quote #19

I made InputKill Kick Prevention apply for players on Team 4.
Tested and working, this should stop the kill-kicking from occurring even in other maps using the Kill input as well.
__________________
ragdoll spam, that is all

Steam profile, where I game, obviously.
Youtube channel, where I do Stick Death Maze animations and some other stuff.
no plugin requests, sorry


My Plugins:
-search list-
Modified Plugins:
1 | 2 | 3 | 4
Shadowysn 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:01.


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