Raised This Month: $ Target: $400
 0% 

[TF2] Search player with determinied class doesn't work..?


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
cidra
Junior Member
Join Date: Jun 2016
Location: Italy
Old 07-04-2016 , 18:03   [TF2] Search player with determinied class doesn't work..?
Reply With Quote #1

Hi. I'm trying to make a plugin that checks if a specified class is a bot or not while on the class menu.
At the begin i looked this plugin and got some ideas from it.

This is the code:
Code:
#include <sourcemod>
#include <tf2_stocks>

public OnPluginStart()
{
	HookEvent ("player_changeclass", Event_ChangeClass);
}

public Event_ChangeClass(Handle:event, const String:name[], bool:dontBroadcast)
{
	new iClient = GetClientOfUserId (GetEventInt (event, "userid")),
		iClass = GetEventInt (event, "class"),
		iTeam = GetClientTeam (iClient);
		
	PrintToChatAll("Test123 %d",iClass);	
	if (IsBotIn(iTeam, iClass))
		{
		PrintToChatAll("BOT SI.");
		}
	else
		{
		PrintToChatAll("BOT NO.");
		}
}
	
bool:IsBotIn(iTeam, iClass)
{
	int i;
	for (i = 0; i <= MAXPLAYERS ; i++)
	if(TF2_GetPlayerClass(i) == iClass && GetClientTeam(i) == iTeam)
		{
		if (IsFakeClient(i))
			{
			return true;
			}
		else if (!IsFakeClient(i))
			{
			return false;
			}
		break;
		}
return false;
}
The problem is that "BOT SI" and "BOT NO" never get printed. What is the problem? I just want to do a specified command if there's a bot using the class chosen on the class menu and another command if there's not. What's wrong?
cidra is offline
asherkin
SourceMod Developer
Join Date: Aug 2009
Location: OnGameFrame()
Old 07-05-2016 , 02:57   Re: [TF2] Search player with determinied class doesn't work..?
Reply With Quote #2

Your IsBotIn function is throwing an error, read your error logs.
__________________
asherkin is offline
Potato Uno
Veteran Member
Join Date: Jan 2014
Location: Atlanta, Georgia
Old 07-05-2016 , 08:40   Re: [TF2] Search player with determinied class doesn't work..?
Reply With Quote #3

Try changing this

PHP Code:
    for (0<= MAXPLAYERS i++) 
to this?

PHP Code:
    for (1<= MaxClients i++) 
Potato Uno is offline
luki1412
Veteran Member
Join Date: Oct 2008
Location: OnPluginStart()
Old 07-05-2016 , 08:51   Re: [TF2] Search player with determinied class doesn't work..?
Reply With Quote #4

You are using the post event hook, so the class change already happened. Not sure what exactly are you trying to do here. Are you trying to ignore bots when limiting classes for real players?

My plugins for limiting bots/humans might be able to help you - https://forums.alliedmods.net/showthread.php?t=229369
__________________
luki1412 is offline
cidra
Junior Member
Join Date: Jun 2016
Location: Italy
Old 07-05-2016 , 09:34   Re: [TF2] Search player with determinied class doesn't work..?
Reply With Quote #5

Quote:
Originally Posted by asherkin View Post
Your IsBotIn function is throwing an error, read your error logs.
There were two warnings: tag mismatch at line 32 and loose indentation at last "return false;" (line 42)
I resolved the tag mismatch warning by changing the line to this:
Code:
if(_:TF2_GetPlayerClass(i) == iClass && GetClientTeam(i) == iTeam)
I also added brackets after the for cycle.

The loose identation warning is still unsolved, could it be the problem?

Quote:
Originally Posted by luki1412 View Post
You are using the post event hook, so the class change already happened. Not sure what exactly are you trying to do here. Are you trying to ignore bots when limiting classes for real players?

My plugins for limiting bots/humans might be able to help you - https://forums.alliedmods.net/showthread.php?t=229369
Haven't made yet the other code. For now the plugin does this:
1. Client opens classmenu (,) and chooses a class
2. If the chosen class is already played by someone else do action: if that player is a bot then go to step 3a, else go to step 3b
3a. print to chat ("BOT SI")
3b. print to chat ("BOT NO")

The problem is that the plugin does not print neither BOT SI nor BOT NO.
Why?

Also, i knew sourcemod can't pre-hook game events... :S



This is the modified code:
Code:
#include <sourcemod>
#include <tf2_stocks>

public OnPluginStart()
{
	HookEvent ("player_changeclass", Event_ChangeClass);
}

public Event_ChangeClass(Handle:event, const String:name[], bool:dontBroadcast)
{
	new iClient = GetClientOfUserId (GetEventInt (event, "userid")),
		iClass = GetEventInt (event, "class"),
		iTeam = GetClientTeam (iClient);
		
	PrintToChatAll("Test123 %d",iClass);	
	if (IsBotIn(iTeam, iClass))
		{
		PrintToChatAll("BOT SI.");
		}
	else
		{
		PrintToChatAll("BOT NO.");
		}
}
	
bool:IsBotIn(iTeam, iClass)
{
	int i;
	for (i = 0; i <= MaxClients ; i++)
	{
	if(_:TF2_GetPlayerClass(i) == iClass && GetClientTeam(i) == iTeam)
		{
		if (IsFakeClient(i))
			{
			return true;
			}
		else if (!IsFakeClient(i))
			{
			return false;
			}
		}
	}
return false;
}
EDIT: Forgot to say that this plugin is meant to be used in highlander mode. This way bots will only fill empty slots during the match. If a real user chooses a class, and that slot is being played by a bot, the plugin will automatically kick it. Else, if a real client is playing that class, there will be a message in chat ("Slot is taken").

However, i won't enable highlander mode on the server, because people will not be able to choose class since all the bots are filling the slots.
This is the reason why during the for cycle there won't be the problem that it will find more than 1 user with a specified class and team. (Except the client, because this is a post hook event... I should add a filter for that)

Last edited by cidra; 07-05-2016 at 10:16.
cidra is offline
Potato Uno
Veteran Member
Join Date: Jan 2014
Location: Atlanta, Georgia
Old 07-05-2016 , 14:09   Re: [TF2] Search player with determinied class doesn't work..?
Reply With Quote #6

Asherkin meant server error logs, not compiler error logs.

Look inside addons/sourcemod/logs for them.
Potato Uno is offline
cidra
Junior Member
Join Date: Jun 2016
Location: Italy
Old 07-05-2016 , 16:33   Re: [TF2] Search player with determinied class doesn't work..?
Reply With Quote #7

Quote:
Originally Posted by Potato Uno View Post
Asherkin meant server error logs, not compiler error logs.

Look inside addons/sourcemod/logs for them.
Here is the log from the last game:

Code:
L 07/05/2016 - 21:05:36: [SM] Native "GetEntProp" reported: Property "m_iClass" not found (entity 0/worldspawn)
L 07/05/2016 - 21:05:36: [SM] Displaying call stack trace for plugin "HIGHLANDER PUB PROJECT.smx":
L 07/05/2016 - 21:05:36: [SM]   [0]  Line 372, C:\Program Files (x86)\Steam\SteamApps\common\Team Fortress 2\tf\addons\sourcemod\scripting\include\tf2_stocks.inc::TF2_GetPlayerClass()
L 07/05/2016 - 21:05:36: [SM]   [1]  Line 31, C:\Program Files (x86)\Steam\SteamApps\common\Team Fortress 2\tf\addons\sourcemod\scripting\HIGHLANDER PUB PROJECT.sp::IsBotIn()
L 07/05/2016 - 21:05:36: [SM]   [2]  Line 16, C:\Program Files (x86)\Steam\SteamApps\common\Team Fortress 2\tf\addons\sourcemod\scripting\HIGHLANDER PUB PROJECT.sp::Event_ChangeClass()
I just can't figure out which is the problem in these lines. Is maybe a tag problem? (Is TFClassType an int value?)

Last edited by cidra; 07-05-2016 at 16:34.
cidra is offline
luki1412
Veteran Member
Join Date: Oct 2008
Location: OnPluginStart()
Old 07-05-2016 , 16:43   Re: [TF2] Search player with determinied class doesn't work..?
Reply With Quote #8

Quote:
Originally Posted by cidra View Post
Here is the log from the last game:

Code:
L 07/05/2016 - 21:05:36: [SM] Native "GetEntProp" reported: Property "m_iClass" not found (entity 0/worldspawn)
L 07/05/2016 - 21:05:36: [SM] Displaying call stack trace for plugin "HIGHLANDER PUB PROJECT.smx":
L 07/05/2016 - 21:05:36: [SM]   [0]  Line 372, C:\Program Files (x86)\Steam\SteamApps\common\Team Fortress 2\tf\addons\sourcemod\scripting\include\tf2_stocks.inc::TF2_GetPlayerClass()
L 07/05/2016 - 21:05:36: [SM]   [1]  Line 31, C:\Program Files (x86)\Steam\SteamApps\common\Team Fortress 2\tf\addons\sourcemod\scripting\HIGHLANDER PUB PROJECT.sp::IsBotIn()
L 07/05/2016 - 21:05:36: [SM]   [2]  Line 16, C:\Program Files (x86)\Steam\SteamApps\common\Team Fortress 2\tf\addons\sourcemod\scripting\HIGHLANDER PUB PROJECT.sp::Event_ChangeClass()
I just can't figure out which is the problem in these lines. Is maybe a tag problem? (Is TFClassType an int value?)
Use this:
Code:
bool:IsBotIn(iTeam, iClass)
{
	for (new i = 1; i <= MaxClients ; i++)
	{
	if(IsClientConnected(i) && IsClientInGame(i) && _:TF2_GetPlayerClass(i) == iClass && GetClientTeam(i) == iTeam)
		{
		if (IsFakeClient(i))
			{
			return true;
			}
		else if (!IsFakeClient(i))
			{
			return false;
			}
		}
	}
return false;
}
__________________
luki1412 is offline
Powerlord
AlliedModders Donor
Join Date: Jun 2008
Location: Seduce Me!
Old 07-05-2016 , 18:45   Re: [TF2] Search player with determinied class doesn't work..?
Reply With Quote #9

If it wasn't obvious from what everyone was saying, you were looping from 0 to MaxClients, but 0 isn't a valid client index.
__________________
Not currently working on SourceMod plugin development.
Powerlord 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:34.


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