AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting (https://forums.alliedmods.net/forumdisplay.php?f=107)
-   -   [TF2] Search player with determinied class doesn't work..? (https://forums.alliedmods.net/showthread.php?t=284813)

cidra 07-04-2016 18:03

[TF2] Search player with determinied class doesn't work..?
 
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?

asherkin 07-05-2016 02:57

Re: [TF2] Search player with determinied class doesn't work..?
 
Your IsBotIn function is throwing an error, read your error logs.

Potato Uno 07-05-2016 08:40

Re: [TF2] Search player with determinied class doesn't work..?
 
Try changing this

PHP Code:

    for (0<= MAXPLAYERS i++) 

to this?

PHP Code:

    for (1<= MaxClients i++) 


luki1412 07-05-2016 08:51

Re: [TF2] Search player with determinied class doesn't work..?
 
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

cidra 07-05-2016 09:34

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

Originally Posted by asherkin (Post 2433627)
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 (Post 2433711)
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)

Potato Uno 07-05-2016 14:09

Re: [TF2] Search player with determinied class doesn't work..?
 
Asherkin meant server error logs, not compiler error logs.

Look inside addons/sourcemod/logs for them.

cidra 07-05-2016 16:33

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

Originally Posted by Potato Uno (Post 2433827)
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?)

luki1412 07-05-2016 16:43

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

Originally Posted by cidra (Post 2433898)
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;
}


Powerlord 07-05-2016 18:45

Re: [TF2] Search player with determinied class doesn't work..?
 
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.


All times are GMT -4. The time now is 21:34.

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