Raised This Month: $ Target: $400
 0% 

[TF2] Can't kick bots!


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
cidra
Junior Member
Join Date: Jun 2016
Location: Italy
Old 06-25-2016 , 13:35   [TF2] Can't kick bots!
Reply With Quote #1

Hi! I'm making a plugin that manages the bots on a server in highlander mode.


First of all i created a new array. 1 index = 1 class
Code:
new Players[18]

Then set that every time a player spawn its client id associates to an index
public Event_PlayerSpawn(Handle:event,const String:name[],bool:dontBroadcast)
Code:
{
		new client = GetClientOfUserId(GetEventInt(event, "userid"))
		new TFTeam:team = TFTeam:GetEventInt(event,"team");
		new TFClassType:class = TF2_GetPlayerClass(client);
		
		if (class == 1 && team == 3)		
			{
			Players[0] = client
			}
		else if (class == 1 && team == 2)		
			{
			Players[1] = client
			}
			else if (class == 3 && team == 3)	
			{
			Players[2] = client
			}
			else if (class == 3 && team == 2)
			{
			Players[3] = client
			}
			else if (class == 7 && team == 3)	
			{
			Players[4] = client
			}
			else if (class == 7 && team == 2)	
			{
			Players[5] = client
			}
			else if (class == 4 && team == 3)	
			{
			Players[6] = client
			}
			else if (class == 4 && team == 2)	
			{
			Players[7] = client
			}
			else if (class == 6 && team == 3)	
			{
			Players[8] = client
			}
			else if (class == 6 && team == 2)	
			{
			Players[9] = client
			}
			else if (class == 9 && team == 3)	
			{
			Players[10] = client
			}
			else if (class == 9 && team == 2)	
			{
			Players[11] = client
			}
			else if (class == 5 && team == 3)	
			{
			Players[12] = client
			}
			else if (class == 5 && team == 2)	
			{
			Players[13] = client
			}
			else if (class == 2 && team == 3)	
			{
			Players[14] = client
			}
			else if (class == 2 && team == 2)	
			{
			Players[15] = client
			}
			else if (class == 8 && team == 3)	
			{
			Players[16] = client
			}
			else if (class == 8 && team == 2)	
			{
			Players[17] = client
			}
			}
This way i can recognize and kicks bots by only knowing its class
Players[0] is Blu Scout, 1 is Red Scout, 2 is Blu Soldier, 3 is Red Soldier, 4 is Blu Pyro, etc...
(Maybe there is a way a lot easier to do this. But it's my first plugin, i just started 1.5 weeks ago )

Now i want that to kick a bot (so only if it is a fake client, else do nothing) through a command in chat / on a menu. I tried a lot of ways but the game does not kick the specified bot.
One of the way i tried is:

*example for the soldier*
Code:
public SoldierMenuHandler(Handle:menu, MenuAction:action, client, param2) 
{
    if (action == MenuAction_Cancel && param2 == MenuCancel_ExitBack) 
    {
        Menu_Test1(client);
    }
    else if (action == MenuAction_End)
    {
        CloseHandle(menu);
    }
	else if (action == MenuAction_Select)
	{
	char info[32];
	GetMenuItem(menu, param2, info, sizeof(info));
	if (StrEqual(info, "1") && !IsFakeClient (Players[2])) //if i select "Blu Team" and the client on index 2 is not a bot
		{
		PrintToChat(client,"Slot is not a bot."); 
		}
	else if (StrEqual(info,"1") && IsFakeClient(Players[2]))
		{
		KickClient (Players[2]);
                }
       }
}
(Obviously, when a client disconnects the plugin will remove that client number from the array. But i still haven't added it. I'm trying this plugin when the match starts and all the player are in-game without anyone disconnecting.)

But i don't see any message in the console. I just see the bot disappear without any notice.
Also, does not get kicked the bot i want everytime. What's wrong?
cidra is offline
Benoist3012
Veteran Member
Join Date: Mar 2014
Location: CWave::ForceFinish()
Old 06-26-2016 , 04:32   Re: [TF2] Can't kick bots!
Reply With Quote #2

Since it's your first plugin, I recommand you to start with the new sourcemod syntax, not the old one, because some new functions from sourcemod are only available in the new sourcemod syntax 1.7+ (https://wiki.alliedmods.net/SourcePa...itional_Syntax)
If I remember correctly, if you wanna kick a bot you have to decrease the bot quota by 1.

Code:
Handle g_hBotQuota; public void OnPluginStart() { g_hBotQuota = FindConVar("tf_bot_quota"); } public void RandomFunction() { int iBotCount = GetConVarInt(g_hBotQuota);//Get the current bot count. iBotCount--;//Decrease it by 1 (--) SetConVarInt(g_hBotQuota,iBotCount);//Set the new bot count. //Kick the bot. }

Also I don't know if you are going to use your array somewhere else. But if you do, you should make it like that:
Code:
#define TF_MAX_CLASS 9 #define MAX_TEAMS 4 int g_iPlayer[MAX_TEAMS][TF_MAX_CLASS+1];

so in your function you just have to do this:
Code:
int team = 3;//Blue team if(IsFakeClient(g_iPlayer[team][view_as<int>(TFClass_Scout)])) //do stuff here;
The enum of class can be found here: https://sm.alliedmods.net/new-api/tf2/TFClassType

Final note: it's fine to use an array if you are looking for bot's class often in the code, otherwise it's a waste of memory. You are also assuming with this array that the class limit is 1 for both team, that you can't have 2 blue bots scouts.
__________________

Last edited by Benoist3012; 06-26-2016 at 04:35.
Benoist3012 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 21:35.


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