AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting (https://forums.alliedmods.net/forumdisplay.php?f=107)
-   -   Chat Hook, What's Wrong? (https://forums.alliedmods.net/showthread.php?t=143678)

badwolf 11-22-2010 23:44

Chat Hook, What's Wrong?
 
Considering the use of valid steam ids. This code doesn't even print a chat message back when someone says something. Any idea what's wrong with it?

Code:

#include <sourcemod>
#include <sdktools_functions>
 
public Plugin:myinfo =
{
        name = "meh",
        author = "meh",
        description = "meh",
        version = "1.0.0.0",
        url = "http://www.sourcemod.net/"
};
 
public OnPluginStart()
{
        HookEvent("player_say", Event_PlayerSay);
}

public Action:Event_PlayerSay(Handle:event, const String:name[], bool:dontBroadcast)
{
        new client = GetClientOfUserId(GetEventInt(event, "userid"));
       
        new String:text[200];
        GetEventString(event, "text", text, 200);
       
        decl String:player_authid[32];
        GetClientAuthString(client, player_authid, sizeof(player_authid));

        PrintToChatAll("[SM] %s", text);
        PrintToChatAll("[SM] %s", player_authid);
       
        //if (StrContains(player_authid, "1111111", false))
        if (StrContains(player_authid, "2222222", false))
        {               
                if (StrContains(text, "fish kill", false))
                {
                        ForcePlayerSuicide(client);
                }
                if (StrContains(text, "not even winded", false))
                {
                        ForcePlayerSuicide(client);
                }
                if (StrContains(text, "lag", false))
                {
                        ForcePlayerSuicide(client);
                }
        }
}


AltPluzF4 11-23-2010 00:29

Re: Chat Hook, What's Wrong?
 
http://wiki.alliedmods.net/Format_Cl...mat_Specifiers

You're using %t (which is for translated files.) While I believe you should be using %s.

I'm sure if you check the server, each time player_say is fired you'd get an error such as:
Code:

L 11/23/2010 - 00:21:22: [SM] Plugin encountered error 4: Invalid parameter or parameter type
L 11/23/2010 - 00:21:22: [SM] Native "VFormat" reported: Language phrase "text" not found
L 11/23/2010 - 00:21:22: [SM] Displaying call stack trace for plugin "plugin.smx":
L 11/23/2010 - 00:21:22: [SM]  [0]  Line 283, <path to SRCDS>\orangebox\tf\addons\sourcemod\scripting\include\halflife.inc::PrintToChatAll()
L 11/23/2010 - 00:21:22: [SM]  [1]  Line 28, plugin.sp::Event_PlayerSay()

I hope this information helps you. If not, let me know and I'll try to further assist you.

badwolf 11-23-2010 00:32

Re: Chat Hook, What's Wrong?
 
The code after that point doesn't work either... I'll try the %s and get back to you.

Edit:

%s isn't working either.. and it doesn't give any error logs.

AltPluzF4 11-23-2010 00:38

Re: Chat Hook, What's Wrong?
 
Quote:

Originally Posted by badwolf (Post 1354908)
The code after that point doesn't work either... I'll try the %s and get back to you.

To the best of my knowledge, once an error is encountered, the rest of the function does not execute.

So, something like:
PHP Code:

TestFunc()
{
    
PrintToServer("one");
    
PrintToServer(two);
    
PrintToServer("three");


It would print "one", then error because there's no variable two, and the function would abort. So it wouldn't display "three".

[edit]
Sorry, didn't notice you edited your post.
Can you please update your original post with the exact code you're using (with %s) so I can see what may be wrong?
Thanks.
[/edit]

badwolf 11-23-2010 01:00

Re: Chat Hook, What's Wrong?
 
The original code has been modified with the %s instead of %t. Any idea what's wrong with it now? It still doesn't print any messages.

AltPluzF4 11-23-2010 01:05

Re: Chat Hook, What's Wrong?
 
Are you actually in the server when you test this?

PrintToChatAll is defined as this:
PHP Code:

stock PrintToChatAll(const String:format[], any:...)
{
    
decl String:buffer[192];
    
    for (new 
1<= MaxClientsi++)
    {
        if (
IsClientInGame(i))
        {
            
SetGlobalTransTarget(i);
            
VFormat(buffersizeof(buffer), format2);
            
PrintToChat(i"%s"buffer);
        }
    }


So, if you're just at the server, it won't actually do anything unless there's someone in-game.

For testing purposes, can you temporarily replace PrintToChatAll with LogMessage? This will let you know if the code is even being reached.

[edit]
Oh, sorry. I'm going to sleep, and I just realized, you're not checking the client index either. So if client is 0 (using say from server), it will error on GetClientAuthString, since it requires a client index between 1 and MaxClients.
Here's a little snippet:
PHP Code:


#pragma semicolon 1

#include <sourcemod>

public OnPluginStart()
{
    
HookEvent("player_say"evPlayerSay);
}

public 
Action:evPlayerSay(Handle:hEvent, const String:szName[], bool:bDontBroadcast)
{
    new 
client GetClientOfUserId(GetEventInt(hEvent"userid"));
    
    if (
client 1)
        return 
Plugin_Continue;
    
    
decl String:szAuth[32];
    
GetClientAuthString(clientszAuthsizeof(szAuth));

    
decl String:szText[256];
    
GetEventString(hEvent"text"szTextsizeof(szText));
    
    
PrintToServer("[Say] %s : %s"szAuthszText);
    
    return 
Plugin_Continue;


Hope that helps.
[/edit]

CrimsonGT 11-23-2010 03:38

Re: Chat Hook, What's Wrong?
 
The more common approach (I am not sure if the game events even actually get called by the game) is to just do RegConsoleCmd("say", Command_PlayerChat); then use that as the callback function.

badwolf 11-23-2010 09:57

Re: Chat Hook, What's Wrong?
 
Yes, I've been in the game for all testing.. on a team.. on the blu team... as a scout...

I have also tried LogMessage, it's what I originally started with, and it didn't work either. I also tried LogToFile, and it didn't work either.

I also tried the RegConsoleCmd for both say and say_team and they didn't work either.

This code that you placed above:

Code:

#pragma semicolon 1

#include <sourcemod>

public OnPluginStart()
{
    HookEvent("player_say", evPlayerSay);
}

public Action:evPlayerSay(Handle:hEvent, const String:szName[], bool:bDontBroadcast)
{
    new client = GetClientOfUserId(GetEventInt(hEvent, "userid"));
   
    if (client < 1)
        return Plugin_Continue;
   
    decl String:szAuth[32];
    GetClientAuthString(client, szAuth, sizeof(szAuth));

    decl String:szText[256];
    GetEventString(hEvent, "text", szText, sizeof(szText));
   
    PrintToServer("[Say] %s : %s", szAuth, szText);
   
    return Plugin_Continue;
}

...it doesn't even work, unmodified... just compiled and loaded in as a plugin. And no... there's no error logs or anything of that nature...

FaTony 11-23-2010 10:15

Re: Chat Hook, What's Wrong?
 
PHP Code:

public OnPluginStart()
{
   
AddCommandListener(Command_Say"say");
}

public 
Action:Command_Say(client, const String:command[], argc)
{
   
decl String:argstring[256];
   
GetCmdArgString(argstring256);
   
PrintToServer("%N : %s"clientargstring);
   
PrintToChatAll("%N : %s"clientargstring);
   return 
Plugin_Continue;



badwolf 11-23-2010 10:51

Re: Chat Hook, What's Wrong?
 
Quote:

Originally Posted by FaTony (Post 1355114)
PHP Code:

public OnPluginStart()
{
   
AddCommandListener(Command_Say"say");
}

public 
Action:Command_Say(client, const String:command[], argc)
{
   
decl String:argstring[256];
   
GetCmdArgString(argstring256);
   
PrintToServer("%N : %s"clientargstring);
   
PrintToChatAll("%N : %s"clientargstring);
   return 
Plugin_Continue;



OK... Now, this works... Thank you!


All times are GMT -4. The time now is 00:06.

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